Interface MediaStream

    • Field Detail

      • PNAME_LOCAL_SSRC

        static final String PNAME_LOCAL_SSRC
        The name of the property which indicates whether the local SSRC is currently available.
        See Also:
        Constant Field Values
      • PNAME_REMOTE_SSRC

        static final String PNAME_REMOTE_SSRC
        The name of the property which indicates whether the remote SSRC is currently available.
        See Also:
        Constant Field Values
    • Method Detail

      • addDynamicRTPPayloadType

        void addDynamicRTPPayloadType​(byte rtpPayloadType,
                                      MediaFormat format)
        Adds a new association in this MediaStream of the specified RTP payload type with the specified MediaFormat in order to allow it to report rtpPayloadType in RTP flows sending and receiving media in format. Usually, rtpPayloadType will be in the range of dynamic RTP payload types.
        Parameters:
        rtpPayloadType - the RTP payload type to be associated in this MediaStream with the specified MediaFormat
        format - the MediaFormat to be associated in this MediaStream with rtpPayloadType
      • clearDynamicRTPPayloadTypes

        void clearDynamicRTPPayloadTypes()
        Clears the dynamic RTP payload type associations in this MediaStream.
      • addDynamicRTPPayloadTypeOverride

        void addDynamicRTPPayloadTypeOverride​(byte originalPt,
                                              byte overloadPt)
        Adds an additional RTP payload mapping that will overriding one that we've set with addDynamicRTPPayloadType(byte, MediaFormat). This is necessary so that we can support the RFC3264 case where the answerer has the right to declare what payload type mappings it wants to receive RTP packets with even if they are different from those in the offer. RFC3264 claims this is for support of legacy protocols such as H.323 but we've been bumping with a number of cases where multi-component pure SIP systems also need to behave this way.

        Parameters:
        originalPt - the payload type that we are overriding
        overloadPt - the payload type that we are overriging it with
      • addPropertyChangeListener

        void addPropertyChangeListener​(PropertyChangeListener listener)
        Adds a property change listener to this stream so that it would be notified upon property change events like for example an SSRC ID which becomes known.
        Parameters:
        listener - the listener that we'd like to register for PropertyChangeEvents
      • addRTPExtension

        void addRTPExtension​(byte extensionID,
                             RTPExtension rtpExtension)
        Adds or updates an association in this MediaStream mapping the specified extensionID to rtpExtension and enabling or disabling its use according to the direction attribute of rtpExtension.
        Parameters:
        extensionID - the ID that is mapped to rtpExtension for the lifetime of this MediaStream.
        rtpExtension - the RTPExtension that we are mapping to extensionID.
      • clearRTPExtensions

        void clearRTPExtensions()
        Clears the RTP header extension associations stored in this instance.
      • close

        void close()
        Releases the resources allocated by this instance in the course of its execution and prepares it to be garbage collected.
      • getActiveRTPExtensions

        Map<Byte,​RTPExtension> getActiveRTPExtensions()
        Returns a map containing all currently active RTPExtensions in use by this stream.
        Returns:
        a map containing all currently active RTPExtensions in use by this stream.
      • getDevice

        MediaDevice getDevice()
        Gets the device that this stream uses to play back and capture media.
        Returns:
        the MediaDevice that this stream uses to play back and capture media.
      • getDirection

        MediaDirection getDirection()
        Gets the direction in which this MediaStream is allowed to stream media.
        Returns:
        the MediaDirection in which this MediaStream is allowed to stream media
      • getDynamicRTPPayloadTypes

        Map<Byte,​MediaFormat> getDynamicRTPPayloadTypes()
        Gets the existing associations in this MediaStream of RTP payload types to MediaFormats. The returned Map only contains associations previously added in this instance with addDynamicRTPPayloadType(byte, MediaFormat) and not globally or well-known associations reported by MediaFormat.getRTPPayloadType().
        Returns:
        a Map of RTP payload type expressed as Byte to MediaFormat describing the existing (dynamic) associations in this instance of RTP payload types to MediaFormats. The Map represents a snapshot of the existing associations at the time of the getDynamicRTPPayloadTypes() method call and modifications to it are not reflected on the internal storage
      • getDynamicRTPPayloadType

        byte getDynamicRTPPayloadType​(String codec)
        Returns the payload type number that has been negotiated for the specified encoding or -1 if no payload type has been negotiated for it. If multiple formats match the specified encoding, then this method would return the first one it encounters while iterating through the map.
        Parameters:
        codec - the encoding whose payload type we are trying to obtain.
        Returns:
        the payload type number that has been negotiated for the specified codec or -1 if no payload type has been negotiated for it.
      • getFormat

        MediaFormat getFormat()
        Returns the MediaFormat that this stream is currently transmitting in.
        Returns:
        the MediaFormat that this stream is currently transmitting in.
      • getFormat

        MediaFormat getFormat​(byte payloadType)
        Returns the MediaFormat that is associated to the payload type passed in as a parameter.
        Parameters:
        payloadType - the payload type of the MediaFormat to get.
        Returns:
        the MediaFormat that is associated to the payload type passed in as a parameter.
      • getLocalSourceID

        long getLocalSourceID()
        Returns the synchronization source (SSRC) identifier of the local participant or -1 if that identifier is not yet known at this point.
        Returns:
        the synchronization source (SSRC) identifier of the local participant or -1 if that identifier is not yet known at this point.
      • getMediaStreamStats

        MediaStreamStats2 getMediaStreamStats()
        Returns a MediaStreamStats object used to get statistics about this MediaStream.
        Returns:
        the MediaStreamStats object used to get statistics about this MediaStream.
      • getName

        String getName()
        Returns the name of this stream or null if no name has been set. A stream name is used by some protocols, for diagnostic purposes mostly. In XMPP for example this is the name of the content element that describes a stream.
        Returns:
        the name of this stream or null if no name has been set.
      • getProperty

        Object getProperty​(String propertyName)
        Gets the value of a specific opaque property of this MediaStream.
        Parameters:
        propertyName - the name of the opaque property of this MediaStream the value of which is to be returned
        Returns:
        the value of the opaque property of this MediaStream specified by propertyName
      • getRemoteControlAddress

        InetSocketAddress getRemoteControlAddress()
        Returns the address that this stream is sending RTCP traffic to.
        Returns:
        an InetSocketAddress instance indicating the address that we are sending RTCP packets to.
      • getRemoteDataAddress

        InetSocketAddress getRemoteDataAddress()
        Returns the address that this stream is sending RTP traffic to.
        Returns:
        an InetSocketAddress instance indicating the address that we are sending RTP packets to.
      • getRemoteSourceID

        long getRemoteSourceID()
        Gets the synchronization source (SSRC) identifier of the remote peer or -1 if that identifier is not yet known at this point in the execution.

        Warning: A MediaStream may receive multiple RTP streams and may thus have multiple remote SSRCs. Since it is not clear how this MediaStream instance chooses which of the multiple remote SSRCs to be returned by the method, it is advisable to always consider getRemoteSourceIDs() first.

        Returns:
        the synchronization source (SSRC) identifier of the remote peer or -1 if that identifier is not yet known at this point in the execution
      • getRemoteSourceIDs

        List<Long> getRemoteSourceIDs()
        Gets the synchronization source (SSRC) identifiers of the remote peer.
        Returns:
        the synchronization source (SSRC) identifiers of the remote peer
      • getStreamRTPManager

        StreamRTPManager getStreamRTPManager()
        Gets the StreamRTPManager which is to forward RTP and RTCP traffic between this and other MediaStreams.
        Returns:
        the StreamRTPManager which is to forward RTP and RTCP traffic between this and other MediaStreams
      • getSrtpControl

        SrtpControl getSrtpControl()
        The ZrtpControl which controls the ZRTP for this stream.
        Returns:
        the ZrtpControl which controls the ZRTP for this stream
      • getTarget

        MediaStreamTarget getTarget()
        Returns the target of this MediaStream to which it is to send and from which it is to receive data (e.g. RTP) and control data (e.g. RTCP).
        Returns:
        the MediaStreamTarget describing the data (e.g. RTP) and the control data (e.g. RTCP) locations to which this MediaStream is to send and from which it is to receive
        See Also:
        setTarget(MediaStreamTarget)
      • getTransportProtocol

        StreamConnector.Protocol getTransportProtocol()
        Returns the transport protocol used by the streams.
        Returns:
        the transport protocol (UDP or TCP) used by the streams. null if the stream connector is not instanciated.
      • isMute

        boolean isMute()
        Determines whether this MediaStream is set to transmit "silence" instead of the media being fed from its MediaDevice. "Silence" for video is understood as video data which is not the captured video data and may represent, for example, a black image.
        Returns:
        true if this MediaStream is set to transmit "silence" instead of the media fed from its MediaDevice; false, otherwise
      • isStarted

        boolean isStarted()
        Determines whether start() has been called on this MediaStream without stop() or close() afterwards.
        Returns:
        true if start() has been called on this MediaStream without stop() or close() afterwards
      • removePropertyChangeListener

        void removePropertyChangeListener​(PropertyChangeListener listener)
        Removes the specified property change listener from this stream so that it won't receive further property change events.
        Parameters:
        listener - the listener that we'd like to remove.
      • removeReceiveStreamForSsrc

        void removeReceiveStreamForSsrc​(long ssrc)
        Removes the ReceiveStream with SSRC ssrc, if there is such a ReceiveStream, from the receive streams of this MediaStream
        Parameters:
        ssrc - the SSRC for which to remove a ReceiveStream
      • setConnector

        void setConnector​(StreamConnector connector)
        Sets the StreamConnector to be used by this MediaStream for sending and receiving media.
        Parameters:
        connector - the StreamConnector to be used by this MediaStream for sending and receiving media
      • setDevice

        void setDevice​(MediaDevice device)
        Sets the device that this stream should use to play back and capture media.
        Parameters:
        device - the MediaDevice that this stream should use to play back and capture media.
      • setDirection

        void setDirection​(MediaDirection direction)
        Sets the direction in which media in this MediaStream is to be streamed. If this MediaStream is not currently started, calls to start() later on will start it only in the specified direction. If it is currently started in a direction different than the specified, directions other than the specified will be stopped.
        Parameters:
        direction - the MediaDirection in which this MediaStream is to stream media when it is started
      • setFormat

        void setFormat​(MediaFormat format)
        Sets the MediaFormat that this MediaStream should transmit in.
        Parameters:
        format - the MediaFormat that this MediaStream should transmit in.
      • setMute

        void setMute​(boolean mute)
        Causes this MediaStream to stop transmitting the media being fed from this stream's MediaDevice and transmit "silence" instead. "Silence" for video is understood as video data which is not the captured video data and may represent, for example, a black image.
        Parameters:
        mute - true if we are to start transmitting "silence" and false if we are to use media from this stream's MediaDevice again.
      • setName

        void setName​(String name)
        Sets the name of this stream. Stream names are used by some protocols, for diagnostic purposes mostly. In XMPP for example this is the name of the content element that describes a stream.
        Parameters:
        name - the name of this stream or null if no name has been set.
      • setProperty

        void setProperty​(String propertyName,
                         Object value)
        Sets the value of a specific opaque property of this MediaStream.
        Parameters:
        propertyName - the name of the opaque property of this MediaStream the value of which is to be set to the specified value
        value - the value of the opaque property of this MediaStream specified by propertyName to be set
      • setRTPTranslator

        void setRTPTranslator​(RTPTranslator rtpTranslator)
        Sets the RTPTranslator which is to forward RTP and RTCP traffic between this and other MediaStreams.
        Parameters:
        rtpTranslator - the RTPTranslator which is to forward RTP and RTCP traffic between this and other MediaStreams
      • getRTPTranslator

        RTPTranslator getRTPTranslator()
        Gets the RTPTranslator which forwards RTP and RTCP traffic between this and other MediaStreams.
        Returns:
        the RTPTranslator which forwards RTP and RTCP traffic between this and other MediaStreams or null
      • setSSRCFactory

        void setSSRCFactory​(SSRCFactory ssrcFactory)
        Sets the SSRCFactory which is to generate new synchronization source (SSRC) identifiers.
        Parameters:
        ssrcFactory - the SSRCFactory which is to generate new synchronization source (SSRC) identifiers or null if this MediaStream is to employ internal logic to generate new synchronization source (SSRC) identifiers
      • setTarget

        void setTarget​(MediaStreamTarget target)
        Sets the target of this MediaStream to which it is to send and from which it is to receive data (e.g. RTP) and control data (e.g. RTCP).
        Parameters:
        target - the MediaStreamTarget describing the data (e.g. RTP) and the control data (e.g. RTCP) locations to which this MediaStream is to send and from which it is to receive
      • start

        void start()
        Starts capturing media from this stream's MediaDevice and then streaming it through the local StreamConnector toward the stream's target address and port. The method also puts the MediaStream in a listening state that would make it play all media received from the StreamConnector on the stream's MediaDevice.
      • stop

        void stop()
        Stops all streaming and capturing in this MediaStream and closes and releases all open/allocated devices/resources. This method has no effect on an already closed stream and is simply ignored.
      • setExternalTransformer

        void setExternalTransformer​(TransformEngine transformEngine)
        Sets the external (application-provided) TransformEngine of this MediaStream.
        Parameters:
        transformEngine - the TransformerEngine to use.
      • injectPacket

        void injectPacket​(RawPacket pkt,
                          boolean data,
                          TransformEngine after)
                   throws TransmissionFailedException
        Sends a given RTP or RTCP packet to the remote peer/side.
        Parameters:
        pkt - the packet to send.
        data - true to send an RTP packet or false to send an RTCP packet.
        after - the TransformEngine in the TransformEngine chain of this MediaStream after which the injection is to begin. If the specified after is not in the TransformEngine chain of this MediaStream, pkt will be injected at the beginning of the TransformEngine chain of this MediaStream. Generally, the value of after should be null unless the injection is being performed by a TransformEngine itself (while executing transform or reverseTransform of a PacketTransformer of its own even).
        Throws:
        TransmissionFailedException - if the transmission failed.
      • isKeyFrame

        boolean isKeyFrame​(byte[] buf,
                           int off,
                           int len)
        Utility method that determines whether or not a packet is a key frame.
        Parameters:
        buf - the buffer that holds the RTP packet.
        off - the offset in the buff where the RTP packet is found.
        len - then length of the RTP packet in the buffer.
        Returns:
        true if the packet is a key frame, false otherwise.
      • isKeyFrame

        boolean isKeyFrame​(RawPacket pkt)
        Utility method that determines whether or not a packet is a key frame.
        Parameters:
        pkt - the packet.
      • getPrimaryREDBlock

        @Deprecated
        REDBlock getPrimaryREDBlock​(org.jitsi.utils.ByteArrayBuffer baf)
        Deprecated.
        use getPrimaryREDBlock(RawPacket)
        Gets the primary REDBlock that contains the payload of the RTP packet passed in as a parameter.
        Parameters:
        baf - the ByteArrayBuffer that holds the RTP payload.
        Returns:
        the primary REDBlock that contains the payload of the RTP packet passed in as a parameter, or null if the buffer is invalid.
      • getPrimaryREDBlock

        REDBlock getPrimaryREDBlock​(RawPacket pkt)
        Deprecated.
        use getPrimaryREDBlock(RawPacket)
        Gets the primary REDBlock that contains the payload of the RTP packet passed in as a parameter.
        Parameters:
        pkt - the RawPacket that holds the RTP payload.
        Returns:
        the primary REDBlock that contains the payload of the RTP packet passed in as a parameter, or null if the buffer is invalid.
      • setTransportCCEngine

        void setTransportCCEngine​(TransportCCEngine engine)
        Sets the TransportCCEngine of this media stream. Note that for this to take effect it needs to be called early, before the transform chain is initialized (i.e. before a connector is set).
        Parameters:
        engine - the engine to set.