aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Staessens <dstaessens@google.com>2021-03-19 15:45:12 +0900
committerChih-Yu Huang <akahuang@google.com>2021-05-12 11:37:10 +0900
commite0f265c120ac90c5f6845e30022df7c28eb95025 (patch)
treebdab47900bdc491229bf6b50918af11c9fef1db6
parent2a741c3132bc7e2be2fb924a27b42f77edd0f762 (diff)
downloadv4l2_codec2-e0f265c120ac90c5f6845e30022df7c28eb95025.tar.gz
v4l2_codec2: Remove video_encode/decode_accelerator files.
This CL cleans up the video_encode_accelerator.h/cc and video_decode_accelerator.h/cc files. These files were copied from Chrome to help with the development of the V4L2 encoder and decoder, but most off their functionality has already been removed in a previous CL. The remaining functionality is integrated into the V4L2Device so these files can be removed now. Bug: 155138142 Test: arc.VideoEncodeAccel.h264_192p_i420_vm Change-Id: I4591e3d03f5ebc6d568cc718ccde5df05af37b36
-rw-r--r--accel/Android.bp2
-rw-r--r--accel/video_decode_accelerator.cc18
-rw-r--r--accel/video_decode_accelerator.h39
-rw-r--r--accel/video_encode_accelerator.cc28
-rw-r--r--accel/video_encode_accelerator.h48
-rw-r--r--common/V4L2Device.cpp258
-rw-r--r--common/include/v4l2_codec2/common/V4L2Device.h34
-rw-r--r--components/V4L2EncodeInterface.cpp5
8 files changed, 157 insertions, 275 deletions
diff --git a/accel/Android.bp b/accel/Android.bp
index 46e77a0..7739f20 100644
--- a/accel/Android.bp
+++ b/accel/Android.bp
@@ -15,8 +15,6 @@ cc_library {
"color_plane_layout.cc",
"fourcc.cc",
"video_codecs.cc",
- "video_decode_accelerator.cc",
- "video_encode_accelerator.cc",
"video_frame.cc",
"video_frame_layout.cc",
"video_pixel_format.cc",
diff --git a/accel/video_decode_accelerator.cc b/accel/video_decode_accelerator.cc
deleted file mode 100644
index 9e18206..0000000
--- a/accel/video_decode_accelerator.cc
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-// Note: ported from Chromium commit head: 85fdf90
-
-#include "base/logging.h"
-
-#include "video_decode_accelerator.h"
-
-namespace media {
-
-VideoDecodeAccelerator::SupportedProfile::SupportedProfile()
- : profile(VIDEO_CODEC_PROFILE_UNKNOWN), encrypted_only(false) {}
-
-VideoDecodeAccelerator::SupportedProfile::~SupportedProfile() = default;
-
-} // namespace media
-
diff --git a/accel/video_decode_accelerator.h b/accel/video_decode_accelerator.h
deleted file mode 100644
index 6a6020f..0000000
--- a/accel/video_decode_accelerator.h
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-// Note: ported from Chromium commit head: 85fdf90
-
-#ifndef VIDEO_DECODE_ACCELERATOR_H_
-#define VIDEO_DECODE_ACCELERATOR_H_
-
-#include <vector>
-
-#include "base/memory/ref_counted.h"
-#include "base/memory/weak_ptr.h"
-
-#include "size.h"
-#include "video_codecs.h"
-
-namespace media {
-
-// Video decoder interface.
-// This interface is extended by the various components that ultimately
-// implement the backend of PPB_VideoDecoder_Dev.
-class VideoDecodeAccelerator {
- public:
- // Specification of a decoding profile supported by an decoder.
- // |max_resolution| and |min_resolution| are inclusive.
- struct SupportedProfile {
- SupportedProfile();
- ~SupportedProfile();
- VideoCodecProfile profile;
- Size max_resolution;
- Size min_resolution;
- bool encrypted_only;
- };
- using SupportedProfiles = std::vector<SupportedProfile>;
-};
-
-} // namespace media
-
-#endif // VIDEO_DECODE_ACCELERATOR_H_
diff --git a/accel/video_encode_accelerator.cc b/accel/video_encode_accelerator.cc
deleted file mode 100644
index 351af8d..0000000
--- a/accel/video_encode_accelerator.cc
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-// Note: ported from Chromium commit head: 9e40822e3a3d
-// Note: only necessary functions are ported.
-
-#include "video_encode_accelerator.h"
-
-namespace media {
-
-VideoEncodeAccelerator::SupportedProfile::SupportedProfile()
- : profile(media::VIDEO_CODEC_PROFILE_UNKNOWN),
- max_framerate_numerator(0),
- max_framerate_denominator(0) {}
-
-VideoEncodeAccelerator::SupportedProfile::SupportedProfile(
- VideoCodecProfile profile,
- const Size& max_resolution,
- uint32_t max_framerate_numerator,
- uint32_t max_framerate_denominator)
- : profile(profile),
- max_resolution(max_resolution),
- max_framerate_numerator(max_framerate_numerator),
- max_framerate_denominator(max_framerate_denominator) {}
-
-VideoEncodeAccelerator::SupportedProfile::~SupportedProfile() = default;
-
-} // namespace media
diff --git a/accel/video_encode_accelerator.h b/accel/video_encode_accelerator.h
deleted file mode 100644
index a47f59b..0000000
--- a/accel/video_encode_accelerator.h
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-// Note: ported from Chromium commit head: 9e40822e3a3d
-// Note: only necessary functions are ported.
-
-#ifndef MEDIA_VIDEO_VIDEO_ENCODE_ACCELERATOR_H_
-#define MEDIA_VIDEO_VIDEO_ENCODE_ACCELERATOR_H_
-
-#include <stddef.h>
-#include <stdint.h>
-
-#include <memory>
-#include <vector>
-
-#include "base/macros.h"
-#include "base/optional.h"
-#include "base/time/time.h"
-
-#include "size.h"
-#include "video_codecs.h"
-
-namespace media {
-
-// Video encoder interface.
-class VideoEncodeAccelerator {
- public:
- // Specification of an encoding profile supported by an encoder.
- struct SupportedProfile {
- SupportedProfile();
- SupportedProfile(VideoCodecProfile profile,
- const Size& max_resolution,
- uint32_t max_framerate_numerator = 0u,
- uint32_t max_framerate_denominator = 1u);
- ~SupportedProfile();
-
- VideoCodecProfile profile;
- Size min_resolution;
- Size max_resolution;
- uint32_t max_framerate_numerator;
- uint32_t max_framerate_denominator;
- };
- using SupportedProfiles = std::vector<SupportedProfile>;
-};
-
-} // namespace media
-
-#endif // MEDIA_VIDEO_VIDEO_ENCODE_ACCELERATOR_H_
diff --git a/common/V4L2Device.cpp b/common/V4L2Device.cpp
index 52ef5ac..0969181 100644
--- a/common/V4L2Device.cpp
+++ b/common/V4L2Device.cpp
@@ -1215,129 +1215,6 @@ std::vector<uint32_t> V4L2Device::preferredInputFormat(Type type) {
return {};
}
-media::VideoDecodeAccelerator::SupportedProfiles V4L2Device::getSupportedDecodeProfiles(
- const size_t numFormats, const uint32_t pixelFormats[]) {
- media::VideoDecodeAccelerator::SupportedProfiles supportedProfiles;
-
- Type type = Type::kDecoder;
- const auto& devices = getDevicesForType(type);
- for (const auto& device : devices) {
- if (!openDevicePath(device.first, type)) {
- ALOGV("Failed opening %s", device.first.c_str());
- continue;
- }
-
- const auto& profiles = enumerateSupportedDecodeProfiles(numFormats, pixelFormats);
- supportedProfiles.insert(supportedProfiles.end(), profiles.begin(), profiles.end());
- closeDevice();
- }
-
- return supportedProfiles;
-}
-
-media::VideoEncodeAccelerator::SupportedProfiles V4L2Device::getSupportedEncodeProfiles() {
- media::VideoEncodeAccelerator::SupportedProfiles supportedProfiles;
-
- Type type = Type::kEncoder;
- const auto& devices = getDevicesForType(type);
- for (const auto& device : devices) {
- if (!openDevicePath(device.first, type)) {
- ALOGV("Failed opening %s", device.first.c_str());
- continue;
- }
-
- const auto& profiles = enumerateSupportedEncodeProfiles();
- supportedProfiles.insert(supportedProfiles.end(), profiles.begin(), profiles.end());
- closeDevice();
- }
-
- return supportedProfiles;
-}
-
-bool V4L2Device::openDevicePath(const std::string& path, Type /*type*/) {
- ALOG_ASSERT(!mDeviceFd.is_valid());
-
- mDeviceFd.reset(HANDLE_EINTR(::open(path.c_str(), O_RDWR | O_NONBLOCK | O_CLOEXEC)));
- if (!mDeviceFd.is_valid()) return false;
-
- return true;
-}
-
-void V4L2Device::closeDevice() {
- ALOGV("%s()", __func__);
-
- mDeviceFd.reset();
-}
-
-void V4L2Device::enumerateDevicesForType(Type type) {
- // video input/output devices are registered as /dev/videoX in V4L2.
- static const std::string kVideoDevicePattern = "/dev/video";
-
- std::string devicePattern;
- v4l2_buf_type bufType;
- switch (type) {
- case Type::kDecoder:
- devicePattern = kVideoDevicePattern;
- bufType = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
- break;
- case Type::kEncoder:
- devicePattern = kVideoDevicePattern;
- bufType = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
- break;
- default:
- ALOGE("Only decoder and encoder types are supported!!");
- return;
- }
-
- std::vector<std::string> candidatePaths;
-
- // TODO(posciak): Remove this legacy unnumbered device once all platforms are updated to use
- // numbered devices.
- candidatePaths.push_back(devicePattern);
-
- // We are sandboxed, so we can't query directory contents to check which devices are actually
- // available. Try to open the first 10; if not present, we will just fail to open immediately.
- for (int i = 0; i < 10; ++i) {
- candidatePaths.push_back(base::StringPrintf("%s%d", devicePattern.c_str(), i));
- }
-
- Devices devices;
- for (const auto& path : candidatePaths) {
- if (!openDevicePath(path, type)) {
- continue;
- }
-
- const auto& supportedPixelformats = enumerateSupportedPixelformats(bufType);
- if (!supportedPixelformats.empty()) {
- ALOGV("Found device: %s", path.c_str());
- devices.push_back(std::make_pair(path, supportedPixelformats));
- }
-
- closeDevice();
- }
-
- ALOG_ASSERT(mDevicesByType.count(type) == 0u);
- mDevicesByType[type] = devices;
-}
-
-const V4L2Device::Devices& V4L2Device::getDevicesForType(Type type) {
- if (mDevicesByType.count(type) == 0) enumerateDevicesForType(type);
-
- ALOG_ASSERT(mDevicesByType.count(type) != 0u);
- return mDevicesByType[type];
-}
-
-std::string V4L2Device::getDevicePathFor(Type type, uint32_t pixFmt) {
- const Devices& devices = getDevicesForType(type);
-
- for (const auto& device : devices) {
- if (std::find(device.second.begin(), device.second.end(), pixFmt) != device.second.end())
- return device.first;
- }
-
- return std::string();
-}
-
// static
uint32_t V4L2Device::videoCodecProfileToV4L2PixFmt(media::VideoCodecProfile profile,
bool sliceBased) {
@@ -1882,9 +1759,48 @@ std::vector<uint32_t> V4L2Device::enumerateSupportedPixelformats(v4l2_buf_type b
return pixelFormats;
}
-media::VideoDecodeAccelerator::SupportedProfiles V4L2Device::enumerateSupportedDecodeProfiles(
+V4L2Device::SupportedDecodeProfiles V4L2Device::getSupportedDecodeProfiles(
const size_t numFormats, const uint32_t pixelFormats[]) {
- media::VideoDecodeAccelerator::SupportedProfiles profiles;
+ SupportedDecodeProfiles supportedProfiles;
+
+ Type type = Type::kDecoder;
+ const auto& devices = getDevicesForType(type);
+ for (const auto& device : devices) {
+ if (!openDevicePath(device.first, type)) {
+ ALOGV("Failed opening %s", device.first.c_str());
+ continue;
+ }
+
+ const auto& profiles = enumerateSupportedDecodeProfiles(numFormats, pixelFormats);
+ supportedProfiles.insert(supportedProfiles.end(), profiles.begin(), profiles.end());
+ closeDevice();
+ }
+
+ return supportedProfiles;
+}
+
+V4L2Device::SupportedEncodeProfiles V4L2Device::getSupportedEncodeProfiles() {
+ SupportedEncodeProfiles supportedProfiles;
+
+ Type type = Type::kEncoder;
+ const auto& devices = getDevicesForType(type);
+ for (const auto& device : devices) {
+ if (!openDevicePath(device.first, type)) {
+ ALOGV("Failed opening %s", device.first.c_str());
+ continue;
+ }
+
+ const auto& profiles = enumerateSupportedEncodeProfiles();
+ supportedProfiles.insert(supportedProfiles.end(), profiles.begin(), profiles.end());
+ closeDevice();
+ }
+
+ return supportedProfiles;
+}
+
+V4L2Device::SupportedDecodeProfiles V4L2Device::enumerateSupportedDecodeProfiles(
+ const size_t numFormats, const uint32_t pixelFormats[]) {
+ SupportedDecodeProfiles profiles;
const auto& supportedPixelformats =
enumerateSupportedPixelformats(V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE);
@@ -1894,7 +1810,7 @@ media::VideoDecodeAccelerator::SupportedProfiles V4L2Device::enumerateSupportedD
pixelFormats + numFormats)
continue;
- media::VideoDecodeAccelerator::SupportedProfile profile;
+ SupportedDecodeProfile profile;
getSupportedResolution(pixelFormat, &profile.min_resolution, &profile.max_resolution);
const auto videoCodecProfiles = v4L2PixFmtToVideoCodecProfiles(pixelFormat, false);
@@ -1913,14 +1829,14 @@ media::VideoDecodeAccelerator::SupportedProfiles V4L2Device::enumerateSupportedD
return profiles;
}
-media::VideoEncodeAccelerator::SupportedProfiles V4L2Device::enumerateSupportedEncodeProfiles() {
- media::VideoEncodeAccelerator::SupportedProfiles profiles;
+V4L2Device::SupportedEncodeProfiles V4L2Device::enumerateSupportedEncodeProfiles() {
+ SupportedEncodeProfiles profiles;
const auto& supportedPixelformats =
enumerateSupportedPixelformats(V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
for (const auto& pixelformat : supportedPixelformats) {
- media::VideoEncodeAccelerator::SupportedProfile profile;
+ SupportedEncodeProfile profile;
profile.max_framerate_numerator = 30;
profile.max_framerate_denominator = 1;
media::Size minResolution;
@@ -2016,4 +1932,88 @@ bool V4L2Device::hasCapabilities(uint32_t capabilities) {
return (caps.capabilities & capabilities) == capabilities;
}
+bool V4L2Device::openDevicePath(const std::string& path, Type /*type*/) {
+ ALOG_ASSERT(!mDeviceFd.is_valid());
+
+ mDeviceFd.reset(HANDLE_EINTR(::open(path.c_str(), O_RDWR | O_NONBLOCK | O_CLOEXEC)));
+ if (!mDeviceFd.is_valid()) return false;
+
+ return true;
+}
+
+void V4L2Device::closeDevice() {
+ ALOGV("%s()", __func__);
+
+ mDeviceFd.reset();
+}
+
+void V4L2Device::enumerateDevicesForType(Type type) {
+ // video input/output devices are registered as /dev/videoX in V4L2.
+ static const std::string kVideoDevicePattern = "/dev/video";
+
+ std::string devicePattern;
+ v4l2_buf_type bufType;
+ switch (type) {
+ case Type::kDecoder:
+ devicePattern = kVideoDevicePattern;
+ bufType = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
+ break;
+ case Type::kEncoder:
+ devicePattern = kVideoDevicePattern;
+ bufType = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
+ break;
+ default:
+ ALOGE("Only decoder and encoder types are supported!!");
+ return;
+ }
+
+ std::vector<std::string> candidatePaths;
+
+ // TODO(posciak): Remove this legacy unnumbered device once all platforms are updated to use
+ // numbered devices.
+ candidatePaths.push_back(devicePattern);
+
+ // We are sandboxed, so we can't query directory contents to check which devices are actually
+ // available. Try to open the first 10; if not present, we will just fail to open immediately.
+ for (int i = 0; i < 10; ++i) {
+ candidatePaths.push_back(base::StringPrintf("%s%d", devicePattern.c_str(), i));
+ }
+
+ Devices devices;
+ for (const auto& path : candidatePaths) {
+ if (!openDevicePath(path, type)) {
+ continue;
+ }
+
+ const auto& supportedPixelformats = enumerateSupportedPixelformats(bufType);
+ if (!supportedPixelformats.empty()) {
+ ALOGV("Found device: %s", path.c_str());
+ devices.push_back(std::make_pair(path, supportedPixelformats));
+ }
+
+ closeDevice();
+ }
+
+ ALOG_ASSERT(mDevicesByType.count(type) == 0u);
+ mDevicesByType[type] = devices;
+}
+
+const V4L2Device::Devices& V4L2Device::getDevicesForType(Type type) {
+ if (mDevicesByType.count(type) == 0) enumerateDevicesForType(type);
+
+ ALOG_ASSERT(mDevicesByType.count(type) != 0u);
+ return mDevicesByType[type];
+}
+
+std::string V4L2Device::getDevicePathFor(Type type, uint32_t pixFmt) {
+ const Devices& devices = getDevicesForType(type);
+
+ for (const auto& device : devices) {
+ if (std::find(device.second.begin(), device.second.end(), pixFmt) != device.second.end())
+ return device.first;
+ }
+
+ return std::string();
+}
+
} // namespace android
diff --git a/common/include/v4l2_codec2/common/V4L2Device.h b/common/include/v4l2_codec2/common/V4L2Device.h
index 70a72b7..b70917f 100644
--- a/common/include/v4l2_codec2/common/V4L2Device.h
+++ b/common/include/v4l2_codec2/common/V4L2Device.h
@@ -24,8 +24,6 @@
#include <size.h>
#include <v4l2_codec2/common/V4L2DevicePoller.h>
#include <video_codecs.h>
-#include <video_decode_accelerator.h>
-#include <video_encode_accelerator.h>
#include <video_frame.h>
#include <video_frame_layout.h>
#include <video_pixel_format.h>
@@ -322,6 +320,26 @@ private:
class V4L2Device : public base::RefCountedThreadSafe<V4L2Device> {
public:
+ // Specification of an encoding profile supported by an encoder.
+ struct SupportedEncodeProfile {
+ media::VideoCodecProfile profile = media::VIDEO_CODEC_PROFILE_UNKNOWN;
+ media::Size min_resolution;
+ media::Size max_resolution;
+ uint32_t max_framerate_numerator = 0;
+ uint32_t max_framerate_denominator = 0;
+ };
+ using SupportedEncodeProfiles = std::vector<SupportedEncodeProfile>;
+
+ // Specification of a decoding profile supported by an decoder.
+ // |max_resolution| and |min_resolution| are inclusive.
+ struct SupportedDecodeProfile {
+ media::VideoCodecProfile profile = media::VIDEO_CODEC_PROFILE_UNKNOWN;
+ media::Size max_resolution;
+ media::Size min_resolution;
+ bool encrypted_only = false;
+ };
+ using SupportedDecodeProfiles = std::vector<SupportedDecodeProfile>;
+
// Utility format conversion functions
// If there is no corresponding single- or multi-planar format, returns 0.
static uint32_t videoCodecProfileToV4L2PixFmt(media::VideoCodecProfile profile,
@@ -415,11 +433,11 @@ public:
// Return supported profiles for decoder, including only profiles for given fourcc
// |pixelFormats|.
- media::VideoDecodeAccelerator::SupportedProfiles getSupportedDecodeProfiles(
- const size_t numFormats, const uint32_t pixelFormats[]);
+ SupportedDecodeProfiles getSupportedDecodeProfiles(const size_t numFormats,
+ const uint32_t pixelFormats[]);
// Return supported profiles for encoder.
- media::VideoEncodeAccelerator::SupportedProfiles getSupportedEncodeProfiles();
+ SupportedEncodeProfiles getSupportedEncodeProfiles();
// Start polling on this V4L2Device. |eventCallback| will be posted to the caller's sequence if
// a buffer is ready to be dequeued and/or a V4L2 event has been posted. |errorCallback| will
@@ -456,10 +474,10 @@ private:
V4L2Device(const V4L2Device&) = delete;
V4L2Device& operator=(const V4L2Device&) = delete;
- media::VideoDecodeAccelerator::SupportedProfiles enumerateSupportedDecodeProfiles(
- const size_t numFormats, const uint32_t pixelFormats[]);
+ SupportedDecodeProfiles enumerateSupportedDecodeProfiles(const size_t numFormats,
+ const uint32_t pixelFormats[]);
- media::VideoEncodeAccelerator::SupportedProfiles enumerateSupportedEncodeProfiles();
+ SupportedEncodeProfiles enumerateSupportedEncodeProfiles();
// Open device node for |path| as a device of |type|.
bool openDevicePath(const std::string& path, Type type);
diff --git a/components/V4L2EncodeInterface.cpp b/components/V4L2EncodeInterface.cpp
index 909480c..bc3c354 100644
--- a/components/V4L2EncodeInterface.cpp
+++ b/components/V4L2EncodeInterface.cpp
@@ -297,8 +297,7 @@ void V4L2EncodeInterface::Initialize(const C2String& name) {
media::VideoCodec codec =
getCodecFromComponentName(name).value_or(media::VideoCodec::kUnknownVideoCodec);
- media::VideoEncodeAccelerator::SupportedProfiles supported_profiles =
- device->getSupportedEncodeProfiles();
+ V4L2Device::SupportedEncodeProfiles supported_profiles = device->getSupportedEncodeProfiles();
// Compile the list of supported profiles. In the case of VP8 only a single profile is
// supported, which is not defined by the C2 framework.
@@ -308,7 +307,7 @@ void V4L2EncodeInterface::Initialize(const C2String& name) {
media::Size maxSize;
if (codec == media::VideoCodec::kCodecVP8) {
auto it = find_if(supported_profiles.begin(), supported_profiles.end(),
- [](const media::VideoEncodeAccelerator::SupportedProfile& profile) {
+ [](const V4L2Device::SupportedEncodeProfile& profile) {
return profile.profile == media::VideoCodecProfile::VP8PROFILE_MIN;
});
if (it == supported_profiles.end()) {