Shaka Packager SDK
video_stream_info.cc
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 #include "packager/media/base/video_stream_info.h"
8 
9 #include "packager/base/logging.h"
10 #include "packager/base/strings/string_number_conversions.h"
11 #include "packager/base/strings/string_util.h"
12 #include "packager/base/strings/stringprintf.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  uint32_t time_scale,
43  uint64_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  uint16_t width,
50  uint16_t height,
51  uint32_t pixel_width,
52  uint32_t pixel_height,
53  uint8_t transfer_characteristics,
54  uint32_t trick_play_factor,
55  uint8_t nalu_length_size,
56  const std::string& language,
57  bool is_encrypted)
58  : StreamInfo(kStreamVideo,
59  track_id,
60  time_scale,
61  duration,
62  codec,
63  codec_string,
64  codec_config,
65  codec_config_size,
66  language,
67  is_encrypted),
68  h26x_stream_format_(h26x_stream_format),
69  width_(width),
70  height_(height),
71  pixel_width_(pixel_width),
72  pixel_height_(pixel_height),
73  transfer_characteristics_(transfer_characteristics),
74  trick_play_factor_(trick_play_factor),
75  nalu_length_size_(nalu_length_size) {}
76 
77 VideoStreamInfo::~VideoStreamInfo() {}
78 
80  return codec() != kUnknownCodec && width_ > 0 &&
81  width_ <= limits::kMaxDimension && height_ > 0 &&
82  height_ <= limits::kMaxDimension &&
83  (nalu_length_size_ <= 2 || nalu_length_size_ == 4);
84 }
85 
86 std::string VideoStreamInfo::ToString() const {
87  return base::StringPrintf(
88  "%s codec: %s\n width: %d\n height: %d\n pixel_aspect_ratio: %d:%d\n "
89  "trick_play_factor: %d\n nalu_length_size: %d\n",
90  StreamInfo::ToString().c_str(), VideoCodecToString(codec()).c_str(),
91  width_, height_, pixel_width_, pixel_height_, trick_play_factor_,
92  nalu_length_size_);
93 }
94 
95 std::unique_ptr<StreamInfo> VideoStreamInfo::Clone() const {
96  return std::unique_ptr<StreamInfo>(new VideoStreamInfo(*this));
97 }
98 
99 } // namespace media
100 } // namespace shaka
Abstract class holds stream information.
Definition: stream_info.h:65
virtual std::string ToString() const
Definition: stream_info.cc:59
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.