Shaka Packager SDK
stream_info.h
1 // Copyright 2014 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_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  kCodecVP8,
36  kCodecVP9,
37  kCodecVideoMaxPlusOne,
38 
39  kCodecAudio = 200,
40  kCodecAAC = kCodecAudio,
41  kCodecAC3,
42  // TODO(kqyang): Use kCodecDTS and a kDtsStreamFormat for the various DTS
43  // streams.
44  kCodecDTSC,
45  kCodecDTSE,
46  kCodecDTSH,
47  kCodecDTSL,
48  kCodecDTSM,
49  kCodecDTSP,
50  kCodecEAC3,
51  kCodecFlac,
52  kCodecOpus,
53  kCodecVorbis,
54  kCodecAudioMaxPlusOne,
55 
56  kCodecText = 300,
57  kCodecWebVtt = kCodecText,
58 };
59 
61 class StreamInfo {
62  public:
63  StreamInfo() = default;
64 
65  StreamInfo(StreamType stream_type,
66  int track_id,
67  uint32_t time_scale,
68  uint64_t duration,
69  Codec codec,
70  const std::string& codec_string,
71  const uint8_t* codec_config,
72  size_t codec_config_size,
73  const std::string& language,
74  bool is_encrypted);
75 
76  virtual ~StreamInfo();
77 
80  virtual bool IsValidConfig() const = 0;
81 
83  virtual std::string ToString() const;
84 
88  virtual std::unique_ptr<StreamInfo> Clone() const = 0;
89 
90  StreamType stream_type() const { return stream_type_; }
91  uint32_t track_id() const { return track_id_; }
92  uint32_t time_scale() const { return time_scale_; }
93  uint64_t duration() const { return duration_; }
94  Codec codec() const { return codec_; }
95  const std::string& codec_string() const { return codec_string_; }
96  const std::vector<uint8_t>& codec_config() const { return codec_config_; }
97  const std::string& language() const { return language_; }
98  bool is_encrypted() const { return is_encrypted_; }
99  bool has_clear_lead() const { return has_clear_lead_; }
100  const EncryptionConfig& encryption_config() const {
101  return encryption_config_;
102  }
103 
104  void set_duration(uint64_t duration) { duration_ = duration; }
105  void set_codec(Codec codec) { codec_ = codec; }
106  void set_codec_config(const std::vector<uint8_t>& data) {
107  codec_config_ = data;
108  }
109  void set_codec_string(const std::string& codec_string) {
110  codec_string_ = codec_string;
111  }
112  void set_language(const std::string& language) { language_ = language; }
113  void set_is_encrypted(bool is_encrypted) { is_encrypted_ = is_encrypted; }
114  void set_has_clear_lead(bool has_clear_lead) {
115  has_clear_lead_ = has_clear_lead;
116  }
117  void set_encryption_config(const EncryptionConfig& encryption_config) {
118  encryption_config_ = encryption_config;
119  }
120 
121  private:
122  // Whether the stream is Audio or Video.
123  StreamType stream_type_;
124  uint32_t track_id_;
125  // The actual time is calculated as time / time_scale_ in seconds.
126  uint32_t time_scale_;
127  // Duration base on time_scale.
128  uint64_t duration_;
129  Codec codec_;
130  std::string codec_string_;
131  std::string language_;
132  // Whether the stream is potentially encrypted.
133  // Note that in a potentially encrypted stream, individual buffers
134  // can be encrypted or not encrypted.
135  bool is_encrypted_;
136  // Whether the stream has clear lead.
137  bool has_clear_lead_ = false;
138  EncryptionConfig encryption_config_;
139  // Optional byte data required for some audio/video decoders such as Vorbis
140  // codebooks.
141  std::vector<uint8_t> codec_config_;
142 
143  // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
144  // generated copy constructor and assignment operator. Since the extra data is
145  // typically small, the performance impact is minimal.
146 };
147 
148 } // namespace media
149 } // namespace shaka
150 
151 #endif // PACKAGER_MEDIA_BASE_STREAM_INFO_H_
Abstract class holds stream information.
Definition: stream_info.h:61
virtual std::unique_ptr< StreamInfo > Clone() const =0
virtual bool IsValidConfig() const =0
virtual std::string ToString() const
Definition: stream_info.cc:58
All the methods that are virtual are virtual for mocking.