Shaka Packager SDK
video_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_VIDEO_STREAM_INFO_H_
8 #define PACKAGER_MEDIA_BASE_VIDEO_STREAM_INFO_H_
9 
10 #include "packager/media/base/stream_info.h"
11 
12 namespace shaka {
13 namespace media {
14 
15 enum class H26xStreamFormat {
16  kUnSpecified,
17  kAnnexbByteStream,
18  kNalUnitStreamWithParameterSetNalus,
19  kNalUnitStreamWithoutParameterSetNalus,
20 };
21 
23 class VideoStreamInfo : public StreamInfo {
24  public:
25  VideoStreamInfo() = default;
26 
30  VideoStreamInfo(int track_id,
31  uint32_t time_scale,
32  uint64_t duration,
33  Codec codec,
34  H26xStreamFormat h26x_stream_format,
35  const std::string& codec_string,
36  const uint8_t* codec_config,
37  size_t codec_config_size,
38  uint16_t width,
39  uint16_t height,
40  uint32_t pixel_width,
41  uint32_t pixel_height,
42  uint8_t transfer_characteristics,
43  uint32_t trick_play_factor,
44  uint8_t nalu_length_size,
45  const std::string& language,
46  bool is_encrypted);
47 
48  ~VideoStreamInfo() override;
49 
52  bool IsValidConfig() const override;
53  std::string ToString() const override;
54  std::unique_ptr<StreamInfo> Clone() const override;
56 
57  const std::vector<uint8_t>& extra_config() const { return extra_config_; }
58  H26xStreamFormat h26x_stream_format() const { return h26x_stream_format_; }
59  uint16_t width() const { return width_; }
60  uint16_t height() const { return height_; }
63  uint32_t pixel_width() const { return pixel_width_; }
66  uint32_t pixel_height() const { return pixel_height_; }
67  uint8_t transfer_characteristics() const { return transfer_characteristics_; }
68  uint8_t nalu_length_size() const { return nalu_length_size_; }
69  uint32_t trick_play_factor() const { return trick_play_factor_; }
70  uint32_t playback_rate() const { return playback_rate_; }
71  const std::vector<uint8_t>& eme_init_data() const { return eme_init_data_; }
72 
73  void set_extra_config(const std::vector<uint8_t>& extra_config) {
74  extra_config_ = extra_config;
75  }
76  void set_width(uint32_t width) { width_ = width; }
77  void set_height(uint32_t height) { height_ = height; }
78  void set_pixel_width(uint32_t pixel_width) { pixel_width_ = pixel_width; }
79  void set_pixel_height(uint32_t pixel_height) { pixel_height_ = pixel_height; }
80  void set_transfer_characteristics(uint8_t transfer_characteristics) {
81  transfer_characteristics_ = transfer_characteristics;
82  }
83  void set_trick_play_factor(uint32_t trick_play_factor) {
84  trick_play_factor_ = trick_play_factor;
85  }
86  void set_playback_rate(uint32_t playback_rate) {
87  playback_rate_ = playback_rate;
88  }
89  void set_eme_init_data(const uint8_t* eme_init_data,
90  size_t eme_init_data_size) {
91  eme_init_data_.assign(eme_init_data, eme_init_data + eme_init_data_size);
92  }
93 
94  private:
95  // Extra codec configuration in a stream of mp4 boxes. It is only applicable
96  // to mp4 container only. It is needed by some codecs, e.g. Dolby Vision.
97  std::vector<uint8_t> extra_config_;
98  H26xStreamFormat h26x_stream_format_;
99  uint16_t width_;
100  uint16_t height_;
101 
102  // pixel_width_:pixel_height_ is the sample aspect ratio.
103  // 0 means unknown.
104  uint32_t pixel_width_;
105  uint32_t pixel_height_;
106  uint8_t transfer_characteristics_ = 0;
107  uint32_t trick_play_factor_ = 0; // Non-zero for trick-play streams.
108 
109  // Playback rate is the attribute for trick play stream, which signals the
110  // playout capabilities
111  // (http://dashif.org/wp-content/uploads/2016/12/DASH-IF-IOP-v4.0-clean.pdf,
112  // page 18, line 1). It is the ratio of main frame rate to the trick play
113  // frame rate. If the time scale and frame duration are not modified after
114  // trick play handler processing, the playback_rate equals to the number of
115  // frames between consecutive key frames selected for trick play stream. For
116  // example, if the video stream has GOP size of 10 and the trick play factor
117  // is 3, the key frames are in this trick play stream are [frame_0, frame_30,
118  // frame_60, ...]. Then the playback_rate is 30.
119  // Non-zero for trick-play streams.
120  uint32_t playback_rate_ = 0;
121 
122  // Specifies the size of the NAL unit length field. Can be 1, 2 or 4 bytes, or
123  // 0 if the stream is not a NAL structured video stream or if it is an AnnexB
124  // byte stream.
125  uint8_t nalu_length_size_;
126 
127  // Container-specific data used by CDM to generate a license request:
128  // https://w3c.github.io/encrypted-media/#initialization-data.
129  std::vector<uint8_t> eme_init_data_;
130 
131  // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
132  // generated copy constructor and assignment operator. Since the extra data is
133  // typically small, the performance impact is minimal.
134 };
135 
136 } // namespace media
137 } // namespace shaka
138 
139 #endif // PACKAGER_MEDIA_BASE_VIDEO_STREAM_INFO_H_
Abstract class holds stream information.
Definition: stream_info.h:65
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.