Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(952)

Unified Diff: media/gpu/v4l2_video_decode_accelerator.cc

Issue 2408703002: V4L2VideoDecodeAccelerator: implement flush by VIDIOC_DECODER_CMD. (Closed)
Patch Set: address kcwu's comments. Remove V4L2_DEC_CMD_START Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/gpu/v4l2_video_decode_accelerator.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/gpu/v4l2_video_decode_accelerator.cc
diff --git a/media/gpu/v4l2_video_decode_accelerator.cc b/media/gpu/v4l2_video_decode_accelerator.cc
index b4ac8a19f993babcca1d4833d9a59ce3e83dc9e4..fef1afd111d5dfc7285fc5849620a5d085b84434 100644
--- a/media/gpu/v4l2_video_decode_accelerator.cc
+++ b/media/gpu/v4l2_video_decode_accelerator.cc
@@ -164,6 +164,8 @@ V4L2VideoDecodeAccelerator::V4L2VideoDecodeAccelerator(
decoder_decode_buffer_tasks_scheduled_(0),
decoder_frames_at_client_(0),
decoder_flushing_(false),
+ decoder_cmd_supported_(false),
+ flush_waiting_last_output_buffer_(false),
reset_pending_(false),
decoder_partial_frame_pending_(false),
input_streamon_(false),
@@ -287,6 +289,8 @@ bool V4L2VideoDecodeAccelerator::Initialize(const Config& config,
return false;
}
+ decoder_cmd_supported_ = IsDecoderCmdSupported();
+
decoder_state_ = kInitialized;
output_mode_ = config.output_mode;
@@ -824,7 +828,16 @@ void V4L2VideoDecodeAccelerator::DecodeBufferTask() {
kFlushBufferId)
schedule_task = FlushInputFrame();
- if (schedule_task && AppendToInputFrame(NULL, 0) && FlushInputFrame()) {
+ if (decoder_cmd_supported_) {
+ DVLOGF(2) << "sending decoder cmd to flush";
+ DCHECK(!flush_waiting_last_output_buffer_);
+ struct v4l2_decoder_cmd cmd;
+ memset(&cmd, 0, sizeof(cmd));
+ cmd.cmd = V4L2_DEC_CMD_STOP;
+ IOCTL_OR_ERROR_RETURN(VIDIOC_DECODER_CMD, &cmd);
+ flush_waiting_last_output_buffer_ = true;
+ } else if (schedule_task && AppendToInputFrame(NULL, 0) &&
+ FlushInputFrame()) {
DVLOGF(2) << "enqueued flush buffer";
decoder_partial_frame_pending_ = false;
schedule_task = true;
@@ -1359,6 +1372,10 @@ bool V4L2VideoDecodeAccelerator::DequeueOutputBuffer() {
// EAGAIN if we're just out of buffers to dequeue.
return false;
}
+ if (errno == EPIPE) {
wuchengli 2016/10/17 16:18:59 We need this because this is not an error. It mean
+ DVLOGF(3) << "Got EPIPE. Last output buffer was already dequeued.";
+ return false;
+ }
PLOGF(ERROR) << "ioctl() failed: VIDIOC_DQBUF";
NOTIFY_ERROR(PLATFORM_FAILURE);
return false;
@@ -1394,6 +1411,17 @@ bool V4L2VideoDecodeAccelerator::DequeueOutputBuffer() {
output_record.cleared = true;
}
}
+ if ((dqbuf.flags & V4L2_BUF_FLAG_LAST)) {
+ DVLOGF(3) << "Got last output buffer. Waiting last buffer="
+ << flush_waiting_last_output_buffer_;
+ if (flush_waiting_last_output_buffer_) {
+ // TODO(wuchengli): use V4L2_DEC_CMD_START when v4l2 core issue is
+ // addressed.
+ if (!(StopDevicePoll() && StopOutputStream() && StartDevicePoll()))
+ return false;
+ flush_waiting_last_output_buffer_ = false;
+ }
+ }
return true;
}
@@ -1531,8 +1559,10 @@ void V4L2VideoDecodeAccelerator::FlushTask() {
TRACE_EVENT0("Video Decoder", "V4L2VDA::FlushTask");
// Flush outstanding buffers.
- if (decoder_state_ == kInitialized) {
- // There's nothing in the pipe, so return done immediately.
+ if (!output_streamon_) {
+ // If output stream is off, output buffers are not allocated. Or the decoder
+ // is initialized, resetting or changing resolution. There's nothing in the
+ // pipe, so return done immediately.
DVLOGF(3) << "returning flush";
child_task_runner_->PostTask(FROM_HERE,
base::Bind(&Client::NotifyFlushDone, client_));
@@ -1568,15 +1598,27 @@ void V4L2VideoDecodeAccelerator::NotifyFlushDoneIfNeeded() {
// * All image processor buffers are returned.
if (!decoder_input_queue_.empty()) {
if (decoder_input_queue_.front()->input_id !=
- decoder_delay_bitstream_buffer_id_)
+ decoder_delay_bitstream_buffer_id_) {
+ DVLOGF(3) << "Some input bitstream buffers are not queued.";
return;
+ }
+ }
+ if (decoder_current_input_buffer_ != -1) {
+ DVLOGF(3) << "Current input buffer != -1";
+ return;
}
- if (decoder_current_input_buffer_ != -1)
+ if ((input_ready_queue_.size() + input_buffer_queued_count_) != 0) {
+ DVLOGF(3) << "Some input buffers are not dequeued.";
return;
- if ((input_ready_queue_.size() + input_buffer_queued_count_) != 0)
+ }
+ if (image_processor_bitstream_buffer_ids_.size() != 0) {
+ DVLOGF(3) << "Waiting for image processor to complete.";
return;
- if (image_processor_bitstream_buffer_ids_.size() != 0)
+ }
+ if (flush_waiting_last_output_buffer_) {
+ DVLOGF(3) << "Waiting for last output buffer.";
return;
+ }
// TODO(posciak): crbug.com/270039. Exynos requires a streamoff-streamon
// sequence after flush to continue, even if we are not resetting. This would
@@ -1603,6 +1645,18 @@ void V4L2VideoDecodeAccelerator::NotifyFlushDoneIfNeeded() {
ScheduleDecodeBufferTaskIfNeeded();
}
+bool V4L2VideoDecodeAccelerator::IsDecoderCmdSupported() {
+ struct v4l2_decoder_cmd cmd;
+ memset(&cmd, 0, sizeof(cmd));
+ cmd.cmd = V4L2_DEC_CMD_STOP;
+ if (device_->Ioctl(VIDIOC_TRY_DECODER_CMD, &cmd) != 0) {
+ DVLOGF(3) "V4L2_DEC_CMD_STOP is not supported.";
+ return false;
+ }
+
+ return true;
+}
+
void V4L2VideoDecodeAccelerator::ResetTask() {
DVLOGF(3);
DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
@@ -1722,6 +1776,7 @@ void V4L2VideoDecodeAccelerator::DestroyTask() {
while (!decoder_input_queue_.empty())
decoder_input_queue_.pop();
decoder_flushing_ = false;
+ flush_waiting_last_output_buffer_ = false;
if (image_processor_)
image_processor_.release()->Destroy();
@@ -1785,6 +1840,9 @@ bool V4L2VideoDecodeAccelerator::StopOutputStream() {
IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_STREAMOFF, &type);
output_streamon_ = false;
+ // Output stream is stopped. No need to wait the buffer anymore.
+ flush_waiting_last_output_buffer_ = false;
+
for (size_t i = 0; i < output_buffer_map_.size(); ++i) {
// After streamoff, the device drops ownership of all buffers, even if we
// don't dequeue them explicitly. Some of them may still be owned by the
« no previous file with comments | « media/gpu/v4l2_video_decode_accelerator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698