Synchronized processors and Incompatible Time Bases

View: New views
4 Messages — Rating Filter:   Alert me  

Synchronized processors and Incompatible Time Bases

by Turner-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello all,

I'm currently trying to implement an applet that enables you to mix tracks, a la Garage Band or Acoustica MP3 Mixer (if you are familiar with those). It seems, after reading up on the JMF, that it suits my needs to a tee. After reading the documentation, it seems I need to implement processor synchronization manually (rather than use a master player/processor), because I want to be able to manipulate tracks individually (set rate, play individual tracks, etc.). So I've been wading through documentation and sample code, trying to figure out how to do this. I'm running into some trouble, though: I read in the JMF guide that you need to set each processor's time base to the same TimeBase object. However, when I try this, I get an IncompatibleTimeBaseException. I don't know why this is--all the files are simple PCM WAV files pulled over HTTP. It seems like this is the simplest situation you could ask for, and yet it's throwing up at me. Relevant code snippets follow:


public synchronized void addProcessorForLocation(MediaLocator locator) throws IOException,
                                NoProcessorException, CannotRealizeException, NoDataSourceException {
        Processor p = Manager.createProcessor(locator);
        p.configure();
        while(p.getState() != Processor.Configured) {
            try {
                Thread.sleep(100);
            }
            catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
       
        p.realize();
        while(p.getState() != Processor.Realized) {
            try {
                Thread.sleep(100);
            }
            catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
       
        addProcessor(p);
    }


public void addProcessor(Processor p) {
        p.addControllerListener(this);
        p.stop();
        p.setRate(DEFAULT_RATE);
        if(masterTimeBase == null)
            masterTimeBase = p.getTimeBase();
       
        processors.add(p);
    }

public void playAll() throws IncompatibleTimeBaseException {
       
        for(Processor p : processors) {
            p.setMediaTime(new Time(0));
            p.prefetch();
        }
       
        while(!allProcessorsPrefetched()) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ex) {
                Logger.getLogger(SynchronizedProcessor.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
       
        boolean updatedLatency = false;
        Time maxLatency = new Time(0);
       
        for(Processor p : processors) {
            Time latency = p.getStartLatency();
            System.out.println("Processor's start latency: " + latency.getNanoseconds() + " nanoseconds");
            if(!latency.equals(Processor.LATENCY_UNKNOWN) && latency.getNanoseconds() > maxLatency.getNanoseconds()) {
                maxLatency = latency;
                updatedLatency = true;
            }
            else if(latency.equals(Processor.LATENCY_UNKNOWN)) {
                System.err.println("Latency unknown");
            }
        }
       
        if(!updatedLatency)
            maxLatency = new Time(Common.DEFAULT_START_LATENCY);
       
        Time startTime = null;
       
        for(Processor p : processors) {
            p.setTimeBase(masterTimeBase);
            if(startTime == null)
                startTime = new Time(p.getTimeBase().getTime().getNanoseconds() + maxLatency.getNanoseconds());
            System.err.println("Sync starting processor " + p + " at start time " + startTime.getNanoseconds() + " nanoseconds");
            p.syncStart(startTime);
        }
    }

I get an IncompatibleTimeBaseException where I call p.setTimeBase(masterTimeBase). Any idea what's going wrong/how I can fix it?

Thanks,
Turner


=========================================================================== FAQ: http://java.sun.com/products/java-media/jmf/forDevelopers/jmffaq.html List Archive: http://archives.java.sun.com/archives/jmf-interest.html

To unsubscribe, send email to listserv@... and include in the body of the message "signoff JMF-INTEREST".


Parent Message unknown Re: Synchronized processors and Incompatible Time Bases

by Ariel Weisberg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Can you post the exact place where the exception is thrown? The JMF source
code is available online so you can see exactly why. Where are you trying to
render the data? A file or a speaker?

===========================================================================
FAQ:  http://java.sun.com/products/java-media/jmf/forDevelopers/jmffaq.html
List Archive: http://archives.java.sun.com/archives/jmf-interest.html

To unsubscribe, send email to listserv@... and include in the body
of the message "signoff JMF-INTEREST".

Re: Synchronized processors and Incompatible Time Bases

by Turner-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Ariel, thanks for replying.



On Fri, Jul 11, 2008 at 4:58 PM, Ariel Weisberg <aweisberg@...> wrote:
Can you post the exact place where the exception is thrown?

javax.media.IncompatibleTimeBaseException
        at com.sun.media.multiplexer.BasicMux.setTimeBase(BasicMux.java:636)
        at com.sun.media.BasicSinkModule.setTimeBase(BasicSinkModule.java:52)
        at com.sun.media.PlaybackEngine.setTimeBase(PlaybackEngine.java:1672)
        at com.sun.media.BasicPlayer.setTimeBase(BasicPlayer.java:272)

 
The JMF source
code is available online so you can see exactly why.

I searched high and low, but Google gave me no help. Could you point me in the right direction?
 
Where are you trying to
render the data? A file or a speaker?

A speaker.
 


===========================================================================
FAQ:  http://java.sun.com/products/java-media/jmf/forDevelopers/jmffaq.html
List Archive: http://archives.java.sun.com/archives/jmf-interest.html

To unsubscribe, send email to listserv@... and include in the body
of the message "signoff JMF-INTEREST".

=========================================================================== FAQ: http://java.sun.com/products/java-media/jmf/forDevelopers/jmffaq.html List Archive: http://archives.java.sun.com/archives/jmf-interest.html

To unsubscribe, send email to listserv@... and include in the body of the message "signoff JMF-INTEREST".


Parent Message unknown Re: Synchronized processors and Incompatible Time Bases

by Ariel Weisberg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

It looks like sun has removed the source code from their web site. It
appears that BasicMux does not support setting a new timebase. I have not
exercised the synchronization aspects of JMF. It may be that it is not
necessary to have them share the same timebase (which they most likely will
anyways) and that all you have to do is make sure you synchronize starting
and stopping.

Regards,
Ariel

===========================================================================
FAQ:  http://java.sun.com/products/java-media/jmf/forDevelopers/jmffaq.html
List Archive: http://archives.java.sun.com/archives/jmf-interest.html

To unsubscribe, send email to listserv@... and include in the body
of the message "signoff JMF-INTEREST".