5#include "codec_bridge.hpp"
6#include "../size_2d.hpp"
7#include "../string.hpp"
8#include "../shims/stdvariant.hpp"
9#include "../utilities/system_info.hpp"
17 inline HandleGuard<CodecBridge::CodecConfig>::HandleGuard(
void* handle) noexcept
18 : HandleGuard<CodecBridge::CodecConfig>(handle, [](
void* handle) { CVB_CALL_CAPI(ReleaseObject(handle)); })
47 return Internal::DoResCallObjectOut<CodecConfig>([&](
void*& handle)
49 return CVB_CALL_CAPI(CVCBCreateCodecConfigTyped(provider.c_str(), handle));
58 return std::make_unique<CodecConfig>(std::move(guard));
61 explicit CodecConfig(HandleGuard<CodecConfig>&& guard) noexcept
62 : handle_(std::move(guard))
67 CodecConfig(
const CodecConfig& other) =
delete;
68 CodecConfig& operator=(
const CodecConfig& other) =
delete;
69 CodecConfig(CodecConfig&& other) =
delete;
70 CodecConfig& operator=(CodecConfig&& other) =
delete;
72 ~CodecConfig() =
default;
74 void* Handle() const noexcept
76 return handle_.Handle();
100 return Property<int64_t>(CExports::CVCBCP_Bitrate);
110 SetProperty(bitRate, CExports::CVCBCP_Bitrate);
120 return { Property<int>(CExports::CVCBCP_Width), Property<int>(CExports::CVCBCP_Height) };
133 return Property<int>(CExports::CVCBCP_ID);
143 SetProperty(size.
Width(), CExports::CVCBCP_Width);
144 SetProperty(size.
Height(), CExports::CVCBCP_Height);
154 auto timeBase = Property<CExports::CVCBRational>(CExports::CVCBCP_TimeBase);
155 return { timeBase.Numerator, timeBase.Denominator };
165 SetProperty(*
reinterpret_cast<CExports::CVCBRational*
>(&timeBase), CExports::CVCBCP_TimeBase);
175 return Property<int>(CExports::CVCBCP_GOPSize);
185 SetProperty(gopSize, CExports::CVCBCP_GOPSize);
195 return Property<int>(CExports::CVCBCP_MaxBFrames);
205 SetProperty(maxBFrames, CExports::CVCBCP_MaxBFrames);
229 SetProperty(
static_cast<CExports::CVCBPixelFormat
>(pixelFormat), CExports::CVCBCP_PixelFormat);
269 size_t size =
sizeof(T);
270 CVB_CALL_CAPI_CHECKED(CVCBCodecConfigGetProperty(Handle(), property, &value, size, optionName.empty() ?
nullptr : ToBytes(optionName).c_str()));
275 void SetProperty(
const T& value, CExports::CVCBCodecProperty property,
const Cvb::String& optionName =
Cvb::String())
277 CVB_CALL_CAPI_CHECKED(CVCBCodecConfigSetProperty(Handle(), property,
const_cast<T*
>(&value),
sizeof(T), optionName.empty() ?
nullptr : ToBytes(optionName).c_str()));
284 asciiText.reserve(text.size());
285 for (
const auto& c : text)
286 asciiText.push_back(
static_cast<char>(c));
295 HandleGuard<CodecConfig> handle_;
299 inline Cvb::String CodecConfig::Property<Cvb::String>(CExports::CVCBCodecProperty property,
const Cvb::String& optionName)
const
303 CVB_CALL_CAPI_CHECKED(CVCBCodecConfigGetProperty(Handle(), property,
nullptr, size, optionName.empty() ?
nullptr : ToBytes(optionName).c_str()));
306 CVB_CALL_CAPI_CHECKED(CVCBCodecConfigGetProperty(Handle(), property, buffer.data(), size, optionName.empty() ?
nullptr : ToBytes(optionName).c_str()));
308 return { buffer.begin(), buffer.end() - 1 };
312 inline void CodecConfig::SetProperty<Cvb::String>(
const Cvb::String& value, CExports::CVCBCodecProperty property,
const Cvb::String& optionName)
314 CVB_CALL_CAPI_CHECKED(CVCBCodecConfigSetProperty(Handle(), property,
const_cast<char*
>(ToBytes(value).c_str()), value.size() + 1, optionName.empty() ?
nullptr : ToBytes(optionName).c_str()));
319 return Property<Cvb::String>(CExports::CVCBCP_Name);
324 return Property<Cvb::String>(CExports::CVCBCP_JSON);
328 inline int64_t CodecConfig::Option<int64_t>(
const Cvb::String& name)
const
330 return Property<int64_t>(CExports::CVCBCP_IntOption, name);
336 return Property<Cvb::String>(CExports::CVCBCP_StringOption, name);
340 inline double CodecConfig::Option<double>(
const Cvb::String& name)
const
342 return Property<double>(CExports::CVCBCP_DoubleOption, name);
346 inline Rational CodecConfig::Option<Rational>(
const Cvb::String& name)
const
348 auto rational = Property<CExports::CVCBRational>(CExports::CVCBCP_DoubleOption, name);
349 return { rational.Numerator, rational.Denominator };
355 SetProperty(value, CExports::CVCBCP_StringOption, name);
359 inline void CodecConfig::AddOption<double>(
const Cvb::String& name,
const double& value)
361 SetProperty(value, CExports::CVCBCP_DoubleOption, name);
365 inline void CodecConfig::AddOption<Rational>(
const Cvb::String& name,
const Rational& value)
367 SetProperty(*
reinterpret_cast<const CExports::CVCBRational*
>(&value), CExports::CVCBCP_RationalOption, name);
371 inline void CodecConfig::AddOption<int64_t>(
const Cvb::String& name,
const int64_t& value)
373 SetProperty(value, CExports::CVCBCP_IntOption, name);
378 SetProperty(url, CExports::CVCBCP_URL);
379 return Property<Cvb::String>(CExports::CVCBCP_SDP);
A configuration defining a codec.
Definition: codec_config.hpp:33
Cvb::String ToJson() const
Create a JSON string that defines this configuration.
Definition: codec_config.hpp:322
Cvb::String Name() const
Get the name of the codec.
Definition: codec_config.hpp:317
Size2D< int > Size() const
Get the size of the frames.
Definition: codec_config.hpp:118
void SetGOPSize(int gopSize)
Set the GOP size.
Definition: codec_config.hpp:183
void AddOption(const Cvb::String &name, const T &value)
Add a generic option from the codec.
int MaxBFrames() const
Get the maximum B frames.
Definition: codec_config.hpp:193
CodecBridge::PixelFormat PixelFormat() const
Get the pixel format used by this codec.
Definition: codec_config.hpp:215
void SetBitRate(int64_t bitRate)
Set the bit rate.
Definition: codec_config.hpp:108
void SetMaxBFrames(int maxBFrames)
Set the maximum B frames.
Definition: codec_config.hpp:203
static std::unique_ptr< CodecConfig > Create(const Cvb::String &provider)
Creates a codec config from given provider.
Definition: codec_config.hpp:45
void SetTimeBase(Rational timeBase)
Set the time base used by the codec.
Definition: codec_config.hpp:163
Rational TimeBase() const
The time base used by the codec.
Definition: codec_config.hpp:152
int ID() const
Get the codec ID.
Definition: codec_config.hpp:131
int64_t BitRate() const
Get the bit rate.
Definition: codec_config.hpp:98
Cvb::String SessionDescription(const Cvb::String &url)
Get the contend of the session description protocol.
Definition: codec_config.hpp:376
void SetSize(Size2D< int > size)
Set the size of the frames.
Definition: codec_config.hpp:141
void SetPixelFormat(CodecBridge::PixelFormat pixelFormat)
Set the pixel format used by this codec.
Definition: codec_config.hpp:227
T Option(const Cvb::String &name) const
Get a generic option from the codec.
int GOPSize() const
Get the GOP size.
Definition: codec_config.hpp:173
A pair of rational numbers.
Definition: codec_bridge.hpp:200
T Height() const noexcept
Gets the vertical component of the size.
Definition: size_2d.hpp:79
T Width() const noexcept
Gets the horizontal component of the size.
Definition: size_2d.hpp:59
PixelFormat
Subset of FFmpeg pixel formats.
Definition: codec_bridge.hpp:92
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24