Commit e39cab4d authored by Emircan Uysaler's avatar Emircan Uysaler Committed by Commit Bot

Force keyframe in regular intervals using MediaRecorder's VEAEncoder

This CL makes sure that we produce a keyframe for every 100 frames when
MediaRecorder uses HW encoder.

Bug: 837450
Change-Id: Ifa1a674012085aa122a8e907ca1f88cb8a949e55
Reviewed-on: https://chromium-review.googlesource.com/1033181
Commit-Queue: Emircan Uysaler <emircan@chromium.org>
Reviewed-by: default avatarMiguel Casas <mcasas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#554552}
parent 81a63dfb
...@@ -29,6 +29,8 @@ const int kVEADefaultBitratePerPixel = 2; ...@@ -29,6 +29,8 @@ const int kVEADefaultBitratePerPixel = 2;
// Number of output buffers used to copy the encoded data coming from HW // Number of output buffers used to copy the encoded data coming from HW
// encoders. // encoders.
const int kVEAEncoderOutputBufferCount = 4; const int kVEAEncoderOutputBufferCount = 4;
// Force a keyframe in regular intervals.
const uint32_t kMaxKeyframeInterval = 100;
} // anonymous namespace } // anonymous namespace
...@@ -47,6 +49,8 @@ VEAEncoder::VEAEncoder( ...@@ -47,6 +49,8 @@ VEAEncoder::VEAEncoder(
gpu_factories_(RenderThreadImpl::current()->GetGpuFactories()), gpu_factories_(RenderThreadImpl::current()->GetGpuFactories()),
codec_(codec), codec_(codec),
error_notified_(false), error_notified_(false),
num_frames_after_keyframe_(0),
force_next_frame_to_be_keyframe_(false),
on_error_callback_(on_error_callback) { on_error_callback_(on_error_callback) {
DCHECK(gpu_factories_); DCHECK(gpu_factories_);
DCHECK_GE(size.width(), kVEAEncoderMinResolutionWidth); DCHECK_GE(size.width(), kVEAEncoderMinResolutionWidth);
...@@ -103,9 +107,14 @@ void VEAEncoder::BitstreamBufferReady(int32_t bitstream_buffer_id, ...@@ -103,9 +107,14 @@ void VEAEncoder::BitstreamBufferReady(int32_t bitstream_buffer_id,
DVLOG(3) << __func__; DVLOG(3) << __func__;
DCHECK(encoding_task_runner_->BelongsToCurrentThread()); DCHECK(encoding_task_runner_->BelongsToCurrentThread());
num_frames_after_keyframe_ = keyframe ? 0 : num_frames_after_keyframe_ + 1;
if (num_frames_after_keyframe_ > kMaxKeyframeInterval) {
force_next_frame_to_be_keyframe_ = true;
num_frames_after_keyframe_ = 0;
}
base::SharedMemory* output_buffer = base::SharedMemory* output_buffer =
output_buffers_[bitstream_buffer_id].get(); output_buffers_[bitstream_buffer_id].get();
std::unique_ptr<std::string> data(new std::string); std::unique_ptr<std::string> data(new std::string);
data->append(reinterpret_cast<char*>(output_buffer->memory()), payload_size); data->append(reinterpret_cast<char*>(output_buffer->memory()), payload_size);
...@@ -231,7 +240,8 @@ void VEAEncoder::EncodeOnEncodingTaskRunner(scoped_refptr<VideoFrame> frame, ...@@ -231,7 +240,8 @@ void VEAEncoder::EncodeOnEncodingTaskRunner(scoped_refptr<VideoFrame> frame,
frames_in_encode_.push(std::make_pair( frames_in_encode_.push(std::make_pair(
media::WebmMuxer::VideoParameters(frame), capture_timestamp)); media::WebmMuxer::VideoParameters(frame), capture_timestamp));
video_encoder_->Encode(video_frame, false); video_encoder_->Encode(video_frame, force_next_frame_to_be_keyframe_);
force_next_frame_to_be_keyframe_ = false;
} }
void VEAEncoder::ConfigureEncoderOnEncodingTaskRunner(const gfx::Size& size) { void VEAEncoder::ConfigureEncoderOnEncodingTaskRunner(const gfx::Size& size) {
......
...@@ -92,6 +92,12 @@ class VEAEncoder final : public VideoTrackRecorder::Encoder, ...@@ -92,6 +92,12 @@ class VEAEncoder final : public VideoTrackRecorder::Encoder,
// Frames and corresponding timestamps in encode as FIFO. // Frames and corresponding timestamps in encode as FIFO.
base::queue<VideoParamsAndTimestamp> frames_in_encode_; base::queue<VideoParamsAndTimestamp> frames_in_encode_;
// Number of encoded frames produced consecutively without a keyframe.
uint32_t num_frames_after_keyframe_;
// Forces next frame to be a keyframe.
bool force_next_frame_to_be_keyframe_;
// This callback can be exercised on any thread. // This callback can be exercised on any thread.
const VideoTrackRecorder::OnErrorCB on_error_callback_; const VideoTrackRecorder::OnErrorCB on_error_callback_;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment