Shaka Packager SDK
dvb_sub_parser.h
1 // Copyright 2020 Google LLC. 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_DVB_DVB_SUB_PARSER_H_
8 #define PACKAGER_MEDIA_DVB_DVB_SUB_PARSER_H_
9 
10 #include <memory>
11 #include <vector>
12 
13 #include <packager/media/base/bit_reader.h>
14 #include <packager/media/base/text_sample.h>
15 #include <packager/media/formats/dvb/dvb_image.h>
16 #include <packager/media/formats/dvb/subtitle_composer.h>
17 
18 namespace shaka {
19 namespace media {
20 
21 // See ETSI EN 300 743 Section 7.2.0.1 and Table 7.
22 enum class DvbSubSegmentType : uint16_t {
23  kPageComposition = 0x10,
24  kRegionComposition = 0x11,
25  kClutDefinition = 0x12,
26  kObjectData = 0x13,
27  kDisplayDefinition = 0x14,
28  kDisparitySignalling = 0x15,
29  kAlternativeClut = 0x16,
30  kEndOfDisplay = 0x80,
31 };
32 
33 class DvbSubParser {
34  public:
35  DvbSubParser();
36  ~DvbSubParser();
37 
38  DvbSubParser(const DvbSubParser&) = delete;
39  DvbSubParser& operator=(const DvbSubParser&) = delete;
40 
41  bool Parse(DvbSubSegmentType segment_type,
42  int64_t pts,
43  const uint8_t* payload,
44  size_t size,
45  std::vector<std::shared_ptr<TextSample>>* samples);
46  bool Flush(std::vector<std::shared_ptr<TextSample>>* samples);
47 
48  private:
49  friend class DvbSubParserTest;
50 
51  const DvbImageColorSpace* GetColorSpace(uint8_t clut_id);
52  const DvbImageBuilder* GetImageForObject(uint16_t object_id);
53 
54  bool ParsePageComposition(int64_t pts,
55  const uint8_t* data,
56  size_t size,
57  std::vector<std::shared_ptr<TextSample>>* samples);
58  bool ParseRegionComposition(const uint8_t* data, size_t size);
59  bool ParseClutDefinition(const uint8_t* data, size_t size);
60  bool ParseObjectData(int64_t pts, const uint8_t* data, size_t size);
61  bool ParseDisplayDefinition(const uint8_t* data, size_t size);
62 
63  bool ParsePixelDataSubObject(size_t sub_object_length,
64  bool is_top_fields,
65  BitReader* reader,
66  DvbImageColorSpace* color_space,
67  DvbImageBuilder* image);
68  bool Parse2BitPixelData(bool is_top_fields,
69  BitReader* reader,
70  DvbImageBuilder* image);
71  bool Parse4BitPixelData(bool is_top_fields,
72  BitReader* reader,
73  DvbImageBuilder* image);
74  bool Parse8BitPixelData(bool is_top_fields,
75  BitReader* reader,
76  DvbImageBuilder* image);
77 
78  SubtitleComposer composer_;
79  int64_t last_pts_;
80  uint8_t timeout_;
81 };
82 
83 } // namespace media
84 } // namespace shaka
85 
86 #endif // PACKAGER_MEDIA_DVB_DVB_SUB_PARSER_H_
A class to read bit streams.
Definition: bit_reader.h:20
All the methods that are virtual are virtual for mocking.
Definition: crypto_flags.cc:66