Audacity 3.2.0
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Static Private Member Functions | List of all members
AVIOContextWrapper Class Referenceabstract

#include <AVIOContextWrapper.h>

Collaboration diagram for AVIOContextWrapper:
[legend]

Public Types

enum class  OpenResult { Success , FileOpenFailed , NoMemory , InternalError }
 

Public Member Functions

 AVIOContextWrapper (const AVIOContextWrapper &)=delete
 
AVIOContextWrapperoperator= (AVIOContextWrapper &)=delete
 
 AVIOContextWrapper (AVIOContextWrapper &&)=delete
 
AVIOContextWrapperoperator= (AVIOContextWrapper &&)=delete
 
 AVIOContextWrapper (const FFmpegFunctions &ffmpeg) noexcept
 
AVIOContextGetWrappedValue () noexcept
 
const AVIOContextGetWrappedValue () const noexcept
 
virtual ~AVIOContextWrapper ()
 
OpenResult Open (const wxString &fileName, bool forWriting)
 
virtual unsigned char * GetBuffer () const noexcept=0
 
virtual int GetBufferSize () const noexcept=0
 
virtual unsigned char * GetBufPtr () const noexcept=0
 
virtual unsigned char * GetBufEnd () const noexcept=0
 
virtual void * GetOpaque () const noexcept=0
 
virtual void SetOpaque (void *opaque) noexcept=0
 
virtual int64_t GetPos () const noexcept=0
 
virtual int GetEofReached () const noexcept=0
 
virtual int GetWriteFlag () const noexcept=0
 
virtual void SetWriteFlag (int write_flag) noexcept=0
 
virtual int GetError () const noexcept=0
 
virtual void SetError (int error) noexcept=0
 
virtual int GetSeekable () const noexcept=0
 
virtual void SetSeekable (int seekable) noexcept=0
 
virtual int GetDirect () const noexcept=0
 
virtual void SetDirect (int direct) noexcept=0
 

Protected Member Functions

virtual int Read (uint8_t *buf, int size)=0
 

Protected Attributes

const FFmpegFunctionsmFFmpeg
 
AVIOContextmAVIOContext { nullptr }
 
std::unique_ptr< wxFile > mpFile
 This is held indirectly by unique_ptr just so it can be swapped. More...
 

Static Private Member Functions

static int FileRead (void *opaque, uint8_t *buf, int size)
 
static int FileWrite (void *opaque, const uint8_t *buf, int size)
 
static int64_t FileSeek (void *opaque, int64_t pos, int whence)
 

Detailed Description

Definition at line 21 of file AVIOContextWrapper.h.

Member Enumeration Documentation

◆ OpenResult

enum class AVIOContextWrapper::OpenResult
strong
Enumerator
Success 
FileOpenFailed 
NoMemory 
InternalError 

Definition at line 24 of file AVIOContextWrapper.h.

25 {
26 Success,
27 FileOpenFailed,
28 NoMemory,
29 InternalError
30 };

Constructor & Destructor Documentation

◆ AVIOContextWrapper() [1/3]

AVIOContextWrapper::AVIOContextWrapper ( const AVIOContextWrapper )
delete

◆ AVIOContextWrapper() [2/3]

AVIOContextWrapper::AVIOContextWrapper ( AVIOContextWrapper &&  )
delete

◆ AVIOContextWrapper() [3/3]

AVIOContextWrapper::AVIOContextWrapper ( const FFmpegFunctions ffmpeg)
explicitnoexcept

Definition at line 20 of file AVIOContextWrapper.cpp.

22 : mFFmpeg(ffmpeg)
23{
24}
const FFmpegFunctions & mFFmpeg

◆ ~AVIOContextWrapper()

AVIOContextWrapper::~AVIOContextWrapper ( )
virtual

Definition at line 36 of file AVIOContextWrapper.cpp.

37{
38 if (mAVIOContext == nullptr)
39 return;
40
41 if (mFFmpeg.avio_context_free != nullptr)
43 else
45}
AVIOContext * mAVIOContext
void(* avio_context_free)(AVIOContext **s)
void(* av_free)(void *ptr)

References AVUtilFunctions::av_free, AVFormatFunctions::avio_context_free, mAVIOContext, and mFFmpeg.

Member Function Documentation

◆ FileRead()

int AVIOContextWrapper::FileRead ( void *  opaque,
uint8_t *  buf,
int  size 
)
staticprivate

Definition at line 84 of file AVIOContextWrapper.cpp.

85{
86 AVIOContextWrapper* wrapper = static_cast<AVIOContextWrapper*>(opaque);
87
88 if (wrapper == nullptr)
89 return AUDACITY_AVERROR(EINVAL);
90
91 return wrapper->Read(buf, size);
92}
#define AUDACITY_AVERROR(e)
Definition: FFmpegTypes.h:28
virtual int Read(uint8_t *buf, int size)=0

References AUDACITY_AVERROR, Read(), and size.

Referenced by Open().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FileSeek()

int64_t AVIOContextWrapper::FileSeek ( void *  opaque,
int64_t  pos,
int  whence 
)
staticprivate

Definition at line 102 of file AVIOContextWrapper.cpp.

103{
104 AVIOContextWrapper* wrapper = static_cast<AVIOContextWrapper*>(opaque);
105 if (!(wrapper && wrapper->mpFile))
106 return {};
107
108 wxSeekMode mode = wxFromStart;
109
110 switch (whence & ~AVSEEK_FORCE)
111 {
112 case (SEEK_SET):
113 mode = wxFromStart;
114 break;
115 case (SEEK_CUR):
116 mode = wxFromCurrent;
117 break;
118 case (SEEK_END):
119 mode = wxFromEnd;
120 break;
121 case (AVSEEK_SIZE):
122 return wrapper->mpFile->Length();
123 }
124
125
126 return wrapper->mpFile->Seek(pos, mode);
127}
#define AVSEEK_SIZE
#define AVSEEK_FORCE
std::unique_ptr< wxFile > mpFile
This is held indirectly by unique_ptr just so it can be swapped.

References AVSEEK_FORCE, AVSEEK_SIZE, and mpFile.

Referenced by Open().

Here is the caller graph for this function:

◆ FileWrite()

int AVIOContextWrapper::FileWrite ( void *  opaque,
const uint8_t *  buf,
int  size 
)
staticprivate

Definition at line 94 of file AVIOContextWrapper.cpp.

95{
96 AVIOContextWrapper* wrapper = static_cast<AVIOContextWrapper*>(opaque);
97 if (!(wrapper && wrapper->mpFile))
98 return {};
99 return wrapper->mpFile->Write(buf, size);
100}

References mpFile, and size.

Referenced by Open().

Here is the caller graph for this function:

◆ GetBufEnd()

virtual unsigned char * AVIOContextWrapper::GetBufEnd ( ) const
pure virtualnoexcept

◆ GetBuffer()

virtual unsigned char * AVIOContextWrapper::GetBuffer ( ) const
pure virtualnoexcept

◆ GetBufferSize()

virtual int AVIOContextWrapper::GetBufferSize ( ) const
pure virtualnoexcept

◆ GetBufPtr()

virtual unsigned char * AVIOContextWrapper::GetBufPtr ( ) const
pure virtualnoexcept

◆ GetDirect()

virtual int AVIOContextWrapper::GetDirect ( ) const
pure virtualnoexcept

◆ GetEofReached()

virtual int AVIOContextWrapper::GetEofReached ( ) const
pure virtualnoexcept

◆ GetError()

virtual int AVIOContextWrapper::GetError ( ) const
pure virtualnoexcept

◆ GetOpaque()

virtual void * AVIOContextWrapper::GetOpaque ( ) const
pure virtualnoexcept

◆ GetPos()

virtual int64_t AVIOContextWrapper::GetPos ( ) const
pure virtualnoexcept

◆ GetSeekable()

virtual int AVIOContextWrapper::GetSeekable ( ) const
pure virtualnoexcept

◆ GetWrappedValue() [1/2]

const AVIOContext * AVIOContextWrapper::GetWrappedValue ( ) const
noexcept

Definition at line 31 of file AVIOContextWrapper.cpp.

32{
33 return mAVIOContext;
34}

