1/* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17//#define LOG_NDEBUG 0 18#define LOG_TAG "OMXClient" 19 20#ifdef __LP64__ 21#define OMX_ANDROID_COMPILE_AS_32BIT_ON_64BIT_PLATFORMS 22#endif 23 24#include <utils/Log.h> 25#include <cutils/properties.h> 26 27#include <binder/IServiceManager.h> 28#include <media/IMediaCodecService.h> 29#include <media/stagefright/OMXClient.h> 30 31#include <media/IOMX.h> 32 33#include <media/omx/1.0/WOmx.h> 34 35namespace android { 36 37OMXClient::OMXClient() { 38} 39 40status_t OMXClient::connect() { 41 return connect(nullptr); 42} 43 44status_t OMXClient::connect(bool* trebleFlag) { 45 if (property_get_bool("persist.media.treble_omx", true)) { 46 if (trebleFlag != nullptr) { 47 *trebleFlag = true; 48 } 49 return connectTreble(); 50 } 51 if (trebleFlag != nullptr) { 52 *trebleFlag = false; 53 } 54 return connectLegacy(); 55} 56 57status_t OMXClient::connectLegacy() { 58 sp<IServiceManager> sm = defaultServiceManager(); 59 sp<IBinder> codecbinder = sm->getService(String16("media.codec")); 60 sp<IMediaCodecService> codecservice = interface_cast<IMediaCodecService>(codecbinder); 61 62 if (codecservice.get() == NULL) { 63 ALOGE("Cannot obtain IMediaCodecService"); 64 return NO_INIT; 65 } 66 67 mOMX = codecservice->getOMX(); 68 if (mOMX.get() == NULL) { 69 ALOGE("Cannot obtain mediacodec IOMX"); 70 return NO_INIT; 71 } 72 73 return OK; 74} 75 76status_t OMXClient::connectTreble() { 77 using namespace ::android::hardware::media::omx::V1_0; 78 sp<IOmx> tOmx = IOmx::getService("default"); 79 if (tOmx.get() == nullptr) { 80 ALOGE("Cannot obtain Treble IOmx."); 81 return NO_INIT; 82 } 83 if (!tOmx->isRemote()) { 84 ALOGE("Treble IOmx is in passthrough mode."); 85 return NO_INIT; 86 } 87 mOMX = new utils::LWOmx(tOmx); 88 ALOGI("Treble IOmx obtained"); 89 return OK; 90} 91 92void OMXClient::disconnect() { 93 mOMX.clear(); 94} 95 96} // namespace android 97