MediaCapture
MediaCapture
#include <icy/av/mediacapture.h>Inherits:
ICapture,RunnableSubclassed by:AudioCapture,VideoCapture
Unified capture and decode source for files and live media devices.
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 ClosingSignals 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 | Open a media file for decoding. Automatically detects video and audio streams. |
void | close virtual | Stop the capture thread and close the media stream and all decoders. |
void | start virtual | Start the background capture and decode thread. Throws std::runtime_error if no media streams have been opened. |
void | stop virtual | Signal the capture thread to stop and join it before returning. |
void | run virtual | Entry point for the background capture thread. Reads and decodes packets from the format context until EOF or stop() is called. |
void | getEncoderFormat virtual | Fill format with the combined encoder-ready video and audio codec parameters. |
void | getEncoderAudioCodec virtual | Fill params with the decoder's output audio codec parameters. Throws std::runtime_error if audio parameters have not been initialised. |
void | getEncoderVideoCodec virtual | 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. |
AVFormatContext * | formatCtx const | #### Returns |
VideoDecoder * | video const | #### Returns |
AudioDecoder * | audio const | #### Returns |
bool | stopping const | #### Returns |
std::string | error const | #### Returns |
MediaCapture
MediaCapture()MediaCapture
MediaCapture(const MediaCapture &) = deleteDeleted constructor.
MediaCapture
MediaCapture(MediaCapture &&) = deleteDeleted constructor.
openFile
virtual
virtual void openFile(const std::string & file)Open a media file for decoding. Automatically detects video and audio streams.
Parameters
filePath to the media file.
close
virtual
virtual void close()Stop the capture thread and close the media stream and all decoders.
start
virtual
virtual void start()Start the background capture and decode thread. Throws std::runtime_error if no media streams have been opened.
stop
virtual
virtual void stop()Signal the capture thread to stop and join it before returning.
run
virtual
virtual void run()Entry point for the background capture thread. Reads and decodes packets from the format context until EOF or stop() is called.
getEncoderFormat
virtual
virtual void getEncoderFormat(Format & format)Fill format with the combined encoder-ready video and audio codec parameters.
Parameters
formatOutput Format struct to populate.
getEncoderAudioCodec
virtual
virtual void getEncoderAudioCodec(AudioCodec & params)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.
getEncoderVideoCodec
virtual
virtual void getEncoderVideoCodec(VideoCodec & params)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.
setLoopInput
void setLoopInput(bool flag)Continuously loop the input file when set.
setLimitFramerate
void setLimitFramerate(bool flag)Limit playback to video FPS.
setRealtimePTS
void setRealtimePTS(bool flag)Set to use realtime PTS calculation. This is preferred when using live captures as FFmpeg-provided values are not always reliable.
formatCtx
const
AVFormatContext * formatCtx() constReturns
The underlying AVFormatContext (thread-safe, mutex-protected).
video
const
VideoDecoder * video() constReturns
The active VideoDecoder, or nullptr if no video stream was opened.
audio
const
AudioDecoder * audio() constReturns
The active AudioDecoder, or nullptr if no audio stream was opened.
stopping
const
bool stopping() constReturns
True if the capture thread has been asked to stop.
error
const
std::string error() constReturns
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 |
_mutex
std::mutex _mutex_thread
Thread _thread_formatCtx
AVFormatContext * _formatCtx_video
std::unique_ptr< VideoDecoder > _video_audio
std::unique_ptr< AudioDecoder > _audio_error
std::string _error_stopping
std::atomic< bool > _stopping_looping
std::atomic< bool > _looping_realtime
std::atomic< bool > _realtime_ratelimit
std::atomic< bool > _ratelimitProtected Methods
| Return | Name | Description |
|---|---|---|
void | openStream virtual | Open the underlying media stream. |
void | emit virtual | Emit an existing packet directly onto the outgoing signal. |
openStream
virtual
virtual void openStream(const std::string & filename, const AVInputFormat * inputFormat, AVDictionary ** formatParams)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.
emit
virtual
virtual void emit(IPacket & packet)Emit an existing packet directly onto the outgoing signal.
Parameters
packetThe packet to forward; must remain valid for the duration of the call.
Public Types
| Name | Description |
|---|---|
Ptr |
Ptr
std::shared_ptr< MediaCapture > Ptr()