2015-10-08 21:48:07 +00:00
|
|
|
// Copyright 2014 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2015-10-14 22:46:23 +00:00
|
|
|
#include "packager/media/formats/webm/webm_video_client.h"
|
2015-10-08 21:48:07 +00:00
|
|
|
|
2015-10-14 22:46:23 +00:00
|
|
|
#include "packager/media/base/video_decoder_config.h"
|
|
|
|
#include "packager/media/formats/webm/webm_constants.h"
|
2015-10-08 21:48:07 +00:00
|
|
|
|
2015-10-14 22:46:23 +00:00
|
|
|
namespace edash_packager {
|
2015-10-08 21:48:07 +00:00
|
|
|
namespace media {
|
|
|
|
|
2015-10-14 22:46:23 +00:00
|
|
|
WebMVideoClient::WebMVideoClient() {
|
2015-10-08 21:48:07 +00:00
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
WebMVideoClient::~WebMVideoClient() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebMVideoClient::Reset() {
|
|
|
|
pixel_width_ = -1;
|
|
|
|
pixel_height_ = -1;
|
|
|
|
crop_bottom_ = -1;
|
|
|
|
crop_top_ = -1;
|
|
|
|
crop_left_ = -1;
|
|
|
|
crop_right_ = -1;
|
|
|
|
display_width_ = -1;
|
|
|
|
display_height_ = -1;
|
|
|
|
display_unit_ = -1;
|
|
|
|
alpha_mode_ = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebMVideoClient::InitializeConfig(
|
2015-10-14 22:46:23 +00:00
|
|
|
const std::string& codec_id,
|
|
|
|
const std::vector<uint8_t>& codec_private,
|
|
|
|
bool is_encrypted,
|
|
|
|
VideoDecoderConfig* config) {
|
2015-10-08 21:48:07 +00:00
|
|
|
DCHECK(config);
|
|
|
|
|
|
|
|
VideoCodec video_codec = kUnknownVideoCodec;
|
|
|
|
VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN;
|
|
|
|
if (codec_id == "V_VP8") {
|
|
|
|
video_codec = kCodecVP8;
|
|
|
|
profile = VP8PROFILE_ANY;
|
|
|
|
} else if (codec_id == "V_VP9") {
|
|
|
|
video_codec = kCodecVP9;
|
|
|
|
profile = VP9PROFILE_ANY;
|
|
|
|
} else {
|
2015-10-14 22:46:23 +00:00
|
|
|
LOG(ERROR) << "Unsupported video codec_id " << codec_id;
|
2015-10-08 21:48:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
VideoPixelFormat format =
|
|
|
|
(alpha_mode_ == 1) ? PIXEL_FORMAT_YV12A : PIXEL_FORMAT_YV12;
|
|
|
|
|
|
|
|
if (pixel_width_ <= 0 || pixel_height_ <= 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Set crop and display unit defaults if these elements are not present.
|
|
|
|
if (crop_bottom_ == -1)
|
|
|
|
crop_bottom_ = 0;
|
|
|
|
|
|
|
|
if (crop_top_ == -1)
|
|
|
|
crop_top_ = 0;
|
|
|
|
|
|
|
|
if (crop_left_ == -1)
|
|
|
|
crop_left_ = 0;
|
|
|
|
|
|
|
|
if (crop_right_ == -1)
|
|
|
|
crop_right_ = 0;
|
|
|
|
|
|
|
|
if (display_unit_ == -1)
|
|
|
|
display_unit_ = 0;
|
|
|
|
|
|
|
|
gfx::Size coded_size(pixel_width_, pixel_height_);
|
|
|
|
gfx::Rect visible_rect(crop_top_, crop_left_,
|
|
|
|
pixel_width_ - (crop_left_ + crop_right_),
|
|
|
|
pixel_height_ - (crop_top_ + crop_bottom_));
|
|
|
|
if (display_unit_ == 0) {
|
|
|
|
if (display_width_ <= 0)
|
|
|
|
display_width_ = visible_rect.width();
|
|
|
|
if (display_height_ <= 0)
|
|
|
|
display_height_ = visible_rect.height();
|
|
|
|
} else if (display_unit_ == 3) {
|
|
|
|
if (display_width_ <= 0 || display_height_ <= 0)
|
|
|
|
return false;
|
|
|
|
} else {
|
2015-10-14 22:46:23 +00:00
|
|
|
LOG(ERROR) << "Unsupported display unit type " << display_unit_;
|
2015-10-08 21:48:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
gfx::Size natural_size = gfx::Size(display_width_, display_height_);
|
2015-10-14 22:46:23 +00:00
|
|
|
const uint8_t* extra_data = NULL;
|
2015-10-08 21:48:07 +00:00
|
|
|
size_t extra_data_size = 0;
|
|
|
|
if (codec_private.size() > 0) {
|
|
|
|
extra_data = &codec_private[0];
|
|
|
|
extra_data_size = codec_private.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
config->Initialize(video_codec, profile, format, COLOR_SPACE_HD_REC709,
|
|
|
|
coded_size, visible_rect, natural_size, extra_data,
|
|
|
|
extra_data_size, is_encrypted);
|
|
|
|
return config->IsValidConfig();
|
|
|
|
}
|
|
|
|
|
2015-10-14 22:46:23 +00:00
|
|
|
bool WebMVideoClient::OnUInt(int id, int64_t val) {
|
|
|
|
int64_t* dst = NULL;
|
2015-10-08 21:48:07 +00:00
|
|
|
|
|
|
|
switch (id) {
|
|
|
|
case kWebMIdPixelWidth:
|
|
|
|
dst = &pixel_width_;
|
|
|
|
break;
|
|
|
|
case kWebMIdPixelHeight:
|
|
|
|
dst = &pixel_height_;
|
|
|
|
break;
|
|
|
|
case kWebMIdPixelCropTop:
|
|
|
|
dst = &crop_top_;
|
|
|
|
break;
|
|
|
|
case kWebMIdPixelCropBottom:
|
|
|
|
dst = &crop_bottom_;
|
|
|
|
break;
|
|
|
|
case kWebMIdPixelCropLeft:
|
|
|
|
dst = &crop_left_;
|
|
|
|
break;
|
|
|
|
case kWebMIdPixelCropRight:
|
|
|
|
dst = &crop_right_;
|
|
|
|
break;
|
|
|
|
case kWebMIdDisplayWidth:
|
|
|
|
dst = &display_width_;
|
|
|
|
break;
|
|
|
|
case kWebMIdDisplayHeight:
|
|
|
|
dst = &display_height_;
|
|
|
|
break;
|
|
|
|
case kWebMIdDisplayUnit:
|
|
|
|
dst = &display_unit_;
|
|
|
|
break;
|
|
|
|
case kWebMIdAlphaMode:
|
|
|
|
dst = &alpha_mode_;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*dst != -1) {
|
2015-10-14 22:46:23 +00:00
|
|
|
LOG(ERROR) << "Multiple values for id " << std::hex << id << " specified ("
|
|
|
|
<< *dst << " and " << val << ")";
|
2015-10-08 21:48:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*dst = val;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-14 22:46:23 +00:00
|
|
|
bool WebMVideoClient::OnBinary(int id, const uint8_t* data, int size) {
|
2015-10-08 21:48:07 +00:00
|
|
|
// Accept binary fields we don't care about for now.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebMVideoClient::OnFloat(int id, double val) {
|
|
|
|
// Accept float fields we don't care about for now.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace media
|
2015-10-14 22:46:23 +00:00
|
|
|
} // namespace edash_packager
|