2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #define LOG_TAG "WVMExtractor"
18 #include <utils/Log.h>
20 #include "include/WVMExtractor.h"
22 #include <arpa/inet.h>
23 #include <utils/String8.h>
24 #include <media/stagefright/foundation/ADebug.h>
25 #include <media/stagefright/Utils.h>
26 #include <media/stagefright/DataSource.h>
27 #include <media/stagefright/MediaSource.h>
28 #include <media/stagefright/MediaDefs.h>
29 #include <media/stagefright/MetaData.h>
30 #include <media/stagefright/MediaErrors.h>
31 #include <media/stagefright/MediaBuffer.h>
34 #include <utils/Errors.h>
36 /* The extractor lifetime is short - just long enough to get
37 * the media sources constructed - so the shared lib needs to remain open
38 * beyond the lifetime of the extractor. So keep the handle as a global
39 * rather than a member of the extractor
41 void *gVendorLibHandle = NULL;
45 static Mutex gWVMutex;
47 WVMExtractor::WVMExtractor(const sp<DataSource> &source)
50 Mutex::Autolock autoLock(gWVMutex);
52 if (!getVendorLibHandle()) {
56 typedef WVMLoadableExtractor *(*GetInstanceFunc)(sp<DataSource>);
57 GetInstanceFunc getInstanceFunc =
58 (GetInstanceFunc) dlsym(gVendorLibHandle,
59 "_ZN7android11GetInstanceENS_2spINS_10DataSourceEEE");
61 if (getInstanceFunc) {
62 if (source->DrmInitialization(
63 MEDIA_MIMETYPE_CONTAINER_WVM) != NULL) {
64 mImpl = (*getInstanceFunc)(source);
68 ALOGE("Drm manager failed to initialize.");
71 ALOGE("Failed to locate GetInstance in libwvm.so");
75 static void init_routine()
77 gVendorLibHandle = dlopen("libwvm.so", RTLD_NOW);
78 if (gVendorLibHandle == NULL) {
79 ALOGE("Failed to open libwvm.so: %s", dlerror());
83 bool WVMExtractor::getVendorLibHandle()
85 static pthread_once_t sOnceControl = PTHREAD_ONCE_INIT;
86 pthread_once(&sOnceControl, init_routine);
88 return gVendorLibHandle != NULL;
91 WVMExtractor::~WVMExtractor() {
94 size_t WVMExtractor::countTracks() {
95 return (mImpl != NULL) ? mImpl->countTracks() : 0;
98 sp<MediaSource> WVMExtractor::getTrack(size_t index) {
102 return mImpl->getTrack(index);
105 sp<MetaData> WVMExtractor::getTrackMetaData(size_t index, uint32_t flags) {
109 return mImpl->getTrackMetaData(index, flags);
112 sp<MetaData> WVMExtractor::getMetaData() {
116 return mImpl->getMetaData();
119 int64_t WVMExtractor::getCachedDurationUs(status_t *finalStatus) {
124 return mImpl->getCachedDurationUs(finalStatus);
127 status_t WVMExtractor::getEstimatedBandwidthKbps(int32_t *kbps) {
129 return UNKNOWN_ERROR;
132 return mImpl->getEstimatedBandwidthKbps(kbps);
136 void WVMExtractor::setAdaptiveStreamingMode(bool adaptive) {
138 mImpl->setAdaptiveStreamingMode(adaptive);
142 void WVMExtractor::setCryptoPluginMode(bool cryptoPluginMode) {
144 mImpl->setCryptoPluginMode(cryptoPluginMode);
148 void WVMExtractor::setUID(uid_t uid) {
154 status_t WVMExtractor::getError() {
156 return UNKNOWN_ERROR;
159 return mImpl->getError();
162 void WVMExtractor::setError(status_t err) {
164 mImpl->setError(err);
169 const sp<DataSource> &source, String8 *mimeType, float *confidence,
172 Mutex::Autolock autoLock(gWVMutex);
174 if (!WVMExtractor::getVendorLibHandle()) {
178 typedef WVMLoadableExtractor *(*SnifferFunc)(const sp<DataSource>&);
179 SnifferFunc snifferFunc =
180 (SnifferFunc) dlsym(gVendorLibHandle,
181 "_ZN7android15IsWidevineMediaERKNS_2spINS_10DataSourceEEE");
184 if ((*snifferFunc)(source)) {
185 *mimeType = MEDIA_MIMETYPE_CONTAINER_WVM;
190 ALOGE("IsWidevineMedia not found in libwvm.so");
196 } //namespace android