5#include "codec_bridge.hpp"
6#include "../global.hpp"
7#include "../size_2d.hpp"
17inline HandleGuard<CodecBridge::Frame>::HandleGuard(
void* handle) noexcept
18 : HandleGuard<CodecBridge::Frame>(handle, [](
void* handle) { CVB_CALL_CAPI(ReleaseObject(handle)); })
46 return Internal::DoResCallObjectOut<Frame>([&](
void*& handle)
48 return CVB_CALL_CAPI(CVCBCreateFrame(size.
Width(), size.
Height(),
static_cast<CExports::CVCBPixelFormat
>(format), buffer, handle));
63 return Create(size, format,
nullptr);
71 return std::make_unique<Frame>(std::move(guard));
74 explicit Frame(HandleGuard<Frame>&& guard) noexcept
75 : handle_(std::move(guard))
80 Frame(
const Frame& other) =
delete;
81 Frame& operator=(
const Frame& other) =
delete;
82 Frame(Frame&& other) =
delete;
83 Frame& operator=(Frame&& other) =
delete;
87 void* Handle() const noexcept
89 return handle_.Handle();
99 return static_cast<int>(Property<CExports::cvbdim_t>(CExports::CVCBFP_Width));
109 return static_cast<int>(Property<CExports::cvbdim_t>(CExports::CVCBFP_Height));
131 return static_cast<int64_t
>(Property<CExports::cvbint64_t>(CExports::CVCBFP_PresentationTimestamp));
143 SetProperty(
static_cast<CExports::cvbint64_t
>(value), CExports::CVCBFP_PresentationTimestamp);
166 CVB_CALL_CAPI_CHECKED(CVCBFrameGetProperty(Handle(), CExports::CVCBFP_SEIUserData, buffer, size));
179 auto timeBase = Property<CExports::CVCBRational>(CExports::CVCBFP_TimeBase);
180 return { timeBase.Numerator , timeBase.Denominator };
194 CVB_CALL_CAPI_CHECKED(CVCBFrameSetProperty(Handle(), CExports::CVCBFP_SEIUserData, buffer, size));
205 CVB_CALL_CAPI_CHECKED(CVCBFrameSetProperty(Handle(), CExports::CVCBFP_SEIUserData,
nullptr, 0));
218 if (!CExports::IsImage(Handle()))
221 if (!CExports::ShareObject(Handle()))
224 HandleGuard<Image> guard(Handle());
236 CExports::cvbdim_t numElements = 0;
237 CExports::CVCPlaneEnumGetCount(Handle(), numElements);
238 return static_cast<int>(numElements);
251 auto candidate = planes_.find(index);
252 if(candidate != planes_.end())
253 if (
auto plane = candidate->second.lock())
256 auto plane = Internal::DoResCallShareOut<Cvb::Plane>([&](
void*& handle)
258 return CVB_CALL_CAPI(CVCPlaneEnumGetAt(Handle(),
static_cast<CExports::cvbdim_t
>(index), handle));
261 planes_[index] = plane;
268 T Property(CExports::CVCBFrameProperty property)
const
271 size_t size =
sizeof(T);
272 CVB_CALL_CAPI_CHECKED(CVCBFrameGetProperty(Handle(), property, &value, size));
277 void SetProperty( T value, CExports::CVCBFrameProperty property)
const
279 CVB_CALL_CAPI_CHECKED(CVCBFrameSetProperty(Handle(), property, &value,
sizeof(T)));
282 HandleGuard<Frame> handle_;
A video frame for encoding and decoding.
Definition: frame.hpp:30
PlanePtr Plane(int index) const
Get a plane of this frame at the given index.
Definition: frame.hpp:248
Size2D< int > Size() const
Get the frame size.
Definition: frame.hpp:117
void UserData(void *buffer, size_t &size) const
Get the user data if available.
Definition: frame.hpp:164
void SetUserData(void *buffer, size_t size)
Set the user data for this frame.
Definition: frame.hpp:192
int PlanesCount() const noexcept
Get the number of planes in this frame.
Definition: frame.hpp:234
CodecBridge::PixelFormat PixelFormat() const
Get the frame pixel format.
Definition: frame.hpp:152
int64_t PresentationTimeStamp() const
Get the frame presentation time stamp.
Definition: frame.hpp:129
int Height() const
Get the frame height.
Definition: frame.hpp:107
Rational TimeBase() const
Get the time base for this frame.
Definition: frame.hpp:177
int Width() const
Get the frame width.
Definition: frame.hpp:97
std::unique_ptr< Image > AsImage() const
Get this frame as image.
Definition: frame.hpp:216
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:44
void DeleteUserData()
Delete user data.
Definition: frame.hpp:203
void SetPresentationTimeStamp(int64_t value)
Set the presentation time stamp for this frame.
Definition: frame.hpp:141
static std::unique_ptr< Frame > Create(Size2D< int > size, CodecBridge::PixelFormat format)
Creates a frame.
Definition: frame.hpp:61
A pair of rational numbers.
Definition: codec_bridge.hpp:200
static std::unique_ptr< Image > FromHandle(HandleGuard< Image > &&guard)
Creates an image from a classic API handle.
Definition: decl_image.hpp:153
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