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
|
|
|
|
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
|
|
|
|
2014-09-19 20:41:13 +00:00
|
|
|
namespace edash_packager {
|
2013-09-24 04:17:12 +00:00
|
|
|
namespace media {
|
|
|
|
|
2014-03-05 23:15:22 +00:00
|
|
|
namespace {
|
|
|
|
std::string VideoCodecToString(VideoCodec video_codec) {
|
|
|
|
switch (video_codec) {
|
|
|
|
case kCodecH264:
|
|
|
|
return "H264";
|
|
|
|
case kCodecVC1:
|
|
|
|
return "VC1";
|
|
|
|
case kCodecMPEG2:
|
|
|
|
return "MPEG2";
|
|
|
|
case kCodecMPEG4:
|
|
|
|
return "MPEG4";
|
|
|
|
case kCodecTheora:
|
|
|
|
return "Theora";
|
|
|
|
case kCodecVP8:
|
|
|
|
return "VP8";
|
|
|
|
case kCodecVP9:
|
|
|
|
return "VP9";
|
|
|
|
default:
|
|
|
|
NOTIMPLEMENTED() << "Unknown Video Codec: " << video_codec;
|
|
|
|
return "UnknownVideoCodec";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
VideoStreamInfo::VideoStreamInfo(int track_id,
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t time_scale,
|
|
|
|
uint64_t duration,
|
2013-09-24 04:17:12 +00:00
|
|
|
VideoCodec codec,
|
2013-10-14 20:55:48 +00:00
|
|
|
const std::string& codec_string,
|
|
|
|
const std::string& language,
|
2014-09-30 21:52:21 +00:00
|
|
|
uint16_t width,
|
|
|
|
uint16_t height,
|
|
|
|
uint8_t nalu_length_size,
|
|
|
|
const uint8_t* extra_data,
|
2013-09-24 04:17:12 +00:00
|
|
|
size_t extra_data_size,
|
|
|
|
bool is_encrypted)
|
|
|
|
: StreamInfo(kStreamVideo,
|
|
|
|
track_id,
|
|
|
|
time_scale,
|
2013-10-14 20:55:48 +00:00
|
|
|
duration,
|
|
|
|
codec_string,
|
|
|
|
language,
|
2013-09-24 04:17:12 +00:00
|
|
|
extra_data,
|
|
|
|
extra_data_size,
|
|
|
|
is_encrypted),
|
|
|
|
codec_(codec),
|
|
|
|
width_(width),
|
2013-11-12 20:32:44 +00:00
|
|
|
height_(height),
|
2014-09-30 21:52:21 +00:00
|
|
|
nalu_length_size_(nalu_length_size) {
|
|
|
|
}
|
2013-09-24 04:17:12 +00:00
|
|
|
|
|
|
|
VideoStreamInfo::~VideoStreamInfo() {}
|
|
|
|
|
|
|
|
bool VideoStreamInfo::IsValidConfig() const {
|
|
|
|
return codec_ != kUnknownVideoCodec &&
|
|
|
|
width_ > 0 && width_ <= limits::kMaxDimension &&
|
2013-11-12 20:32:44 +00:00
|
|
|
height_ > 0 && height_ <= limits::kMaxDimension &&
|
|
|
|
(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(
|
|
|
|
"%s codec: %s\n width: %d\n height: %d\n nalu_length_size: %d\n",
|
|
|
|
StreamInfo::ToString().c_str(),
|
|
|
|
VideoCodecToString(codec_).c_str(),
|
|
|
|
width_,
|
|
|
|
height_,
|
|
|
|
nalu_length_size_);
|
2013-09-24 04:17:12 +00:00
|
|
|
}
|
|
|
|
|
2013-10-14 20:55:48 +00:00
|
|
|
std::string VideoStreamInfo::GetCodecString(VideoCodec codec,
|
2014-09-30 21:52:21 +00:00
|
|
|
uint8_t profile,
|
|
|
|
uint8_t compatible_profiles,
|
|
|
|
uint8_t level) {
|
2013-10-14 20:55:48 +00:00
|
|
|
switch (codec) {
|
|
|
|
case kCodecVP8:
|
|
|
|
return "vp8";
|
|
|
|
case kCodecVP9:
|
|
|
|
return "vp9";
|
|
|
|
case kCodecH264: {
|
2014-09-30 21:52:21 +00:00
|
|
|
const uint8_t bytes[] = {profile, compatible_profiles, level};
|
2013-11-12 20:32:44 +00:00
|
|
|
return "avc1." +
|
|
|
|
StringToLowerASCII(base::HexEncode(bytes, arraysize(bytes)));
|
2013-10-14 20:55:48 +00:00
|
|
|
}
|
|
|
|
default:
|
2014-03-05 23:15:22 +00:00
|
|
|
NOTIMPLEMENTED() << "Unknown Codec: " << codec;
|
2013-10-14 20:55:48 +00:00
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
} // namespace media
|
2014-09-19 20:41:13 +00:00
|
|
|
} // namespace edash_packager
|