Audacity 3.2.0
AVIOContextWrapper.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 AVIOContextWrapper.h
6
7 Dmitry Vedenko
8
9**********************************************************************/
10
11#pragma once
12
13#include <cstdint>
14#include <memory>
15
16#include <wx/file.h>
17
18struct FFmpegFunctions;
19typedef struct AVIOContext AVIOContext;
20
21class FFMPEG_SUPPORT_API AVIOContextWrapper
22{
23public:
24 enum class OpenResult
25 {
26 Success,
27 FileOpenFailed,
28 NoMemory,
29 InternalError
30 };
31
34
37
38 explicit AVIOContextWrapper(const FFmpegFunctions& ffmpeg) noexcept;
39
40 AVIOContext* GetWrappedValue() noexcept;
41 const AVIOContext* GetWrappedValue() const noexcept;
42
43 virtual ~AVIOContextWrapper();
44
45 OpenResult Open(const wxString& fileName, bool forWriting);
46
47 virtual unsigned char* GetBuffer() const noexcept = 0;
48 virtual int GetBufferSize() const noexcept = 0;
49 virtual unsigned char* GetBufPtr() const noexcept = 0;
50 virtual unsigned char* GetBufEnd() const noexcept = 0;
51
52 virtual void* GetOpaque() const noexcept = 0;
53 virtual void SetOpaque(void* opaque) noexcept = 0;
54
55 virtual int64_t GetPos() const noexcept = 0;
56
57 virtual int GetEofReached() const noexcept = 0;
58
59 virtual int GetWriteFlag() const noexcept = 0;
60 virtual void SetWriteFlag(int write_flag) noexcept = 0;
61
62 virtual int GetError() const noexcept = 0;
63 virtual void SetError(int error) noexcept = 0;
64
65 virtual int GetSeekable() const noexcept = 0;
66 virtual void SetSeekable(int seekable) noexcept = 0;
67
68 virtual int GetDirect() const noexcept = 0;
69 virtual void SetDirect(int direct) noexcept = 0;
70
71protected:
72 virtual int Read(uint8_t* buf, int size) = 0;
73 const FFmpegFunctions& mFFmpeg;
74 AVIOContext* mAVIOContext { nullptr };
75
77 std::unique_ptr<wxFile> mpFile;
78
79private:
80 static int FileRead(void* opaque, uint8_t* buf, int size);
81 static int FileWrite(void* opaque, const uint8_t* buf, int size);
82 static int64_t FileSeek(void* opaque, int64_t pos, int whence);
83};
AVIOContextWrapper & operator=(AVIOContextWrapper &)=delete
AVIOContextWrapper & operator=(AVIOContextWrapper &&)=delete
AVIOContextWrapper(AVIOContextWrapper &&)=delete
AVIOContextWrapper(const AVIOContextWrapper &)=delete
std::unique_ptr< wxFile > mpFile
This is held indirectly by unique_ptr just so it can be swapped.
bool GetError()
void SetError()
LV2_API bool GetBufferSize(const EffectDefinitionInterface &effect, int &bufferSize)