5#include "codec_bridge.hpp"
6#include "../global.hpp"
7#include "../size_2d.hpp"
17 inline HandleGuard<CodecBridge::Frame>::HandleGuard(
void *handle) noexcept
18 : HandleGuard<CodecBridge::Frame>(handle, [](
void *handle) { CVB_CALL_CAPI(
ReleaseObject(handle)); })
45 return Internal::DoResCallObjectOut<Frame>([&](
void *&handle) {
46 return CVB_CALL_CAPI(CVCBCreateFrame(size.
Width(), size.
Height(),
47 static_cast<CExports::CVCBPixelFormat
>(format), buffer, handle));
62 return Create(size, format,
nullptr);
70 return std::make_unique<Frame>(
std::move(guard));
73 explicit Frame(HandleGuard<Frame> &&guard) noexcept
78 Frame(
const Frame &other) =
delete;
79 Frame &operator=(
const Frame &other) =
delete;
80 Frame(Frame &&other) =
delete;
81 Frame &operator=(Frame &&other) =
delete;
85 void *Handle() const noexcept
87 return handle_.Handle();
97 return static_cast<int>(Property<CExports::cvbdim_t>(CExports::CVCBFP_Width));
107 return static_cast<int>(Property<CExports::cvbdim_t>(CExports::CVCBFP_Height));
129 return static_cast<int64_t
>(Property<CExports::cvbint64_t>(CExports::CVCBFP_PresentationTimestamp));
141 SetProperty(
static_cast<CExports::cvbint64_t
>(value), CExports::CVCBFP_PresentationTimestamp);
165 CVB_CALL_CAPI_CHECKED(CVCBFrameGetProperty(Handle(), CExports::CVCBFP_SEIUserData, buffer, size));
178 auto timeBase = Property<CExports::CVCBRational>(CExports::CVCBFP_TimeBase);
179 return {timeBase.Numerator, timeBase.Denominator};
193 CVB_CALL_CAPI_CHECKED(CVCBFrameSetProperty(Handle(), CExports::CVCBFP_SEIUserData, buffer, size));
204 CVB_CALL_CAPI_CHECKED(CVCBFrameSetProperty(Handle(), CExports::CVCBFP_SEIUserData,
nullptr, 0));
217 if (!CExports::IsImage(Handle()))
220 if (!CExports::ShareObject(Handle()))
223 HandleGuard<Image> guard(Handle());
234 CExports::cvbdim_t numElements = 0;
235 CExports::CVCPlaneEnumGetCount(Handle(), numElements);
236 return static_cast<int>(numElements);
249 auto candidate = planes_.find(index);
250 if (candidate != planes_.end())
251 if (
auto plane = candidate->second.lock())
254 auto plane = Internal::DoResCallShareOut<Cvb::Plane>([&](
void *&handle) {
255 return CVB_CALL_CAPI(CVCPlaneEnumGetAt(Handle(),
static_cast<CExports::cvbdim_t
>(index), handle));
258 planes_[index] = plane;
264 T Property(CExports::CVCBFrameProperty property)
const
267 size_t size =
sizeof(T);
268 CVB_CALL_CAPI_CHECKED(CVCBFrameGetProperty(Handle(), property, &value, size));
273 void SetProperty(T value, CExports::CVCBFrameProperty property)
const
275 CVB_CALL_CAPI_CHECKED(CVCBFrameSetProperty(Handle(), property, &value,
sizeof(T)));
278 HandleGuard<Frame> handle_;
279 mutable std::mutex planesMtx_;
280 mutable std::map<int, std::weak_ptr<Cvb::Plane>> planes_;
29 class Frame final {
…};
PlanePtr Plane(int index) const
Get a plane of this frame at the given index.
Definition frame.hpp:246
Size2D< int > Size() const
Get the frame size.
Definition frame.hpp:115
void UserData(void *buffer, size_t &size) const
Get the user data if available.
Definition frame.hpp:163
void SetUserData(void *buffer, size_t size)
Set the user data for this frame.
Definition frame.hpp:191
int PlanesCount() const noexcept
Get the number of planes in this frame.
Definition frame.hpp:232
CodecBridge::PixelFormat PixelFormat() const
Get the frame pixel format.
Definition frame.hpp:150
int64_t PresentationTimeStamp() const
Get the frame presentation time stamp.
Definition frame.hpp:127
int Height() const
Get the frame height.
Definition frame.hpp:105
Rational TimeBase() const
Get the time base for this frame.
Definition frame.hpp:176
int Width() const
Get the frame width.
Definition frame.hpp:95
std::unique_ptr< Image > AsImage() const
Get this frame as image.
Definition frame.hpp:215
static std::unique_ptr< Frame > Create(Size2D< int > size, CodecBridge::PixelFormat format, uint8_t *buffer)
Creates a frame as view on external memory.
Definition frame.hpp:43
void DeleteUserData()
Delete user data.
Definition frame.hpp:202
void SetPresentationTimeStamp(int64_t value)
Set the presentation time stamp for this frame.
Definition frame.hpp:139
static std::unique_ptr< Frame > Create(Size2D< int > size, CodecBridge::PixelFormat format)
Creates a frame.
Definition frame.hpp:60
A pair of rational numbers.
Definition codec_bridge.hpp:199
static std::unique_ptr< Image > FromHandle(HandleGuard< Image > &&guard)
Creates an image from a classic API handle.
Definition decl_image.hpp:155
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::shared_ptr< Plane > PlanePtr
Convenience shared pointer for Plane.
Definition global.hpp:78