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