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