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

📄 mediamanager.java

📁 jtapi for telephone
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            if (sdpData == null)
            {
                console.error("The SDP data was null! Cannot open " +
                "a stream withour an SDP Description!");
                throw new MediaException(
                "The SDP data was null! Cannot open " +
                "a stream withour an SDP Description!");
            }
            try
            {
                sessionDescription =  sdpFactory.createSessionDescription(sdpData);
            }
            catch (SdpParseException ex)
            {
                console.error("Incorrect SDP data!", ex);
                throw new MediaException("Incorrect SDP data!", ex);
            }
            Vector mediaDescriptions;
            try
            {
                mediaDescriptions = sessionDescription.
                getMediaDescriptions(true);
            }
            catch (SdpException ex)
            {
                console.error(
                "Failed to extract media descriptions from provided session description!",
                ex);
                throw new MediaException(
                "Failed to extract media descriptions from provided session description!",
                ex);
            }
            Connection connection = sessionDescription.getConnection();
            if (connection == null)
            {
                console.error(
                "A connection parameter was not present in provided session description");
                throw new MediaException(
                "A connection parameter was not present in provided session description");
            }
            String remoteAddress = null;
            try
            {
                remoteAddress = connection.getAddress();
            }
            catch (SdpParseException ex)
            {
                console.error(
                "Failed to extract the connection address parameter"
                + "from privided session description", ex);
                throw new MediaException(
                "Failed to extract the connection address parameter"
                + "from privided session description", ex);
            }
            int mediaPort = -1;
            boolean atLeastOneTransmitterStarted = false;
            ArrayList ports = new ArrayList();
            ArrayList formatSets = new ArrayList();
            for (int i = 0; i < mediaDescriptions.size(); i++)
            {
                Media media = ( (MediaDescription) mediaDescriptions.get(i)).getMedia();
                //Media Type
                String mediaType = null;
                try
                {
                    mediaType = media.getMediaType();
                }
                catch (SdpParseException ex)
                {
                    console.error(
                    "Failed to extract the media type for one of the provided media descriptions!\n"
                    + "Ignoring description!",
                    ex);
                    fireNonFatalMediaError(new MediaException(
                    "Failed to extract the media type for one of the provided media descriptions!\n"
                    + "Ignoring description!",
                    ex
                    ));
                    continue;
                }
                //Find ports
                try
                {
                    mediaPort = media.getMediaPort();
                }
                catch (SdpParseException ex)
                {
                    console.error("Failed to extract port for media type ["
                    + mediaType + "]. Ignoring description!",
                    ex);
                    fireNonFatalMediaError(new MediaException(
                    "Failed to extract port for media type ["
                    + mediaType + "]. Ignoring description!",
                    ex
                    ));
                    continue;
                }
                //Find  formats
                Vector sdpFormats = null;
                try
                {
                    sdpFormats = media.getMediaFormats(true);
                }
                catch (SdpParseException ex)
                {
                    console.error(
                    "Failed to extract media formats for media type ["
                    + mediaType + "]. Ignoring description!",
                    ex);
                    fireNonFatalMediaError(new MediaException(
                    "Failed to extract media formats for media type ["
                    + mediaType + "]. Ignoring description!",
                    ex
                    ));
                    continue;
                }
                //START TRANSMISSION
                try
                {
                    if (isMediaTransmittable(mediaType))
                    {
                        ports.add(new Integer(mediaPort));
                        formatSets.add(extractTransmittableJmfFormats(sdpFormats));
                    }
                    else
                    {
                        //nothing to transmit here so skip setting the flag
                        //bug report and fix - Gary M. Levin - Telecordia
                        continue;
                    }
                }
                catch (MediaException ex)
                {
                    console.error(
                    "Could not start a transmitter for media type ["
                    + mediaType + "]\nIgnoring media [" + mediaType + "]!",
                    ex
                    );
                    fireNonFatalMediaError(new MediaException(
                    "Could not start a transmitter for media type ["
                    + mediaType + "]\nIgnoring media [" + mediaType + "]!",
                    ex
                    ));
                    continue;
                }
                atLeastOneTransmitterStarted = true;
            }
            startReceiver(remoteAddress);
            if (!atLeastOneTransmitterStarted)
            {
                console.error(
                "Apparently all media descriptions failed to initialise!\n" +
                "SIP COMMUNICATOR won't be able to open a media stream!");
                throw new MediaException(
                "Apparently all media descriptions failed to initialise!\n" +
                "SIP COMMUNICATOR won't be able to open a media stream!");
            }
            else
            {
                
                startTransmitter(remoteAddress,  ports,     formatSets);
            }
        }
        finally
        {
            console.logExit();
        }
    }
    
    protected void closeProcessor()
    {
        try
        {
            console.logEntry();
            if(processor != null)
            {
                processor.stop();
                processor.close();
            }
            if(avDataSource!=null)
                avDataSource.disconnect();
        }
        finally
        {
            console.logExit();
        }
    }
    
    public void stop() throws MediaException
    {
        try
        {
            console.logEntry();
            //   closeStreams();
            closeProcessor();
            
        }
        finally
        {
            console.logExit();
        }
    }
    
    
    public void closeStreams(String sdpData )throws MediaException
    {
        SessionDescription sessionDescription = null;
        int mediaPort = -1;//remote port
        String remoteAddress = null;//remote address
        
        try
        {
            sessionDescription =  sdpFactory.createSessionDescription(sdpData);
        }
        catch (SdpParseException ex)
        {
            console.error("Incorrect SDP data!", ex);
        }
        Vector mediaDescriptions = null;
        try
        {
            mediaDescriptions = sessionDescription.getMediaDescriptions(true);
        }
        catch (SdpException ex)
        {
            console.error(
            "Failed to extract media descriptions from provided session description!",
            ex);
            
        }
        Connection connection = sessionDescription.getConnection();
        if (connection == null)
        {
            console.error(
            "A connection parameter was not present in provided session description");
            throw new MediaException(
            "A connection parameter was not present in provided session description");
        }
        try
        {
            remoteAddress = connection.getAddress();
        }
        catch (SdpParseException ex)
        {
            console.error(
            "Failed to extract the connection address parameter"
            + "from privided session description", ex);
            throw new MediaException(
            "Failed to extract the connection address parameter"
            + "from privided session description", ex);
        }
        
        boolean atLeastOneTransmitterStarted = false;
        ArrayList ports = new ArrayList();
        ArrayList formatSets = new ArrayList();
        for (int i = 0; i < mediaDescriptions.size(); i++)
        {
            Media media = ( (MediaDescription) mediaDescriptions.get(i)).getMedia();
            //Media Type
            String mediaType = null;
            try
            {
                mediaType = media.getMediaType();
            }
            catch (SdpParseException ex)
            {
                console.error(
                "Failed to extract the media type for one of the provided media descriptions!\n"
                + "Ignoring description!",
                ex);
                fireNonFatalMediaError(new MediaException(
                "Failed to extract the media type for one of the provided media descriptions!\n"
                + "Ignoring description!",
                ex
                ));
                continue;
            }
            //Find ports
            try
            {
                mediaPort = media.getMediaPort();
            }
            catch (SdpParseException ex)
            {
                console.error("Failed to extract port for media type ["
                + mediaType + "]. Ignoring description!",
                ex);
                fireNonFatalMediaError(new MediaException(
                "Failed to extract port for media type ["
                + mediaType + "]. Ignoring description!",
                ex
                ));
                continue;
            }
            
        }
        
        //======================
        try
        {
            //removeAllRtpManagers();
            console.logEntry();
            SessionAddress addToStop = new SessionAddress(InetAddress.getByName(remoteAddress),mediaPort);
            stopTransmitters(addToStop);
            if(avTransmitters.size()==0)
                stopReceiver("localhost");
            firePlayerStopped();
        }
        
        catch(java.net.UnknownHostException ex)
        {
            console.debug(ex.toString());
        }
        
        finally
        {
            console.logExit();
        }
    }
    
    
    protected void startTransmitter(String destHost,  ArrayList ports,  ArrayList formatSets) throws MediaException
    {
        try
        {
            console.logEntry();
            
            AVTransmitter transmitter = new AVTransmitter(processor, destHost,  ports,  formatSets  );
            transmitter.setMediaManagerCallback(this);
            avTransmitters.add(transmitter);
            console.debug("Starting transmission.");
            transmitter.start();
            transmitters.add(transmitter);
            
        }
        finally
        {
            console.logExit();
        }
    }
    
    protected void stopTransmitters(SessionAddress addToStop)
    {
        try
        {
            console.logEntry();
            for (int i = avTransmitters.size() - 1; i >= 0; i--)
            {
                try
                {
                    ( (AVTransmitter) avTransmitters.elementAt(i)).stop(addToStop);
                } //Catch everything that comes out as we wouldn't want
                //Some null pointer prevent us from closing a device and thus
                //render it unusable
                catch (Exception exc)
                {
                    console.error("Could not close transmitter " + i, exc);
                }
                avTransmitters.removeElementAt(i);
                transmitters.removeElementAt(i);

⌨️ 快捷键说明

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