2022-08-26 15:44:59 +00:00
|
|
|
// Copyright 2014 Google LLC. All rights reserved.
|
2014-02-14 23:21:05 +00:00
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
2013-09-24 04:17:12 +00:00
|
|
|
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/media/base/video_stream_info.h>
|
2013-09-24 04:17:12 +00:00
|
|
|
|
2023-10-09 23:21:41 +00:00
|
|
|
#include <absl/strings/str_format.h>
|
|
|
|
#include <glog/logging.h>
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/macros.h>
|
|
|
|
#include <packager/media/base/limits.h>
|
2013-09-24 04:17:12 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2013-09-24 04:17:12 +00:00
|
|
|
namespace media {
|
|
|
|
|
2014-03-05 23:15:22 +00:00
|
|
|
namespace {
|
2016-07-27 00:51:08 +00:00
|
|
|
std::string VideoCodecToString(Codec codec) {
|
|
|
|
switch (codec) {
|
2018-08-25 02:04:00 +00:00
|
|
|
case kCodecAV1:
|
|
|
|
return "AV1";
|
2014-03-05 23:15:22 +00:00
|
|
|
case kCodecH264:
|
|
|
|
return "H264";
|
2017-03-23 18:34:20 +00:00
|
|
|
case kCodecH265:
|
|
|
|
return "H265";
|
2019-09-21 01:02:13 +00:00
|
|
|
case kCodecH265DolbyVision:
|
|
|
|
return "H265 Dolby Vision";
|
2014-03-05 23:15:22 +00:00
|
|
|
case kCodecVP8:
|
|
|
|
return "VP8";
|
|
|
|
case kCodecVP9:
|
|
|
|
return "VP9";
|
|
|
|
default:
|
2016-07-27 00:51:08 +00:00
|
|
|
NOTIMPLEMENTED() << "Unknown Video Codec: " << codec;
|
|
|
|
return "UnknownCodec";
|
2014-03-05 23:15:22 +00:00
|
|
|
}
|
|
|
|
}
|
2015-06-17 22:42:56 +00:00
|
|
|
|
2014-03-05 23:15:22 +00:00
|
|
|
} // namespace
|
|
|
|
|
2017-03-23 18:34:20 +00:00
|
|
|
VideoStreamInfo::VideoStreamInfo(int track_id,
|
2021-08-04 18:56:44 +00:00
|
|
|
int32_t time_scale,
|
|
|
|
int64_t duration,
|
2017-03-23 18:34:20 +00:00
|
|
|
Codec codec,
|
|
|
|
H26xStreamFormat h26x_stream_format,
|
|
|
|
const std::string& codec_string,
|
|
|
|
const uint8_t* codec_config,
|
|
|
|
size_t codec_config_size,
|
2022-11-04 22:46:41 +00:00
|
|
|
uint32_t width,
|
|
|
|
uint32_t height,
|
2017-03-23 18:34:20 +00:00
|
|
|
uint32_t pixel_width,
|
|
|
|
uint32_t pixel_height,
|
2019-09-23 06:24:33 +00:00
|
|
|
uint8_t transfer_characteristics,
|
2017-05-15 16:22:06 +00:00
|
|
|
uint32_t trick_play_factor,
|
2017-03-23 18:34:20 +00:00
|
|
|
uint8_t nalu_length_size,
|
|
|
|
const std::string& language,
|
|
|
|
bool is_encrypted)
|
|
|
|
: StreamInfo(kStreamVideo,
|
|
|
|
track_id,
|
|
|
|
time_scale,
|
|
|
|
duration,
|
|
|
|
codec,
|
|
|
|
codec_string,
|
|
|
|
codec_config,
|
|
|
|
codec_config_size,
|
|
|
|
language,
|
2013-09-24 04:17:12 +00:00
|
|
|
is_encrypted),
|
2017-03-23 18:34:20 +00:00
|
|
|
h26x_stream_format_(h26x_stream_format),
|
2013-09-24 04:17:12 +00:00
|
|
|
width_(width),
|
2013-11-12 20:32:44 +00:00
|
|
|
height_(height),
|
2015-06-17 22:42:56 +00:00
|
|
|
pixel_width_(pixel_width),
|
|
|
|
pixel_height_(pixel_height),
|
2019-09-23 06:24:33 +00:00
|
|
|
transfer_characteristics_(transfer_characteristics),
|
2017-05-15 16:22:06 +00:00
|
|
|
trick_play_factor_(trick_play_factor),
|
2016-07-27 00:51:08 +00:00
|
|
|
nalu_length_size_(nalu_length_size) {}
|
2013-09-24 04:17:12 +00:00
|
|
|
|
|
|
|
VideoStreamInfo::~VideoStreamInfo() {}
|
|
|
|
|
|
|
|
bool VideoStreamInfo::IsValidConfig() const {
|
2016-07-27 00:51:08 +00:00
|
|
|
return codec() != kUnknownCodec && width_ > 0 &&
|
|
|
|
width_ <= limits::kMaxDimension && height_ > 0 &&
|
|
|
|
height_ <= limits::kMaxDimension &&
|
2013-11-12 20:32:44 +00:00
|
|
|
(nalu_length_size_ <= 2 || nalu_length_size_ == 4);
|
2013-09-24 04:17:12 +00:00
|
|
|
}
|
|
|
|
|
2013-10-14 20:55:48 +00:00
|
|
|
std::string VideoStreamInfo::ToString() const {
|
2022-11-04 22:46:41 +00:00
|
|
|
return absl::StrFormat(
|
2015-12-09 23:54:02 +00:00
|
|
|
"%s codec: %s\n width: %d\n height: %d\n pixel_aspect_ratio: %d:%d\n "
|
2017-05-15 16:22:06 +00:00
|
|
|
"trick_play_factor: %d\n nalu_length_size: %d\n",
|
2016-07-27 00:51:08 +00:00
|
|
|
StreamInfo::ToString().c_str(), VideoCodecToString(codec()).c_str(),
|
2017-05-15 16:22:06 +00:00
|
|
|
width_, height_, pixel_width_, pixel_height_, trick_play_factor_,
|
2015-09-25 22:48:18 +00:00
|
|
|
nalu_length_size_);
|
2013-09-24 04:17:12 +00:00
|
|
|
}
|
|
|
|
|
2017-09-12 17:24:24 +00:00
|
|
|
std::unique_ptr<StreamInfo> VideoStreamInfo::Clone() const {
|
|
|
|
return std::unique_ptr<StreamInfo>(new VideoStreamInfo(*this));
|
|
|
|
}
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|