References mAVIOContext.

◆ GetWrappedValue() [2/2]

AVIOContext * AVIOContextWrapper::GetWrappedValue ( )
noexcept

Definition at line 26 of file AVIOContextWrapper.cpp.

27{
28 return mAVIOContext;
29}

References mAVIOContext.

◆ GetWriteFlag()

virtual int AVIOContextWrapper::GetWriteFlag ( ) const
pure virtualnoexcept

◆ Open()

AVIOContextWrapper::OpenResult AVIOContextWrapper::Open ( const wxString &  fileName,
bool  forWriting 
)

Definition at line 48 of file AVIOContextWrapper.cpp.

49{
50 auto pFile = std::make_unique<wxFile>();
51 if (!pFile->Open(fileName, forWriting ? wxFile::write : wxFile::read))
53
54 unsigned char* buffer =
55 static_cast<unsigned char*>(mFFmpeg.av_malloc(BufferSize));
56
57 if (buffer == nullptr)
59
60 /*
61 "The buffer must be allocated with av_malloc() and friends. It may be freed
62 and replaced with a new buffer by libavformat. AVIOContext.buffer holds the
63 buffer currently in use, which must be later freed with av_free()."
64
65 See ~AVIOContextWrapperImpl() for the deallocation
66 */
68 buffer, BufferSize,
69 static_cast<int>(forWriting),
70 this,
72 );
73
74 if (mAVIOContext == nullptr) {
75 mFFmpeg.av_free(buffer);
77 }
78
79 mpFile = move(pFile);
80
82}
constexpr int BufferSize
static int64_t FileSeek(void *opaque, int64_t pos, int whence)
static int FileRead(void *opaque, uint8_t *buf, int size)
static int FileWrite(void *opaque, const uint8_t *buf, int size)
AVIOContext *(* avio_alloc_context)(unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, const uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
void *(* av_malloc)(size_t size)

References AVUtilFunctions::av_free, AVUtilFunctions::av_malloc, AVFormatFunctions::avio_alloc_context, BufferSize, FileOpenFailed, FileRead(), FileSeek(), FileWrite(), mAVIOContext, mFFmpeg, mpFile, NoMemory, and Success.

Here is the call graph for this function:

◆ operator=() [1/2]

AVIOContextWrapper & AVIOContextWrapper::operator= ( AVIOContextWrapper &&  )
delete

◆ operator=() [2/2]

AVIOContextWrapper & AVIOContextWrapper::operator= ( AVIOContextWrapper )
delete

◆ Read()

virtual int AVIOContextWrapper::Read ( uint8_t *  buf,
int  size 
)
protectedpure virtual

Referenced by FileRead().

Here is the caller graph for this function:

◆ SetDirect()

virtual void AVIOContextWrapper::SetDirect ( int  direct)
pure virtualnoexcept

◆ SetError()

virtual void AVIOContextWrapper::SetError ( int  error)
pure virtualnoexcept

◆ SetOpaque()

virtual void AVIOContextWrapper::SetOpaque ( void *  opaque)
pure virtualnoexcept

◆ SetSeekable()

virtual void AVIOContextWrapper::SetSeekable ( int  seekable)
pure virtualnoexcept

◆ SetWriteFlag()

virtual void AVIOContextWrapper::SetWriteFlag ( int  write_flag)
pure virtualnoexcept

Member Data Documentation

◆ mAVIOContext

AVIOContext* AVIOContextWrapper::mAVIOContext { nullptr }
protected

Definition at line 74 of file AVIOContextWrapper.h.

Referenced by GetWrappedValue(), Open(), and ~AVIOContextWrapper().

◆ mFFmpeg

const FFmpegFunctions& AVIOContextWrapper::mFFmpeg
protected

Definition at line 73 of file AVIOContextWrapper.h.

Referenced by Open(), and ~AVIOContextWrapper().

◆ mpFile

std::unique_ptr<wxFile> AVIOContextWrapper::mpFile
protected

This is held indirectly by unique_ptr just so it can be swapped.

Definition at line 77 of file AVIOContextWrapper.h.

Referenced by FileSeek(), FileWrite(), and Open().


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