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