CVB++ 15.0
output_container.hpp
1#pragma once
2
3
4#include "codec_bridge.hpp"
5#include "../global.hpp"
6#include "../utilities/system_info.hpp"
7
8#include "packet.hpp"
9#include "encoder.hpp"
10
11
12namespace Cvb
13{
14
15 CVB_BEGIN_INLINE_NS
16
17 template <>
18 inline HandleGuard<CodecBridge::OutputContainer>::HandleGuard(void* handle) noexcept
19 : HandleGuard<CodecBridge::OutputContainer>(handle, [](void* handle) { CVB_CALL_CAPI(ReleaseObject(handle)); })
20 {
21 }
22
23 namespace CodecBridge
24 {
25
31 class OutputContainer final
32 {
33
34 public:
35
37
49 {
50 return Internal::DoResCallObjectOut<OutputContainer>([&](void*& handle)
51 {
52 return CVB_CALL_CAPI(CVCBCreateOutputContainerTyped(encoder.Handle(), fileName.c_str(), handle));
53 });
54 }
55
56 static std::unique_ptr<OutputContainer> FromHandle(HandleGuard<OutputContainer>&& guard)
57 {
58 if (!guard.Handle())
59 throw std::runtime_error("handle must not be null");
60
61 return std::make_unique<OutputContainer>(std::move(guard));
62 }
63
64 explicit OutputContainer(HandleGuard<OutputContainer>&& guard) noexcept
65 : handle_(std::move(guard))
66 {
67
68 }
69
70 OutputContainer(const OutputContainer& other) = delete;
71 OutputContainer& operator=(const OutputContainer& other) = delete;
72 OutputContainer(OutputContainer&& other) = delete;
73 OutputContainer& operator=(OutputContainer&& other) = delete;
74
75 ~OutputContainer() = default;
76
77 void* Handle() const noexcept
78 {
79 return handle_.Handle();
80 }
81
83
90 {
91 CExports::CVCBPACKET handle = packet->Handle();
92 CVB_CALL_CAPI_CHECKED(CVCBOutputContainerWritePacket(Handle(), handle));
93 }
94
96
102 {
103 CVB_CALL_CAPI_CHECKED(CVCBOutputContainerWriteHeader(Handle()));
104 }
105
107
113 {
114 CVB_CALL_CAPI_CHECKED(CVCBOutputContainerWriteTrailer(Handle()));
115 }
116
117
118 private:
119
120 HandleGuard<OutputContainer> handle_;
121 };
122
123}
124
125CVB_END_INLINE_NS
126}
An encoder for video frames.
Definition: encoder.hpp:33
A container file for writing encoded videos to disk.
Definition: output_container.hpp:32
void WriteHeader()
Write a header to the container.
Definition: output_container.hpp:101
void WriteTrailer()
Write a trailer to the container.
Definition: output_container.hpp:112
void WritePacket(std::unique_ptr< Packet > &&packet)
Write a packet to the container.
Definition: output_container.hpp:89
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:48
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24