⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 avreceiver.java

📁 jtapi for telephone
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    if (console.isDebugEnabled())
                    {
                        String msg = "The previously unidentified stream ";
                        if (ctl != null)
                        {
                            msg += ctl.getFormat();
                        }
                        msg += " had now been identified as sent by: "
                        + participant.getCNAME();
                        console.debug(msg);
                    }
                }
            }
            else if (evt instanceof ByeEvent)
            {
                console.debug("Got \"bye\" from: " + participant.getCNAME());
            }
        }
        finally
        {
            console.logExit();
        }
    }
    
    /**
     * ControllerListener for the Players.
     */
    public synchronized void controllerUpdate(ControllerEvent ce)
    {
        try
        {
            console.logEntry();
            Player p = (Player) ce.getSourceController();
            if (p == null)
            {
                return;
            }
            // Get this when the internal players are realized.
            if (ce instanceof RealizeCompleteEvent)
            {
                console.debug("A player was realized and will be started.");
                p.start();
            }
            if (ce instanceof StartEvent)
            {
                console.debug("Received a StartEvent");
                mediaManager.firePlayerStarting(p);
            }
            if (ce instanceof ControllerErrorEvent)
            {
                console.error(
                "The following error was reported while starting a player"
                + ce);
            }
            if (ce instanceof ControllerClosedEvent)
            {
                console.debug("Received a ControllerClosedEvent");
                mediaManager.firePlayerStopped();
            }
        }
        finally
        {
            console.logExit();
        }
    }
    
    /**
     * A utility class to parse the session addresses.
     */
    class SessionLabel
    {
        public String addr = null;
        public int port;
        public int ttl = 1;
        private Console console = Console.getConsole(SessionLabel.class);
        SessionLabel(String session) throws IllegalArgumentException
        {
            try
            {
                console.logEntry();
                int off;
                String portStr = null, ttlStr = null;
                if (session != null && session.length() > 0)
                {
                    while (session.length() > 1 && session.charAt(0) == '/')
                    {
                        session = session.substring(1);
                        // Now see if there's a addr specified.
                    }
                    off = session.indexOf('/');
                    if (off == -1)
                    {
                        if (!session.equals(""))
                        {
                            addr = session;
                        }
                    }
                    else
                    {
                        addr = session.substring(0, off);
                        session = session.substring(off + 1);
                        // Now see if there's a port specified
                        off = session.indexOf('/');
                        if (off == -1)
                        {
                            if (!session.equals(""))
                            {
                                portStr = session;
                            }
                        }
                        else
                        {
                            portStr = session.substring(0, off);
                            session = session.substring(off + 1);
                            // Now see if there's a ttl specified
                            off = session.indexOf('/');
                            if (off == -1)
                            {
                                if (!session.equals(""))
                                {
                                    ttlStr = session;
                                }
                            }
                            else
                            {
                                ttlStr = session.substring(0, off);
                            }
                        }
                    }
                }
                if (addr == null)
                {
                    throw new IllegalArgumentException();
                }
                if (portStr != null)
                {
                    
                    Integer integer = Integer.valueOf(portStr);
                    if (integer != null)
                    {
                        port = integer.intValue();
                    }
                    
                    
                }
                else
                {
                    throw new IllegalArgumentException();
                }
                if (ttlStr != null)
                {
                    try
                    {
                        Integer integer = Integer.valueOf(ttlStr);
                        if (integer != null)
                        {
                            ttl = integer.intValue();
                        }
                    }
                    catch (Throwable t)
                    {
                        throw new IllegalArgumentException();
                    }
                }
            }
            finally
            {
                console.logExit();
            }
        }
    }
    
    public void update(SendStreamEvent event)
    {
        console.debug(
        "received the following JMF Session event - "
        + event.getClass().getName());
    }
    
    public Processor getProcessor()
    {
        return processor;
    }
    
    
    protected void configureProcessor(Processor p) throws MediaException
    {
        processor = p;
        try
        {
            
            console.logEntry();
            if (processor == null)
            {
                console.error("Processor is null.");
                throw new MediaException("Processor is null.");
            }
            // Wait for the processor to configure
            boolean result = true;
            if (processor.getState() < Processor.Configured)
            {
                result = waitForState(processor, Processor.Configured);
            }
            if (result == false)
            {
                console.error("Couldn't configure processor");
                throw new MediaException("Couldn't configure processor");
            }
            // Get the tracks from the processor
            TrackControl[] tracks = processor.getTrackControls();
            
            console.debug("-----"+ tracks[0].getFormat());
            int t = tracks[0].getSupportedFormats().length;
            for(int i=0;i<t;i++)
            {
                console.debug("--------------------------------------"+tracks[0].getSupportedFormats()[i]);
            }
            
            
            
            // Do we have atleast one track?
            if (tracks == null || tracks.length < 1)
            {
                console.error("Couldn't find tracks in processor");
                throw new MediaException("Couldn't find tracks in processor");
            }
            // Set the output content descriptor to RAW_RTP
            // This will limit the supported formats reported from
            // Track.getSupportedFormats to only valid RTP formats.
            //   ContentDescriptor cd = new ContentDescriptor(ContentDescriptor.RAW_RTP);
            //kk
            
          FileTypeDescriptor fd = new FileTypeDescriptor(FileTypeDescriptor.BASIC_AUDIO);
        
            processor.setContentDescriptor(fd);
            
            
            //
            // processor.setContentDescriptor(new AudioFileFormat(AudioFileFormat.Type.WAVE));
            
            
        }
        finally
        {
            console.logExit();
        }
    }
    /****************************************************************
     * Convenience methods to handle processor's state changes.
     ****************************************************************/
    protected Integer stateLock = new Integer(0);
    protected boolean failed = false;
    Integer getStateLock()
    {
        return stateLock;
    }
    
    void setFailed()
    {
        failed = true;
    }
    
    protected synchronized boolean waitForState(Processor p, int state)
    {
        
        p.addControllerListener(new StateListener());
        failed = false;
        // Call the required method on the processor
        if (state == Processor.Configured)
        {
            p.configure();
        }
        else if (state == Processor.Realized)
        {
            p.realize();
        }
        // Wait until we get an event that confirms the
        // success of the method, or a failure event.
        // See StateListener inner class
        while (p.getState() < state && !failed)
        {
            synchronized (getStateLock())
            {
                try
                {
                    getStateLock().wait();
                }
                catch (InterruptedException ie)
                {
                    return false;
                }
            }
        }
        if (failed)
        {
            return false;
        }
        else
        {
            return true;
        }
    }
    protected int findFirstMatchingFormat(Format[] hayStack, ArrayList needles)
    {
        try
        {
            console.logEntry();
            if (hayStack == null || needles == null)
            {
                return -1;
            }
            for (int j = 0; j < needles.size(); j++)
            {
                ArrayList currentSet = (ArrayList) needles.get(j);
                for (int k = 0; k < currentSet.size(); k++)
                {
                    for (int i = 0; i < hayStack.length; i++)
                    {
                        if (hayStack[i].getEncoding().equals( currentSet.get(k)))
                        {
                            return i;
                        }
                    }
                }
            }
            return -1;
        }
        finally
        {
            console.logExit();
        }
    }
    /****************************************************************
     * Inner Classes
     ****************************************************************/
    class StateListener
    implements ControllerListener
    {
        public void controllerUpdate(ControllerEvent ce)
        {
            try
            {
                console.logEntry();
                console.debug(ce.toString());
                // If there was an error during configure or
                // realize, the processor will be closed
                if (ce instanceof ControllerClosedEvent)
                {
                    setFailed();
                    // All controller events, send a notification
                    // to the waiting thread in waitForState method.
                }
                if (ce instanceof ControllerEvent)
                {
                    synchronized (getStateLock())
                    {
                        getStateLock().notifyAll();
                    }
                }
                //stop the stream at the end of the audio file
                if (ce instanceof EndOfMediaEvent)
                {
                    try
                    {
                        processor.stop();
                        
                    }catch(Exception ex)
                    {
                        console.debug(ex.toString());
                    }
                }
            }
            finally
            {
                console.logExit();
            }
        }
    }
    
} // end of AVReceive2

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -