blob: e7dea6e210f2b7f455ffeffc894e006a2668874e [file] [log] [blame]
Andreas Huber1b19c9d2012-08-29 11:34:22 -07001/*
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
Andreas Huberefbb7812012-09-18 10:36:32 -070039 typedef HDCPModule *(*CreateHDCPModuleFunc)(
40 void *, HDCPModule::ObserverFunc);
41
Andreas Huber1b19c9d2012-08-29 11:34:22 -070042 CreateHDCPModuleFunc createHDCPModule =
43 (CreateHDCPModuleFunc)dlsym(mLibHandle, "createHDCPModule");
44
45 if (createHDCPModule == NULL) {
46 ALOGE("Unable to find symbol 'createHDCPModule'.");
Andreas Huberefbb7812012-09-18 10:36:32 -070047 } else if ((mHDCPModule = createHDCPModule(
48 this, &HDCP::ObserveWrapper)) == NULL) {
Andreas Huber1b19c9d2012-08-29 11:34:22 -070049 ALOGE("createHDCPModule failed.");
50 }
51}
52
53HDCP::~HDCP() {
54 if (mHDCPModule != NULL) {
55 delete mHDCPModule;
56 mHDCPModule = NULL;
57 }
58
59 if (mLibHandle != NULL) {
60 dlclose(mLibHandle);
61 mLibHandle = NULL;
62 }
63}
64
65status_t HDCP::setObserver(const sp<IHDCPObserver> &observer) {
66 if (mHDCPModule == NULL) {
67 return NO_INIT;
68 }
69
70 mObserver = observer;
71
72 return OK;
73}
74
75status_t HDCP::initAsync(const char *host, unsigned port) {
76 if (mHDCPModule == NULL) {
77 return NO_INIT;
78 }
79
80 return mHDCPModule->initAsync(host, port);
81}
82
83status_t HDCP::shutdownAsync() {
84 if (mHDCPModule == NULL) {
85 return NO_INIT;
86 }
87
88 return mHDCPModule->shutdownAsync();
89}
90
91status_t HDCP::encrypt(
92 const void *inData, size_t size, uint32_t streamCTR,
93 uint64_t *outInputCTR, void *outData) {
94 if (mHDCPModule == NULL) {
95 *outInputCTR = 0;
96
97 return NO_INIT;
98 }
99
100 return mHDCPModule->encrypt(inData, size, streamCTR, outInputCTR, outData);
101}
102
Andreas Huberefbb7812012-09-18 10:36:32 -0700103// static
104void HDCP::ObserveWrapper(void *me, int msg, int ext1, int ext2) {
105 static_cast<HDCP *>(me)->observe(msg, ext1, ext2);
106}
107
108void HDCP::observe(int msg, int ext1, int ext2) {
109 if (mObserver != NULL) {
110 mObserver->notify(msg, ext1, ext2, NULL /* obj */);
111 }
112}
113
Andreas Huber1b19c9d2012-08-29 11:34:22 -0700114} // namespace android
115