Class ProducerStreamSink

  • All Implemented Interfaces:
    MediaSourceSink

    public class ProducerStreamSink
    extends Object
    implements MediaSourceSink
    Implementation of the MediaSourceSink interface that pushes frames and stream configuration into an instance of KinesisVideoProducerStream.

    Primary purpose of this is to be used by the KinesisVideoClient implementation.

    For example, when an instance of media source is being created or registered with KinesisVideoClient, an instance of this sink is created, and the media source is initialized with this.

    It's then media source's job to produce the frames and push them into the sink it has been initialized with.

    See Also:
    MediaSourceSink, KinesisVideoClient, MediaSource, OnStreamDataAvailable
    • Method Detail

      • onFrame

        public void onFrame​(@Nonnull
                            KinesisVideoFrame kinesisVideoFrame)
                     throws KinesisVideoException
        Description copied from interface: MediaSourceSink
        Receives a video or audio frame from the MediaSource for streaming to Kinesis Video Streams.

        This is the primary method for frame delivery. The MediaSource calls this method for each frame it produces (video frames, audio frames, or both).

        Frame requirements:

        • Frame must contain valid encoded data (H.264, H.265, AAC, etc.)
        • Frame timestamps must be monotonically increasing
        • Key frames should be marked appropriately for video
        • Frame duration should be set for proper playback timing

        Error handling:

        • Throws KinesisVideoException if frame cannot be processed
        • MediaSource should handle exceptions and decide whether to continue or stop, combined with listening for any StreamCallbacks.
        Specified by:
        onFrame in interface MediaSourceSink
        Parameters:
        kinesisVideoFrame - the frame to be streamed, containing encoded media data and metadata
        Throws:
        KinesisVideoException - if the frame cannot be processed or streamed
      • onCodecPrivateData

        public void onCodecPrivateData​(@Nullable
                                       byte[] codecPrivateData)
                                throws KinesisVideoException
        Description copied from interface: MediaSourceSink
        Receives codec private data (codec configuration) for the default track.

        Codec private data contains essential configuration information that decoders need to properly decode the stream. Examples include:

        • H.264: SPS (Sequence Parameter Set) and PPS (Picture Parameter Set)
        • H.265: VPS, SPS, and PPS

        When to send:

        • At stream start, before sending any frames
        • When codec parameters change (e.g. resolution)
        • After stream errors that require reinitialization

        This method is equivalent to calling MediaSourceSink.onCodecPrivateData(byte[], int) with the default track ID.

        Specified by:
        onCodecPrivateData in interface MediaSourceSink
        Parameters:
        codecPrivateData - the codec configuration data, or null if not available
        Throws:
        KinesisVideoException - if the codec data cannot be processed
      • onCodecPrivateData

        public void onCodecPrivateData​(@Nullable
                                       byte[] bytes,
                                       int trackId)
                                throws KinesisVideoException
        Description copied from interface: MediaSourceSink
        Receives codec private data (codec configuration) for a specific track in multi-track streams.

        This method is used for streams with multiple tracks (e.g., separate video and audio tracks). Each track can have its own codec configuration data.

        Example multi-track scenario:

        • Video track (ID 1) with H.264 SPS/PPS
        • Audio track (ID 2) with AAC configuration

        Track ID management:

        • Track IDs should be consistent with those used in KinesisVideoFrame
        • Track IDs must be unique within the stream
        Specified by:
        onCodecPrivateData in interface MediaSourceSink
        Parameters:
        bytes - the codec configuration data for the specified track
        trackId - the unique identifier for the track this codec data applies to
        Throws:
        KinesisVideoException - if the codec data cannot be processed
      • onFragmentMetadata

        public void onFragmentMetadata​(@Nonnull
                                       String metadataName,
                                       @Nonnull
                                       String metadataValue,
                                       boolean persistent)
                                throws KinesisVideoException
        Description copied from interface: MediaSourceSink
        Receives fragment-level metadata to be associated with the stream.

        Fragment metadata allows attaching custom key-value pairs to stream fragments. This metadata can be retrieved when consuming the stream and is useful for:

        • Adding timestamps or sensor readings
        • Marking important events or scenes
        • Storing application-specific annotations (e.g. bounding boxes)
        • Adding searchable tags for content discovery

        Usage examples:

         // Mark motion detection event
         sink.onFragmentMetadata("motion_detected", "true", false);
        
         // Add sensor data
         sink.onFragmentMetadata("temperature", "23.5", false);
         
        Specified by:
        onFragmentMetadata in interface MediaSourceSink
        Parameters:
        metadataName - the name/key of the metadata field
        metadataValue - the value of the metadata field
        persistent - true if metadata should be stored permanently, false for transient metadata
        Throws:
        KinesisVideoException - if the metadata cannot be processed
        See Also:
        Fragment metadata limits