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

#include <AVIOContextWrapper.h>

Collaboration diagram for AVIOContextWrapper:
[legend]

Public Types

enum  OpenResult { OpenResult::Success, OpenResult::FileOpenFailed, OpenResult::NoMemory, OpenResult::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 Attributes

const FFmpegFunctionsmFFmpeg
 
AVIOContextmAVIOContext { nullptr }
 

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)
 

Private Attributes

std::unique_ptr< wxFile > mpFile
 This is held indirectly by unique_ptr just so it can be swapped. More...
 

Detailed Description

Definition at line 21 of file AVIOContextWrapper.h.

Member Enumeration Documentation

◆ OpenResult

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 }

◆ ~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 }

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  if (!(wrapper && wrapper->mpFile))
88  return {};
89  return wrapper->mpFile->Read(buf, size);
90 }

References mpFile, and size.

Referenced by Open().

Here is the caller graph for this function:

◆ FileSeek()

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

Definition at line 100 of file AVIOContextWrapper.cpp.

101 {
102  AVIOContextWrapper* wrapper = static_cast<AVIOContextWrapper*>(opaque);
103  if (!(wrapper && wrapper->mpFile))
104  return {};
105 
106  wxSeekMode mode = wxFromStart;
107 
108  switch (whence & ~AVSEEK_FORCE)
109  {
110  case (SEEK_SET):
111  mode = wxFromStart;
112  break;
113  case (SEEK_CUR):
114  mode = wxFromCurrent;
115  break;
116  case (SEEK_END):
117  mode = wxFromEnd;
118  break;
119  case (AVSEEK_SIZE):
120  return wrapper->mpFile->Length();
121  }
122 
123 
124  return wrapper->mpFile->Seek(pos, mode);
125 }

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 92 of file AVIOContextWrapper.cpp.

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

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)
58  return OpenResult::NoMemory;
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);
76  return OpenResult::NoMemory;
77  }
78 
79  mpFile = move(pFile);
80 
81  return OpenResult::Success;
82 }

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

◆ 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 72 of file AVIOContextWrapper.h.

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

◆ mFFmpeg

const FFmpegFunctions& AVIOContextWrapper::mFFmpeg
protected

Definition at line 71 of file AVIOContextWrapper.h.

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

◆ mpFile

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

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

Definition at line 80 of file AVIOContextWrapper.h.

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


The documentation for this class was generated from the following files:
size
size_t size
Definition: ffmpeg-2.3.6-single-header.h:412
AVIOContextWrapper::mpFile
std::unique_ptr< wxFile > mpFile
This is held indirectly by unique_ptr just so it can be swapped.
Definition: AVIOContextWrapper.h:80
BasicUI::ProgressResult::Success
@ Success
AVIOContextWrapper
Definition: AVIOContextWrapper.h:22
AVIOContextWrapper::OpenResult::FileOpenFailed
@ FileOpenFailed
AVIOContextWrapper::mFFmpeg
const FFmpegFunctions & mFFmpeg
Definition: AVIOContextWrapper.h:71
AVIOContextWrapper::FileSeek
static int64_t FileSeek(void *opaque, int64_t pos, int whence)
Definition: AVIOContextWrapper.cpp:100
AVSEEK_SIZE
#define AVSEEK_SIZE
Definition: AVIOContextWrapper.cpp:16
AVUtilFunctions::av_free
void(* av_free)(void *ptr)
Definition: AVUtilFunctions.h:23
AVIOContextWrapper::OpenResult::NoMemory
@ NoMemory
AVIOContextWrapper::OpenResult::Success
@ Success
AVIOContextWrapper::mAVIOContext
AVIOContext * mAVIOContext
Definition: AVIOContextWrapper.h:72
AVFormatFunctions::avio_context_free
void(* avio_context_free)(AVIOContext **s)
Definition: AVFormatFunctions.h:40
BufferSize
constexpr int BufferSize
Definition: AVIOContextWrapper.cpp:18
AVIOContextWrapper::FileWrite
static int FileWrite(void *opaque, const uint8_t *buf, int size)
Definition: AVIOContextWrapper.cpp:92
AVSEEK_FORCE
#define AVSEEK_FORCE
Definition: AVIOContextWrapper.cpp:15
AVFormatFunctions::avio_alloc_context
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))
Definition: AVFormatFunctions.h:34
AVIOContextWrapper::FileRead
static int FileRead(void *opaque, uint8_t *buf, int size)
Definition: AVIOContextWrapper.cpp:84
AVUtilFunctions::av_malloc
void *(* av_malloc)(size_t size)
Definition: AVUtilFunctions.h:22