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