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