Commit bf3a3fc7 authored by Miguel Casas's avatar Miguel Casas Committed by Chromium LUCI CQ

media/v4l2: simplify V4L2VideoDecoder::Initialize and clarify logs

ToT V4L2VideoDecoder::Initialize() tries to Open() |device_| with both
stateless and stateful formats -- which is fine, but log printouts are
confusing, as they read oftentimes like:

  [v4l2_video_decoder.cc(166)] Initialize(): Found V4L2 device capable of stateless decoding for S264
  ...
  [v4l2_video_decoder.cc(175)] Initialize(): Failed to open device for profile: 3 fourcc: H264

which seems to imply that Initialize() failed, when in reality it
worked. Moreover, ToT code checks for |input_format_fourcc_stateful|
and |input_format_fourcc_stateless| values and has an else() path that
is never reached (l.218 LHS).

This CL refactors that code to make evident that the stateful API takes
precedence if present and working, sprinkles constexpr names, and takes
the chance to improve some loggings using e.g. FourccToString() and
GetProfileName().

No new functionality intended.

Bug: b/170870476
Change-Id: I6ad00c1ce4d9b8cf2588d7a2751484a743f4225f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2616881Reviewed-by: default avatarFritz Koenig <frkoenig@chromium.org>
Commit-Queue: Miguel Casas <mcasas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842210}
parent a01520e6
......@@ -958,8 +958,7 @@ base::Optional<struct v4l2_format> V4L2Queue::SetFormat(uint32_t fourcc,
struct v4l2_format format = BuildV4L2Format(type_, fourcc, size, buffer_size);
if (device_->Ioctl(VIDIOC_S_FMT, &format) != 0 ||
format.fmt.pix_mp.pixelformat != fourcc) {
VPQLOGF(2) << "Failed to set format (format_fourcc=0x" << std::hex << fourcc
<< ")";
VPQLOGF(2) << "Failed to set format fourcc: " << FourccToString(fourcc);
return base::nullopt;
}
......@@ -973,8 +972,7 @@ base::Optional<struct v4l2_format> V4L2Queue::TryFormat(uint32_t fourcc,
struct v4l2_format format = BuildV4L2Format(type_, fourcc, size, buffer_size);
if (device_->Ioctl(VIDIOC_TRY_FMT, &format) != 0 ||
format.fmt.pix_mp.pixelformat != fourcc) {
VPQLOGF(2) << "Tried format not supported (format_fourcc=0x" << std::hex
<< fourcc << ")";
VPQLOGF(2) << "Failed to try format fourcc: " << FourccToString(fourcc);
return base::nullopt;
}
......
......@@ -152,35 +152,25 @@ void V4L2VideoDecoder::Initialize(const VideoDecoderConfig& config,
SetState(State::kUninitialized);
}
// Open V4L2 device.
VideoCodecProfile profile = config.profile();
uint32_t input_format_fourcc_stateless =
V4L2Device::VideoCodecProfileToV4L2PixFmt(profile, true);
if (!input_format_fourcc_stateless ||
!device_->Open(V4L2Device::Type::kDecoder,
input_format_fourcc_stateless)) {
VLOGF(1) << "Failed to open device for profile: " << profile
<< " fourcc: " << FourccToString(input_format_fourcc_stateless);
input_format_fourcc_stateless = 0;
} else {
VLOGF(1) << "Found V4L2 device capable of stateless decoding for "
<< FourccToString(input_format_fourcc_stateless);
}
uint32_t input_format_fourcc_stateful =
V4L2Device::VideoCodecProfileToV4L2PixFmt(profile, false);
if (!input_format_fourcc_stateful ||
!device_->Open(V4L2Device::Type::kDecoder,
input_format_fourcc_stateful)) {
VLOGF(1) << "Failed to open device for profile: " << profile
<< " fourcc: " << FourccToString(input_format_fourcc_stateful);
input_format_fourcc_stateful = 0;
} else {
VLOGF(1) << "Found V4L2 device capable of stateful decoding for "
<< FourccToString(input_format_fourcc_stateful);
const VideoCodecProfile profile = config.profile();
constexpr bool kStateful = false;
constexpr bool kStateless = true;
base::Optional<std::pair<bool, uint32_t>> api_and_format;
// Try both kStateful and kStateless APIs via |fourcc| and select the first
// combination where Open()ing the |device_| works.
for (const auto api : {kStateful, kStateless}) {
const auto fourcc = V4L2Device::VideoCodecProfileToV4L2PixFmt(profile, api);
constexpr uint32_t kInvalidV4L2PixFmt = 0;
if (fourcc == kInvalidV4L2PixFmt ||
!device_->Open(V4L2Device::Type::kDecoder, fourcc)) {
continue;
}
api_and_format = std::make_pair(api, fourcc);
break;
}
if (!input_format_fourcc_stateless && !input_format_fourcc_stateful) {
if (!api_and_format.has_value()) {
VLOGF(1) << "No V4L2 API found for profile: " << GetProfileName(profile);
std::move(init_cb).Run(StatusCode::kV4l2NoDecoder);
return;
}
......@@ -206,19 +196,19 @@ void V4L2VideoDecoder::Initialize(const VideoDecoderConfig& config,
return;
}
uint32_t input_format_fourcc;
if (input_format_fourcc_stateful) {
const auto preferred_api_and_format = api_and_format.value();
const uint32_t input_format_fourcc = preferred_api_and_format.second;
if (preferred_api_and_format.first == kStateful) {
VLOGF(1) << "Using a stateful API for profile: " << GetProfileName(profile)
<< " and fourcc: " << FourccToString(input_format_fourcc);
backend_ = std::make_unique<V4L2StatefulVideoDecoderBackend>(
this, device_, profile, decoder_task_runner_);
input_format_fourcc = input_format_fourcc_stateful;
} else if (input_format_fourcc_stateless) {
} else {
DCHECK_EQ(preferred_api_and_format.first, kStateless);
VLOGF(1) << "Using a stateless API for profile: " << GetProfileName(profile)
<< " and fourcc: " << FourccToString(input_format_fourcc);
backend_ = std::make_unique<V4L2StatelessVideoDecoderBackend>(
this, device_, profile, decoder_task_runner_);
input_format_fourcc = input_format_fourcc_stateless;
} else {
VLOGF(1) << "No backend capable of taking this profile.";
std::move(init_cb).Run(StatusCode::kV4l2FailedResourceAllocation);
return;
}
if (!backend_->Initialize()) {
......@@ -227,7 +217,6 @@ void V4L2VideoDecoder::Initialize(const VideoDecoderConfig& config,
return;
}
// Setup input format.
if (!SetupInputFormat(input_format_fourcc)) {
VLOGF(1) << "Failed to setup input format.";
std::move(init_cb).Run(StatusCode::kV4l2BadFormat);
......
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