Shaka Packager SDK
Loading...
Searching...
No Matches
video_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_VIDEO_STREAM_INFO_H_
8#define PACKAGER_MEDIA_BASE_VIDEO_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/fourccs.h>
17#include <packager/media/base/stream_info.h>
18
19namespace shaka {
20namespace media {
21
22enum class H26xStreamFormat {
23 kUnSpecified,
24 kAnnexbByteStream,
25 kNalUnitStreamWithParameterSetNalus,
26 kNalUnitStreamWithoutParameterSetNalus,
27};
28
31 public:
32 VideoStreamInfo() = default;
33
37 VideoStreamInfo(int track_id,
38 int32_t time_scale,
39 int64_t duration,
40 Codec codec,
41 H26xStreamFormat h26x_stream_format,
42 const std::string& codec_string,
43 const uint8_t* codec_config,
44 size_t codec_config_size,
45 uint32_t width,
46 uint32_t height,
47 uint32_t pixel_width,
48 uint32_t pixel_height,
49 uint8_t color_primaries,
50 uint8_t matrix_coefficients,
51 uint8_t transfer_characteristics,
52 uint32_t trick_play_factor,
53 uint8_t nalu_length_size,
54 const std::string& language,
55 bool is_encrypted);
56
57 ~VideoStreamInfo() override;
58
61 bool IsValidConfig() const override;
62 std::string ToString() const override;
63 std::unique_ptr<StreamInfo> Clone() const override;
65
66 const std::string supplemental_codec() const { return supplemental_codec_; }
67 FourCC compatible_brand() const { return compatible_brand_; }
68 const std::vector<uint8_t>& extra_config() const { return extra_config_; }
69 H26xStreamFormat h26x_stream_format() const { return h26x_stream_format_; }
70 uint32_t width() const { return width_; }
71 uint32_t height() const { return height_; }
74 uint32_t pixel_width() const { return pixel_width_; }
77 uint32_t pixel_height() const { return pixel_height_; }
78 uint8_t transfer_characteristics() const { return transfer_characteristics_; }
79 uint8_t color_primaries() const { return color_primaries_; }
80 uint8_t matrix_coefficients() const { return matrix_coefficients_; }
81 uint8_t nalu_length_size() const { return nalu_length_size_; }
82 uint32_t trick_play_factor() const { return trick_play_factor_; }
83 uint32_t playback_rate() const { return playback_rate_; }
84 const std::vector<uint8_t>& eme_init_data() const { return eme_init_data_; }
85 const std::vector<uint8_t>& colr_data() const { return colr_data_; }
86
87 void set_supplemental_codec(const std::string supplemental_codec) {
88 supplemental_codec_ = supplemental_codec;
89 }
90
91 void set_compatible_brand(const FourCC compatible_brand) {
92 compatible_brand_ = compatible_brand;
93 }
94
95 void set_extra_config(const std::vector<uint8_t>& extra_config) {
96 extra_config_ = extra_config;
97 }
98 void set_width(uint32_t width) { width_ = width; }
99 void set_height(uint32_t height) { height_ = height; }
100 void set_pixel_width(uint32_t pixel_width) { pixel_width_ = pixel_width; }
101 void set_pixel_height(uint32_t pixel_height) { pixel_height_ = pixel_height; }
102 void set_transfer_characteristics(uint8_t transfer_characteristics) {
103 transfer_characteristics_ = transfer_characteristics;
104 }
105 void set_color_primaries(uint8_t color_primaries) {
106 color_primaries_ = color_primaries;
107 }
108 void set_matrix_coefficients(uint8_t matrix_coefficients) {
109 matrix_coefficients_ = matrix_coefficients;
110 }
111 void set_trick_play_factor(uint32_t trick_play_factor) {
112 trick_play_factor_ = trick_play_factor;
113 }
114 void set_playback_rate(uint32_t playback_rate) {
115 playback_rate_ = playback_rate;
116 }
117 void set_eme_init_data(const uint8_t* eme_init_data,
118 size_t eme_init_data_size) {
119 eme_init_data_.assign(eme_init_data, eme_init_data + eme_init_data_size);
120 }
121 void set_colr_data(const uint8_t* colr_data, size_t colr_data_size) {
122 colr_data_.assign(colr_data, colr_data + colr_data_size);
123 }
124
125 private:
126 // Extra codec configuration in a stream of mp4 boxes. It is only applicable
127 // to mp4 container only. It is needed by some codecs, e.g. Dolby Vision or
128 // MV-HEVC (currently only stereo video is supported).
129 std::string supplemental_codec_ = "";
130 FourCC compatible_brand_ = FOURCC_NULL;
131 std::vector<uint8_t> extra_config_;
132 H26xStreamFormat h26x_stream_format_;
133 uint32_t width_;
134 uint32_t height_;
135
136 // pixel_width_:pixel_height_ is the sample aspect ratio.
137 // 0 means unknown.
138 uint32_t pixel_width_;
139 uint32_t pixel_height_;
140 uint8_t transfer_characteristics_ = 0;
141 uint8_t color_primaries_ = 0;
142 uint8_t matrix_coefficients_ = 0;
143 uint32_t trick_play_factor_ = 0; // Non-zero for trick-play streams.
144
145 // Playback rate is the attribute for trick play stream, which signals the
146 // playout capabilities
147 // (http://dashif.org/wp-content/uploads/2016/12/DASH-IF-IOP-v4.0-clean.pdf,
148 // page 18, line 1). It is the ratio of main frame rate to the trick play
149 // frame rate. If the time scale and frame duration are not modified after
150 // trick play handler processing, the playback_rate equals to the number of
151 // frames between consecutive key frames selected for trick play stream. For
152 // example, if the video stream has GOP size of 10 and the trick play factor
153 // is 3, the key frames are in this trick play stream are [frame_0, frame_30,
154 // frame_60, ...]. Then the playback_rate is 30.
155 // Non-zero for trick-play streams.
156 uint32_t playback_rate_ = 0;
157
158 // Specifies the size of the NAL unit length field. Can be 1, 2 or 4 bytes, or
159 // 0 if the stream is not a NAL structured video stream or if it is an AnnexB
160 // byte stream.
161 uint8_t nalu_length_size_;
162
163 // Container-specific data used by CDM to generate a license request:
164 // https://w3c.github.io/encrypted-media/#initialization-data.
165 std::vector<uint8_t> eme_init_data_;
166
167 // Raw colr atom data. It is only applicable to the mp4 container.
168 std::vector<uint8_t> colr_data_;
169
170 // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
171 // generated copy constructor and assignment operator. Since the extra data is
172 // typically small, the performance impact is minimal.
173};
174
175} // namespace media
176} // namespace shaka
177
178#endif // PACKAGER_MEDIA_BASE_VIDEO_STREAM_INFO_H_
Abstract class holds stream information.
Definition stream_info.h:73
Holds video stream information.
std::unique_ptr< StreamInfo > Clone() const override
bool IsValidConfig() const override
std::string ToString() const override
All the methods that are virtual are virtual for mocking.