Hirokazu Honda | 407e798 | 2018-03-30 10:59:00 +0900 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // #define LOG_NDEBUG 0 |
| 6 | #define LOG_TAG "C2ArcVideoAcceleratorFactory" |
| 7 | |
| 8 | #include <C2ArcVideoAcceleratorFactory.h> |
| 9 | |
| 10 | #include <base/bind.h> |
| 11 | #include <binder/IServiceManager.h> |
| 12 | #include <mojo/edk/embedder/embedder.h> |
| 13 | #include <mojo/public/cpp/bindings/interface_request.h> |
| 14 | #include <mojo/public/cpp/system/handle.h> |
| 15 | #include <utils/Log.h> |
| 16 | |
| 17 | namespace android { |
| 18 | |
| 19 | ANDROID_SINGLETON_STATIC_INSTANCE(C2ArcVideoAcceleratorFactory) |
| 20 | |
| 21 | bool C2ArcVideoAcceleratorFactory::createVideoDecodeAccelerator( |
| 22 | ::arc::mojom::VideoDecodeAcceleratorRequest request) { |
| 23 | if (!mRemoteFactory) { |
| 24 | ALOGE("Factory is not ready"); |
| 25 | return false; |
| 26 | } |
| 27 | mRemoteFactory->CreateDecodeAccelerator(std::move(request)); |
| 28 | return true; |
| 29 | } |
| 30 | |
Hirokazu Honda | 26963d1 | 2018-04-02 14:16:20 +0900 | [diff] [blame] | 31 | bool C2ArcVideoAcceleratorFactory::createVideoEncodeAccelerator( |
| 32 | ::arc::mojom::VideoEncodeAcceleratorRequest request) { |
| 33 | if (!mRemoteFactory) { |
| 34 | ALOGE("Factory is not ready"); |
| 35 | return false; |
| 36 | } |
| 37 | mRemoteFactory->CreateEncodeAccelerator(std::move(request)); |
| 38 | return true; |
| 39 | } |
| 40 | |
Hirokazu Honda | fa6c835 | 2018-05-21 12:19:29 +0900 | [diff] [blame] | 41 | bool C2ArcVideoAcceleratorFactory::createVideoProtectedBufferAllocator( |
| 42 | ::arc::mojom::VideoProtectedBufferAllocatorRequest request) { |
| 43 | if (!mRemoteFactory) { |
| 44 | ALOGE("Factory is not ready"); |
| 45 | return false; |
| 46 | } |
| 47 | mRemoteFactory->CreateProtectedBufferAllocator(std::move(request)); |
| 48 | return true; |
| 49 | } |
| 50 | |
Hirokazu Honda | 407e798 | 2018-03-30 10:59:00 +0900 | [diff] [blame] | 51 | int32_t C2ArcVideoAcceleratorFactory::hostVersion() const { |
| 52 | return mHostVersion; |
| 53 | } |
| 54 | |
| 55 | C2ArcVideoAcceleratorFactory::C2ArcVideoAcceleratorFactory() : mHostVersion(0) { |
| 56 | sp<IBinder> binder = |
| 57 | defaultServiceManager()->getService(String16("android.os.IArcVideoBridge")); |
| 58 | if (binder == nullptr) { |
| 59 | ALOGE("Failed to find IArcVideoBridge service"); |
| 60 | return; |
| 61 | } |
| 62 | mArcVideoBridge = interface_cast<IArcVideoBridge>(binder); |
| 63 | mHostVersion = mArcVideoBridge->hostVersion(); |
| 64 | if (mHostVersion < 4) { |
| 65 | ALOGW("HostVersion(%d) is outdated", mHostVersion); |
| 66 | return; |
| 67 | } |
| 68 | |
| 69 | ALOGV("HostVersion: %d", mHostVersion); |
| 70 | |
| 71 | ::arc::MojoBootstrapResult bootstrapResult = |
| 72 | mArcVideoBridge->bootstrapVideoAcceleratorFactory(); |
| 73 | if (!bootstrapResult.is_valid()) { |
| 74 | ALOGE("bootstrapVideoAcceleratorFactory returns invalid result"); |
| 75 | return; |
| 76 | } |
| 77 | mojo::edk::ScopedPlatformHandle handle( |
| 78 | mojo::edk::PlatformHandle(bootstrapResult.releaseFd().release())); |
| 79 | ALOGV("SetParentPipeHandle(fd=%d)", handle.get().handle); |
| 80 | mojo::edk::SetParentPipeHandle(std::move(handle)); |
| 81 | mojo::ScopedMessagePipeHandle server_pipe = |
| 82 | mojo::edk::CreateChildMessagePipe(bootstrapResult.releaseToken()); |
| 83 | mRemoteFactory.Bind(mojo::InterfacePtrInfo<::arc::mojom::VideoAcceleratorFactory>( |
Hirokazu Honda | fa6c835 | 2018-05-21 12:19:29 +0900 | [diff] [blame] | 84 | std::move(server_pipe), 7u)); |
Hirokazu Honda | 407e798 | 2018-03-30 10:59:00 +0900 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | } // namespace android |