CVB++ 15.0
output_container.hpp
1#pragma once
2
3#include "codec_bridge.hpp"
4#include "../global.hpp"
5#include "../utilities/system_info.hpp"
6
7#include "packet.hpp"
8#include "encoder.hpp"
9
10namespace Cvb
11{
12
13 CVB_BEGIN_INLINE_NS
14
15 template <>
16 inline HandleGuard<CodecBridge::OutputContainer>::HandleGuard(void *handle) noexcept
17 : HandleGuard<CodecBridge::OutputContainer>(handle, [](void *handle) { CVB_CALL_CAPI(ReleaseObject(handle)); })
18 {
19 }
20
21 namespace CodecBridge
22 {
23
29 class OutputContainer final
30 {
31
32 public:
34
46 {
47 return Internal::DoResCallObjectOut<OutputContainer>([&](void *&handle) {
48 return CVB_CALL_CAPI(CVCBCreateOutputContainerTyped(encoder.Handle(), fileName.c_str(), handle));
49 });
50 }
51
52 static std::unique_ptr<OutputContainer> FromHandle(HandleGuard<OutputContainer> &&guard)
53 {
54 if (!guard.Handle())
55 throw std::runtime_error("handle must not be null");
56
57 return std::make_unique<OutputContainer>(std::move(guard));
58 }
59
60 explicit OutputContainer(HandleGuard<OutputContainer> &&guard) noexcept
61 : handle_(std::move(guard))
62 {
63 }
64
65 OutputContainer(const OutputContainer &other) = delete;
66 OutputContainer &operator=(const OutputContainer &other) = delete;
67 OutputContainer(OutputContainer &&other) = delete;
68 OutputContainer &operator=(OutputContainer &&other) = delete;
69
70 ~OutputContainer() = default;
71
72 void *Handle() const noexcept
73 {
74 return handle_.Handle();
75 }
76
78
85 {
86 CExports::CVCBPACKET handle = packet->Handle();
87 CVB_CALL_CAPI_CHECKED(CVCBOutputContainerWritePacket(Handle(), handle));
88 }
89
91
97 {
98 CVB_CALL_CAPI_CHECKED(CVCBOutputContainerWriteHeader(Handle()));
99 }
100
102
108 {
109 CVB_CALL_CAPI_CHECKED(CVCBOutputContainerWriteTrailer(Handle()));
110 }
111
112 private:
113 HandleGuard<OutputContainer> handle_;
114 };
115
116 } // namespace CodecBridge
117
118 CVB_END_INLINE_NS
119} // namespace Cvb
An encoder for video frames.
Definition encoder.hpp:32
void WriteHeader()
Write a header to the container.
Definition output_container.hpp:96
void WriteTrailer()
Write a trailer to the container.
Definition output_container.hpp:107
void WritePacket(std::unique_ptr< Packet > &&packet)
Write a packet to the container.
Definition output_container.hpp:84
static std::unique_ptr< OutputContainer > Create(const Cvb::String &fileName, Encoder &encoder)
Creates an output container based on a file name and an encoder.
Definition output_container.hpp:45
cvbbool_t ReleaseObject(OBJ &Object)
T move(T... args)
Namespace for encoding and decoding videos.
Definition codec_bridge.hpp:24
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