Skip to content

Commit

Permalink
media/gpu/v4l2: Correct v4l2_format from Tegra driver.
Browse files Browse the repository at this point in the history
Originally, we use the value of num_planes returned from driver.
However, the Tegra driver returns the wrong value for YM12 pixel
format. This CL change to use the correct value.

BUG=938156
TEST=run video_encode_accelerator_unittests on nyan_blaze
TEST=run video_decode_accelerator_tests on nyan_blaze

Change-Id: I6fc19e8a9f4a20a5b8c92628ea485c633fd7d8cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1765093
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691497}
  • Loading branch information
Chih-Yu Huang authored and Commit Bot committed Aug 29, 2019
1 parent 70ae458 commit cef551b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
25 changes: 18 additions & 7 deletions media/gpu/v4l2/tegra_v4l2_device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,26 @@ int TegraV4L2Device::Ioctl(int flags, void* arg) {
return ret;

// Workarounds for Tegra's broken closed-source V4L2 interface.
struct v4l2_format* format;
switch (flags) {
// VIDIOC_G_FMT returns 0 planes for multiplanar formats with 1 plane.
case static_cast<int>(VIDIOC_G_FMT):
format = static_cast<struct v4l2_format*>(arg);
if (V4L2_TYPE_IS_MULTIPLANAR(format->type) &&
format->fmt.pix_mp.num_planes == 0)
format->fmt.pix_mp.num_planes = 1;
case static_cast<int>(VIDIOC_S_FMT): {
struct v4l2_format format;
memcpy(&format, arg, sizeof(struct v4l2_format));
v4l2_format_cache_[static_cast<enum v4l2_buf_type>(format.type)] = format;
break;
}
case static_cast<int>(VIDIOC_G_FMT): {
// The driver doesn't fill values of returned v4l2_format correctly. Set
// the value that is previously passed to driver via VIDIOC_S_FMT.
struct v4l2_format* format = static_cast<struct v4l2_format*>(arg);
const auto it = v4l2_format_cache_.find(
static_cast<enum v4l2_buf_type>(format->type));
if (it != v4l2_format_cache_.end()) {
format->fmt.pix_mp.pixelformat = it->second.fmt.pix_mp.pixelformat;
if (format->fmt.pix_mp.num_planes == 0)
format->fmt.pix_mp.num_planes = it->second.fmt.pix_mp.num_planes;
}
break;
}
default:
break;
}
Expand Down
5 changes: 5 additions & 0 deletions media/gpu/v4l2/tegra_v4l2_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <stddef.h>
#include <stdint.h>

#include <map>
#include <vector>

#include "base/macros.h"
Expand Down Expand Up @@ -86,6 +87,10 @@ class TegraV4L2Device : public V4L2Device {
// The actual device fd.
int device_fd_ = -1;

// The v4l2_format cache passed to the driver via VIDIOC_S_FMT. The key is
// v4l2_buf_type.
std::map<enum v4l2_buf_type, struct v4l2_format> v4l2_format_cache_;

DISALLOW_COPY_AND_ASSIGN(TegraV4L2Device);
};

Expand Down

0 comments on commit cef551b

Please sign in to comment.