Audacity  3.0.3
AVDictionaryWrapper.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  AVDictionaryWrapper.cpp
6 
7  Dmitry Vedenko
8 
9 **********************************************************************/
10 
11 #include "AVDictionaryWrapper.h"
12 
13 #include "FFmpegFunctions.h"
14 #include "FFmpegTypes.h"
15 
16 #include <utility>
17 
19  const FFmpegFunctions& ffmpeg) noexcept
20  : mFFmpeg(ffmpeg)
21 {
22 }
23 
25  const FFmpegFunctions& ffmpeg, AVDictionary* rhs) noexcept
26  : mFFmpeg(ffmpeg)
27 {
28  if (rhs != nullptr)
29  mFFmpeg.av_dict_copy(&mAVDictionary, rhs, 0);
30 }
31 
33  const AVDictionaryWrapper& rhs) noexcept
34  : AVDictionaryWrapper(rhs.mFFmpeg, rhs.mAVDictionary)
35 {
36 }
37 
39  AVDictionaryWrapper&& rhs) noexcept
40  : mFFmpeg(rhs.mFFmpeg)
41 {
42  *this = std::move(rhs);
43 }
44 
47 {
48  assert(&mFFmpeg == &rhs.mFFmpeg);
49 
50  if (rhs.mAVDictionary != nullptr)
51  mFFmpeg.av_dict_copy(&mAVDictionary, rhs.mAVDictionary, 0);
52 
53  return *this;
54 }
55 
58 {
59  assert(&mFFmpeg == &rhs.mFFmpeg);
60 
61  std::swap(mAVDictionary, rhs.mAVDictionary);
62 
63  return *this;
64 }
65 
67 {
68  return mAVDictionary;
69 }
70 
72 {
73  return mAVDictionary;
74 }
75 
77 {
79 }
80 
82  const std::string_view& key, const std::string& value,
83  int flags) noexcept
84 {
85  mFFmpeg.av_dict_set(&mAVDictionary, key.data(), value.data(), flags);
86 }
87 
89  const std::string_view& key, const wxString& value, int flags) noexcept
90 {
91  mFFmpeg.av_dict_set(&mAVDictionary, key.data(), value.ToUTF8().data(), flags);
92 }
93 
95  const std::string_view& key, const char* value, int flags) noexcept
96 {
97  mFFmpeg.av_dict_set(
98  &mAVDictionary, key.data(), value, flags);
99 }
100 
101 std::string_view AVDictionaryWrapper::Get(
102  const std::string_view& key, const std::string_view& defaultValue,
103  int flags) const
104 {
105  if (mAVDictionary == nullptr)
106  return defaultValue;
107 
109  mFFmpeg.av_dict_get(mAVDictionary, key.data(), nullptr, flags);
110 
111  if (entry != nullptr)
112  return entry->value;
113 
114  return defaultValue;
115 }
116 
118  const std::string_view& key, int flags) const noexcept
119 {
120  if (mAVDictionary == nullptr)
121  return false;
122 
124  mFFmpeg.av_dict_get(mAVDictionary, key.data(), nullptr, flags);
125 
126  return entry != nullptr;
127 }
128 
130 {
131  auto temp = mAVDictionary;
132  mAVDictionary = nullptr;
133 
134  return temp;
135 }
AVDictionaryWrapper::Release
AVDictionary * Release() noexcept
Definition: AVDictionaryWrapper.cpp:129
AVDictionary
struct AVDictionary AVDictionary
Definition: FFmpegTypes.h:112
AudacityAVDictionaryEntry
Simply an overlay of AVDictionaryEntry, but we avoid including that type.
Definition: FFmpegTypes.h:138
AVUtilFunctions::av_dict_free
void(* av_dict_free)(AVDictionary **m)
Definition: AVUtilFunctions.h:24
AVDictionaryWrapper::operator=
AVDictionaryWrapper & operator=(const AVDictionaryWrapper &rhs) noexcept
Definition: AVDictionaryWrapper.cpp:46
AVDictionaryWrapper::mAVDictionary
AVDictionary * mAVDictionary
Definition: AVDictionaryWrapper.h:58
AVDictionaryWrapper
Definition: AVDictionaryWrapper.h:24
AVDictionaryWrapper::Get
std::string_view Get(const std::string_view &key, const std::string_view &defaultValue, int flags=0) const
Definition: AVDictionaryWrapper.cpp:101
entry
static ProjectFileIORegistry::WriterEntry entry
Definition: ProjectSettings.cpp:197
AVDictionaryWrapper::mFFmpeg
const FFmpegFunctions & mFFmpeg
Definition: AVDictionaryWrapper.h:57
AVDictionaryWrapper::GetWrappedValue
AVDictionary * GetWrappedValue() noexcept
Definition: AVDictionaryWrapper.cpp:66
AVDictionaryWrapper::~AVDictionaryWrapper
virtual ~AVDictionaryWrapper()
Definition: AVDictionaryWrapper.cpp:76
AVDictionaryWrapper::AVDictionaryWrapper
AVDictionaryWrapper(const AVDictionaryWrapper &rhs) noexcept
Unlike the other FFmpeg wrapper classes, this one is copyable.
Definition: AVDictionaryWrapper.cpp:32
FFmpegFunctions
Definition: FFmpegFunctions.h:85
AVDictionaryWrapper.h
anonymous_namespace{NoteTrack.cpp}::swap
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:735
AVDictionaryWrapper::Set
void Set(const std::string_view &key, const std::string &value, int flags=0) noexcept
Definition: AVDictionaryWrapper.cpp:81
AVDictionaryWrapper::HasValue
bool HasValue(const std::string_view &key, int flags=0) const noexcept
Definition: AVDictionaryWrapper.cpp:117
key
static const AudacityProject::AttachedObjects::RegisteredFactory key
Definition: CommandManager.cpp:201
FFmpegFunctions.h
AVUtilFunctions::av_dict_get
AudacityAVDictionaryEntry *(* av_dict_get)(const AVDictionary *m, const char *key, const AudacityAVDictionaryEntry *prev, int flags)
Definition: AVUtilFunctions.h:26
FFmpegTypes.h