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)); })
31 class CodecConfig final
46 return Internal::DoResCallObjectOut<CodecConfig>(
47 [&](
void *&handle) {
return CVB_CALL_CAPI(CVCBCreateCodecConfigTyped(provider.c_str(), handle)); });
55 return std::make_unique<CodecConfig>(
std::move(guard));
58 explicit CodecConfig(HandleGuard<CodecConfig> &&guard) noexcept
63 CodecConfig(
const CodecConfig &other) =
delete;
64 CodecConfig &operator=(
const CodecConfig &other) =
delete;
65 CodecConfig(CodecConfig &&other) =
delete;
66 CodecConfig &operator=(CodecConfig &&other) =
delete;
68 ~CodecConfig() =
default;
70 void *Handle() const noexcept
72 return handle_.Handle();
96 return Property<int64_t>(CExports::CVCBCP_Bitrate);
106 SetProperty(bitRate, CExports::CVCBCP_Bitrate);
116 return {Property<int>(CExports::CVCBCP_Width), Property<int>(CExports::CVCBCP_Height)};
129 return Property<int>(CExports::CVCBCP_ID);
139 SetProperty(size.
Width(), CExports::CVCBCP_Width);
140 SetProperty(size.
Height(), CExports::CVCBCP_Height);
150 auto timeBase = Property<CExports::CVCBRational>(CExports::CVCBCP_TimeBase);
151 return {timeBase.Numerator, timeBase.Denominator};
161 SetProperty(*
reinterpret_cast<CExports::CVCBRational *
>(&timeBase), CExports::CVCBCP_TimeBase);
171 return Property<int>(CExports::CVCBCP_GOPSize);
181 SetProperty(gopSize, CExports::CVCBCP_GOPSize);
191 return Property<int>(CExports::CVCBCP_MaxBFrames);
201 SetProperty(maxBFrames, CExports::CVCBCP_MaxBFrames);
225 SetProperty(
static_cast<CExports::CVCBPixelFormat
>(pixelFormat), CExports::CVCBCP_PixelFormat);
264 size_t size =
sizeof(T);
265 CVB_CALL_CAPI_CHECKED(CVCBCodecConfigGetProperty(Handle(), property, &value, size,
266 optionName.empty() ?
nullptr : ToBytes(optionName).c_str()));
271 void SetProperty(
const T &value, CExports::CVCBCodecProperty property,
274 CVB_CALL_CAPI_CHECKED(CVCBCodecConfigSetProperty(
275 Handle(), property,
const_cast<T *
>(&value),
sizeof(T),
276 optionName.empty() ?
nullptr
277 : ToBytes(optionName).c_str()));
284 asciiText.reserve(text.size());
285 for (
const auto &c : text)
286 asciiText.push_back(
static_cast<char>(c));
290 static std::string ToBytes(
const std::string &text)
295 HandleGuard<CodecConfig> handle_;
31 class CodecConfig final {
…};
299 inline Cvb::String CodecConfig::Property<Cvb::String>(CExports::CVCBCodecProperty property,
304 CVB_CALL_CAPI_CHECKED(CVCBCodecConfigGetProperty(Handle(), property,
nullptr, size,
305 optionName.empty() ?
nullptr : ToBytes(optionName).c_str()));
307 std::vector<char> buffer(size);
308 CVB_CALL_CAPI_CHECKED(CVCBCodecConfigGetProperty(Handle(), property, buffer.data(), size,
309 optionName.empty() ?
nullptr : ToBytes(optionName).c_str()));
311 return {buffer.begin(), buffer.end() - 1};
315 inline void CodecConfig::SetProperty<Cvb::String>(
const Cvb::String &value, CExports::CVCBCodecProperty property,
318 CVB_CALL_CAPI_CHECKED(CVCBCodecConfigSetProperty(
319 Handle(), property,
const_cast<char *
>(ToBytes(value).c_str()), value.size() + 1,
320 optionName.empty() ?
nullptr
321 : ToBytes(optionName).c_str()));
326 return Property<Cvb::String>(CExports::CVCBCP_Name);
331 return Property<Cvb::String>(CExports::CVCBCP_JSON);
337 return Property<int64_t>(CExports::CVCBCP_IntOption, name);
343 return Property<Cvb::String>(CExports::CVCBCP_StringOption, name);
349 return Property<double>(CExports::CVCBCP_DoubleOption, name);
355 auto rational = Property<CExports::CVCBRational>(CExports::CVCBCP_DoubleOption, name);
356 return {rational.Numerator, rational.Denominator};
362 SetProperty(value, CExports::CVCBCP_StringOption, name);
368 SetProperty(value, CExports::CVCBCP_DoubleOption, name);
374 SetProperty(*
reinterpret_cast<const CExports::CVCBRational *
>(&value), CExports::CVCBCP_RationalOption, name);
380 SetProperty(value, CExports::CVCBCP_IntOption, name);
385 SetProperty(url, CExports::CVCBCP_URL);
386 return Property<Cvb::String>(CExports::CVCBCP_SDP);
Cvb::String ToJson() const
Create a JSON string that defines this configuration.
Definition codec_config.hpp:329
Cvb::String Name() const
Get the name of the codec.
Definition codec_config.hpp:324
Size2D< int > Size() const
Get the size of the frames.
Definition codec_config.hpp:114
void SetGOPSize(int gopSize)
Set the GOP size.
Definition codec_config.hpp:179
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:189
CodecBridge::PixelFormat PixelFormat() const
Get the pixel format used by this codec.
Definition codec_config.hpp:211
void SetBitRate(int64_t bitRate)
Set the bit rate.
Definition codec_config.hpp:104
void SetMaxBFrames(int maxBFrames)
Set the maximum B frames.
Definition codec_config.hpp:199
static std::unique_ptr< CodecConfig > Create(const Cvb::String &provider)
Creates a codec config from given provider.
Definition codec_config.hpp:44
void SetTimeBase(Rational timeBase)
Set the time base used by the codec.
Definition codec_config.hpp:159
Rational TimeBase() const
The time base used by the codec.
Definition codec_config.hpp:148
int ID() const
Get the codec ID.
Definition codec_config.hpp:127
int64_t BitRate() const
Get the bit rate.
Definition codec_config.hpp:94
Cvb::String SessionDescription(const Cvb::String &url)
Get the contend of the session description protocol.
Definition codec_config.hpp:383
void SetSize(Size2D< int > size)
Set the size of the frames.
Definition codec_config.hpp:137
void SetPixelFormat(CodecBridge::PixelFormat pixelFormat)
Set the pixel format used by this codec.
Definition codec_config.hpp:223
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:169
A pair of rational numbers.
Definition codec_bridge.hpp:199
Stores a pair of numbers that represents the width and the height of a subject, typically a rectangle...
Definition size_2d.hpp:20
T Height() const noexcept
Gets the vertical component of the size.
Definition size_2d.hpp:77
T Width() const noexcept
Gets the horizontal component of the size.
Definition size_2d.hpp:57
cvbbool_t ReleaseObject(OBJ &Object)
Namespace for encoding and decoding videos.
Definition codec_bridge.hpp:24
PixelFormat
Subset of FFmpeg pixel formats.
Definition codec_bridge.hpp:91
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
std::string String
String for wide characters or unicode characters.
Definition string.hpp:49