Skip to content
Snippets Groups Projects
Commit 7596c34d authored by Pin-chih Lin's avatar Pin-chih Lin
Browse files

codec2: move AVAFactory code from external/v4l2_codec2 to vendor/google_arc

C2AVAFactory is strongly ARC-related code which depends on some ARC libraries,
it should not be placed under external/v4l2_codec2. Moreover,
external/v4l2_codec2 does not have pi-arc-dev branch so we could not handle the
library difference between pi-dev and pi-arc-dev.

We move C2AVAFactory to vendor/google_arc and provide the united API for codec2
component's usage. By doing so we could keep other codec2 codes unchanged and
are able to handle both pi-dev and pi-arc-dev.

Note that this change should be uploaded after the vendor/google_arc change is
merged to pi-arc-dev.

Bug: 110177751
Test: build cheets image on pi-arc-dev
Test: vendor/google/build/build_test.bash on pi-dev

Change-Id: Ib3fd6a55bd587be9340232903438e314e4f55c3f
parent d06a69c8
No related branches found
No related tags found
No related merge requests found
cc_library_shared {
name: "libv4l2_codec2_arcva_factory",
vendor_available: true,
product_variables: {
arc: {
srcs: ["C2ArcVideoAcceleratorFactory.cpp"],
shared_libs: [
"libarcbridge",
"libarcbridgeservice",
"libarcvideobridge",
"libbinder",
"libchrome",
"liblog",
"libmojo",
"libutils",
],
// -Wno-unused-parameter is needed for libchrome/base codes
cflags: [
"-Wall",
"-Werror",
"-Wno-unused-parameter",
"-std=c++14",
],
},
},
clang: true,
export_include_dirs: [
"include",
],
}
......@@ -56,7 +56,7 @@ LOCAL_SRC_FILES := $(filter-out C2VDAAdaptor.cpp, $(LOCAL_SRC_FILES))
LOCAL_SHARED_LIBRARIES += libarcbridge \
libarcbridgeservice \
libmojo \
libv4l2_codec2_arcva_factory \
libcodec2_arcva_factory \
endif # ifneq (,$(findstring cheets_,$(TARGET_PRODUCT)))
......
// Copyright 2018 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.
// #define LOG_NDEBUG 0
#define LOG_TAG "C2ArcVideoAcceleratorFactory"
#include <C2ArcVideoAcceleratorFactory.h>
#include <base/bind.h>
#include <binder/IServiceManager.h>
#include <mojo/edk/embedder/embedder.h>
#include <mojo/public/cpp/bindings/interface_request.h>
#include <mojo/public/cpp/system/handle.h>
#include <utils/Log.h>
namespace android {
ANDROID_SINGLETON_STATIC_INSTANCE(C2ArcVideoAcceleratorFactory)
bool C2ArcVideoAcceleratorFactory::createVideoDecodeAccelerator(
::arc::mojom::VideoDecodeAcceleratorRequest request) {
if (!mRemoteFactory) {
ALOGE("Factory is not ready");
return false;
}
mRemoteFactory->CreateDecodeAccelerator(std::move(request));
return true;
}
bool C2ArcVideoAcceleratorFactory::createVideoEncodeAccelerator(
::arc::mojom::VideoEncodeAcceleratorRequest request) {
if (!mRemoteFactory) {
ALOGE("Factory is not ready");
return false;
}
mRemoteFactory->CreateEncodeAccelerator(std::move(request));
return true;
}
bool C2ArcVideoAcceleratorFactory::createVideoProtectedBufferAllocator(
::arc::mojom::VideoProtectedBufferAllocatorRequest request) {
if (!mRemoteFactory) {
ALOGE("Factory is not ready");
return false;
}
mRemoteFactory->CreateProtectedBufferAllocator(std::move(request));
return true;
}
int32_t C2ArcVideoAcceleratorFactory::hostVersion() const {
return mHostVersion;
}
C2ArcVideoAcceleratorFactory::C2ArcVideoAcceleratorFactory() : mHostVersion(0) {
sp<IBinder> binder =
defaultServiceManager()->getService(String16("android.os.IArcVideoBridge"));
if (binder == nullptr) {
ALOGE("Failed to find IArcVideoBridge service");
return;
}
mArcVideoBridge = interface_cast<IArcVideoBridge>(binder);
mHostVersion = mArcVideoBridge->hostVersion();
if (mHostVersion < 4) {
ALOGW("HostVersion(%d) is outdated", mHostVersion);
return;
}
ALOGV("HostVersion: %d", mHostVersion);
::arc::MojoBootstrapResult bootstrapResult =
mArcVideoBridge->bootstrapVideoAcceleratorFactory();
if (!bootstrapResult.is_valid()) {
ALOGE("bootstrapVideoAcceleratorFactory returns invalid result");
return;
}
mojo::edk::ScopedPlatformHandle handle(
mojo::edk::PlatformHandle(bootstrapResult.releaseFd().release()));
ALOGV("SetParentPipeHandle(fd=%d)", handle.get().handle);
mojo::edk::SetParentPipeHandle(std::move(handle));
mojo::ScopedMessagePipeHandle server_pipe =
mojo::edk::CreateChildMessagePipe(bootstrapResult.releaseToken());
mRemoteFactory.Bind(mojo::InterfacePtrInfo<::arc::mojom::VideoAcceleratorFactory>(
std::move(server_pipe), 7u));
}
} // namespace android
......@@ -64,7 +64,7 @@ bool C2VDAAdaptorProxy::establishChannel() {
}
void C2VDAAdaptorProxy::establishChannelOnMojoThread(std::shared_ptr<::arc::Future<bool>> future) {
C2ArcVideoAcceleratorFactory& factory = ::android::C2ArcVideoAcceleratorFactory::getInstance();
auto& factory = ::android::GetC2ArcVideoAcceleratorFactory();
if (!factory.createVideoDecodeAccelerator(mojo::MakeRequest(&mVDAPtr))) {
future->set(false);
......
// Copyright 2018 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.
#ifndef ANDROID_C2_ARC_VIDEO_ACCELERATOR_FACTORY_H
#define ANDROID_C2_ARC_VIDEO_ACCELERATOR_FACTORY_H
#include <media/arcvideobridge/IArcVideoBridge.h>
#include <utils/Singleton.h>
#include <components/arc/common/video.mojom.h>
#include <components/arc/common/video_decode_accelerator.mojom.h>
#include <components/arc/common/video_encode_accelerator.mojom.h>
namespace android {
// Helper class to create message pipe to the ArcVideoAccelerator.
// This class should only be used in the Mojo thread.
class C2ArcVideoAcceleratorFactory : public Singleton<C2ArcVideoAcceleratorFactory> {
public:
bool createVideoDecodeAccelerator(::arc::mojom::VideoDecodeAcceleratorRequest request);
bool createVideoEncodeAccelerator(::arc::mojom::VideoEncodeAcceleratorRequest request);
bool createVideoProtectedBufferAllocator(
::arc::mojom::VideoProtectedBufferAllocatorRequest request);
int32_t hostVersion() const;
private:
C2ArcVideoAcceleratorFactory();
uint32_t mHostVersion;
sp<IArcVideoBridge> mArcVideoBridge;
::arc::mojom::VideoAcceleratorFactoryPtr mRemoteFactory;
friend class Singleton<C2ArcVideoAcceleratorFactory>;
};
} // namespace android
#endif // ANDROID_C2_ARC_VIDEO_ACCELERATOR_FACTORY_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment