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 kCodecH264:
22  return "H264";
23  case kCodecH265:
24  return "H265";
25  case kCodecVP8:
26  return "VP8";
27  case kCodecVP9:
28  return "VP9";
29  case kCodecVP10:
30  return "VP10";
31  default:
32  NOTIMPLEMENTED() << "Unknown Video Codec: " << codec;
33  return "UnknownCodec";
34  }
35 }
36 
37 } // namespace
38 
39 VideoStreamInfo::VideoStreamInfo(int track_id,
40  uint32_t time_scale,
41  uint64_t duration,
42  Codec codec,
43  H26xStreamFormat h26x_stream_format,
44  const std::string& codec_string,
45  const uint8_t* codec_config,
46  size_t codec_config_size,
47  uint16_t width,
48  uint16_t height,
49  uint32_t pixel_width,
50  uint32_t pixel_height,
51  uint32_t trick_play_factor,
52  uint8_t nalu_length_size,
53  const std::string& language,
54  bool is_encrypted)
55  : StreamInfo(kStreamVideo,
56  track_id,
57  time_scale,
58  duration,
59  codec,
60  codec_string,
61  codec_config,
62  codec_config_size,
63  language,
64  is_encrypted),
65  h26x_stream_format_(h26x_stream_format),
66  width_(width),
67  height_(height),
68  pixel_width_(pixel_width),
69  pixel_height_(pixel_height),
70  trick_play_factor_(trick_play_factor),
71  nalu_length_size_(nalu_length_size) {}
72 
73 VideoStreamInfo::~VideoStreamInfo() {}
74 
76  return codec() != kUnknownCodec && width_ > 0 &&
77  width_ <= limits::kMaxDimension && height_ > 0 &&
78  height_ <= limits::kMaxDimension &&
79  (nalu_length_size_ <= 2 || nalu_length_size_ == 4);
80 }
81 
82 std::string VideoStreamInfo::ToString() const {
83  return base::StringPrintf(
84  "%s codec: %s\n width: %d\n height: %d\n pixel_aspect_ratio: %d:%d\n "
85  "trick_play_factor: %d\n nalu_length_size: %d\n",
86  StreamInfo::ToString().c_str(), VideoCodecToString(codec()).c_str(),
87  width_, height_, pixel_width_, pixel_height_, trick_play_factor_,
88  nalu_length_size_);
89 }
90 
91 std::unique_ptr<StreamInfo> VideoStreamInfo::Clone() const {
92  return std::unique_ptr<StreamInfo>(new VideoStreamInfo(*this));
93 }
94 
95 } // namespace media
96 } // namespace shaka
Abstract class holds stream information.
Definition: stream_info.h:58
bool IsValidConfig() const override
std::unique_ptr< StreamInfo > Clone() const override
virtual std::string ToString() const
Definition: stream_info.cc:37
All the methods that are virtual are virtual for mocking.
Holds video stream information.
std::string ToString() const override