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