Class BytesMediaSource
- java.lang.Object
-
- com.amazonaws.kinesisvideo.internal.mediasource.bytes.BytesMediaSource
-
- All Implemented Interfaces:
MediaSource
public class BytesMediaSource extends Object implements MediaSource
-
-
Constructor Summary
Constructors Constructor Description BytesMediaSource(String streamName)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconfigure(MediaSourceConfiguration configuration)Applies configuration settings to this media source.voidfree()Releases all resources held by this media source and performs final cleanup.MediaSourceConfigurationgetConfiguration()Returns the configuration object used to create and configure this media source.MediaSourceSinkgetMediaSourceSink()Returns the sink that receives frames from this media source.MediaSourceStategetMediaSourceState()Returns the current state of this media source.StreamCallbacksgetStreamCallbacks()Returns stream-specific callback implementations for handling producer events.StreamInfogetStreamInfo()Returns stream information describing the Kinesis Video Stream this is producing frames for.voidinitialize(MediaSourceSink mediaSourceSink)Initializes the media source with a sink that will receive produced frames.booleanisStopped()Returns true if the media source has been stopped and is no longer producing frames.voidstart()Starts frame production and streaming.voidstop()Stops frame production and streaming synchronously.
-
-
-
Method Detail
-
getMediaSourceState
public MediaSourceState getMediaSourceState()
Description copied from interface:MediaSourceReturns the current state of this media source.States include: STARTED, STOPPED, etc.
Use this to check if the media source is ready to start streaming.
- Specified by:
getMediaSourceStatein interfaceMediaSource- Returns:
- the current
MediaSourceState
-
getConfiguration
public MediaSourceConfiguration getConfiguration()
Description copied from interface:MediaSourceReturns the configuration object used to create and configure this media source.The configuration contains media source specific settings such as:
- Media source description
- Source-specific parameters (mime type, camera id, file path, etc.)
- Specified by:
getConfigurationin interfaceMediaSource- Returns:
- the
MediaSourceConfigurationfor this media source
-
getStreamInfo
public StreamInfo getStreamInfo()
Description copied from interface:MediaSourceReturns stream information describing the Kinesis Video Stream this is producing frames for.NativeKinesisVideoClient.registerMediaSource(MediaSource)willMediaSource.initialize(MediaSourceSink)it with an instance ofProducerStreamSinkcreated using the providedStreamInforeturned by this method.- Specified by:
getStreamInfoin interfaceMediaSource- Returns:
- the
StreamInfodescribing this stream
-
initialize
public void initialize(@Nonnull MediaSourceSink mediaSourceSink) throws KinesisVideoException
Description copied from interface:MediaSourceInitializes the media source with a sink that will receive produced frames.NativeKinesisVideoClient.registerMediaSource(MediaSource)will call this method with an instance ofProducerStreamSinkcreated using the providedStreamInfoviaMediaSource.getStreamInfo()This method:
- Establishes the connection between this MediaSource and the provided sink
- Prepares the media source for frame production
- Must be called before
MediaSource.start()
After initialization, the MediaSource should be ready to start producing frames when
MediaSource.start()is called.- Specified by:
initializein interfaceMediaSource- Parameters:
mediaSourceSink- the sink that will receive frames from this media source- Throws:
KinesisVideoException- if initialization fails
-
configure
public void configure(MediaSourceConfiguration configuration)
Description copied from interface:MediaSourceApplies configuration settings to this media source.This method allows runtime configuration of the media source with source-specific parameters. Should typically be called before
MediaSource.initialize(MediaSourceSink).- Specified by:
configurein interfaceMediaSource- Parameters:
configuration- the configuration to apply to this media source
-
start
public void start() throws KinesisVideoExceptionDescription copied from interface:MediaSourceStarts frame production and streaming.After calling this method:
- MediaSource begins capturing/generating frames
- Frames are continuously sent to the MediaSourceSink via
MediaSourceSink.onFrame(com.amazonaws.kinesisvideo.producer.KinesisVideoFrame) - Codec private data is sent via
MediaSourceSink.onCodecPrivateData(byte[]) - Any metadata is sent via
MediaSourceSink.onFragmentMetadata(String, String, boolean)
The MediaSource must be initialized before starting.
- Specified by:
startin interfaceMediaSource- Throws:
KinesisVideoException- if the media source cannot be started or is not properly initialized
-
stop
public void stop() throws KinesisVideoExceptionDescription copied from interface:MediaSourceStops frame production and streaming synchronously. This method should be idempotent.After calling this method and it returns:
- No more frames will be produced or sent to the sink
- Resources may be released, but the MediaSource can potentially be restarted
- Use
MediaSource.isStopped()to verify the stop operation completed
To completely clean up resources, call
MediaSource.free()after stopping.- Specified by:
stopin interfaceMediaSource- Throws:
KinesisVideoException- if the media source cannot be stopped cleanly
-
isStopped
public boolean isStopped()
Description copied from interface:MediaSourceReturns true if the media source has been stopped and is no longer producing frames.This method can be used to:
- Verify that
MediaSource.stop()completed successfully - Check if the media source needs to be restarted
- Determine if cleanup is needed
- Specified by:
isStoppedin interfaceMediaSource- Returns:
- true if the media source is stopped, false if it's still active
- Verify that
-
free
public void free() throws KinesisVideoExceptionDescription copied from interface:MediaSourceReleases all resources held by this media source and performs final cleanup.NativeKinesisVideoClientwill call this whenNativeKinesisVideoClient.free()is called with this Media Source still registered. If the Media Source wasNativeKinesisVideoClient.unregisterMediaSource(MediaSource), then you will need to call this method yourself.MediaSourcecannot be used again after freeing.This method:
- Releases native resources (the native Kinesis Video Stream).
- Should be called after
MediaSource.stop()to ensure clean shutdown - Makes the MediaSource unusable - it cannot be restarted after freeing
- Specified by:
freein interfaceMediaSource- Throws:
KinesisVideoException- if cleanup fails
-
getMediaSourceSink
public MediaSourceSink getMediaSourceSink()
Description copied from interface:MediaSourceReturns the sink that receives frames from this media source.This is the same sink that was provided to
MediaSource.initialize(MediaSourceSink). Useful for accessing the underlying producer stream or for debugging.- Specified by:
getMediaSourceSinkin interfaceMediaSource- Returns:
- the
MediaSourceSinkreceiving frames from this source, or null if not initialized
-
getStreamCallbacks
@Nullable public StreamCallbacks getStreamCallbacks()
Description copied from interface:MediaSourceReturns stream-specific callback implementations for handling producer events.StreamCallbacks allow the MediaSource to:
- Receive acknowledgments from Kinesis Video Streams
- Handle stream errors and implement custom retry logic
- Monitor stream health and performance metrics
- Implement custom stream lifecycle management
Return null if no custom callbacks are needed (default behavior will be used).
- Specified by:
getStreamCallbacksin interfaceMediaSource- Returns:
- custom
StreamCallbacksimplementation, or null for default behavior
-
-