1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
/**********************************************************************
Audacity: A Digital Audio Editor
AVDictionaryWrapper.cpp
Dmitry Vedenko
**********************************************************************/
#include "AVDictionaryWrapper.h"
#include "FFmpegFunctions.h"
#include "FFmpegTypes.h"
#include <utility>
AVDictionaryWrapper::AVDictionaryWrapper(
const FFmpegFunctions& ffmpeg) noexcept
: mFFmpeg(ffmpeg)
{
}
AVDictionaryWrapper::AVDictionaryWrapper(
const FFmpegFunctions& ffmpeg, AVDictionary* rhs) noexcept
: mFFmpeg(ffmpeg)
{
if (rhs != nullptr)
mFFmpeg.av_dict_copy(&mAVDictionary, rhs, 0);
}
AVDictionaryWrapper::AVDictionaryWrapper(
const AVDictionaryWrapper& rhs) noexcept
: AVDictionaryWrapper(rhs.mFFmpeg, rhs.mAVDictionary)
{
}
AVDictionaryWrapper::AVDictionaryWrapper(
AVDictionaryWrapper&& rhs) noexcept
: mFFmpeg(rhs.mFFmpeg)
{
*this = std::move(rhs);
}
AVDictionaryWrapper&
AVDictionaryWrapper::operator=(const AVDictionaryWrapper& rhs) noexcept
{
assert(&mFFmpeg == &rhs.mFFmpeg);
if (rhs.mAVDictionary != nullptr)
mFFmpeg.av_dict_copy(&mAVDictionary, rhs.mAVDictionary, 0);
return *this;
}
AVDictionaryWrapper&
AVDictionaryWrapper::operator=(AVDictionaryWrapper&& rhs) noexcept
{
assert(&mFFmpeg == &rhs.mFFmpeg);
std::swap(mAVDictionary, rhs.mAVDictionary);
return *this;
}
AVDictionary* AVDictionaryWrapper::GetWrappedValue() noexcept
{
return mAVDictionary;
}
const AVDictionary* AVDictionaryWrapper::GetWrappedValue() const noexcept
{
return mAVDictionary;
}
AVDictionaryWrapper::~AVDictionaryWrapper()
{
mFFmpeg.av_dict_free(&mAVDictionary);
}
void AVDictionaryWrapper::Set(
const std::string_view& key, const std::string& value,
int flags) noexcept
{
mFFmpeg.av_dict_set(&mAVDictionary, key.data(), value.data(), flags);
}
void AVDictionaryWrapper::Set(
const std::string_view& key, const wxString& value, int flags) noexcept
{
mFFmpeg.av_dict_set(&mAVDictionary, key.data(), value.ToUTF8().data(), flags);
}
void AVDictionaryWrapper::Set(
const std::string_view& key, const char* value, int flags) noexcept
{
mFFmpeg.av_dict_set(
&mAVDictionary, key.data(), value, flags);
}
std::string_view AVDictionaryWrapper::Get(
const std::string_view& key, const std::string_view& defaultValue,
int flags) const
{
if (mAVDictionary == nullptr)
return defaultValue;
AudacityAVDictionaryEntry* entry =
mFFmpeg.av_dict_get(mAVDictionary, key.data(), nullptr, flags);
if (entry != nullptr)
return entry->value;
return defaultValue;
}
bool AVDictionaryWrapper::HasValue(
const std::string_view& key, int flags) const noexcept
{
if (mAVDictionary == nullptr)
return false;
AudacityAVDictionaryEntry* entry =
mFFmpeg.av_dict_get(mAVDictionary, key.data(), nullptr, flags);
return entry != nullptr;
}
AVDictionary* AVDictionaryWrapper::Release() noexcept
{
auto temp = mAVDictionary;
mAVDictionary = nullptr;
return temp;
}
|