libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
cea708cdp.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_PROAV
13#include <cstdint>
14#include <promeki/buffer.h>
15#include <promeki/error.h>
16#include <promeki/framerate.h>
17#include <promeki/json.h>
18#include <promeki/list.h>
19#include <promeki/namespace.h>
20#include <promeki/result.h>
21#include <promeki/string.h>
22#include <promeki/timecode.h>
23
24PROMEKI_NAMESPACE_BEGIN
25
26class DataStream;
27
122class Cea708Cdp {
123 public:
124 PROMEKI_DATATYPE(Cea708Cdp, DataTypeCea708Cdp, 1)
125
126
127 static constexpr uint16_t Identifier = 0x9669;
128
130 static constexpr uint8_t FooterId = 0x74;
131
133 static constexpr uint8_t TimeCodeSectionId = 0x71;
134
136 static constexpr uint8_t CcDataSectionId = 0x72;
137
139 static constexpr uint8_t CcSvcInfoSectionId = 0x73;
140
149 struct CcData {
150 bool valid = true;
151 uint8_t type = 0;
152 uint8_t b1 = 0;
153 uint8_t b2 = 0;
154
155 bool operator==(const CcData &o) const {
156 return valid == o.valid && type == o.type && b1 == o.b1 && b2 == o.b2;
157 }
158 bool operator!=(const CcData &o) const { return !(*this == o); }
159 };
160
162 using CcDataList = ::promeki::List<CcData>;
163
208 struct CcSvcInfoEntry {
209 bool csnSize5Bit = false;
210 uint8_t captionServiceNumber = 0;
214 uint8_t languageCode[3] = {0, 0, 0};
215 bool digitalCc = false;
216 bool line21Field = false;
217 bool easyReader = false;
218 bool wideAspect = false;
219
220 bool operator==(const CcSvcInfoEntry &o) const {
221 return csnSize5Bit == o.csnSize5Bit
222 && captionServiceNumber == o.captionServiceNumber
223 && languageCode[0] == o.languageCode[0]
224 && languageCode[1] == o.languageCode[1]
225 && languageCode[2] == o.languageCode[2]
226 && digitalCc == o.digitalCc
227 && line21Field == o.line21Field
228 && easyReader == o.easyReader
229 && wideAspect == o.wideAspect;
230 }
231 bool operator!=(const CcSvcInfoEntry &o) const { return !(*this == o); }
232 };
233
235 using CcSvcInfoEntryList = ::promeki::List<CcSvcInfoEntry>;
236
237 // -- Header fields ----------------------------------------
238
240 uint8_t frameRateCode = 0;
241
243 bool timeCodePresent = false;
244
246 bool ccDataPresent = false;
247
250 bool svcInfoPresent = false;
251
253 bool svcInfoStart = false;
254
256 bool svcInfoChange = false;
257
259 bool svcInfoComplete = false;
260
262 bool captionServiceActive = false;
263
266 uint16_t sequenceCounter = 0;
267
268 // -- Sections ---------------------------------------------
269
276 Timecode timeCode;
277
288 bool tcFieldFlag = false;
289
293 CcDataList ccData;
294
306 CcSvcInfoEntryList ccSvcInfo;
307
318 Buffer extraBytes;
319
331 uint32_t svcInfoMismatches = 0;
332
333 // -- Construction -----------------------------------------
334
335 Cea708Cdp() = default;
336
351 Cea708Cdp(uint8_t frameRateCode, CcDataList ccData, uint16_t sequenceCounter = 0)
352 : frameRateCode(frameRateCode)
353 , ccDataPresent(!ccData.isEmpty())
354 , captionServiceActive(!ccData.isEmpty())
355 , sequenceCounter(sequenceCounter)
356 , ccData(std::move(ccData)) {}
357
358 // -- Wire round-trip --------------------------------------
359
370 Buffer toBuffer() const;
371
384 static Result<Cea708Cdp> fromBuffer(const void *data, size_t size);
385
387 static Result<Cea708Cdp> fromBuffer(const Buffer &buf);
388
400 static uint8_t frameRateCodeFor(const FrameRate &frameRate);
401
402 // -- JSON dump --------------------------------------------
403
413 JsonObject toJson() const;
414
415 // -- Comparison -------------------------------------------
416
426 bool operator==(const Cea708Cdp &o) const;
427
429 bool operator!=(const Cea708Cdp &o) const { return !(*this == o); }
430
431 // -- Diagnostics ------------------------------------------
432
440 String toString() const;
441
450 Error writeToStream(DataStream &s) const;
451
456 template <uint32_t V> static Result<Cea708Cdp> readFromStream(DataStream &s);
457};
458
459PROMEKI_NAMESPACE_END
460
461#endif // PROMEKI_ENABLE_PROAV