Home
AV module

MediaCapture

Unified capture and decode source for files and live media devices.

MediaCapture

#include <icy/av/mediacapture.h>
class MediaCapture

Defined in src/av/include/icy/av/mediacapture.h:37

Inherits: ICapture, Runnable Subclassed by: AudioCapture, VideoCapture

Unified capture and decode source for files and live media devices.

List of all members

NameKindOwner
ClosingvariableDeclared here
MediaCapturefunctionDeclared here
~MediaCapturefunctionDeclared here
MediaCapturefunctionDeclared here
operator=functionDeclared here
MediaCapturefunctionDeclared here
operator=functionDeclared here
openFilefunctionDeclared here
closefunctionDeclared here
startfunctionDeclared here
stopfunctionDeclared here
runfunctionDeclared here
getEncoderFormatfunctionDeclared here
getEncoderAudioCodecfunctionDeclared here
getEncoderVideoCodecfunctionDeclared here
setLoopInputfunctionDeclared here
setLimitFrameratefunctionDeclared here
setRealtimePTSfunctionDeclared here
setOpenOptionsfunctionDeclared here
setPassthroughVideofunctionDeclared here
formatCtxfunctionDeclared here
videofunctionDeclared here
audiofunctionDeclared here
stoppingfunctionDeclared here
errorfunctionDeclared here
_mutexvariableDeclared here
_threadvariableDeclared here
_formatCtxvariableDeclared here
_videovariableDeclared here
_audiovariableDeclared here
_errorvariableDeclared here
_stoppingvariableDeclared here
_loopingvariableDeclared here
_realtimevariableDeclared here
_ratelimitvariableDeclared here
_passthroughVideovariableDeclared here
_openOptionsvariableDeclared here
_videoStreamvariableDeclared here
openStreamfunctionDeclared here
emitfunctionDeclared here
PtrtypedefDeclared here
emittervariableInherited from ICapture
ICapturefunctionInherited from ICapture
~ICapturefunctionInherited from ICapture
startfunctionInherited from ICapture
stopfunctionInherited from ICapture
openFilefunctionInherited from ICapture
closefunctionInherited from ICapture
getEncoderFormatfunctionInherited from ICapture
getEncoderAudioCodecfunctionInherited from ICapture
getEncoderVideoCodecfunctionInherited from ICapture
openAudiofunctionInherited from ICapture
openVideofunctionInherited from ICapture
onStreamStateChangefunctionInherited from ICapture
openStreamfunctionInherited from ICapture
PacketStreamAdapterfunctionInherited from PacketStreamAdapter
~PacketStreamAdapterfunctionInherited from PacketStreamAdapter
emitfunctionInherited from PacketStreamAdapter
emitfunctionInherited from PacketStreamAdapter
emitfunctionInherited from PacketStreamAdapter
emitfunctionInherited from PacketStreamAdapter
emitfunctionInherited from PacketStreamAdapter
getEmitterfunctionInherited from PacketStreamAdapter
retentionfunctionInherited from PacketStreamAdapter
onStreamStateChangefunctionInherited from PacketStreamAdapter
_emittervariableInherited from PacketStreamAdapter
PacketStreamAdapterfunctionInherited from PacketStreamAdapter
operator=functionInherited from PacketStreamAdapter
PacketStreamAdapterfunctionInherited from PacketStreamAdapter
operator=functionInherited from PacketStreamAdapter
startfunctionInherited from Startable
stopfunctionInherited from Startable
RunnablefunctionInherited from Runnable
~RunnablefunctionInherited from Runnable
runfunctionInherited from Runnable
cancelfunctionInherited from Runnable
cancelledfunctionInherited from Runnable
exitvariableInherited from Runnable

Inherited from ICapture

