Shaka Packager SDK
Loading...
Searching...
No Matches
es_parser_teletext.h
1// Copyright 2020 Google Inc. All rights reserved.
2//
3// Use of this source code is governed by a BSD-style
4// license that can be found in the LICENSE file or at
5// https://developers.google.com/open-source/licenses/bsd
6
7#ifndef PACKAGER_MEDIA_FORMATS_MP2T_ES_PARSER_TELETEXT_H_
8#define PACKAGER_MEDIA_FORMATS_MP2T_ES_PARSER_TELETEXT_H_
9
10#include <cstddef>
11#include <cstdint>
12#include <string>
13#include <unordered_map>
14#include <vector>
15
16#include <packager/media/base/text_sample.h>
17#include <packager/media/formats/mp2t/es_parser.h>
18
19namespace shaka {
20namespace media {
21namespace mp2t {
22
23const int64_t ttx_cue_duration_placeholder = 30 * 90000; // 30s
24
25class EsParserTeletext : public EsParser {
26 public:
27 EsParserTeletext(const uint32_t pid,
28 const NewStreamInfoCB& new_stream_info_cb,
29 const EmitTextSampleCB& emit_sample_cb,
30 const uint8_t* descriptor,
31 const size_t descriptor_length);
32
33 EsParserTeletext(const EsParserTeletext&) = delete;
34 EsParserTeletext& operator=(const EsParserTeletext&) = delete;
35
36 bool Parse(const uint8_t* buf, int size, int64_t pts, int64_t dts) override;
37 bool Flush() override;
38 void Reset() override;
39
40 private:
41 using RowColReplacementMap =
42 std::unordered_map<uint8_t, std::unordered_map<uint8_t, std::string>>;
43
44 struct TextRow {
45 TextAlignment alignment;
46 int row_number;
47 bool double_height;
48 TextFragment fragment;
49 };
50
51 struct TextBlock {
52 std::vector<TextRow> rows;
53 RowColReplacementMap packet_26_replacements;
54 int64_t pts;
55 };
56
57 bool ParseInternal(const uint8_t* data, const size_t size, const int64_t pts);
58 bool ParseDataBlock(const int64_t pts,
59 const uint8_t* data_block,
60 const uint8_t packet_nr,
61 const uint8_t magazine,
62 TextRow& display_text);
63 void UpdateCharset();
64 TextRow BuildRow(const uint8_t* data_block, const uint8_t row) const;
65 void ParsePacket26(const uint8_t* data_block);
66 void UpdateNationalSubset(const uint8_t national_subset[13][3]);
67 void SendCueStart(const uint16_t index);
68 void SendCueEnd(const uint16_t index, const int64_t pts);
69 void SendTextHeartBeat(const uint16_t index, const int64_t pts);
70
71 static void SetPacket26ReplacementString(
72 RowColReplacementMap& replacement_map,
73 const uint8_t row,
74 const uint8_t column,
75 std::string&& replacement_string);
76
77 NewStreamInfoCB new_stream_info_cb_;
78 EmitTextSampleCB emit_sample_cb_;
79
80 std::unordered_map<uint16_t, std::string> languages_;
81 bool sent_info_ = false;
82 uint8_t magazine_;
83 uint8_t page_number_;
84 std::unordered_map<uint16_t, TextBlock> page_state_;
85 uint8_t charset_code_;
86 char current_charset_[96][3];
87 int64_t last_pts_;
88 int64_t last_end_pts_;
89 bool inside_sample_;
90};
91
92} // namespace mp2t
93} // namespace media
94} // namespace shaka
95
96#endif // PACKAGER_MEDIA_FORMATS_MP2T_ES_PARSER_TELETEXT_H_
All the methods that are virtual are virtual for mocking.