1/* 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#include <dlfcn.h> 18 19#include <media/stagefright/DataSource.h> 20 21#include "include/chromium_http_stub.h" 22#include "include/HTTPBase.h" 23 24namespace android { 25 26static bool gFirst = true; 27static void *gHandle; 28static Mutex gLibMutex; 29 30HTTPBase *(*gLib_createChromiumHTTPDataSource)(uint32_t flags); 31DataSource *(*gLib_createDataUriSource)(const char *uri); 32 33static bool load_libstagefright_chromium_http() { 34 Mutex::Autolock autoLock(gLibMutex); 35 void *sym; 36 37 if (!gFirst) { 38 return (gHandle != NULL); 39 } 40 41 gFirst = false; 42 43 gHandle = dlopen("libstagefright_chromium_http.so", RTLD_NOW); 44 if (gHandle == NULL) { 45 return false; 46 } 47 48 sym = dlsym(gHandle, "createChromiumHTTPDataSource"); 49 if (sym == NULL) { 50 gHandle = NULL; 51 return false; 52 } 53 gLib_createChromiumHTTPDataSource = (HTTPBase *(*)(uint32_t))sym; 54 55 sym = dlsym(gHandle, "createDataUriSource"); 56 if (sym == NULL) { 57 gHandle = NULL; 58 return false; 59 } 60 gLib_createDataUriSource = (DataSource *(*)(const char *))sym; 61 62 return true; 63} 64 65HTTPBase *createChromiumHTTPDataSource(uint32_t flags) { 66 if (!load_libstagefright_chromium_http()) { 67 return NULL; 68 } 69 70 return gLib_createChromiumHTTPDataSource(flags); 71} 72 73DataSource *createDataUriSource(const char *uri) { 74 if (!load_libstagefright_chromium_http()) { 75 return NULL; 76 } 77 78 return gLib_createDataUriSource(uri); 79} 80 81} 82