Shaka Packager SDK
stream_info.h
1 // Copyright 2014 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_BASE_STREAM_INFO_H_
8 #define PACKAGER_MEDIA_BASE_STREAM_INFO_H_
9 
10 #include <memory>
11 #include <string>
12 #include <vector>
13 
14 #include <packager/media/base/encryption_config.h>
15 
16 namespace shaka {
17 namespace media {
18 
19 enum StreamType {
20  kStreamUnknown = 0,
21  kStreamAudio,
22  kStreamVideo,
23  kStreamText,
24 };
25 
26 std::string StreamTypeToString(StreamType type);
27 
28 enum Codec {
29  kUnknownCodec = 0,
30 
31  kCodecVideo = 100,
32  kCodecAV1 = kCodecVideo,
33  kCodecH264,
34  kCodecH265,
35  kCodecH265DolbyVision,
36  kCodecVP8,
37  kCodecVP9,
38  kCodecVideoMaxPlusOne,
39 
40  kCodecAudio = 200,
41  kCodecAAC = kCodecAudio,
42  kCodecAC3,
43  kCodecAC4,
44  kCodecALAC,
45  // TODO(kqyang): Use kCodecDTS and a kDtsStreamFormat for the various DTS
46  // streams.
47  kCodecDTSC,
48  kCodecDTSE,
49  kCodecDTSH,
50  kCodecDTSL,
51  kCodecDTSM,
52  kCodecDTSP,
53  kCodecDTSX,
54  kCodecEAC3,
55  kCodecFlac,
56  kCodecIAMF,
57  kCodecOpus,
58  kCodecPcm,
59  kCodecVorbis,
60  kCodecMP3,
61  kCodecMha1,
62  kCodecMhm1,
63  kCodecAudioMaxPlusOne,
64 
65  kCodecText = 300,
66  kCodecWebVtt = kCodecText,
67  kCodecTtml,
68 };
69 
71 class StreamInfo {
72  public:
73  StreamInfo() = default;
74 
75  StreamInfo(StreamType stream_type,
76  int track_id,
77  int32_t time_scale,
78  int64_t duration,
79  Codec codec,
80  const std::string& codec_string,
81  const uint8_t* codec_config,
82  size_t codec_config_size,
83  const std::string& language,
84  bool is_encrypted);
85 
86  virtual ~StreamInfo();
87 
90  virtual bool IsValidConfig() const = 0;
91 
93  virtual std::string ToString() const;
94 
98  virtual std::unique_ptr<StreamInfo> Clone() const = 0;
99 
100  StreamType stream_type() const { return stream_type_; }
101  uint32_t track_id() const { return track_id_; }
102  int32_t time_scale() const { return time_scale_; }
103  int64_t duration() const { return duration_; }
104  Codec codec() const { return codec_; }
105  const std::string& codec_string() const { return codec_string_; }
106  const std::vector<uint8_t>& codec_config() const { return codec_config_; }
107  const std::string& language() const { return language_; }
108  bool is_encrypted() const { return is_encrypted_; }
109  bool has_clear_lead() const { return has_clear_lead_; }
110  const EncryptionConfig& encryption_config() const {
111  return encryption_config_;
112  }
113 
114  void set_duration(int64_t duration) { duration_ = duration; }
115  void set_codec(Codec codec) { codec_ = codec; }
116  void set_codec_config(const std::vector<uint8_t>& data) {
117  codec_config_ = data;
118  }
119  void set_codec_string(const std::string& codec_string) {
120  codec_string_ = codec_string;
121  }
122  void set_language(const std::string& language) { language_ = language; }
123  void set_is_encrypted(bool is_encrypted) { is_encrypted_ = is_encrypted; }
124  void set_has_clear_lead(bool has_clear_lead) {
125  has_clear_lead_ = has_clear_lead;
126  }
127  void set_encryption_config(const EncryptionConfig& encryption_config) {
128  encryption_config_ = encryption_config;
129  }
130 
131  private:
132  // Whether the stream is Audio or Video.
133  StreamType stream_type_;
134  uint32_t track_id_;
135  // The actual time is calculated as time / time_scale_ in seconds.
136  int32_t time_scale_;
137  // Duration base on time_scale.
138  int64_t duration_;
139  Codec codec_;
140  std::string codec_string_;
141  std::string language_;
142  // Whether the stream is potentially encrypted.
143  // Note that in a potentially encrypted stream, individual buffers
144  // can be encrypted or not encrypted.
145  bool is_encrypted_;
146  // Whether the stream has clear lead.
147  bool has_clear_lead_ = false;
148  EncryptionConfig encryption_config_;
149  // Optional byte data required for some audio/video decoders such as Vorbis
150  // codebooks.
151  std::vector<uint8_t> codec_config_;
152 
153  // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
154  // generated copy constructor and assignment operator. Since the extra data is
155  // typically small, the performance impact is minimal.
156 };
157 
158 } // namespace media
159 } // namespace shaka
160 
161 #endif // PACKAGER_MEDIA_BASE_STREAM_INFO_H_
Abstract class holds stream information.
Definition: stream_info.h:71
virtual bool IsValidConfig() const =0
virtual std::string ToString() const
Definition: stream_info.cc:62
virtual std::unique_ptr< StreamInfo > Clone() const =0
All the methods that are virtual are virtual for mocking.
Definition: crypto_flags.cc:66