DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
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 MEDIA_BASE_STREAM_INFO_H_
8 #define MEDIA_BASE_STREAM_INFO_H_
9 
10 #include <string>
11 #include <vector>
12 
13 #include "packager/media/base/encryption_config.h"
14 
15 namespace shaka {
16 namespace media {
17 
18 enum StreamType {
19  kStreamUnknown = 0,
20  kStreamAudio,
21  kStreamVideo,
22  kStreamText,
23 };
24 
25 enum Codec {
26  kUnknownCodec = 0,
27 
28  kCodecVideo = 100,
29  kCodecH264 = kCodecVideo,
30  kCodecH265,
31  kCodecVP8,
32  kCodecVP9,
33  kCodecVP10,
34  kCodecVideoMaxPlusOne,
35 
36  kCodecAudio = 200,
37  kCodecAAC = kCodecAudio,
38  kCodecAC3,
39  // TODO(kqyang): Use kCodecDTS and a kDtsStreamFormat for the various DTS
40  // streams.
41  kCodecDTSC,
42  kCodecDTSE,
43  kCodecDTSH,
44  kCodecDTSL,
45  kCodecDTSM,
46  kCodecDTSP,
47  kCodecEAC3,
48  kCodecOpus,
49  kCodecVorbis,
50  kCodecAudioMaxPlusOne,
51 
52  kCodecText = 300,
53  kCodecWebVtt = kCodecText,
54 };
55 
57 class StreamInfo {
58  public:
59  StreamInfo() = default;
60 
61  StreamInfo(StreamType stream_type, int track_id, uint32_t time_scale,
62  uint64_t duration, Codec codec, const std::string& codec_string,
63  const uint8_t* codec_config, size_t codec_config_size,
64  const std::string& language, bool is_encrypted);
65 
66  virtual ~StreamInfo();
67 
70  virtual bool IsValidConfig() const = 0;
71 
73  virtual std::string ToString() const;
74 
75  StreamType stream_type() const { return stream_type_; }
76  uint32_t track_id() const { return track_id_; }
77  uint32_t time_scale() const { return time_scale_; }
78  uint64_t duration() const { return duration_; }
79  Codec codec() const { return codec_; }
80  const std::string& codec_string() const { return codec_string_; }
81  const std::vector<uint8_t>& codec_config() const { return codec_config_; }
82  const std::string& language() const { return language_; }
83  bool is_encrypted() const { return is_encrypted_; }
84  const EncryptionConfig& encryption_config() const {
85  return encryption_config_;
86  }
87 
88  void set_duration(uint64_t duration) { duration_ = duration; }
89  void set_codec(Codec codec) { codec_ = codec; }
90  void set_codec_config(const std::vector<uint8_t>& data) { codec_config_ = data; }
91  void set_codec_string(const std::string& codec_string) {
92  codec_string_ = codec_string;
93  }
94  void set_language(const std::string& language) { language_ = language; }
95  void set_is_encrypted(bool is_encrypted) { is_encrypted_ = is_encrypted; }
96  void set_encryption_config(const EncryptionConfig& encryption_config) {
97  encryption_config_ = encryption_config;
98  }
99 
100  private:
101  // Whether the stream is Audio or Video.
102  StreamType stream_type_;
103  uint32_t track_id_;
104  // The actual time is calculated as time / time_scale_ in seconds.
105  uint32_t time_scale_;
106  // Duration base on time_scale.
107  uint64_t duration_;
108  Codec codec_;
109  std::string codec_string_;
110  std::string language_;
111  // Whether the stream is potentially encrypted.
112  // Note that in a potentially encrypted stream, individual buffers
113  // can be encrypted or not encrypted.
114  bool is_encrypted_;
115  EncryptionConfig encryption_config_;
116  // Optional byte data required for some audio/video decoders such as Vorbis
117  // codebooks.
118  std::vector<uint8_t> codec_config_;
119 
120  // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
121  // generated copy constructor and assignment operator. Since the extra data is
122  // typically small, the performance impact is minimal.
123 };
124 
125 } // namespace media
126 } // namespace shaka
127 
128 #endif // MEDIA_BASE_STREAM_INFO_H_
Abstract class holds stream information.
Definition: stream_info.h:57
virtual bool IsValidConfig() const =0
virtual std::string ToString() const
Definition: stream_info.cc:37