Shaka Packager SDK
text_stream_info.h
1 // Copyright 2015 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_BASE_TEXT_STREAM_INFO_H_
8 #define PACKAGER_MEDIA_BASE_TEXT_STREAM_INFO_H_
9 
10 #include "packager/media/base/stream_info.h"
11 #include "packager/media/base/text_sample.h"
12 
13 #include <map>
14 #include <string>
15 
16 namespace shaka {
17 namespace media {
18 
19 struct TextRegion {
21  TextNumber width{100, TextUnitType::kPercent};
23  TextNumber height{100, TextUnitType::kPercent};
24 
28  TextNumber window_anchor_x{0, TextUnitType::kPercent};
29  TextNumber window_anchor_y{0, TextUnitType::kPercent};
35  TextNumber region_anchor_x{0, TextUnitType::kPercent};
36  TextNumber region_anchor_y{0, TextUnitType::kPercent};
37 
40  bool scroll = false;
41 };
42 
46  std::string language;
47 };
48 
49 class TextStreamInfo : public StreamInfo {
50  public:
63  TextStreamInfo(int track_id, uint32_t time_scale, uint64_t duration,
64  Codec codec,
65  const std::string& codec_string,
66  const std::string& codec_config, uint16_t width,
67  uint16_t height, const std::string& language);
68 
69  ~TextStreamInfo() override;
70 
71  bool IsValidConfig() const override;
72 
73  std::string ToString() const override;
74  std::unique_ptr<StreamInfo> Clone() const override;
75 
76  uint16_t width() const { return width_; }
77  uint16_t height() const { return height_; }
78  const std::map<std::string, TextRegion>& regions() const { return regions_; }
79  void AddRegion(const std::string& id, const TextRegion& region) {
80  regions_[id] = region;
81  }
82  const std::string& css_styles() const { return css_styles_; }
83  void set_css_styles(const std::string& styles) { css_styles_ = styles; }
84 
85  void AddSubStream(uint16_t index, TextSubStreamInfo info) {
86  sub_streams_.emplace(index, std::move(info));
87  }
88  const std::map<uint16_t, TextSubStreamInfo>& sub_streams() const {
89  return sub_streams_;
90  }
91 
92  private:
93  std::map<std::string, TextRegion> regions_;
94  std::map<uint16_t, TextSubStreamInfo> sub_streams_;
95  std::string css_styles_;
96  uint16_t width_;
97  uint16_t height_;
98 
99  // Allow copying. This is very light weight.
100 };
101 
102 } // namespace media
103 } // namespace shaka
104 
105 #endif // PACKAGER_MEDIA_BASE_TEXT_STREAM_INFO_H_
shaka::media::TextSubStreamInfo
Definition: text_stream_info.h:45
shaka::media::TextStreamInfo::TextStreamInfo
TextStreamInfo(int track_id, uint32_t time_scale, uint64_t duration, Codec codec, const std::string &codec_string, const std::string &codec_config, uint16_t width, uint16_t height, const std::string &language)
Definition: text_stream_info.cc:14
shaka
All the methods that are virtual are virtual for mocking.
Definition: gflags_hex_bytes.cc:11
shaka::media::TextStreamInfo
Definition: text_stream_info.h:49
shaka::media::TextStreamInfo::IsValidConfig
bool IsValidConfig() const override
Definition: text_stream_info.cc:29
shaka::media::TextRegion
Definition: text_stream_info.h:19
shaka::media::TextRegion::window_anchor_x
TextNumber window_anchor_x
Definition: text_stream_info.h:28
shaka::media::TextRegion::scroll
bool scroll
Definition: text_stream_info.h:40
shaka::media::TextRegion::height
TextNumber height
The height of the region; percent units are relative to the window.
Definition: text_stream_info.h:23
shaka::media::TextNumber
Definition: text_sample.h:48
shaka::media::TextRegion::region_anchor_x
TextNumber region_anchor_x
Definition: text_stream_info.h:35
shaka::media::TextStreamInfo::ToString
std::string ToString() const override
Definition: text_stream_info.cc:33
shaka::media::TextStreamInfo::Clone
std::unique_ptr< StreamInfo > Clone() const override
Definition: text_stream_info.cc:45
shaka::media::StreamInfo
Abstract class holds stream information.
Definition: stream_info.h:65
shaka::media::TextRegion::width
TextNumber width
The width of the region; percent units are relative to the window.
Definition: text_stream_info.h:21