Class JNIEncoder

  • All Implemented Interfaces:
    javax.media.Codec, javax.media.Controls, javax.media.PlugIn, RTCPFeedbackMessageListener

    public class JNIEncoder
    extends net.sf.fmj.media.AbstractCodec
    implements RTCPFeedbackMessageListener
    Implements an FMJ H.264 encoder using FFmpeg (and x264).
    Author:
    Damian Minkov, Lyubomir Marinov, Sebastien Vincent
    • Constructor Summary

      Constructors 
      Constructor Description
      JNIEncoder()
      Initializes a new JNIEncoder instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes this Codec.
      String getName()
      Gets the name of this Codec.
      javax.media.Format[] getSupportedOutputFormats​(javax.media.Format in)
      Returns the list of formats supported at the output.
      void open()
      Opens this Codec.
      int process​(javax.media.Buffer inBuffer, javax.media.Buffer outBuffer)
      Processes/encodes a buffer.
      void rtcpFeedbackMessageReceived​(RTCPFeedbackMessageEvent ev)
      Notifies this RTCPFeedbackListener that an RTCP feedback message has been received
      void setAdditionalCodecSettings​(Map<String,​String> additionalCodecSettings)
      Sets additional settings on this Codec.
      javax.media.Format setInputFormat​(javax.media.Format format)
      Sets the Format of the media data to be input to this Codec.
      void setKeyFrameControl​(KeyFrameControl keyFrameControl)
      Sets the KeyFrameControl to be used by this JNIEncoder as a means of control over its key frame-related logic.
      javax.media.Format setOutputFormat​(javax.media.Format format)
      Sets the Format in which this Codec is to output media data.
      void setPacketizationMode​(String packetizationMode)
      Sets the packetization mode to be used for the H.264 RTP payload output by this JNIEncoder and the associated packetizer.
      • Methods inherited from class net.sf.fmj.media.AbstractCodec

        checkInputBuffer, dump, getInputFormat, getOutputFormat, getSupportedInputFormats, isEOM, propagateEOM
      • Methods inherited from class net.sf.fmj.media.AbstractPlugIn

        reset
      • Methods inherited from class net.sf.fmj.media.AbstractControls

        addControl, getControl, getControls, removeControl
      • Methods inherited from interface javax.media.Controls

        getControl, getControls
      • Methods inherited from interface javax.media.PlugIn

        reset
    • Field Detail

      • AVAILABLE_PRESETS

        public static final String[] AVAILABLE_PRESETS
        The available presets we can use with the encoder.
      • BASELINE_PROFILE

        public static final String BASELINE_PROFILE
        The name of the baseline H.264 (encoding) profile.
        See Also:
        Constant Field Values
      • DEFAULT_FRAME_RATE

        public static final int DEFAULT_FRAME_RATE
        The frame rate to be assumed by JNIEncoder instances in the absence of any other frame rate indication.
        See Also:
        Constant Field Values
      • DEFAULT_INTRA_REFRESH_PNAME

        public static final String DEFAULT_INTRA_REFRESH_PNAME
        The name of the boolean ConfigurationService property which specifies whether Periodic Intra Refresh is to be used by default. The default value is true. The value may be overridden by setAdditionalCodecSettings(Map).
        See Also:
        Constant Field Values
      • DEFAULT_KEYINT

        public static final int DEFAULT_KEYINT
        The default maximum GOP (group of pictures) size i.e. the maximum interval between keyframes. The x264 library defaults to 250.
        See Also:
        Constant Field Values
      • DEFAULT_PRESET

        public static final String DEFAULT_PRESET
        The default value of the PRESET_PNAME ConfigurationService property.
      • DEFAULT_PROFILE_PNAME

        public static final String DEFAULT_PROFILE_PNAME
        The name of the ConfigurationService property which specifies the H.264 (encoding) profile to be used in the absence of negotiation. Though it seems that RFC 3984 "RTP Payload Format for H.264 Video" specifies the baseline profile as the default, we have till the time of this writing defaulted to the main profile and we do not currently want to change from the main to the base profile unless we really have to.
        See Also:
        Constant Field Values
      • KEYINT_PNAME

        public static final String KEYINT_PNAME
        The name of the integer ConfigurationService property which specifies the maximum GOP (group of pictures) size i.e. the maximum interval between keyframes. FFmpeg calls it gop_size, x264 refers to it as keyint or i_keyint_max.
        See Also:
        Constant Field Values
      • PRESET_PNAME

        public static final String PRESET_PNAME
        The name of the ConfigurationService property which specifies the x264 preset to be used by JNIEncoder. A preset is a collection of x264 options that will provide a certain encoding speed to compression ratio. A slower preset will provide better compression i.e. quality per size.
        See Also:
        Constant Field Values
      • X264_KEYINT_MAX_INFINITE

        public static final int X264_KEYINT_MAX_INFINITE
        See Also:
        Constant Field Values
    • Constructor Detail

      • JNIEncoder

        public JNIEncoder()
        Initializes a new JNIEncoder instance.
    • Method Detail

      • close

        public void close()
        Closes this Codec.
        Specified by:
        close in interface javax.media.PlugIn
        Overrides:
        close in class net.sf.fmj.media.AbstractPlugIn
      • getName

        public String getName()
        Gets the name of this Codec.
        Specified by:
        getName in interface javax.media.PlugIn
        Overrides:
        getName in class net.sf.fmj.media.AbstractPlugIn
        Returns:
        codec name
      • getSupportedOutputFormats

        public javax.media.Format[] getSupportedOutputFormats​(javax.media.Format in)
        Returns the list of formats supported at the output.
        Specified by:
        getSupportedOutputFormats in interface javax.media.Codec
        Specified by:
        getSupportedOutputFormats in class net.sf.fmj.media.AbstractCodec
        Parameters:
        in - input Format to determine corresponding output Formats
        Returns:
        array of formats supported at output
      • open

        public void open()
                  throws javax.media.ResourceUnavailableException
        Opens this Codec.
        Specified by:
        open in interface javax.media.PlugIn
        Overrides:
        open in class net.sf.fmj.media.AbstractPlugIn
        Throws:
        javax.media.ResourceUnavailableException
      • process

        public int process​(javax.media.Buffer inBuffer,
                           javax.media.Buffer outBuffer)
        Processes/encodes a buffer.
        Specified by:
        process in interface javax.media.Codec
        Specified by:
        process in class net.sf.fmj.media.AbstractCodec
        Parameters:
        inBuffer - input buffer
        outBuffer - output buffer
        Returns:
        BUFFER_PROCESSED_OK if buffer has been successfully processed
      • rtcpFeedbackMessageReceived

        public void rtcpFeedbackMessageReceived​(RTCPFeedbackMessageEvent ev)
        Notifies this RTCPFeedbackListener that an RTCP feedback message has been received
        Specified by:
        rtcpFeedbackMessageReceived in interface RTCPFeedbackMessageListener
        Parameters:
        ev - an RTCPFeedbackMessageEvent which specifies the details of the notification event such as the feedback message type and the payload type
      • setAdditionalCodecSettings

        public void setAdditionalCodecSettings​(Map<String,​String> additionalCodecSettings)
        Sets additional settings on this Codec.
        Parameters:
        additionalCodecSettings - the additional settings to be set on this Codec
      • setInputFormat

        public javax.media.Format setInputFormat​(javax.media.Format format)
        Sets the Format of the media data to be input to this Codec.
        Specified by:
        setInputFormat in interface javax.media.Codec
        Overrides:
        setInputFormat in class net.sf.fmj.media.AbstractCodec
        Parameters:
        format - the Format of media data to set on this Codec
        Returns:
        the Format of media data set on this Codec or null if the specified format is not supported by this Codec
      • setKeyFrameControl

        public void setKeyFrameControl​(KeyFrameControl keyFrameControl)
        Sets the KeyFrameControl to be used by this JNIEncoder as a means of control over its key frame-related logic.
        Parameters:
        keyFrameControl - the KeyFrameControl to be used by this JNIEncoder as a means of control over its key frame-related logic
      • setOutputFormat

        public javax.media.Format setOutputFormat​(javax.media.Format format)
        Sets the Format in which this Codec is to output media data.
        Specified by:
        setOutputFormat in interface javax.media.Codec
        Overrides:
        setOutputFormat in class net.sf.fmj.media.AbstractCodec
        Parameters:
        format - the Format in which this Codec is to output media data
        Returns:
        the Format in which this Codec is currently configured to output media data or null if format was found to be incompatible with this Codec
      • setPacketizationMode

        public void setPacketizationMode​(String packetizationMode)
        Sets the packetization mode to be used for the H.264 RTP payload output by this JNIEncoder and the associated packetizer.
        Parameters:
        packetizationMode - the packetization mode to be used for the H.264 RTP payload output by this JNIEncoder and the associated packetizer