1 /* 2 * Copyright (C) 2017 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 //#define LOG_NDEBUG 0 17 #define LOG_TAG "PlayerServuceDataSourceFactory" 18 19 20 #include <datasource/PlayerServiceDataSourceFactory.h> 21 #include <datasource/PlayerServiceFileSource.h> 22 #include <datasource/PlayerServiceMediaHTTP.h> 23 #include <media/MediaHTTPConnection.h> 24 #include <media/MediaHTTPService.h> 25 26 namespace android { 27 28 // static 29 sp<PlayerServiceDataSourceFactory> PlayerServiceDataSourceFactory::sInstance; 30 // static 31 Mutex PlayerServiceDataSourceFactory::sInstanceLock; 32 33 // static getInstance()34sp<PlayerServiceDataSourceFactory> PlayerServiceDataSourceFactory::getInstance() { 35 Mutex::Autolock l(sInstanceLock); 36 if (!sInstance) { 37 sInstance = new PlayerServiceDataSourceFactory(); 38 } 39 return sInstance; 40 } 41 CreateMediaHTTP(const sp<MediaHTTPService> & httpService)42sp<DataSource> PlayerServiceDataSourceFactory::CreateMediaHTTP( 43 const sp<MediaHTTPService> &httpService) { 44 if (httpService == NULL) { 45 return NULL; 46 } 47 48 sp<MediaHTTPConnection> conn = httpService->makeHTTPConnection(); 49 if (conn == NULL) { 50 ALOGE("Failed to make http connection from http service!"); 51 return NULL; 52 } else { 53 return new PlayerServiceMediaHTTP(conn); 54 } 55 } 56 CreateFileSource(const char * uri)57sp<DataSource> PlayerServiceDataSourceFactory::CreateFileSource(const char *uri) { 58 return new PlayerServiceFileSource(uri); 59 } 60 61 } // namespace android 62