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