Skip to content

📡 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

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 Android MediaMuxer API. It writes to a file or a content. It supports MP4, OGG, 3GP and WebM containers.
  • Combine endpoints:

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 an OutputStream.
  • ChunkedOutputStreamSink: A sink that writes the container to an OutputStream in 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
        }
    }
}