Shaka Packager SDK
Loading...
Searching...
No Matches
stream_info.h
1// Copyright 2014 Google LLC. 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 <cstddef>
11#include <cstdint>
12#include <memory>
13#include <string>
14#include <vector>
15
16#include <packager/media/base/encryption_config.h>
17
18namespace shaka {
19namespace media {
20
21enum StreamType {
22 kStreamUnknown = 0,
23 kStreamAudio,
24 kStreamVideo,
25 kStreamText,
26};
27
28std::string StreamTypeToString(StreamType type);
29
30enum Codec {
31 kUnknownCodec = 0,
32
33 kCodecVideo = 100,
34 kCodecAV1 = kCodecVideo,
35 kCodecH264,
36 kCodecH265,
37 kCodecH265DolbyVision,
38 kCodecVP8,
39 kCodecVP9,
40 kCodecVideoMaxPlusOne,
41
42 kCodecAudio = 200,
43 kCodecAAC = kCodecAudio,
44 kCodecAC3,
45 kCodecAC4,
46 kCodecALAC,
47 // TODO(kqyang): Use kCodecDTS and a kDtsStreamFormat for the various DTS
48 // streams.
49 kCodecDTSC,
50 kCodecDTSE,
51 kCodecDTSH,
52 kCodecDTSL,
53 kCodecDTSM,
54 kCodecDTSP,
55 kCodecDTSX,
56 kCodecEAC3,
57 kCodecFlac,
58 kCodecIAMF,
59 kCodecOpus,
60 kCodecPcm,
61 kCodecVorbis,
62 kCodecMP3,
63 kCodecMha1,
64 kCodecMhm1,
65 kCodecAudioMaxPlusOne,
66
67 kCodecText = 300,
68 kCodecWebVtt = kCodecText,
69 kCodecTtml,
70};
71
74 public:
75 StreamInfo() = default;
76
77 StreamInfo(StreamType stream_type,
78 int track_id,
79 int32_t time_scale,
80 int64_t duration,
81 Codec codec,
82 const std::string& codec_string,
83 const uint8_t* codec_config,
84 size_t codec_config_size,
85 const std::string& language,
86 bool is_encrypted);
87
88 virtual ~StreamInfo();
89
92 virtual bool IsValidConfig() const = 0;
93
95 virtual std::string ToString() const;
96
100 virtual std::unique_ptr<StreamInfo> Clone() const = 0;
101
102 StreamType stream_type() const { return stream_type_; }
103 uint32_t track_id() const { return track_id_; }
104 int32_t time_scale() const { return time_scale_; }
105 int64_t duration() const { return duration_; }
106 Codec codec() const { return codec_; }
107 const std::string& codec_string() const { return codec_string_; }
108 const std::vector<uint8_t>& codec_config() const { return codec_config_; }
109 const std::vector<uint8_t>& layered_codec_config() const {
110 return layered_codec_config_;
111 }
112 const std::string& language() const { return language_; }
113 bool is_encrypted() const { return is_encrypted_; }
114 bool has_clear_lead() const { return has_clear_lead_; }
115 const EncryptionConfig& encryption_config() const {
116 return encryption_config_;
117 }
118
119 void set_duration(int64_t duration) { duration_ = duration; }
120 void set_codec(Codec codec) { codec_ = codec; }
121 void set_codec_config(const std::vector<uint8_t>& data) {
122 codec_config_ = data;
123 }
124
125 void set_layered_codec_config(const std::vector<uint8_t>& data) {
126 layered_codec_config_ = data;
127 }
128
129 void set_codec_string(const std::string& codec_string) {
130 codec_string_ = codec_string;
131 }
132 void set_language(const std::string& language) { language_ = language; }
133 void set_is_encrypted(bool is_encrypted) { is_encrypted_ = is_encrypted; }
134 void set_has_clear_lead(bool has_clear_lead) {
135 has_clear_lead_ = has_clear_lead;
136 }
137 void set_encryption_config(const EncryptionConfig& encryption_config) {
138 encryption_config_ = encryption_config;
139 }
140
141 private:
142 // Whether the stream is Audio or Video.
143 StreamType stream_type_;
144 uint32_t track_id_;
145 // The actual time is calculated as time / time_scale_ in seconds.
146 int32_t time_scale_;
147 // Duration base on time_scale.
148 int64_t duration_;
149 Codec codec_;
150 std::string codec_string_;
151 std::string language_;
152 // Whether the stream is potentially encrypted.
153 // Note that in a potentially encrypted stream, individual buffers
154 // can be encrypted or not encrypted.
155 bool is_encrypted_;
156 // Whether the stream has clear lead.
157 bool has_clear_lead_ = false;
158 EncryptionConfig encryption_config_;
159 // Optional byte data required for some audio/video decoders such as Vorbis
160 // codebooks.
161 std::vector<uint8_t> codec_config_;
162 // Optional byte data required for some layered video decoders such as
163 // MV-HEVC.
164 std::vector<uint8_t> layered_codec_config_;
165
166 // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
167 // generated copy constructor and assignment operator. Since the extra data is
168 // typically small, the performance impact is minimal.
169};
170
171} // namespace media
172} // namespace shaka
173
174#endif // PACKAGER_MEDIA_BASE_STREAM_INFO_H_
Abstract class holds stream information.
Definition stream_info.h:73
virtual std::unique_ptr< StreamInfo > Clone() const =0
virtual bool IsValidConfig() const =0
virtual std::string ToString() const
All the methods that are virtual are virtual for mocking.