MediaCapture
MediaCapture
#include <icy/av/mediacapture.h>class MediaCaptureDefined in src/av/include/icy/av/mediacapture.h:37
Inherits:
ICapture,RunnableSubclassed by:AudioCapture,VideoCapture
Unified capture and decode source for files and live media devices.
List of all members
| Name | Kind | Owner |
|---|---|---|
Closing | variable | Declared here |
MediaCapture | function | Declared here |
~MediaCapture | function | Declared here |
MediaCapture | function | Declared here |
operator= | function | Declared here |
MediaCapture | function | Declared here |
operator= | function | Declared here |
openFile | function | Declared here |
close | function | Declared here |
start | function | Declared here |
stop | function | Declared here |
run | function | Declared here |
getEncoderFormat | function | Declared here |
getEncoderAudioCodec | function | Declared here |
getEncoderVideoCodec | function | Declared here |
setLoopInput | function | Declared here |
setLimitFramerate | function | Declared here |
setRealtimePTS | function | Declared here |
setOpenOptions | function | Declared here |
setPassthroughVideo | function | Declared here |
formatCtx | function | Declared here |
video | function | Declared here |
audio | function | Declared here |
stopping | function | Declared here |
error | function | Declared here |
_mutex | variable | Declared here |
_thread | variable | Declared here |
_formatCtx | variable | Declared here |
_video | variable | Declared here |
_audio | variable | Declared here |
_error | variable | Declared here |
_stopping | variable | Declared here |
_looping | variable | Declared here |
_realtime | variable | Declared here |
_ratelimit | variable | Declared here |
_passthroughVideo | variable | Declared here |
_openOptions | variable | Declared here |
_videoStream | variable | Declared here |
openStream | function | Declared here |
emit | function | Declared here |
Ptr | typedef | Declared here |
emitter | variable | Inherited from ICapture |
ICapture | function | Inherited from ICapture |
~ICapture | function | Inherited from ICapture |
start | function | Inherited from ICapture |
stop | function | Inherited from ICapture |
openFile | function | Inherited from ICapture |
close | function | Inherited from ICapture |
getEncoderFormat | function | Inherited from ICapture |
getEncoderAudioCodec | function | Inherited from ICapture |
getEncoderVideoCodec | function | Inherited from ICapture |
openAudio | function | Inherited from ICapture |
openVideo | function | Inherited from ICapture |
onStreamStateChange | function | Inherited from ICapture |
openStream | function | Inherited from ICapture |
PacketStreamAdapter | function | Inherited from PacketStreamAdapter |
~PacketStreamAdapter | function | Inherited from PacketStreamAdapter |
emit | function | Inherited from PacketStreamAdapter |
emit | function | Inherited from PacketStreamAdapter |
emit | function | Inherited from PacketStreamAdapter |
emit | function | Inherited from PacketStreamAdapter |
emit | function | Inherited from PacketStreamAdapter |
getEmitter | function | Inherited from PacketStreamAdapter |
retention | function | Inherited from PacketStreamAdapter |
onStreamStateChange | function | Inherited from PacketStreamAdapter |
_emitter | variable | Inherited from PacketStreamAdapter |
PacketStreamAdapter | function | Inherited from PacketStreamAdapter |
operator= | function | Inherited from PacketStreamAdapter |
PacketStreamAdapter | function | Inherited from PacketStreamAdapter |
operator= | function | Inherited from PacketStreamAdapter |
start | function | Inherited from Startable |
stop | function | Inherited from Startable |
Runnable | function | Inherited from Runnable |
~Runnable | function | Inherited from Runnable |
run | function | Inherited from Runnable |
cancel | function | Inherited from Runnable |
cancelled | function | Inherited from Runnable |
exit | variable | Inherited from Runnable |
Inherited from ICapture
| Kind | Name | Description |
|---|---|---|
variable | emitter | |
function | ICapture inline | |
function | ~ICapture virtual | Defaulted destructor. |
function | start virtual override | Start capturing and emitting packets. |
function | stop virtual override | Stop capturing and release device resources. |
function | openFile virtual inline | Open a media file as the capture source. |
function | close virtual inline | Release the capture source and any associated resources. |
function | getEncoderFormat virtual | Populate iformat with the encoder-ready format derived from this capture source. |
function | getEncoderAudioCodec virtual inline | Populate params with the encoder-ready audio codec parameters. |
function | getEncoderVideoCodec virtual inline | Populate params with the encoder-ready video codec parameters. |
function | openAudio virtual inline | Open an audio capture device with the given parameters. |
function | openVideo virtual inline | Open a video capture device with the given parameters. |
function | onStreamStateChange virtual inline override | React to PacketStream state transitions by starting or stopping capture. |
function | openStream virtual inline |
Inherited from PacketStreamAdapter
| Kind | Name | Description |
|---|---|---|
function | PacketStreamAdapter | Construct the adapter, binding it to the given packet signal. |
function | ~PacketStreamAdapter virtual inline | |
function | emit virtual | Emit a mutable raw buffer as a packet. |
function | emit virtual | Emit a read-only raw buffer as a packet (data is copied internally). |
function | emit virtual | Emit a string as a packet (data is copied internally). |
function | emit virtual | Emit a flag-only packet carrying no payload data. |
function | emit virtual | Emit an existing packet directly onto the outgoing signal. |
function | getEmitter | Returns a reference to the outgoing packet signal. |
function | retention virtual const | Returns 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. |
function | onStreamStateChange virtual inline | Called 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 | |
function | PacketStreamAdapter | NonCopyable and NonMovable. |
function | operator= | Deleted assignment operator. |
function | PacketStreamAdapter | Deleted constructor. |
function | operator= | Deleted assignment operator. |
Inherited from Startable
| Kind | Name | Description |
|---|---|---|
function | start virtual | Starts the object (e.g. begins processing or listening). |
function | stop virtual | Stops the object (e.g. halts processing or closes resources). |
Inherited from Runnable
| Kind | Name | Description |
|---|---|---|
function | Runnable inline | |
function | ~Runnable virtual | Defaulted destructor. |
function | run virtual | The run method will be called by the asynchronous context. |
function | cancel virtual inline | Cancel the current task. The run() method should return ASAP. |
function | cancelled virtual const inline | Returns true when the task has been cancelled. |
variable | exit |
Public Attributes
| Return | Name | Description |
|---|---|---|
NullSignal | Closing | Signals that the capture thread is closing. This signal is emitted from the capture thread context. |
Closing
NullSignal ClosingDefined 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
| Return | Name | Description |
|---|---|---|
MediaCapture | ||
MediaCapture | Deleted constructor. | |
MediaCapture | Deleted constructor. | |
void | openFile virtual override | Open a media file for decoding. Automatically detects video and audio streams. |
void | close virtual override | Stop the capture thread and close the media stream and all decoders. |
void | start virtual override | Start the background capture and decode thread. Throws std::runtime_error if no media streams have been opened. |
void | stop virtual override | Signal the capture thread to stop and join it before returning. |
void | run virtual override | Entry point for the background capture thread. Reads and decodes packets from the format context until EOF or stop() is called. |
void | getEncoderFormat virtual override | Fill format with the combined encoder-ready video and audio codec parameters. |
void | getEncoderAudioCodec virtual override | Fill params with the decoder's output audio codec parameters. Throws std::runtime_error if audio parameters have not been initialised. |
void | getEncoderVideoCodec virtual override | Fill params with the decoder's output video codec parameters. Throws std::runtime_error if video parameters have not been initialised. |
void | setLoopInput | Continuously loop the input file when set. |
void | setLimitFramerate | Limit playback to video FPS. |
void | setRealtimePTS | Set to use realtime PTS calculation. This is preferred when using live captures as FFmpeg-provided values are not always reliable. |
void | setOpenOptions | 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. |
void | setPassthroughVideo | 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. |
AVFormatContext * | formatCtx const | |
VideoDecoder * | video const | |
AudioDecoder * | audio const | |
bool | stopping const | |
std::string | error const |
MediaCapture
MediaCapture()Defined in src/av/include/icy/av/mediacapture.h:43
MediaCapture
MediaCapture(const MediaCapture &) = deleteDefined in src/av/include/icy/av/mediacapture.h:46
Deleted constructor.
MediaCapture
MediaCapture(MediaCapture &&) = deleteDefined in src/av/include/icy/av/mediacapture.h:48
Deleted constructor.
openFile
virtual override
virtual void openFile(const std::string & file) overrideDefined in src/av/include/icy/av/mediacapture.h:53
Open a media file for decoding. Automatically detects video and audio streams.
Parameters
filePath to the media file.
Reimplements
close
virtual override
virtual void close() overrideDefined 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() overrideDefined 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() overrideDefined 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() overrideDefined 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) overrideDefined in src/av/include/icy/av/mediacapture.h:75
Fill format with the combined encoder-ready video and audio codec parameters.
Parameters
formatOutput Format struct to populate.
Reimplements
getEncoderAudioCodec
virtual override
virtual void getEncoderAudioCodec(AudioCodec & params) overrideDefined 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
paramsOutput AudioCodec struct to populate.
Reimplements
getEncoderVideoCodec
virtual override
virtual void getEncoderVideoCodec(VideoCodec & params) overrideDefined 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
paramsOutput VideoCodec struct to populate.
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() constDefined in src/av/include/icy/av/mediacapture.h:117
Returns
The underlying AVFormatContext (thread-safe, mutex-protected).
video
const
VideoDecoder * video() constDefined 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() constDefined 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() constDefined 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() constDefined 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
| Return | Name | Description |
|---|---|---|
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 _mutexDefined in src/av/include/icy/av/mediacapture.h:146
_thread
Thread _threadDefined in src/av/include/icy/av/mediacapture.h:147
_formatCtx
AVFormatContext * _formatCtxDefined in src/av/include/icy/av/mediacapture.h:148
_video
std::unique_ptr< VideoDecoder > _videoDefined in src/av/include/icy/av/mediacapture.h:149
_audio
std::unique_ptr< AudioDecoder > _audioDefined in src/av/include/icy/av/mediacapture.h:150
_error
std::string _errorDefined in src/av/include/icy/av/mediacapture.h:151
_stopping
std::atomic< bool > _stoppingDefined in src/av/include/icy/av/mediacapture.h:152
_looping
std::atomic< bool > _loopingDefined in src/av/include/icy/av/mediacapture.h:153
_realtime
std::atomic< bool > _realtimeDefined in src/av/include/icy/av/mediacapture.h:154
_ratelimit
std::atomic< bool > _ratelimitDefined 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 > _openOptionsDefined in src/av/include/icy/av/mediacapture.h:157
_videoStream
AVStream * _videoStream = nullptrDefined in src/av/include/icy/av/mediacapture.h:161
Protected Methods
| Return | Name | Description |
|---|---|---|
void | openStream virtual override | Open the underlying media stream. |
void | emit virtual override | Emit an existing packet directly onto the outgoing signal. |
openStream
virtual override
virtual void openStream(const std::string & filename, const AVInputFormat * inputFormat, AVDictionary ** formatParams) overrideDefined in src/av/include/icy/av/mediacapture.h:141
Open the underlying media stream.
Parameters
filenameThe file path or device name to open.inputFormatThe forced input format, or nullptr for auto-detect.formatParamsOptional format parameters; may be updated by FFmpeg on return.
Reimplements
emit
virtual override
virtual void emit(IPacket & packet) overrideDefined in src/av/include/icy/av/mediacapture.h:143
Emit an existing packet directly onto the outgoing signal.
Parameters
packetThe packet to forward; must remain valid for the duration of the call.
Reimplements
Public Types
| Name | Description |
|---|---|
Ptr |
Ptr
using Ptr = std::shared_ptr< MediaCapture >