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 86e6676582eae54ec17c1c4cc3c840e7b126a2da..dd429c639f598b8997aa55d6e7f2fab8c05d304f 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> |
#include <utility> |
@@ -12,22 +12,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 |
@@ -72,10 +72,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, |
Pawel Osciak
2016/04/19 09:22:55
Could we please keep the comment at the new locati
Mark Dittmer
2016/05/02 03:51:24
Ditto to other comment. UMA requirements appear to
|
}; |
- |
} |
// Round |value| up to |alignment|, which must be a power of 2. |
@@ -86,10 +84,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 { |
@@ -176,15 +172,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; |
@@ -373,8 +369,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; |
@@ -412,8 +407,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; |
@@ -444,8 +438,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; |
@@ -457,8 +450,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; |
@@ -466,8 +458,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; |
@@ -475,9 +466,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; |
@@ -495,8 +485,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, |
@@ -510,8 +499,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, |
@@ -762,9 +750,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(); |
} |
@@ -851,10 +838,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; |
@@ -958,13 +947,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. |
@@ -1063,10 +1052,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 |