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 33status_t (*gLib_UpdateChromiumHTTPDataSourceProxyConfig)( 34 const char *host, int32_t port, const char *exclusionList); 35 36static bool load_libstagefright_chromium_http() { 37 Mutex::Autolock autoLock(gLibMutex); 38 void *sym; 39 40 if (!gFirst) { 41 return (gHandle != NULL); 42 } 43 44 gFirst = false; 45 46 gHandle = dlopen("libstagefright_chromium_http.so", RTLD_NOW); 47 if (gHandle == NULL) { 48 return false; 49 } 50 51 sym = dlsym(gHandle, "createChromiumHTTPDataSource"); 52 if (sym == NULL) { 53 gHandle = NULL; 54 return false; 55 } 56 gLib_createChromiumHTTPDataSource = (HTTPBase *(*)(uint32_t))sym; 57 58 sym = dlsym(gHandle, "createDataUriSource"); 59 if (sym == NULL) { 60 gHandle = NULL; 61 return false; 62 } 63 gLib_createDataUriSource = (DataSource *(*)(const char *))sym; 64 65 sym = dlsym(gHandle, "UpdateChromiumHTTPDataSourceProxyConfig"); 66 if (sym == NULL) { 67 gHandle = NULL; 68 return false; 69 } 70 gLib_UpdateChromiumHTTPDataSourceProxyConfig = 71 (status_t (*)(const char *, int32_t, const char *))sym; 72 73 return true; 74} 75 76HTTPBase *createChromiumHTTPDataSource(uint32_t flags) { 77 if (!load_libstagefright_chromium_http()) { 78 return NULL; 79 } 80 81 return gLib_createChromiumHTTPDataSource(flags); 82} 83 84status_t UpdateChromiumHTTPDataSourceProxyConfig( 85 const char *host, int32_t port, const char *exclusionList) { 86 if (!load_libstagefright_chromium_http()) { 87 return INVALID_OPERATION; 88 } 89 90 return gLib_UpdateChromiumHTTPDataSourceProxyConfig( 91 host, port, exclusionList); 92} 93 94DataSource *createDataUriSource(const char *uri) { 95 if (!load_libstagefright_chromium_http()) { 96 return NULL; 97 } 98 99 return gLib_createDataUriSource(uri); 100} 101 102} 103