Commit 73ca8856 authored by Chih-Yu Huang's avatar Chih-Yu Huang Committed by Commit Bot

media/gpu: Move the general check from VaapiImageProcessor to ImageProcessor.

This CL moves the frame format checks from VaapiImageProcessor to
ImageProcessor, because all IP implementation should verify frame
format.

Bug: 1028889
Test: Run image_processor_test on Kevin and Eve and no break new tests
Test: Pass video_decode_accelerator on Kukui

Change-Id: I3751f608785b0ee2a1087228d655405f56043c62
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1939078
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
Reviewed-by: default avatarDavid Staessens <dstaessens@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719864}
parent aa9775ec
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "media/base/video_frame.h" #include "media/base/video_frame.h"
#include "media/base/video_types.h"
#include "media/gpu/macros.h"
namespace media { namespace media {
...@@ -34,6 +36,33 @@ std::string VectorToString(const std::vector<T>& vec) { ...@@ -34,6 +36,33 @@ std::string VectorToString(const std::vector<T>& vec) {
return result.str(); return result.str();
} }
// Verify if the format of |frame| matches |config|.
bool CheckVideoFrameFormat(const ImageProcessor::PortConfig& config,
const VideoFrame& frame) {
// Because propriatary format fourcc will map to other common VideoPixelFormat
// with same layout, we convert to VideoPixelFormat to check.
if (frame.format() != config.fourcc.ToVideoPixelFormat()) {
VLOGF(1) << "Invalid frame format="
<< VideoPixelFormatToString(frame.format())
<< ", expected=" << config.fourcc.ToString();
return false;
}
if (frame.layout().coded_size() != config.size) {
VLOGF(1) << "Invalid frame size=" << frame.layout().coded_size().ToString()
<< ", expected=" << config.size.ToString();
return false;
}
if (frame.storage_type() != config.storage_type()) {
VLOGF(1) << "Invalid frame.storage_type=" << frame.storage_type()
<< ", input_storage_type=" << config.storage_type();
return false;
}
return true;
}
} // namespace } // namespace
ImageProcessor::PortConfig::PortConfig(const PortConfig&) = default; ImageProcessor::PortConfig::PortConfig(const PortConfig&) = default;
...@@ -94,6 +123,12 @@ bool ImageProcessor::Process(scoped_refptr<VideoFrame> input_frame, ...@@ -94,6 +123,12 @@ bool ImageProcessor::Process(scoped_refptr<VideoFrame> input_frame,
FrameReadyCB cb) { FrameReadyCB cb) {
DCHECK_CALLED_ON_VALID_SEQUENCE(client_sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(client_sequence_checker_);
DCHECK_EQ(output_mode(), OutputMode::IMPORT); DCHECK_EQ(output_mode(), OutputMode::IMPORT);
DCHECK(input_frame);
DCHECK(output_frame);
if (!CheckVideoFrameFormat(input_config_, *input_frame) ||
!CheckVideoFrameFormat(output_config_, *output_frame))
return false;
return ProcessInternal(std::move(input_frame), std::move(output_frame), return ProcessInternal(std::move(input_frame), std::move(output_frame),
std::move(cb)); std::move(cb));
......
...@@ -167,51 +167,6 @@ bool VaapiImageProcessor::ProcessInternal( ...@@ -167,51 +167,6 @@ bool VaapiImageProcessor::ProcessInternal(
FrameReadyCB cb) { FrameReadyCB cb) {
DVLOGF(4); DVLOGF(4);
DCHECK_CALLED_ON_VALID_SEQUENCE(client_sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(client_sequence_checker_);
DCHECK(input_frame);
DCHECK(output_frame);
const Fourcc input_frame_fourcc =
Fourcc::FromVideoPixelFormat(input_frame->layout().format());
if (input_frame_fourcc != input_config_.fourcc) {
VLOGF(1) << "Invalid input_frame format=" << input_frame_fourcc.ToString()
<< ", expected=" << input_config_.fourcc.ToString();
return false;
}
if (input_frame->layout().coded_size() != input_config_.size) {
VLOGF(1) << "Invalid input_frame size="
<< input_frame->layout().coded_size().ToString()
<< ", expected=" << input_config_.size.ToString();
return false;
}
const Fourcc output_frame_fourcc =
Fourcc::FromVideoPixelFormat(output_frame->layout().format());
if (output_frame_fourcc != output_config_.fourcc) {
VLOGF(1) << "Invalid output_frame format=" << output_frame_fourcc.ToString()
<< ", expected=" << output_config_.fourcc.ToString();
return false;
}
if (output_frame->layout().coded_size() != output_config_.size) {
VLOGF(1) << "Invalid output_frame size="
<< output_frame->layout().coded_size().ToString()
<< ", expected=" << output_config_.size.ToString();
return false;
}
if (input_frame->storage_type() != input_config_.storage_type()) {
VLOGF(1) << "Invalid input_frame->storage_type="
<< input_frame->storage_type()
<< ", input_storage_type=" << input_config_.storage_type();
return false;
}
if (output_frame->storage_type() != output_config_.storage_type()) {
VLOGF(1) << "Invalid output_frame->storage_type="
<< output_frame->storage_type()
<< ", expected=" << output_config_.storage_type();
return false;
}
// TODO(akahuang): Use WeakPtr to replace base::Unretained(this). // TODO(akahuang): Use WeakPtr to replace base::Unretained(this).
process_task_tracker_.PostTask( process_task_tracker_.PostTask(
......
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