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