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

📄 mediamanager.java

📁 jtapi for telephone
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        if (media.equalsIgnoreCase("audio")  /*&& isAudioTransmissionSupported()*/)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    
    protected String[] getReceivableAudioFormats()
    {
        return receivableAudioFormats;
    }
    
    protected String[] getReceivableVideoFormats()
    {
        return receivableVideoFormats;
    }
    
    protected String findCorrespondingJmfFormat(String sdpFormatStr)
    {
        int sdpFormat = -1;
        try
        {
            sdpFormat = Integer.parseInt(sdpFormatStr);
        }
        catch (NumberFormatException ex)
        {
            return null;
        }
        switch (sdpFormat)
        {
            case SdpConstants.PCMU:
                return AudioFormat.ULAW_RTP;
            case SdpConstants.GSM:
                return AudioFormat.GSM_RTP;
            case SdpConstants.G723:
                return AudioFormat.G723_RTP;
            case SdpConstants.DVI4_8000:
                return AudioFormat.DVI_RTP;
            case SdpConstants.DVI4_16000:
                return AudioFormat.DVI_RTP;
            case SdpConstants.PCMA:
                return AudioFormat.ALAW;
            case SdpConstants.G728:
                return AudioFormat.G728_RTP;
            case SdpConstants.G729:
                return AudioFormat.G729_RTP;
            case SdpConstants.H263:
                return VideoFormat.H263_RTP;
            case SdpConstants.JPEG:
                return VideoFormat.JPEG_RTP;
            case SdpConstants.H261:
                return VideoFormat.H261_RTP;
            default:
                return null;
        }
    }
    
    protected String findCorrespondingSdpFormat(String jmfFormat)
    {
        if (jmfFormat == null)
        {
            return null;
        }
        else if (jmfFormat.equals(AudioFormat.ULAW_RTP))
        {
            return Integer.toString(SdpConstants.PCMU);
        }
        else if (jmfFormat.equals(AudioFormat.GSM_RTP))
        {
            return Integer.toString(SdpConstants.GSM);
        }
        else if (jmfFormat.equals(AudioFormat.G723_RTP))
        {
            return Integer.toString(SdpConstants.G723);
        }
        else if (jmfFormat.equals(AudioFormat.DVI_RTP))
        {
            return Integer.toString(SdpConstants.DVI4_8000);
        }
        else if (jmfFormat.equals(AudioFormat.DVI_RTP))
        {
            return Integer.toString(SdpConstants.DVI4_16000);
        }
        else if (jmfFormat.equals(AudioFormat.ALAW))
        {
            return Integer.toString(SdpConstants.PCMA);
        }
        else if (jmfFormat.equals(AudioFormat.G728_RTP))
        {
            return Integer.toString(SdpConstants.G728);
        }
        else if (jmfFormat.equals(AudioFormat.G729_RTP))
        {
            return Integer.toString(SdpConstants.G729);
        }
        else if (jmfFormat.equals(VideoFormat.H263_RTP))
        {
            return Integer.toString(SdpConstants.H263);
        }
        else if (jmfFormat.equals(VideoFormat.JPEG_RTP))
        {
            return Integer.toString(SdpConstants.JPEG);
        }
        else if (jmfFormat.equals(VideoFormat.H261_RTP))
        {
            return Integer.toString(SdpConstants.H261);
        }
        else
        {
            return null;
        }
    }
    
    /**
     * @param sdpFormats
     * @return
     * @throws MediaException
     */
    protected ArrayList extractTransmittableJmfFormats(Vector sdpFormats) throws
    MediaException
    {
        try
        {
            console.logEntry();
            ArrayList jmfFormats = new ArrayList();
            for (int i = 0; i < sdpFormats.size(); i++)
            {
                
                String jmfFormat =
                findCorrespondingJmfFormat(sdpFormats.elementAt(i).toString());
                if (jmfFormat != null)
                {
                    jmfFormats.add(jmfFormat);
                }
            }
            if (jmfFormats.size() == 0)
            {
                throw new MediaException(
                "None of the supplied sdp formats for is supported by SIP COMMUNICATOR");
            }
            return jmfFormats;
        }
        finally
        {
            console.logExit();
        }
    }
    
    //This is the data source that we'll be using to transmit
    //let's see what can it do
    
    
    protected void initProcessor(DataSource dataSource) throws MediaException
    {
        try
        {
            console.logEntry();
            try
            {
                try
                {
                    dataSource.connect();
                }
                //Thrown when operation is not supported by the OS
                catch (NullPointerException ex)
                {
                    console.error(
                    "An internal error occurred while"
                    + " trying to connec to to datasource!", ex);
                    throw new MediaException(
                    "An internal error occurred while"
                    + " trying to connec to to datasource!", ex);
                }
                processor = Manager.createProcessor(dataSource);
                procUtility.waitForState(processor, Processor.Configured);
            }
            catch (NoProcessorException ex)
            {
                console.error(
                "Media manager could not create a processor\n"
                + "for the specified data source",
                ex
                );
                throw new MediaException(
                "Media manager could not create a processor\n"
                + "for the specified data source", ex);
            }
            catch (IOException ex)
            {
                console.error(
                "Media manager could not connect "
                + "to the specified data source",
                ex);
                throw new MediaException("Media manager could not connect "
                + "to the specified data source", ex);
            }
            processor.setContentDescriptor(new ContentDescriptor( ContentDescriptor.RAW_RTP));
            TrackControl[] trackControls = processor.getTrackControls();
            
            console.debug("We will be able to transmit in:");
            for (int i = 0; i < trackControls.length; i++)
            {
                Format[] formats = trackControls[i].getSupportedFormats();
                for (int j = 0; j < formats.length; j++)
                {
                    Format format = formats[j];
                    String encoding = format.getEncoding();
                    if (format instanceof AudioFormat)
                    {
                        String sdp = findCorrespondingSdpFormat(encoding);
                        if (sdp != null && !transmittableAudioFormats.contains(sdp))
                        {
                            if (console.isDebugEnabled())
                            {
                                console.debug("Audio=[" + (j + 1) + "]=" +   encoding + "; sdp=" + sdp);
                            }
                            transmittableAudioFormats.add(sdp);
                        }
                    }
                    
                }
            }
        }
        finally
        {
            console.logExit();
        }
        
    }
    /**
     * Returns a cached instance of an RtpManager bound on the specified local
     * address. If no such instance exists null is returned.
     * @param localAddress the address where the rtp manager must be bound locally.
     * @return an rtp manager bound on the specified address or null if such an
     * instance was not found.
     */
    synchronized RTPManager getRtpManager(SessionAddress localAddress)
    {
        return (RTPManager)activeRtpManagers.get(localAddress);
    }
    
    /**
     * Maps the specified rtp manager against the specified local address so
     * that it may be later retrieved in case someone wants to operate
     * (transmit/receive) on the same port.
     * @param localAddress the address where the rtp manager is bound
     * @param rtpManager the rtp manager itself
     */
    synchronized void putRtpManager(SessionAddress localAddress, RTPManager rtpManager)
    {
        activeRtpManagers.put(localAddress, rtpManager);
    }
    
    /**
     * Removes all rtp managers from the rtp manager cache.
     */
    synchronized void removeAllRtpManagers()
    {
        Enumeration rtpManages = activeRtpManagers.keys();
        while (rtpManages.hasMoreElements())
        {
            SessionAddress item = (SessionAddress)rtpManages.nextElement();
            activeRtpManagers.remove(item);
        }
    }
    
    
    
    /**
     * Moves formats with the specified encoding to the top of the array list
     * so that they are the ones chosen for transmission (if supported by the
     * remote party) (feature request by Vince Fourcade)
     */
    protected void surfacePreferredEncodings(String[] formats)
    {
        try
        {
            console.logEntry();
            String preferredAudioEncoding = sipProp.getProperty("net.java.sip.communicator.media.PREFERRED_AUDIO_ENCODING");
            String preferredVideoEncoding = sipProp.getProperty("sipProp.java.sip.communicator.media.PREFERRED_VIDEO_ENCODING");
            if (preferredAudioEncoding == null    && preferredVideoEncoding == null)
            {
                return;
            }
            for (int i = 0; i < formats.length; i++)
            {
                String encoding = formats[i];
                if ( (preferredAudioEncoding != null
                && encoding.equalsIgnoreCase(preferredAudioEncoding))
                || (preferredVideoEncoding != null
                && encoding.equalsIgnoreCase(preferredVideoEncoding)))
                {
                    formats[i] = formats[0];
                    formats[0] = encoding;
                    if (console.isDebugEnabled())
                    {
                        console.debug("Encoding  [" +
                        findCorrespondingJmfFormat(encoding) +
                        "] is set as preferred.");
                    }
                    break;
                }
            }
        }
        finally
        {
            console.logExit();
        }
    }
    protected synchronized boolean waitForState(Processor p, int state)
    {
        
        
        boolean 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 Integer stateLock = new Integer(0);
    Integer getStateLock()
    {
        return stateLock;
    }
}

⌨️ 快捷键说明

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