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 <cstdint>
11#include <string>
12#include <unordered_map>
13#include <vector>
14
15#include <packager/media/base/text_stream_info.h>
16#include <packager/media/formats/mp2t/es_parser.h>
17
18namespace shaka {
19namespace media {
20namespace mp2t {
21
22const int64_t ttx_cue_duration_placeholder = 30 * 90000; // 30s
23
24class EsParserTeletext : public EsParser {
25 public:
26 EsParserTeletext(const uint32_t pid,
27 const NewStreamInfoCB& new_stream_info_cb,
28 const EmitTextSampleCB& emit_sample_cb,
29 const uint8_t* descriptor,
30 const size_t descriptor_length);
31
32 EsParserTeletext(const EsParserTeletext&) = delete;
33 EsParserTeletext& operator=(const EsParserTeletext&) = delete;
34
35 bool Parse(const uint8_t* buf, int size, int64_t pts, int64_t dts) override;
36 bool Flush() override;
37 void Reset() override;
38
39 private:
40 using RowColReplacementMap =
41 std::unordered_map<uint8_t, std::unordered_map<uint8_t, std::string>>;
42
43 struct TextRow {
44 TextAlignment alignment;
45 int row_number;
46 bool double_height;
47 TextFragment fragment;
48 };
49
50 struct TextBlock {
51 std::vector<TextRow> rows;
52 RowColReplacementMap packet_26_replacements;
53 int64_t pts;
54 };
55
56 bool ParseInternal(const uint8_t* data, const size_t size, const int64_t pts);
57 bool ParseDataBlock(const int64_t pts,
58 const uint8_t* data_block,
59 const uint8_t packet_nr,
60 const uint8_t magazine,
61 TextRow& display_text);
62 void UpdateCharset();
63 TextRow BuildRow(const uint8_t* data_block, const uint8_t row) const;
64 void ParsePacket26(const uint8_t* data_block);
65 void UpdateNationalSubset(const uint8_t national_subset[13][3]);
66 void SendCueStart(const uint16_t index);
67 void SendCueEnd(const uint16_t index, const int64_t pts);
68 void SendTextHeartBeat(const uint16_t index, const int64_t pts);
69
70 static void SetPacket26ReplacementString(
71 RowColReplacementMap& replacement_map,
72 const uint8_t row,
73 const uint8_t column,
74 std::string&& replacement_string);
75
76 NewStreamInfoCB new_stream_info_cb_;
77 EmitTextSampleCB emit_sample_cb_;
78
79 std::unordered_map<uint16_t, std::string> languages_;
80 bool sent_info_ = false;
81 uint8_t magazine_;
82 uint8_t page_number_;
83 std::unordered_map<uint16_t, TextBlock> page_state_;
84 uint8_t charset_code_;
85 char current_charset_[96][3];
86 int64_t last_pts_;
87 int64_t last_end_pts_;
88 bool inside_sample_;
89};
90
91} // namespace mp2t
92} // namespace media
93} // namespace shaka
94
95#endif // PACKAGER_MEDIA_FORMATS_MP2T_ES_PARSER_TELETEXT_H_
All the methods that are virtual are virtual for mocking.