HDCP.cpp revision 1b19c9d120869c3182373a9b06a1ed98898df882
1/* 2 * Copyright (C) 2012 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 "HDCP" 19#include <utils/Log.h> 20 21#include "HDCP.h" 22 23#include <media/stagefright/foundation/ADebug.h> 24 25#include <dlfcn.h> 26 27namespace android { 28 29HDCP::HDCP() 30 : mLibHandle(NULL), 31 mHDCPModule(NULL) { 32 mLibHandle = dlopen("libstagefright_hdcp.so", RTLD_NOW); 33 34 if (mLibHandle == NULL) { 35 ALOGE("Unable to locate libstagefright_hdcp.so"); 36 return; 37 } 38 39 typedef HDCPModule *(*CreateHDCPModuleFunc)(); 40 CreateHDCPModuleFunc createHDCPModule = 41 (CreateHDCPModuleFunc)dlsym(mLibHandle, "createHDCPModule"); 42 43 if (createHDCPModule == NULL) { 44 ALOGE("Unable to find symbol 'createHDCPModule'."); 45 } else if ((mHDCPModule = createHDCPModule()) == NULL) { 46 ALOGE("createHDCPModule failed."); 47 } 48} 49 50HDCP::~HDCP() { 51 if (mHDCPModule != NULL) { 52 delete mHDCPModule; 53 mHDCPModule = NULL; 54 } 55 56 if (mLibHandle != NULL) { 57 dlclose(mLibHandle); 58 mLibHandle = NULL; 59 } 60} 61 62status_t HDCP::setObserver(const sp<IHDCPObserver> &observer) { 63 if (mHDCPModule == NULL) { 64 return NO_INIT; 65 } 66 67 mObserver = observer; 68 69 return OK; 70} 71 72status_t HDCP::initAsync(const char *host, unsigned port) { 73 if (mHDCPModule == NULL) { 74 return NO_INIT; 75 } 76 77 return mHDCPModule->initAsync(host, port); 78} 79 80status_t HDCP::shutdownAsync() { 81 if (mHDCPModule == NULL) { 82 return NO_INIT; 83 } 84 85 return mHDCPModule->shutdownAsync(); 86} 87 88status_t HDCP::encrypt( 89 const void *inData, size_t size, uint32_t streamCTR, 90 uint64_t *outInputCTR, void *outData) { 91 if (mHDCPModule == NULL) { 92 *outInputCTR = 0; 93 94 return NO_INIT; 95 } 96 97 return mHDCPModule->encrypt(inData, size, streamCTR, outInputCTR, outData); 98} 99 100} // namespace android 101 102