KindNameDescription
variableemitter
functionICapture inline
function~ICapture virtualDefaulted destructor.
functionstart virtual overrideStart capturing and emitting packets.
functionstop virtual overrideStop capturing and release device resources.
functionopenFile virtual inlineOpen a media file as the capture source.
functionclose virtual inlineRelease the capture source and any associated resources.
functiongetEncoderFormat virtualPopulate iformat with the encoder-ready format derived from this capture source.
functiongetEncoderAudioCodec virtual inlinePopulate params with the encoder-ready audio codec parameters.
functiongetEncoderVideoCodec virtual inlinePopulate params with the encoder-ready video codec parameters.
functionopenAudio virtual inlineOpen an audio capture device with the given parameters.
functionopenVideo virtual inlineOpen a video capture device with the given parameters.
functiononStreamStateChange virtual inline overrideReact to PacketStream state transitions by starting or stopping capture.
functionopenStream virtual inline

Inherited from PacketStreamAdapter

KindNameDescription
functionPacketStreamAdapterConstruct the adapter, binding it to the given packet signal.
function~PacketStreamAdapter virtual inline
functionemit virtualEmit a mutable raw buffer as a packet.
functionemit virtualEmit a read-only raw buffer as a packet (data is copied internally).
functionemit virtualEmit a string as a packet (data is copied internally).
functionemit virtualEmit a flag-only packet carrying no payload data.
functionemit virtualEmit an existing packet directly onto the outgoing signal.
functiongetEmitterReturns a reference to the outgoing packet signal.
functionretention virtual constReturns how this adapter treats incoming packet lifetime. Most adapters are synchronous and therefore only borrow the packet for the current call chain. Queue-style adapters override this to advertise that they clone before deferred use. Callers may treat the first adapter reporting Cloned or Retained as the explicit ownership boundary in the stream graph.
functiononStreamStateChange virtual inlineCalled by the PacketStream to notify when the internal Stream state changes. On receiving the Stopped state, it is the responsibility of the adapter to have ceased all outgoing packet transmission, especially in multi-thread scenarios.
variable_emitter
functionPacketStreamAdapterNonCopyable and NonMovable.
functionoperator=Deleted assignment operator.
functionPacketStreamAdapterDeleted constructor.
functionoperator=Deleted assignment operator.

Inherited from Startable

KindNameDescription
functionstart virtualStarts the object (e.g. begins processing or listening).
functionstop virtualStops the object (e.g. halts processing or closes resources).

Inherited from Runnable

KindNameDescription
functionRunnable inline
function~Runnable virtualDefaulted destructor.
functionrun virtualThe run method will be called by the asynchronous context.
functioncancel virtual inlineCancel the current task. The run() method should return ASAP.
functioncancelled virtual const inlineReturns true when the task has been cancelled.
variableexit

Public Attributes

ReturnNameDescription
NullSignalClosingSignals that the capture thread is closing. This signal is emitted from the capture thread context.

Closing

NullSignal Closing

Defined in src/av/include/icy/av/mediacapture.h:133

Signals that the capture thread is closing. This signal is emitted from the capture thread context.

Public Methods

