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

Unified Diff: content/common/gpu/media/v4l2_video_decode_accelerator.cc

Issue 836093002: V4L2VDA: Fix format initialization order. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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 | « content/common/gpu/media/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: content/common/gpu/media/v4l2_video_decode_accelerator.cc
diff --git a/content/common/gpu/media/v4l2_video_decode_accelerator.cc b/content/common/gpu/media/v4l2_video_decode_accelerator.cc
index 76f436470aa243cd5d69dbee3aac3bf015d87347..ded062a42247692bb469e8cb70812f3d1215ea3a 100644
--- a/content/common/gpu/media/v4l2_video_decode_accelerator.cc
+++ b/content/common/gpu/media/v4l2_video_decode_accelerator.cc
@@ -267,10 +267,7 @@ bool V4L2VideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile,
return false;
}
- if (!CreateInputBuffers())
- return false;
-
- if (!SetupOutputFormat())
+ if (!SetupFormats())
return false;
// Subscribe to the resolution change event.
@@ -284,6 +281,9 @@ bool V4L2VideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile,
decoder_h264_parser_.reset(new media::H264Parser());
}
+ if (!CreateInputBuffers())
+ return false;
+
if (!decoder_thread_.Start()) {
LOG(ERROR) << "Initialize(): decoder thread failed to start";
NOTIFY_ERROR(PLATFORM_FAILURE);
@@ -1629,6 +1629,12 @@ bool V4L2VideoDecodeAccelerator::GetFormatInfo(struct v4l2_format* format,
}
}
+ // Make sure we are still getting the format we set on initialization.
+ if (format->fmt.pix_mp.pixelformat != output_format_fourcc_) {
+ LOG(ERROR) << "Unexpected format from G_FMT on output";
+ return false;
+ }
+
return true;
}
@@ -1654,24 +1660,6 @@ bool V4L2VideoDecodeAccelerator::CreateInputBuffers() {
DCHECK(!input_streamon_);
DCHECK(input_buffer_map_.empty());
- __u32 pixelformat = V4L2Device::VideoCodecProfileToV4L2PixFmt(video_profile_);
- if (!pixelformat) {
- NOTREACHED();
- return false;
- }
-
- struct v4l2_format format;
- memset(&format, 0, sizeof(format));
- format.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
- format.fmt.pix_mp.pixelformat = pixelformat;
- if (base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kIgnoreResolutionLimitsForAcceleratedVideoDecode))
- format.fmt.pix_mp.plane_fmt[0].sizeimage = kInputBufferMaxSizeFor4k;
- else
- format.fmt.pix_mp.plane_fmt[0].sizeimage = kInputBufferMaxSizeFor1080p;
- format.fmt.pix_mp.num_planes = 1;
- IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_S_FMT, &format);
-
struct v4l2_requestbuffers reqbufs;
memset(&reqbufs, 0, sizeof(reqbufs));
reqbufs.count = kInputBufferCount;
@@ -1709,10 +1697,37 @@ bool V4L2VideoDecodeAccelerator::CreateInputBuffers() {
return true;
}
-bool V4L2VideoDecodeAccelerator::SetupOutputFormat() {
- // We have to set up the format for output beforehand, because the driver may
- // not allow changing it once we start streaming; whether it can support our
- // chosen output format or not may depend on the input format.
+bool V4L2VideoDecodeAccelerator::SetupFormats() {
+ // We always run this as we prepare to initialize.
+ DCHECK_EQ(decoder_state_, kUninitialized);
+ DCHECK(!input_streamon_);
+ DCHECK(!output_streamon_);
+
+ __u32 input_format_fourcc =
+ V4L2Device::VideoCodecProfileToV4L2PixFmt(video_profile_);
+ if (!input_format_fourcc) {
+ NOTREACHED();
+ return false;
+ }
+
+ size_t input_size;
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kIgnoreResolutionLimitsForAcceleratedVideoDecode))
+ input_size = kInputBufferMaxSizeFor4k;
+ else
+ input_size = kInputBufferMaxSizeFor1080p;
+
+ struct v4l2_format format;
+ memset(&format, 0, sizeof(format));
+ format.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
+ format.fmt.pix_mp.pixelformat = input_format_fourcc;
+ format.fmt.pix_mp.plane_fmt[0].sizeimage = input_size;
+ format.fmt.pix_mp.num_planes = 1;
+ IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_S_FMT, &format);
+
+ // We have to set up the format for output, because the driver may not allow
+ // changing it once we start streaming; whether it can support our chosen
+ // output format or not may depend on the input format.
struct v4l2_fmtdesc fmtdesc;
memset(&fmtdesc, 0, sizeof(fmtdesc));
fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
@@ -1731,7 +1746,6 @@ bool V4L2VideoDecodeAccelerator::SetupOutputFormat() {
// Just set the fourcc for output; resolution, etc., will come from the
// driver once it extracts it from the stream.
- struct v4l2_format format;
memset(&format, 0, sizeof(format));
format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
format.fmt.pix_mp.pixelformat = output_format_fourcc_;
« no previous file with comments | « content/common/gpu/media/v4l2_video_decode_accelerator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698