FFmpegfs Fuse Multi Media Filesystem 2.19
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
FFmpeg_FormatContext Class Reference

RAII wrapper for AVFormatContext. More...

#include <ffmpeg_formatcontext.h>

Public Types

enum class  TYPE { INPUT , OUTPUT }
 Managed AVFormatContext direction. More...
 

Public Member Functions

 FFmpeg_FormatContext (TYPE type=TYPE::INPUT)
 Construct an empty format-context wrapper.
 
 ~FFmpeg_FormatContext ()
 Release the owned format context, if any.
 
 FFmpeg_FormatContext (const FFmpeg_FormatContext &)=delete
 
FFmpeg_FormatContextoperator= (const FFmpeg_FormatContext &)=delete
 
 FFmpeg_FormatContext (FFmpeg_FormatContext &&context) noexcept
 Move-construct a format-context wrapper.
 
FFmpeg_FormatContextoperator= (FFmpeg_FormatContext &&context) noexcept
 Move-assign a format-context wrapper.
 
int alloc_input_context ()
 Allocate a new input format context.
 
int alloc_output_context (const char *format_name, const char *filename=nullptr)
 Allocate a new output format context.
 
void set_type (TYPE type)
 Set the context direction used for later cleanup.
 
void set_custom_io (bool custom_io=true)
 Mark whether the context owns a custom AVIOContext.
 
bool reset ()
 Free the owned format context and reset the wrapper to empty.
 
bool empty () const
 Check whether the wrapper currently owns a format context.
 
AVFormatContext * get ()
 Get the owned FFmpeg format context pointer.
 
const AVFormatContext * get () const
 Get the owned FFmpeg format context pointer.
 
AVFormatContext ** address ()
 Get a writable pointer-to-pointer for FFmpeg APIs.
 
AVFormatContext * release ()
 Release ownership without freeing the format context.
 
 operator AVFormatContext * ()
 Convert to the underlying mutable format context pointer.
 
 operator const AVFormatContext * () const
 Convert to the underlying const format context pointer.
 
AVFormatContext * operator-> ()
 Access members of the underlying mutable format context.
 
const AVFormatContext * operator-> () const
 Access members of the underlying const format context.
 

Private Member Functions

void free_custom_io ()
 Free the custom AVIOContext attached to the format context.
 

Private Attributes

AVFormatContext * m_context
 Pointer to underlying AVFormatContext.
 
TYPE m_type
 Input or output context.
 
bool m_custom_io
 true if pb was allocated with avio_alloc_context().
 

Detailed Description

RAII wrapper for AVFormatContext.

Owns the AVFormatContext and releases it with the correct FFmpeg function. Input contexts are closed with avformat_close_input(), output contexts are released with avformat_free_context(). Custom AVIO contexts allocated with avio_alloc_context() are freed before the format context is released.

Definition at line 32 of file ffmpeg_formatcontext.h.

Member Enumeration Documentation

◆ TYPE

enum class FFmpeg_FormatContext::TYPE
strong

Managed AVFormatContext direction.

Enumerator
INPUT 

Input context closed with avformat_close_input().

OUTPUT 

Output context freed with avformat_free_context().

Definition at line 38 of file ffmpeg_formatcontext.h.

Constructor & Destructor Documentation

◆ FFmpeg_FormatContext() [1/2]

FFmpeg_FormatContext::FFmpeg_FormatContext ( TYPE  type = TYPE::INPUT)
explicit

Construct an empty format-context wrapper.

Parameters
[in]typeInitial context direction used when resetting/freeing.

Definition at line 33 of file ffmpeg_formatcontext.cc.

◆ ~FFmpeg_FormatContext()

FFmpeg_FormatContext::~FFmpeg_FormatContext ( )

Release the owned format context, if any.

Definition at line 40 of file ffmpeg_formatcontext.cc.

References reset().

◆ FFmpeg_FormatContext() [2/2]

FFmpeg_FormatContext::FFmpeg_FormatContext ( FFmpeg_FormatContext &&  context)
noexcept

Move-construct a format-context wrapper.

Parameters
[in,out]contextSource wrapper whose context ownership is transferred.

Definition at line 45 of file ffmpeg_formatcontext.cc.

Member Function Documentation

◆ address()

AVFormatContext ** FFmpeg_FormatContext::address ( )

Get a writable pointer-to-pointer for FFmpeg APIs.

Any currently owned context is released first so that FFmpeg can write a fresh context pointer without leaking the previous one.

Returns
Address of the managed context pointer.

Definition at line 145 of file ffmpeg_formatcontext.cc.

References m_context.

Referenced by FFmpeg_Transcoder::open_input_file().

◆ alloc_input_context()

int FFmpeg_FormatContext::alloc_input_context ( )

Allocate a new input format context.

Returns
0 on success, or a negative FFmpeg error code.

Definition at line 71 of file ffmpeg_formatcontext.cc.

References INPUT, m_context, m_type, and reset().

Referenced by FFmpeg_Transcoder::open_input_file().

◆ alloc_output_context()

int FFmpeg_FormatContext::alloc_output_context ( const char *  format_name,
const char *  filename = nullptr 
)

Allocate a new output format context.

Parameters
[in]format_nameOutput container format name, or nullptr for automatic selection.
[in]filenameOptional output file name used by FFmpeg for format probing.
Returns
0 on success, or a negative FFmpeg error code.

Definition at line 81 of file ffmpeg_formatcontext.cc.

References m_context, m_type, OUTPUT, and reset().

Referenced by FFmpeg_Transcoder::open_output_filestreams().

◆ empty()

bool FFmpeg_FormatContext::empty ( ) const

Check whether the wrapper currently owns a format context.

Returns
true if no format context is owned, false otherwise.

Definition at line 130 of file ffmpeg_formatcontext.cc.

References m_context.

◆ free_custom_io()

void FFmpeg_FormatContext::free_custom_io ( )
private

Free the custom AVIOContext attached to the format context.

Definition at line 180 of file ffmpeg_formatcontext.cc.

References m_context, and m_custom_io.

Referenced by reset().

◆ get() [1/2]

AVFormatContext * FFmpeg_FormatContext::get ( )

Get the owned FFmpeg format context pointer.

Returns
Mutable AVFormatContext pointer, or nullptr if empty.

Definition at line 135 of file ffmpeg_formatcontext.cc.

References m_context.

◆ get() [2/2]

const AVFormatContext * FFmpeg_FormatContext::get ( ) const

Get the owned FFmpeg format context pointer.

Returns
Const AVFormatContext pointer, or nullptr if empty.

Definition at line 140 of file ffmpeg_formatcontext.cc.

References m_context.

◆ operator AVFormatContext *()

FFmpeg_FormatContext::operator AVFormatContext * ( )

Convert to the underlying mutable format context pointer.

Definition at line 160 of file ffmpeg_formatcontext.cc.

◆ operator const AVFormatContext *()

FFmpeg_FormatContext::operator const AVFormatContext * ( ) const

Convert to the underlying const format context pointer.

Definition at line 165 of file ffmpeg_formatcontext.cc.

◆ operator->() [1/2]

AVFormatContext * FFmpeg_FormatContext::operator-> ( )

Access members of the underlying mutable format context.

Returns
Mutable AVFormatContext pointer.

Definition at line 170 of file ffmpeg_formatcontext.cc.

References m_context.

◆ operator->() [2/2]

const AVFormatContext * FFmpeg_FormatContext::operator-> ( ) const

Access members of the underlying const format context.

Returns
Const AVFormatContext pointer.

Definition at line 175 of file ffmpeg_formatcontext.cc.

References m_context.

◆ operator=()

FFmpeg_FormatContext & FFmpeg_FormatContext::operator= ( FFmpeg_FormatContext &&  context)
noexcept

Move-assign a format-context wrapper.

Parameters
[in,out]contextSource wrapper whose context ownership is transferred.
Returns
Reference to this wrapper.

Definition at line 54 of file ffmpeg_formatcontext.cc.

◆ release()

AVFormatContext * FFmpeg_FormatContext::release ( )

Release ownership without freeing the format context.

Returns
Previously owned AVFormatContext pointer, or nullptr if empty.

Definition at line 150 of file ffmpeg_formatcontext.cc.

References m_context, and m_custom_io.

◆ reset()

bool FFmpeg_FormatContext::reset ( )

Free the owned format context and reset the wrapper to empty.

Returns
true if a context or custom IO object was released, false otherwise.

Definition at line 106 of file ffmpeg_formatcontext.cc.

References free_custom_io(), m_context, m_custom_io, m_type, and OUTPUT.

Referenced by alloc_input_context(), alloc_output_context(), FFmpeg_Transcoder::close_input_file(), FFmpeg_Transcoder::close_output_file(), FFmpeg_Transcoder::open_input_file(), and ~FFmpeg_FormatContext().

◆ set_custom_io()

void FFmpeg_FormatContext::set_custom_io ( bool  custom_io = true)

Mark whether the context owns a custom AVIOContext.

Parameters
[in]custom_iotrue if pb was allocated with avio_alloc_context().

Definition at line 101 of file ffmpeg_formatcontext.cc.

References m_custom_io.

Referenced by FFmpeg_Transcoder::open_input_file(), and FFmpeg_Transcoder::open_output_filestreams().

◆ set_type()

void FFmpeg_FormatContext::set_type ( TYPE  type)

Set the context direction used for later cleanup.

Parameters
[in]typeInput or output context direction.

Definition at line 96 of file ffmpeg_formatcontext.cc.

References m_type.

Member Data Documentation

◆ m_context

AVFormatContext* FFmpeg_FormatContext::m_context
private

Pointer to underlying AVFormatContext.

Definition at line 166 of file ffmpeg_formatcontext.h.

Referenced by address(), alloc_input_context(), alloc_output_context(), empty(), free_custom_io(), get(), get(), operator->(), operator->(), release(), and reset().

◆ m_custom_io

bool FFmpeg_FormatContext::m_custom_io
private

true if pb was allocated with avio_alloc_context().

Definition at line 168 of file ffmpeg_formatcontext.h.

Referenced by free_custom_io(), release(), reset(), and set_custom_io().

◆ m_type

TYPE FFmpeg_FormatContext::m_type
private

Input or output context.

Definition at line 167 of file ffmpeg_formatcontext.h.

Referenced by alloc_input_context(), alloc_output_context(), reset(), and set_type().


The documentation for this class was generated from the following files: