2014-02-14 23:21:05 +00:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/media/base/video_stream_info.h"
|
2013-09-24 04:17:12 +00:00
|
|
|
|
2015-08-20 19:06:02 +00:00
|
|
|
#include "packager/base/logging.h"
|
2015-08-20 17:57:51 +00:00
|
|
|
#include "packager/base/stl_util.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/base/strings/string_number_conversions.h"
|
|
|
|
#include "packager/base/strings/string_util.h"
|
|
|
|
#include "packager/base/strings/stringprintf.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) {
|
2014-03-05 23:15:22 +00:00
|
|
|
case kCodecH264:
|
|
|
|
return "H264";
|
2015-10-29 00:26:29 +00:00
|
|
|
case kCodecHEV1:
|
|
|
|
return "HEV1";
|
|
|
|
case kCodecHVC1:
|
|
|
|
return "HVC1";
|
2014-03-05 23:15:22 +00:00
|
|
|
case kCodecVC1:
|
|
|
|
return "VC1";
|
|
|
|
case kCodecMPEG2:
|
|
|
|
return "MPEG2";
|
|
|
|
case kCodecMPEG4:
|
|
|
|
return "MPEG4";
|
|
|
|
case kCodecTheora:
|
|
|
|
return "Theora";
|
|
|
|
case kCodecVP8:
|
|
|
|
return "VP8";
|
|
|
|
case kCodecVP9:
|
|
|
|
return "VP9";
|
2015-10-26 20:50:22 +00:00
|
|
|
case kCodecVP10:
|
|
|
|
return "VP10";
|
2014-03-05 23:15:22 +00:00
|
|
|
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
|
|
|
|
|
2016-07-27 00:51:08 +00:00
|
|
|
VideoStreamInfo::VideoStreamInfo(
|
|
|
|
int track_id, uint32_t time_scale, uint64_t duration, Codec codec,
|
|
|
|
const std::string& codec_string, const uint8_t* codec_config,
|
|
|
|
size_t codec_config_size, uint16_t width, uint16_t height,
|
|
|
|
uint32_t pixel_width, uint32_t pixel_height, int16_t trick_play_rate,
|
|
|
|
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),
|
|
|
|
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),
|
2015-06-02 21:41:49 +00:00
|
|
|
trick_play_rate_(trick_play_rate),
|
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 {
|
2014-03-05 23:15:22 +00:00
|
|
|
return base::StringPrintf(
|
2015-12-09 23:54:02 +00:00
|
|
|
"%s codec: %s\n width: %d\n height: %d\n pixel_aspect_ratio: %d:%d\n "
|
2015-09-25 22:48:18 +00:00
|
|
|
"trick_play_rate: %d\n nalu_length_size: %d\n",
|
2016-07-27 00:51:08 +00:00
|
|
|
StreamInfo::ToString().c_str(), VideoCodecToString(codec()).c_str(),
|
2015-09-25 22:48:18 +00:00
|
|
|
width_, height_, pixel_width_, pixel_height_, trick_play_rate_,
|
|
|
|
nalu_length_size_);
|
2013-09-24 04:17:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|