ReturnNameDescription
MediaCapture
MediaCaptureDeleted constructor.
MediaCaptureDeleted constructor.
voidopenFile virtual overrideOpen a media file for decoding. Automatically detects video and audio streams.
voidclose virtual overrideStop the capture thread and close the media stream and all decoders.
voidstart virtual overrideStart the background capture and decode thread. Throws std::runtime_error if no media streams have been opened.
voidstop virtual overrideSignal the capture thread to stop and join it before returning.
voidrun virtual overrideEntry point for the background capture thread. Reads and decodes packets from the format context until EOF or stop() is called.
voidgetEncoderFormat virtual overrideFill format with the combined encoder-ready video and audio codec parameters.
voidgetEncoderAudioCodec virtual overrideFill params with the decoder's output audio codec parameters. Throws std::runtime_error if audio parameters have not been initialised.
voidgetEncoderVideoCodec virtual overrideFill params with the decoder's output video codec parameters. Throws std::runtime_error if video parameters have not been initialised.
voidsetLoopInputContinuously loop the input file when set.
voidsetLimitFramerateLimit playback to video FPS.
voidsetRealtimePTSSet to use realtime PTS calculation. This is preferred when using live captures as FFmpeg-provided values are not always reliable.
voidsetOpenOptionsSet demuxer options applied at the next openFile() call. Keys map to libavformat AVOption entries (e.g. "rtsp_transport", "fflags", "analyzeduration", "probesize"). Useful for live network sources that need low-latency hints. Pass an empty map to clear.
voidsetPassthroughVideoSkip the video decoder. Encoded video AVPackets from the input stream are emitted directly as [av::VideoPacket](icy-av-VideoPacket.html#videopacket) without decoding. The emitted packets carry the source's encoded payload and a time in microseconds rescaled from the stream's timebase. The iframe flag is set from AV_PKT_FLAG_KEY.
AVFormatContext *formatCtx const
VideoDecoder *video const
AudioDecoder *audio const
boolstopping const
std::stringerror const

MediaCapture

MediaCapture()

Defined in src/av/include/icy/av/mediacapture.h:43


MediaCapture

MediaCapture(const MediaCapture &) = delete

Defined in src/av/include/icy/av/mediacapture.h:46

Deleted constructor.


MediaCapture

MediaCapture(MediaCapture &&) = delete

Defined in src/av/include/icy/av/mediacapture.h:48

Deleted constructor.


openFile

virtual override

virtual void openFile(const std::string & file) override

Defined in src/av/include/icy/av/mediacapture.h:53

Open a media file for decoding. Automatically detects video and audio streams.

Parameters

  • file Path to the media file.
Reimplements

close

virtual override

virtual void close() override

Defined in src/av/include/icy/av/mediacapture.h:60

Stop the capture thread and close the media stream and all decoders.

Reimplements

start

virtual override

virtual void start() override

Defined in src/av/include/icy/av/mediacapture.h:64

Start the background capture and decode thread. Throws std::runtime_error if no media streams have been opened.

Reimplements

stop

virtual override

virtual void stop() override

Defined in src/av/include/icy/av/mediacapture.h:67

Signal the capture thread to stop and join it before returning.

Reimplements

run

virtual override

virtual void run() override

Defined in src/av/include/icy/av/mediacapture.h:71

Entry point for the background capture thread. Reads and decodes packets from the format context until EOF or stop() is called.

Reimplements

getEncoderFormat

virtual override

virtual void getEncoderFormat(Format & format) override

Defined in src/av/include/icy/av/mediacapture.h:75

Fill format with the combined encoder-ready video and audio codec parameters.

Parameters

  • format Output Format struct to populate.
Reimplements

getEncoderAudioCodec

virtual override

virtual void getEncoderAudioCodec(AudioCodec & params) override

Defined in src/av/include/icy/av/mediacapture.h:80

Fill params with the decoder's output audio codec parameters. Throws std::runtime_error if audio parameters have not been initialised.

Parameters

Reimplements

getEncoderVideoCodec

virtual override

virtual void getEncoderVideoCodec(VideoCodec & params) override

Defined in src/av/include/icy/av/mediacapture.h:85

Fill params with the decoder's output video codec parameters. Throws std::runtime_error if video parameters have not been initialised.

Parameters

Reimplements

setLoopInput

void setLoopInput(bool flag)

Defined in src/av/include/icy/av/mediacapture.h:88

Continuously loop the input file when set.


setLimitFramerate

void setLimitFramerate(bool flag)

Defined in src/av/include/icy/av/mediacapture.h:91

Limit playback to video FPS.


setRealtimePTS

void setRealtimePTS(bool flag)

Defined in src/av/include/icy/av/mediacapture.h:96

Set to use realtime PTS calculation. This is preferred when using live captures as FFmpeg-provided values are not always reliable.


setOpenOptions

void setOpenOptions(const std::map< std::string, std::string > & options)

Defined in src/av/include/icy/av/mediacapture.h:102

Set demuxer options applied at the next openFile() call. Keys map to libavformat AVOption entries (e.g. "rtsp_transport", "fflags", "analyzeduration", "probesize"). Useful for live network sources that need low-latency hints. Pass an empty map to clear.


setPassthroughVideo

void setPassthroughVideo(bool flag)

Defined in src/av/include/icy/av/mediacapture.h:114

Skip the video decoder. Encoded video AVPackets from the input stream are emitted directly as [av::VideoPacket](icy-av-VideoPacket.html#videopacket) without decoding. The emitted packets carry the source's encoded payload and a time in microseconds rescaled from the stream's timebase. The iframe flag is set from AV_PKT_FLAG_KEY.

Use case: forwarding already-browser-compatible H.264 to a WebRTC sender without the cost of decode plus re-encode. Must be called before openFile(); changing the mode after the stream is open is not supported.


formatCtx

const

AVFormatContext * formatCtx() const

Defined in src/av/include/icy/av/mediacapture.h:117

Returns

The underlying AVFormatContext (thread-safe, mutex-protected).


video

const

VideoDecoder * video() const

Defined in src/av/include/icy/av/mediacapture.h:120

Returns

The active VideoDecoder, or nullptr if no video stream was opened.


audio

const

AudioDecoder * audio() const

Defined in src/av/include/icy/av/mediacapture.h:123

Returns

The active AudioDecoder, or nullptr if no audio stream was opened.


stopping

const

bool stopping() const

Defined in src/av/include/icy/av/mediacapture.h:126

Returns

True if the capture thread has been asked to stop.


error

const

std::string error() const

Defined in src/av/include/icy/av/mediacapture.h:129

Returns

The last error message, or an empty string if no error has occurred.

Protected Attributes

ReturnNameDescription
std::mutex_mutex
Thread_thread
AVFormatContext *_formatCtx
std::unique_ptr< VideoDecoder >_video
std::unique_ptr< AudioDecoder >_audio
std::string_error
std::atomic< bool >_stopping
std::atomic< bool >_looping
std::atomic< bool >_realtime
std::atomic< bool >_ratelimit
std::atomic< bool >_passthroughVideo
std::map< std::string, std::string >_openOptions
AVStream *_videoStream

_mutex

std::mutex _mutex

Defined in src/av/include/icy/av/mediacapture.h:146


_thread

Thread _thread

Defined in src/av/include/icy/av/mediacapture.h:147


_formatCtx

AVFormatContext * _formatCtx

Defined in src/av/include/icy/av/mediacapture.h:148


_video

std::unique_ptr< VideoDecoder > _video

Defined in src/av/include/icy/av/mediacapture.h:149


_audio

std::unique_ptr< AudioDecoder > _audio

Defined in src/av/include/icy/av/mediacapture.h:150


_error

std::string _error

Defined in src/av/include/icy/av/mediacapture.h:151


_stopping

std::atomic< bool > _stopping

Defined in src/av/include/icy/av/mediacapture.h:152


_looping

std::atomic< bool > _looping

Defined in src/av/include/icy/av/mediacapture.h:153


_realtime

std::atomic< bool > _realtime

Defined in src/av/include/icy/av/mediacapture.h:154


_ratelimit

std::atomic< bool > _ratelimit

Defined in src/av/include/icy/av/mediacapture.h:155


_passthroughVideo

std::atomic< bool > _passthroughVideo {false}

Defined in src/av/include/icy/av/mediacapture.h:156


_openOptions

std::map< std::string, std::string > _openOptions

Defined in src/av/include/icy/av/mediacapture.h:157


_videoStream

AVStream * _videoStream = nullptr

Defined in src/av/include/icy/av/mediacapture.h:161

Protected Methods

ReturnNameDescription
voidopenStream virtual overrideOpen the underlying media stream.
voidemit virtual overrideEmit an existing packet directly onto the outgoing signal.

openStream

virtual override

virtual void openStream(const std::string & filename, const AVInputFormat * inputFormat, AVDictionary ** formatParams) override

Defined in src/av/include/icy/av/mediacapture.h:141

Open the underlying media stream.

Parameters

  • filename The file path or device name to open.

  • inputFormat The forced input format, or nullptr for auto-detect.

  • formatParams Optional format parameters; may be updated by FFmpeg on return.

Reimplements

emit

virtual override

virtual void emit(IPacket & packet) override

Defined in src/av/include/icy/av/mediacapture.h:143

Emit an existing packet directly onto the outgoing signal.

Parameters

  • packet The packet to forward; must remain valid for the duration of the call.
Reimplements

Public Types

NameDescription
Ptr

Ptr

using Ptr = std::shared_ptr< MediaCapture >

Defined in src/av/include/icy/av/mediacapture.h:41