Gloria Wang | c2c22e7 | 2010-11-01 15:53:16 -0700 | [diff] [blame] | 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 | |
Jeff Tinker | 7310411 | 2011-07-01 07:13:42 -0700 | [diff] [blame] | 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 | |
Gloria Wang | c2c22e7 | 2010-11-01 15:53:16 -0700 | [diff] [blame] | 43 | namespace android { |
| 44 | |
Jeff Tinker | 7310411 | 2011-07-01 07:13:42 -0700 | [diff] [blame] | 45 | static Mutex gWVMutex; |
Gloria Wang | c2c22e7 | 2010-11-01 15:53:16 -0700 | [diff] [blame] | 46 | |
| 47 | WVMExtractor::WVMExtractor(const sp<DataSource> &source) |
James Dong | d70c64d | 2011-12-14 10:57:05 -0800 | [diff] [blame] | 48 | : mDataSource(source) { |
| 49 | { |
| 50 | Mutex::Autolock autoLock(gWVMutex); |
| 51 | if (gVendorLibHandle == NULL) { |
| 52 | gVendorLibHandle = dlopen("libwvm.so", RTLD_NOW); |
| 53 | } |
Gloria Wang | c2c22e7 | 2010-11-01 15:53:16 -0700 | [diff] [blame] | 54 | |
James Dong | d70c64d | 2011-12-14 10:57:05 -0800 | [diff] [blame] | 55 | if (gVendorLibHandle == NULL) { |
| 56 | LOGE("Failed to open libwvm.so"); |
| 57 | return; |
| 58 | } |
Gloria Wang | c2c22e7 | 2010-11-01 15:53:16 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Jeffrey Tinker | 8264641 | 2011-05-21 18:19:17 -0700 | [diff] [blame] | 61 | typedef WVMLoadableExtractor *(*GetInstanceFunc)(sp<DataSource>); |
Gloria Wang | c2c22e7 | 2010-11-01 15:53:16 -0700 | [diff] [blame] | 62 | GetInstanceFunc getInstanceFunc = |
Jeff Tinker | 7310411 | 2011-07-01 07:13:42 -0700 | [diff] [blame] | 63 | (GetInstanceFunc) dlsym(gVendorLibHandle, |
Gloria Wang | c2c22e7 | 2010-11-01 15:53:16 -0700 | [diff] [blame] | 64 | "_ZN7android11GetInstanceENS_2spINS_10DataSourceEEE"); |
| 65 | |
| 66 | if (getInstanceFunc) { |
Gloria Wang | c2c22e7 | 2010-11-01 15:53:16 -0700 | [diff] [blame] | 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 | |
Andreas Huber | 77d8dc2 | 2011-04-21 10:06:43 -0700 | [diff] [blame] | 102 | int64_t WVMExtractor::getCachedDurationUs(status_t *finalStatus) { |
Jeffrey Tinker | 8264641 | 2011-05-21 18:19:17 -0700 | [diff] [blame] | 103 | if (mImpl == NULL) { |
| 104 | return 0; |
| 105 | } |
Andreas Huber | 77d8dc2 | 2011-04-21 10:06:43 -0700 | [diff] [blame] | 106 | |
Jeffrey Tinker | 8264641 | 2011-05-21 18:19:17 -0700 | [diff] [blame] | 107 | return mImpl->getCachedDurationUs(finalStatus); |
Andreas Huber | 77d8dc2 | 2011-04-21 10:06:43 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | void WVMExtractor::setAdaptiveStreamingMode(bool adaptive) { |
Jeffrey Tinker | 8264641 | 2011-05-21 18:19:17 -0700 | [diff] [blame] | 111 | if (mImpl != NULL) { |
| 112 | mImpl->setAdaptiveStreamingMode(adaptive); |
| 113 | } |
Andreas Huber | 77d8dc2 | 2011-04-21 10:06:43 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Gloria Wang | c2c22e7 | 2010-11-01 15:53:16 -0700 | [diff] [blame] | 116 | } //namespace android |
| 117 | |