| Index: media/gpu/vaapi_video_encode_accelerator.cc
|
| diff --git a/content/common/gpu/media/vaapi_video_encode_accelerator.cc b/media/gpu/vaapi_video_encode_accelerator.cc
|
| similarity index 93%
|
| rename from content/common/gpu/media/vaapi_video_encode_accelerator.cc
|
| rename to media/gpu/vaapi_video_encode_accelerator.cc
|
| index dfa7f9f8a0006928cb0d3fd234423651ee86e5ba..5eea88e5335b78e457ff784a2789c0e7f850b3cd 100644
|
| --- a/content/common/gpu/media/vaapi_video_encode_accelerator.cc
|
| +++ b/media/gpu/vaapi_video_encode_accelerator.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "content/common/gpu/media/vaapi_video_encode_accelerator.h"
|
| +#include "media/gpu/vaapi_video_encode_accelerator.h"
|
|
|
| #include <string.h>
|
|
|
| @@ -14,22 +14,22 @@
|
| #include "base/macros.h"
|
| #include "base/metrics/histogram.h"
|
| #include "base/numerics/safe_conversions.h"
|
| -#include "content/common/gpu/media/h264_dpb.h"
|
| -#include "content/common/gpu/media/shared_memory_region.h"
|
| #include "media/base/bind_to_current_loop.h"
|
| +#include "media/gpu/h264_dpb.h"
|
| +#include "media/gpu/shared_memory_region.h"
|
| #include "third_party/libva/va/va_enc_h264.h"
|
|
|
| #define DVLOGF(level) DVLOG(level) << __FUNCTION__ << "(): "
|
|
|
| -#define NOTIFY_ERROR(error, msg) \
|
| - do { \
|
| - SetState(kError); \
|
| - LOG(ERROR) << msg; \
|
| - LOG(ERROR) << "Calling NotifyError(" << error << ")";\
|
| - NotifyError(error); \
|
| +#define NOTIFY_ERROR(error, msg) \
|
| + do { \
|
| + SetState(kError); \
|
| + LOG(ERROR) << msg; \
|
| + LOG(ERROR) << "Calling NotifyError(" << error << ")"; \
|
| + NotifyError(error); \
|
| } while (0)
|
|
|
| -namespace content {
|
| +namespace media {
|
|
|
| namespace {
|
| // Need 2 surfaces for each frame: one for input data and one for
|
| @@ -74,10 +74,8 @@ const int kCPBWindowSizeMs = 1500;
|
| // UMA errors that the VaapiVideoEncodeAccelerator class reports.
|
| enum VAVEAEncoderFailure {
|
| VAAPI_ERROR = 0,
|
| - // UMA requires that max must be greater than 1.
|
| - VAVEA_ENCODER_FAILURES_MAX = 2,
|
| + VAVEA_ENCODER_FAILURES_MAX,
|
| };
|
| -
|
| }
|
|
|
| // Round |value| up to |alignment|, which must be a power of 2.
|
| @@ -88,10 +86,8 @@ static inline size_t RoundUpToPowerOf2(size_t value, size_t alignment) {
|
| }
|
|
|
| static void ReportToUMA(VAVEAEncoderFailure failure) {
|
| - UMA_HISTOGRAM_ENUMERATION(
|
| - "Media.VAVEA.EncoderFailure",
|
| - failure,
|
| - VAVEA_ENCODER_FAILURES_MAX);
|
| + UMA_HISTOGRAM_ENUMERATION("Media.VAVEA.EncoderFailure", failure,
|
| + VAVEA_ENCODER_FAILURES_MAX + 1);
|
| }
|
|
|
| struct VaapiVideoEncodeAccelerator::InputFrameRef {
|
| @@ -178,15 +174,15 @@ bool VaapiVideoEncodeAccelerator::Initialize(
|
|
|
| const SupportedProfiles& profiles = GetSupportedProfiles();
|
| auto profile = find_if(profiles.begin(), profiles.end(),
|
| - [output_profile](const SupportedProfile& profile) {
|
| - return profile.profile == output_profile;
|
| - });
|
| + [output_profile](const SupportedProfile& profile) {
|
| + return profile.profile == output_profile;
|
| + });
|
| if (profile == profiles.end()) {
|
| DVLOGF(1) << "Unsupported output profile " << output_profile;
|
| return false;
|
| }
|
| if (input_visible_size.width() > profile->max_resolution.width() ||
|
| - input_visible_size.height() > profile->max_resolution.height()) {
|
| + input_visible_size.height() > profile->max_resolution.height()) {
|
| DVLOGF(1) << "Input size too big: " << input_visible_size.ToString()
|
| << ", max supported size: " << profile->max_resolution.ToString();
|
| return false;
|
| @@ -375,8 +371,7 @@ bool VaapiVideoEncodeAccelerator::SubmitFrameParameters() {
|
| #undef SPS_TO_SP
|
|
|
| if (!vaapi_wrapper_->SubmitBuffer(VAEncSequenceParameterBufferType,
|
| - sizeof(seq_param),
|
| - &seq_param))
|
| + sizeof(seq_param), &seq_param))
|
| return false;
|
|
|
| VAEncPictureParameterBufferH264 pic_param;
|
| @@ -414,8 +409,7 @@ bool VaapiVideoEncodeAccelerator::SubmitFrameParameters() {
|
| #undef PPS_TO_PP_PF
|
|
|
| if (!vaapi_wrapper_->SubmitBuffer(VAEncPictureParameterBufferType,
|
| - sizeof(pic_param),
|
| - &pic_param))
|
| + sizeof(pic_param), &pic_param))
|
| return false;
|
|
|
| VAEncSliceParameterBufferH264 slice_param;
|
| @@ -446,8 +440,7 @@ bool VaapiVideoEncodeAccelerator::SubmitFrameParameters() {
|
| }
|
|
|
| if (!vaapi_wrapper_->SubmitBuffer(VAEncSliceParameterBufferType,
|
| - sizeof(slice_param),
|
| - &slice_param))
|
| + sizeof(slice_param), &slice_param))
|
| return false;
|
|
|
| VAEncMiscParameterRateControl rate_control_param;
|
| @@ -459,8 +452,7 @@ bool VaapiVideoEncodeAccelerator::SubmitFrameParameters() {
|
| rate_control_param.rc_flags.bits.disable_frame_skip = true;
|
|
|
| if (!vaapi_wrapper_->SubmitVAEncMiscParamBuffer(
|
| - VAEncMiscParameterTypeRateControl,
|
| - sizeof(rate_control_param),
|
| + VAEncMiscParameterTypeRateControl, sizeof(rate_control_param),
|
| &rate_control_param))
|
| return false;
|
|
|
| @@ -468,8 +460,7 @@ bool VaapiVideoEncodeAccelerator::SubmitFrameParameters() {
|
| memset(&framerate_param, 0, sizeof(framerate_param));
|
| framerate_param.framerate = framerate_;
|
| if (!vaapi_wrapper_->SubmitVAEncMiscParamBuffer(
|
| - VAEncMiscParameterTypeFrameRate,
|
| - sizeof(framerate_param),
|
| + VAEncMiscParameterTypeFrameRate, sizeof(framerate_param),
|
| &framerate_param))
|
| return false;
|
|
|
| @@ -477,9 +468,8 @@ bool VaapiVideoEncodeAccelerator::SubmitFrameParameters() {
|
| memset(&hrd_param, 0, sizeof(hrd_param));
|
| hrd_param.buffer_size = cpb_size_;
|
| hrd_param.initial_buffer_fullness = cpb_size_ / 2;
|
| - if (!vaapi_wrapper_->SubmitVAEncMiscParamBuffer(VAEncMiscParameterTypeHRD,
|
| - sizeof(hrd_param),
|
| - &hrd_param))
|
| + if (!vaapi_wrapper_->SubmitVAEncMiscParamBuffer(
|
| + VAEncMiscParameterTypeHRD, sizeof(hrd_param), &hrd_param))
|
| return false;
|
|
|
| return true;
|
| @@ -497,8 +487,7 @@ bool VaapiVideoEncodeAccelerator::SubmitHeadersIfNeeded() {
|
| par_buffer.bit_length = packed_sps_.BytesInBuffer() * 8;
|
|
|
| if (!vaapi_wrapper_->SubmitBuffer(VAEncPackedHeaderParameterBufferType,
|
| - sizeof(par_buffer),
|
| - &par_buffer))
|
| + sizeof(par_buffer), &par_buffer))
|
| return false;
|
|
|
| if (!vaapi_wrapper_->SubmitBuffer(VAEncPackedHeaderDataBufferType,
|
| @@ -512,8 +501,7 @@ bool VaapiVideoEncodeAccelerator::SubmitHeadersIfNeeded() {
|
| par_buffer.bit_length = packed_pps_.BytesInBuffer() * 8;
|
|
|
| if (!vaapi_wrapper_->SubmitBuffer(VAEncPackedHeaderParameterBufferType,
|
| - sizeof(par_buffer),
|
| - &par_buffer))
|
| + sizeof(par_buffer), &par_buffer))
|
| return false;
|
|
|
| if (!vaapi_wrapper_->SubmitBuffer(VAEncPackedHeaderDataBufferType,
|
| @@ -764,9 +752,8 @@ void VaapiVideoEncodeAccelerator::Destroy() {
|
| // Early-exit encoder tasks if they are running and join the thread.
|
| if (encoder_thread_.IsRunning()) {
|
| encoder_thread_.message_loop()->PostTask(
|
| - FROM_HERE,
|
| - base::Bind(&VaapiVideoEncodeAccelerator::DestroyTask,
|
| - base::Unretained(this)));
|
| + FROM_HERE, base::Bind(&VaapiVideoEncodeAccelerator::DestroyTask,
|
| + base::Unretained(this)));
|
| encoder_thread_.Stop();
|
| }
|
|
|
| @@ -853,10 +840,12 @@ void VaapiVideoEncodeAccelerator::UpdateSPS() {
|
| current_sps_.cpb_size_scale = kCPBSizeScale;
|
| current_sps_.bit_rate_value_minus1[0] =
|
| (bitrate_ >>
|
| - (kBitRateScale + media::H264SPS::kBitRateScaleConstantTerm)) - 1;
|
| + (kBitRateScale + media::H264SPS::kBitRateScaleConstantTerm)) -
|
| + 1;
|
| current_sps_.cpb_size_value_minus1[0] =
|
| (cpb_size_ >>
|
| - (kCPBSizeScale + media::H264SPS::kCPBSizeScaleConstantTerm)) - 1;
|
| + (kCPBSizeScale + media::H264SPS::kCPBSizeScaleConstantTerm)) -
|
| + 1;
|
| current_sps_.cbr_flag[0] = true;
|
| current_sps_.initial_cpb_removal_delay_length_minus_1 =
|
| media::H264SPS::kDefaultInitialCPBRemovalDelayLength - 1;
|
| @@ -960,13 +949,13 @@ void VaapiVideoEncodeAccelerator::GeneratePackedSPS() {
|
| packed_sps_.AppendBool(current_sps_.low_delay_hrd_flag);
|
|
|
| packed_sps_.AppendBool(false); // pic_struct_present_flag
|
| - packed_sps_.AppendBool(true); // bitstream_restriction_flag
|
| + packed_sps_.AppendBool(true); // bitstream_restriction_flag
|
|
|
| packed_sps_.AppendBool(false); // motion_vectors_over_pic_boundaries_flag
|
| - packed_sps_.AppendUE(2); // max_bytes_per_pic_denom
|
| - packed_sps_.AppendUE(1); // max_bits_per_mb_denom
|
| - packed_sps_.AppendUE(16); // log2_max_mv_length_horizontal
|
| - packed_sps_.AppendUE(16); // log2_max_mv_length_vertical
|
| + packed_sps_.AppendUE(2); // max_bytes_per_pic_denom
|
| + packed_sps_.AppendUE(1); // max_bits_per_mb_denom
|
| + packed_sps_.AppendUE(16); // log2_max_mv_length_horizontal
|
| + packed_sps_.AppendUE(16); // log2_max_mv_length_vertical
|
|
|
| // Explicitly set max_num_reorder_frames to 0 to allow the decoder to
|
| // output pictures early.
|
| @@ -1065,10 +1054,8 @@ void VaapiVideoEncodeAccelerator::NotifyError(Error error) {
|
| }
|
|
|
| VaapiVideoEncodeAccelerator::EncodeJob::EncodeJob()
|
| - : coded_buffer(VA_INVALID_ID), keyframe(false) {
|
| -}
|
| + : coded_buffer(VA_INVALID_ID), keyframe(false) {}
|
|
|
| -VaapiVideoEncodeAccelerator::EncodeJob::~EncodeJob() {
|
| -}
|
| +VaapiVideoEncodeAccelerator::EncodeJob::~EncodeJob() {}
|
|
|
| -} // namespace content
|
| +} // namespace media
|
|
|