📡 Endpoint Configuration
Setting the Endpoint
By default, the Streamer supports all StreamPack output protocols thanks to the DynamicEndpoint. It infers the endpoint type dynamically from the MediaDescriptor you provide.
However, if you want to limit the supported protocols, or need to use a specific endpoint (for example, to explicitly write an FLV file or stream over SRT), you can explicitly set it by passing an EndpointFactory directly to the Streamer constructor.
import io.github.thibaultbee.streampack.ext.flv.elements.endpoints.FlvFileEndpointFactory
import io.github.thibaultbee.streampack.ext.rtmp.elements.endpoints.RtmpEndpointFactory
// For single streamer (or helpers like cameraSingleStreamer)
val streamer = cameraSingleStreamer(
context = context,
endpointFactory = FlvFileEndpointFactory()
)
// For dual streamer
val dualStreamer = DualStreamer(
context,
firstEndpointFactory = RtmpEndpointFactory(),
secondEndpointFactory = FlvFileEndpointFactory()
)
// For streamer pipeline
val streamerPipeline = StreamerPipeline(context)
streamerPipeline.createEncodingOutput(
endpointFactory = RtmpEndpointFactory()
)
Available Endpoints
- Composite endpoints:
CompositeEndpoint: An endpoint that is composed of aIMuxerand aISink.SrtEndpoint: AnCompositeEndpointthat streams to a SRT server in MPEG-TS (available in SRT package).
- Other endpoints:
RtmpEndpoint: An endpoint that streams directly to a RTMP server (available in RTMP package).FlvEndpoint: An endpoint that writes an FLV stream directly to a file (FlvFileEndpoint) or content URI (FlvContentEndpoint) without using a composite muxer/sink (available in the FLV package).
You can create your own endpoint by extending the CompositeEndpoint class.
Example, you can create a MPEG-TS endpoint that writes to a file:
class TsFileEndpoint : CompositeEndpoint(
TsMuxer(),
FileSink()
)
See available muxers and sinks below.
-
Android based endpoints:
MediaMuxerEndpoint: An endpoint based on AndroidMediaMuxerAPI. It writes to a file or a content. It supports MP4, OGG, 3GP and WebM containers.
-
Combine endpoints:
DynamicEndpoint: The default endpoint of theStreamer. It infers the endpoint from theMediaDescriptorobject.CombineEndpoint: An endpoint that combines multiple endpoints.DualEndpoint: ACombineEndpointthat streams to 2 endpoints. It is useful to stream to a file (main) and a remote server at the same time (second).
If you need to stream to an endpoint that isn't provided out of the box, check out the Creating Custom Endpoints guide.
Available muxers
TsMuxer: A muxer that packs audio and video frames to a MPEG-TS container.Mp4Muxer: A muxer that packs audio and video frames to a fragmented MP4 container (WIP).
Available sinks
SrtSink: A sink that sends the container to a SRT server (available in SRT package).FileSink: A sink that writes the container to a file.ContentSink: A sink that writes the container to a content provider.OutputStreamSink: A sink that writes the container to anOutputStream.ChunkedOutputStreamSink: A sink that writes the container to anOutputStreamin chunks (WIP).
On-the-fly control
The endpoint object is accessible from the streamer object: endpoint directly as IEndpoint. This allows you to have access to specific endpoint information and configuration on the fly while streaming.
val streamer = cameraSingleStreamer()
// Endpoint
streamer.endpoint.apply {
// Specific endpoint configuration
// Example: When the endpoint supports metrics, you can get them
if (this is WithEndpointMetrics<*>) {
Log.i(TAG, "Metrics: ${this.metrics}")
}
// Example: When the endpoint is an `ICompositeEndpoint`, you can get the muxer and sink
if (this is ICompositeEndpoint) {
muxer.apply {
// Specific muxer configuration
}
sink.apply {
// Specific sink configuration
}
}
}