Class ProducerStreamSink
- java.lang.Object
-
- com.amazonaws.kinesisvideo.internal.mediasource.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.
-
-
Constructor Summary
Constructors Constructor Description ProducerStreamSink(KinesisVideoProducerStream producerStream)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description KinesisVideoProducerStreamgetProducerStream()Returns the underlying Kinesis Video Producer stream that receives the media data.voidonCodecPrivateData(byte[] codecPrivateData)Receives codec private data (codec configuration) for the default track.voidonCodecPrivateData(byte[] bytes, int trackId)Receives codec private data (codec configuration) for a specific track in multi-track streams.voidonEventMetadata(int event, StreamEventMetadata streamEventMetadata)voidonFragmentMetadata(String metadataName, String metadataValue, boolean persistent)Receives fragment-level metadata to be associated with the stream.voidonFrame(KinesisVideoFrame kinesisVideoFrame)Receives a video or audio frame from the MediaSource for streaming to Kinesis Video Streams.
-
-
-
Constructor Detail
-
ProducerStreamSink
public ProducerStreamSink(KinesisVideoProducerStream producerStream)
-
-
Method Detail
-
onFrame
public void onFrame(@Nonnull KinesisVideoFrame kinesisVideoFrame) throws KinesisVideoException
Description copied from interface:MediaSourceSinkReceives 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:
onFramein interfaceMediaSourceSink- 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:MediaSourceSinkReceives 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:
onCodecPrivateDatain interfaceMediaSourceSink- 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:MediaSourceSinkReceives 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:
onCodecPrivateDatain interfaceMediaSourceSink- Parameters:
bytes- the codec configuration data for the specified tracktrackId- 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:MediaSourceSinkReceives 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:
onFragmentMetadatain interfaceMediaSourceSink- Parameters:
metadataName- the name/key of the metadata fieldmetadataValue- the value of the metadata fieldpersistent- true if metadata should be stored permanently, false for transient metadata- Throws:
KinesisVideoException- if the metadata cannot be processed- See Also:
- Fragment metadata limits
-
onEventMetadata
public void onEventMetadata(int event, @Nullable StreamEventMetadata streamEventMetadata) throws KinesisVideoException- Specified by:
onEventMetadatain interfaceMediaSourceSink- Throws:
KinesisVideoException
-
getProducerStream
public KinesisVideoProducerStream getProducerStream()
Description copied from interface:MediaSourceSinkReturns the underlying Kinesis Video Producer stream that receives the media data.Caution: Direct manipulation of the producer stream should be done carefully to avoid interfering with the normal MediaSource → MediaSourceSink flow.
- Specified by:
getProducerStreamin interfaceMediaSourceSink- Returns:
- the underlying
KinesisVideoProducerStreaminstance
-
-