Shaka Packager SDK
video_stream_info.cc
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 #include <packager/media/base/video_stream_info.h>
8 
9 #include <absl/log/log.h>
10 #include <absl/strings/str_format.h>
11 
12 #include <packager/macros/logging.h>
13 #include <packager/media/base/limits.h>
14 
15 namespace shaka {
16 namespace media {
17 
18 namespace {
19 std::string VideoCodecToString(Codec codec) {
20  switch (codec) {
21  case kCodecAV1:
22  return "AV1";
23  case kCodecH264:
24  return "H264";
25  case kCodecH265:
26  return "H265";
27  case kCodecH265DolbyVision:
28  return "H265 Dolby Vision";
29  case kCodecVP8:
30  return "VP8";
31  case kCodecVP9:
32  return "VP9";
33  default:
34  NOTIMPLEMENTED() << "Unknown Video Codec: " << codec;
35  return "UnknownCodec";
36  }
37 }
38 
39 } // namespace
40 
41 VideoStreamInfo::VideoStreamInfo(int track_id,
42  int32_t time_scale,
43  int64_t duration,
44  Codec codec,
45  H26xStreamFormat h26x_stream_format,
46  const std::string& codec_string,
47  const uint8_t* codec_config,
48  size_t codec_config_size,
49  uint32_t width,
50  uint32_t height,
51  uint32_t pixel_width,
52  uint32_t pixel_height,
53  uint8_t color_primaries,
54  uint8_t matrix_coefficients,
55  uint8_t transfer_characteristics,
56  uint32_t trick_play_factor,
57  uint8_t nalu_length_size,
58  const std::string& language,
59  bool is_encrypted)
60  : StreamInfo(kStreamVideo,
61  track_id,
62  time_scale,
63  duration,
64  codec,
65  codec_string,
66  codec_config,
67  codec_config_size,
68  language,
69  is_encrypted),
70  h26x_stream_format_(h26x_stream_format),
71  width_(width),
72  height_(height),
73  pixel_width_(pixel_width),
74  pixel_height_(pixel_height),
75  transfer_characteristics_(transfer_characteristics),
76  color_primaries_(color_primaries),
77  matrix_coefficients_(matrix_coefficients),
78  trick_play_factor_(trick_play_factor),
79  nalu_length_size_(nalu_length_size) {}
80 
81 VideoStreamInfo::~VideoStreamInfo() {}
82 
84  return codec() != kUnknownCodec && width_ > 0 &&
85  width_ <= limits::kMaxDimension && height_ > 0 &&
86  height_ <= limits::kMaxDimension &&
87  (nalu_length_size_ <= 2 || nalu_length_size_ == 4);
88 }
89 
90 std::string VideoStreamInfo::ToString() const {
91  return absl::StrFormat(
92  "%s codec: %s\n width: %d\n height: %d\n pixel_aspect_ratio: %d:%d\n "
93  "trick_play_factor: %d\n nalu_length_size: %d\n",
94  StreamInfo::ToString().c_str(), VideoCodecToString(codec()).c_str(),
95  width_, height_, pixel_width_, pixel_height_, trick_play_factor_,
96  nalu_length_size_);
97 }
98 
99 std::unique_ptr<StreamInfo> VideoStreamInfo::Clone() const {
100  return std::unique_ptr<StreamInfo>(new VideoStreamInfo(*this));
101 }
102 
103 } // namespace media
104 } // namespace shaka
Abstract class holds stream information.
Definition: stream_info.h:71
virtual std::string ToString() const
Definition: stream_info.cc:62
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.
Definition: crypto_flags.cc:66