diff --git a/java/JavaDecoder.java b/java/JavaDecoder.java new file mode 100644 index 0000000..ea49000 --- /dev/null +++ b/java/JavaDecoder.java @@ -0,0 +1,401 @@ +/* JOrbisCodec -- JMF codec for the JOrbis project. + * + * Copyright (C) 2001 Solomon Peachy + * + * JOrbisCodec depends on JOrbis. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +package com.jcraft.media.codec.audio.vorbis; + +import java.io.*; +import java.util.Vector; + +import javax.media.*; +import javax.media.format.*; +import javax.media.bean.playerbean.MediaPlayer; + +import com.jcraft.jorbis.*; +import com.jcraft.jogg.*; + +public class JavaDecoder implements Codec { + + public static final String ENCODING_VORBIS = "oggvorbis"; + + public static final int START = 0; + public static final int OK = 1; + public static final int FAILED = -1; + public static final int NEEDMORE = 2; + public static final int FINISHED = 3; + private int state = 0; + + SyncState oy; + StreamState os; + Page og; + Packet op; + Info vi; + Comment vc; + DspState vd; + Block vb; + double[][][] _pcm; + float[][][] _pcmf; + int[] _index; + + byte[] buffer=null; + int bytes=0; + + InputStream bitStream = null; + + // plugIn stuff + + public JavaDecoder() { + // + } + + public void open() + throws ResourceUnavailableException + { + oy=new SyncState(); + os=new StreamState(); + og=new Page(); + op=new Packet(); + + vi=new Info(); + vc=new Comment(); + vd=new DspState(); + vb=new Block(vd); + + buffer=null; + bytes=0; + + oy.init(); + state = START; + } + + public void close() + { + os.clear(); + vb.clear(); + vd.clear(); + vi.clear(); + oy.clear(); + + state = FINISHED; + } + + public void reset() + { + try { + close(); + open(); + } catch (ResourceUnavailableException e) { + // ignore + } + } + + public String getName() + { + return "JOrbis JMF codec"; + } + + // Control stuff + public Object[] getControls() + { + return new Object[0]; + } + + public Object getControl(java.lang.String controlType) + { + return null; + } + + // Codec stuff. + protected Format inFormat; + protected Format outFormat; + + public Format setInputFormat(Format format) { + inFormat = format; + return format; + } + + public Format setOutputFormat(Format format) { + outFormat = format; + return format; + } + + public Format[] getSupportedInputFormats() { + Format[] fs = new Format[1]; + + fs[0] = new AudioFormat(ENCODING_VORBIS, 44100.0, 16, 2); + + return fs; + } + + public Format[] getSupportedOutputFormats(Format f) { + Format[] fs = new Format[1]; + + fs[0] = new AudioFormat(AudioFormat.LINEAR, 44100.0, 16, 2); + + return fs; + } + + public int process(javax.media.Buffer input, javax.media.Buffer output) + { + Object inObject = input.getData(); + Object outObject = output.getData(); + + if (outObject == null) { + outObject = new byte[0]; + output.setData(outObject); + } + + if (!(inObject instanceof byte[]) || + !(outObject instanceof byte[])) + return PlugIn.BUFFER_PROCESSED_FAILED; + + byte[] inData = (byte[]) inObject; + + bitStream = new SequenceInputStream(bitStream, new ByteArrayInputStream(inData)); + + byte[] outData = (byte[]) outObject; + + if (state == FINISHED) { + return PlugIn.PLUGIN_TERMINATED; // XXX need to check exit conditions. + } + + if (state == START) { + int retval = FAILED; + try { + retval = init_feed(); + } catch (IOException e) { + return PlugIn.BUFFER_PROCESSED_FAILED; + } + + if (retval != OK) + return PlugIn.BUFFER_PROCESSED_FAILED; + + state = 1; + output.setFormat(outFormat); // assert? + } + + if (state == OK) { // normal running. + try { + outData = decode_main(); + } catch (IOException e) { + throw new IllegalStateException("gak.."); + } + + if (outData == null) + return PlugIn.PLUGIN_TERMINATED; + + output.setData(outData); + + return BUFFER_PROCESSED_OK; + } + + /* + BUFFER_PROCESSED_FAILED + BUFFER_PROCESSED_OK + INPUT_BUFFER_NOT_CONSUMED -- never. + OUTPUT_BUFFER_NOT_FILLED -- possible. + PLUGIN_TERMINATED -- on failure, we die. + */ + return PlugIn.BUFFER_PROCESSED_FAILED; + } + + static final int BUFSIZE=4096*2; + + + public int init_feed() + throws IOException + { + int index=oy.buffer(BUFSIZE); + buffer=oy.data; + bytes=bitStream.read(buffer, index, BUFSIZE); + oy.wrote(bytes); + if (oy.pageout(og) != 1) { + if (bytes < BUFSIZE) + throw new EOFException("not enough data"); // XXXX + else + throw new IllegalArgumentException("Not Ogg bitstream"); + } + os.init(og.serialno()); + os.reset(); + vi.init(); + vc.init(); + + if(os.pagein(og) < 0) + return FAILED; + if(os.packetout(op) != 1) + return FAILED; + + if(vi.synthesis_headerin(vc, op) < 0) + return FAILED; + + // XXXX need to work this out. + + /* +AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, (float) vi.rate, 16, vi.channels, outFormat.getFrameSize(), AudioSystem.NOT_SPECIFIED, false); + if (!outFormat.matches(format)) { + System.err.println(format); + System.err.println(outFormat); + throw new IllegalArgumentException("Incompatible AudioFormat"); + } + */ + + int i = 0 ; + while(i<2){ + while(i<2){ + int result=oy.pageout(og); + if(result==0) + break; // Need more data + if(result==1){ + os.pagein(og); + while(i<2){ + result=os.packetout(op); + if(result==0) + break; + if(result==-1) + return FAILED; + } + vi.synthesis_headerin(vc, op); + i++; + } + } + index=oy.buffer(BUFSIZE); + buffer=oy.data; + bytes=bitStream.read(buffer, index, BUFSIZE); + if(bytes==0 && i<2) + return FAILED; + oy.wrote(bytes); + } + + { + byte[][] ptr=vc.user_comments; + for(int j=0; j0){ + double[][] pcm=_pcm[0]; + float[][] pcmf=_pcmf[0]; + boolean clipflag=false; + for(i=0;i32767){ + val=32767; + clipflag=true; + } + if(val<-32768){ + val=-32768; + clipflag=true; + } + if(val<0) val=val|0x8000; + bas.write((byte)val); + bas.write((byte)val>>8); + } + } + vd.synthesis_read(samples); + } + } + + int index = oy.buffer(BUFSIZE); + buffer = oy.data; + bytes = bitStream.read(buffer,index,BUFSIZE); + if (bytes == -1) + break; + if (bytes == 0) + break; + oy.wrote(bytes); + } + + return bas.toByteArray(); + } + + public static void main(String argv[]) + { + JavaDecoder x = new JavaDecoder(); + + if (PlugInManager.addPlugIn(x.getClass().getName(), x.getSupportedInputFormats(), x.getSupportedOutputFormats(null), PlugInManager.CODEC)) + System.out.println("ok on codec"); + + if (com.sun.media.MimeManager.addMimeType("ogg", "audio/vorbis")) + System.out.println("ok on mime"); + + Vector v = javax.media.PackageManager.getProtocolPrefixList(); + v.add("com.jcraft"); + javax.media.PackageManager.setProtocolPrefixList(v); + v = javax.media.PackageManager.getContentPrefixList(); + v.add("com.jcraft"); + javax.media.PackageManager.setContentPrefixList(v); + + // com.sun.media.JMFSecurityManager.DEBUG = true; + + MediaPlayer xxx = new MediaPlayer(); + xxx.setMediaLocation("/home/pizza/down/track01-128k.ogg"); + xxx.prefetch(); + String strMediaLocation = xxx.getMediaLocation(); + + if (strMediaLocation == null) + System.out.println("ok!"); + else + System.out.println("ack."); + + } + +} diff --git a/java/dnsjava-1.2.3.tar.gz b/java/dnsjava-1.2.3.tar.gz new file mode 100644 index 0000000..aaea63d Binary files /dev/null and b/java/dnsjava-1.2.3.tar.gz differ diff --git a/java/dnsjava-ixfr.diff b/java/dnsjava-ixfr.diff new file mode 100644 index 0000000..ed9ed49 --- /dev/null +++ b/java/dnsjava-ixfr.diff @@ -0,0 +1,168 @@ +diff -aur dnsjava-1.2.3/org/xbill/DNS/Zone.java dnsjava-devel/org/xbill/DNS/Zone.java +--- dnsjava-1.2.3/org/xbill/DNS/Zone.java Wed Mar 14 20:49:55 2001 ++++ dnsjava-devel/org/xbill/DNS/Zone.java Mon Feb 11 23:31:13 2002 +@@ -15,6 +15,14 @@ + + public class Zone extends NameSet { + ++ private static final int FIRSTSOA = 0; ++ private static final int SECONDSOA = 1; ++ private static final int ADD = 2; ++ private static final int DEL = 3; ++ private static final int LASTSOA = 4; ++ private static final int DONE = 5; ++ private static final int AXFR = 6; ++ + class AXFREnumeration implements Enumeration { + private Enumeration znames; + private Name currentName; +@@ -173,6 +181,11 @@ + Record rec = Record.newRecord(zone, Type.AXFR, dclass); + Message query = Message.newQuery(rec); + Message response = res.send(query); ++ ++ if (response.getHeader().getRcode() != Rcode.NOERROR) { ++ // XXX uh, oh. we fux0red up. return an error! ++ } ++ + Record [] recs = response.getSectionArray(Section.ANSWER); + for (int i = 0; i < recs.length; i++) { + if (!recs[i].getName().subdomain(origin)) { +@@ -191,6 +204,114 @@ + validate(); + } + ++ /** Perform an IXFR (if possible) to update the zone. ++ @return false if unsuccessful, true if updated. ++ non-success may be because unsupported! */ ++ public boolean updateZone(String remote, Cache cache) ++ throws IOException ++ { ++ Resolver res = new SimpleResolver(remote); ++ Record rec = Record.newRecord(origin, Type.IXFR, dclass); ++ Message query = Message.newQuery(rec); ++ query.addRecord(getSOA(), Section.AUTHORITY); ++ Message response = res.send(query); ++ ++ if (response.getHeader().getRcode() == Rcode.NOTIMPL) { ++ // IXFR not supported. try again as an AXFR. ++ rec = Record.newRecord(origin, Type.AXFR, dclass); ++ query = Message.newQuery(rec); ++ response = res.send(query); ++ } ++ ++ if (response.getHeader().getRcode() != Rcode.NOERROR) ++ return false; // uh, oh. we fux0red up. return an error! ++ ++ // XXX what about other errors? permission, etc? ++ ++ Record [] recs = response.getSectionArray(Section.ANSWER); ++ ++ // check for UDP overflow. ++ if ((response.getHeader().getFlag(Flags.TC) == true) || ++ ((recs.length == 1) && (recs[0].getType() == Type.SOA))) { ++ SOARecord r = (SOARecord) recs[0]; ++ return (r.getSerial() <= getSOA().getSerial()); ++ // if >, then it needs updating. otherwise we're okay. ++ } ++ ++ SOARecord oldSOA = getSOA(); ++ SOARecord newSOA = null; ++ ++ int state = FIRSTSOA; ++ ++ // we're getting a successful IXFR! ++ for (int i = 0; i < recs.length; i++) { ++ if (!recs[i].getName().subdomain(origin)) { ++ if (Options.check("verbose")) ++ System.err.println(recs[i].getName() + ++ "is not in zone " + origin); ++ continue; ++ } ++ ++ // now for the state machine. ++ switch(state) { ++ case FIRSTSOA: { ++ newSOA = (SOARecord) recs[i]; ++ state = SECONDSOA; ++ break; ++ } ++ case SECONDSOA: { ++ Record r = recs[i]; ++ if (! (r instanceof SOARecord)) { ++ clear(); ++ addRecord(r); ++ state = AXFR; ++ } else { ++ state = DEL; ++ deleteRecord(r); ++ } ++ } ++ case DEL: { ++ Record r = recs[i]; ++ if (r instanceof SOARecord) { ++ state = ADD; ++ addRecord(r); ++ } else { ++ deleteRecord(r); ++ } ++ } ++ case ADD: { ++ Record r = recs[i]; ++ if (r instanceof SOARecord) { ++ SOARecord x = (SOARecord) r; ++ if (x.getSerial() == newSOA.getSerial()) { ++ addRecord(r); ++ state = DONE; ++ } else { ++ state = DEL; ++ deleteRecord(r); ++ } ++ } else { ++ addRecord(r); ++ } ++ } ++ case AXFR: { ++ Record r = recs[i]; ++ addRecord(r); ++ } ++ case DONE: { ++ // XXX wtF? nothing should get here. ++ } ++ } // end switch ++ } ++ if (cache != null) { ++ recs = response.getSectionArray(Section.ADDITIONAL); ++ for (int i = 0; i < recs.length; i++) ++ cache.addRecord(recs[i], Credibility.ZONE_GLUE, recs); ++ } ++ validate(); ++ return true; ++} ++ + /** Returns the Zone's origin */ + public Name + getOrigin() { +@@ -326,6 +447,22 @@ + rrset.addRR(r); + } + ++/** ++ * Deletes a record from the Zone ++ * @param r The record to be deleted ++ * @see Record ++ */ ++public void ++deleteRecord(Record r) { ++ Name name = r.getName(); ++ short type = r.getRRsetType(); ++ RRset rrset = (RRset) findExactSet (name, type); ++ if (rrset == null) ++ return; ++ else ++ rrset.deleteRR(r); ++} ++ + public Enumeration + AXFR() { + return new AXFREnumeration();