Commit f1c7e58d authored by Shuo-Peng Liao's avatar Shuo-Peng Liao Committed by Commit Bot

video: Add fourcc field in ImageProcessor::PortConfig.

For some platform specific format, e.g. V4L2_PIX_FMT_MT21C, it does not
have corresponding VideoPixelFormat mapping. As the format is only used
between video decoder accelerator (VDA) and image processor, we shall
add an optional field, fourcc, in PortConfig so that VDA can tell image
processor which input format it should be used.

BUG=985683, b:132589320
TEST=Run VDA_unittest and media_unittest on elm

Change-Id: I1362a6805b64bab03db254010e7b62b0cc4fd68a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1724269
Commit-Queue: Shuo-Peng Liao <deanliao@chromium.org>
Reviewed-by: default avatarChrome Cunningham <chcunningham@chromium.org>
Reviewed-by: default avatarAlexandre Courbot <acourbot@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682596}
parent 1114f7dd
......@@ -12,7 +12,18 @@ ImageProcessor::PortConfig::PortConfig(
const VideoFrameLayout& layout,
const gfx::Size& visible_size,
const std::vector<VideoFrame::StorageType>& preferred_storage_types)
: PortConfig(layout,
kUnassignedFourCC,
visible_size,
preferred_storage_types) {}
ImageProcessor::PortConfig::PortConfig(
const VideoFrameLayout& layout,
uint32_t fourcc,
const gfx::Size& visible_size,
const std::vector<VideoFrame::StorageType>& preferred_storage_types)
: layout(layout),
fourcc(fourcc),
visible_size(visible_size),
preferred_storage_types(preferred_storage_types) {}
......
......@@ -5,6 +5,8 @@
#ifndef MEDIA_GPU_IMAGE_PROCESSOR_H_
#define MEDIA_GPU_IMAGE_PROCESSOR_H_
#include <stdint.h>
#include <vector>
#include "base/callback_forward.h"
......@@ -46,15 +48,26 @@ class MEDIA_GPU_EXPORT ImageProcessor {
};
// Encapsulates ImageProcessor input / output configurations.
// Note that |fourcc| is used when format cannot be described in |layout|,
// e.g. platform specific format not listed in VideoPixelFormat. The default
// value of |fourcc| is kUnassignedFourCC.
struct MEDIA_GPU_EXPORT PortConfig {
PortConfig() = delete;
PortConfig(
const VideoFrameLayout& layout,
const gfx::Size& visible_size,
const std::vector<VideoFrame::StorageType>& preferred_storage_types);
PortConfig(
const VideoFrameLayout& layout,
uint32_t fourcc,
const gfx::Size& visible_size,
const std::vector<VideoFrame::StorageType>& preferred_storage_types);
~PortConfig();
static const uint32_t kUnassignedFourCC = 0u;
const VideoFrameLayout layout;
const uint32_t fourcc;
const gfx::Size visible_size;
const std::vector<VideoFrame::StorageType> preferred_storage_types;
};
......
......@@ -1004,8 +1004,15 @@ VideoPixelFormat V4L2Device::V4L2PixFmtToVideoPixelFormat(uint32_t pix_fmt) {
case V4L2_PIX_FMT_NV12M:
return PIXEL_FORMAT_NV12;
// V4L2_PIX_FMT_MT21C is only used for MT8173 hardware video decoder output
// and should be converted by MT8173 image processor for compositor to
// render. Since it is an intermediate format for video decoder,
// VideoPixelFormat shall not have its mapping. However, we need to create a
// VideoFrameLayout for the format to process the intermediate frame. Hence
// we map V4L2_PIX_FMT_MT21C to PIXEL_FORMAT_NV12 as their layout are the
// same.
case V4L2_PIX_FMT_MT21C:
return PIXEL_FORMAT_MT21;
return PIXEL_FORMAT_NV12;
case V4L2_PIX_FMT_YUV420:
case V4L2_PIX_FMT_YUV420M:
......
......@@ -172,16 +172,19 @@ std::unique_ptr<V4L2ImageProcessor> V4L2ImageProcessor::Create(
}
const VideoFrameLayout& input_layout = input_config.layout;
// Use input_config.fourcc as input format if it is specified, i.e. non-zero.
const uint32_t input_format_fourcc =
V4L2Device::VideoFrameLayoutToV4L2PixFmt(input_layout);
input_config.fourcc == ImageProcessor::PortConfig::kUnassignedFourCC
? V4L2Device::VideoFrameLayoutToV4L2PixFmt(input_layout)
: input_config.fourcc;
if (!input_format_fourcc) {
VLOGF(1) << "Invalid VideoFrameLayout: " << input_layout;
return nullptr;
}
if (!device->Open(V4L2Device::Type::kImageProcessor, input_format_fourcc)) {
VLOGF(1) << "Failed to open device for input format: "
<< VideoPixelFormatToString(input_layout.format())
<< " fourcc: " << FourccToString(input_format_fourcc);
VLOGF(1) << "Failed to open device with input fourcc: "
<< FourccToString(input_format_fourcc);
return nullptr;
}
......
......@@ -2431,17 +2431,29 @@ bool V4L2VideoDecodeAccelerator::CreateImageProcessor() {
(output_mode_ == Config::OutputMode::ALLOCATE
? ImageProcessor::OutputMode::ALLOCATE
: ImageProcessor::OutputMode::IMPORT);
size_t num_planes =
V4L2Device::GetNumPlanesOfV4L2PixFmt(output_format_fourcc_);
size_t num_planes = 0;
base::Optional<VideoFrameLayout> input_layout;
if (num_planes == 1) {
input_layout = VideoFrameLayout::Create(
V4L2Device::V4L2PixFmtToVideoPixelFormat(output_format_fourcc_),
coded_size_);
} else {
// V4L2 specific format hack:
// If VDA's output format is V4L2_PIX_FMT_MT21C, which is a platform specific
// format and now is only used for MT8173 VDA output and its image processor
// input, we set VideoFrameLayout for image processor's input with format
// PIXEL_FORMAT_NV12 as NV12's layout is the same as MT21.
if (output_format_fourcc_ == V4L2_PIX_FMT_MT21C) {
num_planes = 2;
input_layout = VideoFrameLayout::CreateMultiPlanar(
V4L2Device::V4L2PixFmtToVideoPixelFormat(output_format_fourcc_),
coded_size_, std::vector<VideoFrameLayout::Plane>(num_planes));
PIXEL_FORMAT_NV12, coded_size_,
std::vector<VideoFrameLayout::Plane>(num_planes));
} else {
num_planes = V4L2Device::GetNumPlanesOfV4L2PixFmt(output_format_fourcc_);
if (num_planes == 1) {
input_layout = VideoFrameLayout::Create(
V4L2Device::V4L2PixFmtToVideoPixelFormat(output_format_fourcc_),
coded_size_);
} else {
input_layout = VideoFrameLayout::CreateMultiPlanar(
V4L2Device::V4L2PixFmtToVideoPixelFormat(output_format_fourcc_),
coded_size_, std::vector<VideoFrameLayout::Plane>(num_planes));
}
}
if (!input_layout) {
VLOGF(1) << "Invalid input layout";
......@@ -2471,8 +2483,8 @@ bool V4L2VideoDecodeAccelerator::CreateImageProcessor() {
// |image_processor_device_| from V4L2VideoDecodeAccelerator.
image_processor_ = V4L2ImageProcessor::Create(
image_processor_device_,
ImageProcessor::PortConfig(*input_layout, visible_size_,
{VideoFrame::STORAGE_DMABUFS}),
ImageProcessor::PortConfig(*input_layout, output_format_fourcc_,
visible_size_, {VideoFrame::STORAGE_DMABUFS}),
ImageProcessor::PortConfig(*output_layout, visible_size_,
{VideoFrame::STORAGE_DMABUFS}),
image_processor_output_mode, output_buffer_map_.size(),
......
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