blob: 26eda0c4cfb179dccc4a4c723b20d17730460cf2 [file] [log] [blame]
Gloria Wangc2c22e72010-11-01 15:53:16 -07001/*
2 * Copyright (C) 2010 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_TAG "WVMExtractor"
18#include <utils/Log.h>
19
20#include "include/WVMExtractor.h"
21
22#include <arpa/inet.h>
23#include <utils/String8.h>
24#include <media/stagefright/Utils.h>
25#include <media/stagefright/DataSource.h>
26#include <media/stagefright/MediaSource.h>
27#include <media/stagefright/MediaDefs.h>
28#include <media/stagefright/MetaData.h>
29#include <media/stagefright/MediaErrors.h>
30#include <media/stagefright/MediaBuffer.h>
31#include <media/stagefright/MediaDebug.h>
32#include <dlfcn.h>
33
34#include <utils/Errors.h>
35
Jeff Tinker73104112011-07-01 07:13:42 -070036/* 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
40 */
41void *gVendorLibHandle = NULL;
42
Gloria Wangc2c22e72010-11-01 15:53:16 -070043namespace android {
44
Jeff Tinker73104112011-07-01 07:13:42 -070045static Mutex gWVMutex;
Gloria Wangc2c22e72010-11-01 15:53:16 -070046
47WVMExtractor::WVMExtractor(const sp<DataSource> &source)
James Dongd70c64d2011-12-14 10:57:05 -080048 : mDataSource(source) {
49 {
50 Mutex::Autolock autoLock(gWVMutex);
51 if (gVendorLibHandle == NULL) {
52 gVendorLibHandle = dlopen("libwvm.so", RTLD_NOW);
53 }
Gloria Wangc2c22e72010-11-01 15:53:16 -070054
James Dongd70c64d2011-12-14 10:57:05 -080055 if (gVendorLibHandle == NULL) {
56 LOGE("Failed to open libwvm.so");
57 return;
58 }
Gloria Wangc2c22e72010-11-01 15:53:16 -070059 }
60
Jeffrey Tinker82646412011-05-21 18:19:17 -070061 typedef WVMLoadableExtractor *(*GetInstanceFunc)(sp<DataSource>);
Gloria Wangc2c22e72010-11-01 15:53:16 -070062 GetInstanceFunc getInstanceFunc =
Jeff Tinker73104112011-07-01 07:13:42 -070063 (GetInstanceFunc) dlsym(gVendorLibHandle,
Gloria Wangc2c22e72010-11-01 15:53:16 -070064 "_ZN7android11GetInstanceENS_2spINS_10DataSourceEEE");
65
66 if (getInstanceFunc) {
Gloria Wangc2c22e72010-11-01 15:53:16 -070067 mImpl = (*getInstanceFunc)(source);
68 CHECK(mImpl != NULL);
69 } else {
70 LOGE("Failed to locate GetInstance in libwvm.so");
71 }
72}
73
74WVMExtractor::~WVMExtractor() {
75}
76
77size_t WVMExtractor::countTracks() {
78 return (mImpl != NULL) ? mImpl->countTracks() : 0;
79}
80
81sp<MediaSource> WVMExtractor::getTrack(size_t index) {
82 if (mImpl == NULL) {
83 return NULL;
84 }
85 return mImpl->getTrack(index);
86}
87
88sp<MetaData> WVMExtractor::getTrackMetaData(size_t index, uint32_t flags) {
89 if (mImpl == NULL) {
90 return NULL;
91 }
92 return mImpl->getTrackMetaData(index, flags);
93}
94
95sp<MetaData> WVMExtractor::getMetaData() {
96 if (mImpl == NULL) {
97 return NULL;
98 }
99 return mImpl->getMetaData();
100}
101
Andreas Huber77d8dc22011-04-21 10:06:43 -0700102int64_t WVMExtractor::getCachedDurationUs(status_t *finalStatus) {
Jeffrey Tinker82646412011-05-21 18:19:17 -0700103 if (mImpl == NULL) {
104 return 0;
105 }
Andreas Huber77d8dc22011-04-21 10:06:43 -0700106
Jeffrey Tinker82646412011-05-21 18:19:17 -0700107 return mImpl->getCachedDurationUs(finalStatus);
Andreas Huber77d8dc22011-04-21 10:06:43 -0700108}
109
110void WVMExtractor::setAdaptiveStreamingMode(bool adaptive) {
Jeffrey Tinker82646412011-05-21 18:19:17 -0700111 if (mImpl != NULL) {
112 mImpl->setAdaptiveStreamingMode(adaptive);
113 }
Andreas Huber77d8dc22011-04-21 10:06:43 -0700114}
115
Gloria Wangc2c22e72010-11-01 15:53:16 -0700116} //namespace android
117