Use C2VDAPixelForamt to resolve pixel format
A function to get supported format from crcb and semiplanar is identical in Android path and ARC++
path. So they can be unified.
The other function is to return pixel format on a platform with zero knowledge. A small
C2AllocationGralloc is allocated inside of the function, and detects its pixel format.
Because C2ArcProtectedGraphicAllocator needs to call these function, the code is located in
device/google/cheets2/.
Bug: 73870167
Test: Play secure videos with ExoPlayer.app
Change-Id: I34975f869b465e347b9ef1521d12998539be5658
diff --git a/Android.mk b/Android.mk
index e369912..32656ff 100644
--- a/Android.mk
+++ b/Android.mk
@@ -37,6 +37,7 @@
libstagefright_foundation \
libutils \
libv4l2_codec2_vda \
+ libvda_c2_pixelformat \
libvda_c2componentstore \
# -Wno-unused-parameter is needed for libchrome/base codes
diff --git a/C2VDAAdaptor.cpp b/C2VDAAdaptor.cpp
index 81470c6..2e837a9 100644
--- a/C2VDAAdaptor.cpp
+++ b/C2VDAAdaptor.cpp
@@ -18,13 +18,6 @@
namespace android {
-constexpr SupportedPixelFormat kSupportedPixelFormats[] = {
- // {mCrcb, mSemiplanar, mPixelFormat}
- {false, true, HalPixelFormat::NV12},
- {true, false, HalPixelFormat::YV12},
- // Add more buffer formats when needed
-};
-
C2VDAAdaptor::C2VDAAdaptor() : mNumOutputBuffers(0u) {}
C2VDAAdaptor::~C2VDAAdaptor() {
@@ -145,17 +138,6 @@
return supportedProfiles;
}
-//static
-HalPixelFormat C2VDAAdaptor::ResolveBufferFormat(bool crcb, bool semiplanar) {
- auto value = std::find_if(std::begin(kSupportedPixelFormats), std::end(kSupportedPixelFormats),
- [crcb, semiplanar](const struct SupportedPixelFormat& f) {
- return f.mCrcb == crcb && f.mSemiplanar == semiplanar;
- });
- LOG_ALWAYS_FATAL_IF(value == std::end(kSupportedPixelFormats),
- "Unsupported pixel format: (crcb=%d, semiplanar=%d)", crcb, semiplanar);
- return value->mPixelFormat;
-}
-
void C2VDAAdaptor::ProvidePictureBuffers(uint32_t requested_num_of_buffers,
media::VideoPixelFormat output_format,
const media::Size& dimensions) {
diff --git a/C2VDAAdaptorProxy.cpp b/C2VDAAdaptorProxy.cpp
index 5c3a990..5b1558b 100644
--- a/C2VDAAdaptorProxy.cpp
+++ b/C2VDAAdaptorProxy.cpp
@@ -30,13 +30,6 @@
namespace android {
namespace arc {
-constexpr SupportedPixelFormat kSupportedPixelFormats[] = {
- // {mCrcb, mSemiplanar, mPixelFormat}
- {false, true, HalPixelFormat::NV12},
- {true, false, HalPixelFormat::YV12},
- // Add more buffer formats when needed
-};
-
C2VDAAdaptorProxy::C2VDAAdaptorProxy()
: C2VDAAdaptorProxy(::arc::MojoProcessSupport::getLeakyInstance()) {}
@@ -177,17 +170,6 @@
return profiles;
}
-//static
-HalPixelFormat C2VDAAdaptorProxy::ResolveBufferFormat(bool crcb, bool semiplanar) {
- auto value = std::find_if(std::begin(kSupportedPixelFormats), std::end(kSupportedPixelFormats),
- [crcb, semiplanar](const struct SupportedPixelFormat& f) {
- return f.mCrcb == crcb && f.mSemiplanar == semiplanar;
- });
- LOG_ALWAYS_FATAL_IF(value == std::end(kSupportedPixelFormats),
- "Unsupported pixel format: (crcb=%d, semiplanar=%d)", crcb, semiplanar);
- return value->mPixelFormat;
-}
-
VideoDecodeAcceleratorAdaptor::Result C2VDAAdaptorProxy::initialize(
media::VideoCodecProfile profile, bool secureMode,
VideoDecodeAcceleratorAdaptor::Client* client) {
diff --git a/C2VDAComponent.cpp b/C2VDAComponent.cpp
index dd48d33..65656e3 100644
--- a/C2VDAComponent.cpp
+++ b/C2VDAComponent.cpp
@@ -13,10 +13,11 @@
#define __C2_GENERATE_GLOBAL_VARS__
#include <C2VDAAllocatorStore.h>
+#include <C2VDAComponent.h>
+#include <C2VDAPixelFormat.h>
+#include <C2VDASupport.h> // to getParamReflector from vda store
#include <C2VdaBqBlockPool.h>
#include <C2VdaPooledBlockPool.h>
-#include <C2VDAComponent.h>
-#include <C2VDASupport.h> // to getParamReflector from vda store
#include <videodev2_custom.h>
@@ -821,11 +822,7 @@
for (uint32_t i = 0; i < passedNumPlanes; ++i) {
ALOGV("plane %u: stride: %d, offset: %u", i, layout.planes[i].rowInc, offsets[i]);
}
-#ifdef V4L2_CODEC2_ARC
- info.mPixelFormat = arc::C2VDAAdaptorProxy::ResolveBufferFormat(crcb, semiplanar);
-#else
- info.mPixelFormat = C2VDAAdaptor::ResolveBufferFormat(crcb, semiplanar);
-#endif
+ info.mPixelFormat = resolveBufferFormat(crcb, semiplanar);
ALOGV("HAL pixel format: 0x%x", static_cast<uint32_t>(info.mPixelFormat));
::base::ScopedFD passedHandle(dup(info.mGraphicBlock->handle()->data[0]));
@@ -857,8 +854,14 @@
return;
}
- // TODO(hiroh): resolve pixel format here.
- android::HalPixelFormat pixelFormat = pixelFormat == android::HalPixelFormat::NV12;
+ android::HalPixelFormat pixelFormat = getPlatformPixelFormat();
+ if (pixelFormat == android::HalPixelFormat::UNKNOWN) {
+ ALOGE("Failed to get pixel format on platform.");
+ reportError(C2_CORRUPTED);
+ return;
+ }
+ CHECK(pixelFormat == android::HalPixelFormat::YV12 ||
+ pixelFormat == android::HalPixelFormat::NV12);
ALOGV("HAL pixel format: 0x%x", static_cast<uint32_t>(pixelFormat));
GraphicBlockInfo info;
diff --git a/include/C2VDAAdaptor.h b/include/C2VDAAdaptor.h
index 8f24d10..3ba85f2 100644
--- a/include/C2VDAAdaptor.h
+++ b/include/C2VDAAdaptor.h
@@ -36,8 +36,6 @@
static media::VideoDecodeAccelerator::SupportedProfiles GetSupportedProfiles(
uint32_t inputFormatFourcc);
- static HalPixelFormat ResolveBufferFormat(bool crcb, bool semiplanar);
-
// Implementation of the media::VideoDecodeAccelerator::Client interface.
void ProvidePictureBuffers(uint32_t requested_num_of_buffers,
media::VideoPixelFormat output_format,
diff --git a/include/C2VDAAdaptorProxy.h b/include/C2VDAAdaptorProxy.h
index fbfe009..eab6882 100644
--- a/include/C2VDAAdaptorProxy.h
+++ b/include/C2VDAAdaptorProxy.h
@@ -59,7 +59,6 @@
static media::VideoDecodeAccelerator::SupportedProfiles GetSupportedProfiles(
uint32_t inputFormatFourcc);
- static HalPixelFormat ResolveBufferFormat(bool crcb, bool semiplanar);
private:
void onConnectionError(const std::string& pipeName);
diff --git a/include/VideoDecodeAcceleratorAdaptor.h b/include/VideoDecodeAcceleratorAdaptor.h
index c9fc50b..9118467 100644
--- a/include/VideoDecodeAcceleratorAdaptor.h
+++ b/include/VideoDecodeAcceleratorAdaptor.h
@@ -22,13 +22,6 @@
uint32_t mStride;
};
-// The HAL pixel format information supported by Android flexible YUV format.
-struct SupportedPixelFormat {
- bool mCrcb;
- bool mSemiplanar;
- HalPixelFormat mPixelFormat;
-};
-
// Video decoder accelerator adaptor interface.
// The adaptor plays the role of providing unified adaptor API functions and client callback to
// codec component side.