1 /* 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 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 40 */ 41 void *gVendorLibHandle = NULL; 42 43 namespace android { 44 45 static Mutex gWVMutex; 46 47 WVMExtractor::WVMExtractor(const sp<DataSource> &source) 48 : mDataSource(source) { 49 { 50 Mutex::Autolock autoLock(gWVMutex); 51 if (gVendorLibHandle == NULL) { 52 gVendorLibHandle = dlopen("libwvm.so", RTLD_NOW); 53 } 54 55 if (gVendorLibHandle == NULL) { 56 LOGE("Failed to open libwvm.so"); 57 return; 58 } 59 } 60 61 typedef WVMLoadableExtractor *(*GetInstanceFunc)(sp<DataSource>); 62 GetInstanceFunc getInstanceFunc = 63 (GetInstanceFunc) dlsym(gVendorLibHandle, 64 "_ZN7android11GetInstanceENS_2spINS_10DataSourceEEE"); 65 66 if (getInstanceFunc) { 67 mImpl = (*getInstanceFunc)(source); 68 CHECK(mImpl != NULL); 69 } else { 70 LOGE("Failed to locate GetInstance in libwvm.so"); 71 } 72 } 73 74 WVMExtractor::~WVMExtractor() { 75 } 76 77 size_t WVMExtractor::countTracks() { 78 return (mImpl != NULL) ? mImpl->countTracks() : 0; 79 } 80 81 sp<MediaSource> WVMExtractor::getTrack(size_t index) { 82 if (mImpl == NULL) { 83 return NULL; 84 } 85 return mImpl->getTrack(index); 86 } 87 88 sp<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 95 sp<MetaData> WVMExtractor::getMetaData() { 96 if (mImpl == NULL) { 97 return NULL; 98 } 99 return mImpl->getMetaData(); 100 } 101 102 int64_t WVMExtractor::getCachedDurationUs(status_t *finalStatus) { 103 if (mImpl == NULL) { 104 return 0; 105 } 106 107 return mImpl->getCachedDurationUs(finalStatus); 108 } 109 110 void WVMExtractor::setAdaptiveStreamingMode(bool adaptive) { 111 if (mImpl != NULL) { 112 mImpl->setAdaptiveStreamingMode(adaptive); 113 } 114 } 115 116 } //namespace android 117 118