Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 "MediaExtractorService" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | #include <utils/Log.h> |
| 20 | |
Marco Nelissen | a48a51c | 2016-02-25 10:52:54 -0800 | [diff] [blame] | 21 | #include <utils/Vector.h> |
| 22 | |
Marco Nelissen | fa8be7d | 2019-09-23 12:15:57 -0700 | [diff] [blame] | 23 | #include <datasource/DataSourceFactory.h> |
Dongwon Kang | d91dc5a | 2017-10-10 00:07:09 -0700 | [diff] [blame] | 24 | #include <media/DataSource.h> |
Dongwon Kang | d91dc5a | 2017-10-10 00:07:09 -0700 | [diff] [blame] | 25 | #include <media/stagefright/InterfaceUtils.h> |
| 26 | #include <media/stagefright/MediaExtractorFactory.h> |
Andy Hung | d49dbd6 | 2016-07-07 14:20:35 -0700 | [diff] [blame] | 27 | #include <media/stagefright/RemoteDataSource.h> |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 28 | #include "MediaExtractorService.h" |
| 29 | |
| 30 | namespace android { |
| 31 | |
Marco Nelissen | dab79b3 | 2019-11-18 08:25:47 -0800 | [diff] [blame] | 32 | MediaExtractorService::MediaExtractorService() { |
Dongwon Kang | c728a42 | 2019-05-08 11:17:01 -0700 | [diff] [blame] | 33 | MediaExtractorFactory::LoadExtractors(); |
| 34 | } |
Dongwon Kang | 7fa7c86 | 2018-12-06 09:07:58 -0800 | [diff] [blame] | 35 | |
Marco Nelissen | dab79b3 | 2019-11-18 08:25:47 -0800 | [diff] [blame] | 36 | MediaExtractorService::~MediaExtractorService() { |
| 37 | ALOGE("should not be in ~MediaExtractorService"); |
| 38 | } |
| 39 | |
| 40 | ::android::binder::Status MediaExtractorService::makeExtractor( |
| 41 | const ::android::sp<::android::IDataSource>& remoteSource, |
| 42 | const ::std::unique_ptr< ::std::string> &mime, |
| 43 | ::android::sp<::android::IMediaExtractor>* _aidl_return) { |
| 44 | ALOGV("@@@ MediaExtractorService::makeExtractor for %s", mime.get()->c_str()); |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 45 | |
Dongwon Kang | d91dc5a | 2017-10-10 00:07:09 -0700 | [diff] [blame] | 46 | sp<DataSource> localSource = CreateDataSourceFromIDataSource(remoteSource); |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 47 | |
Marco Nelissen | dab79b3 | 2019-11-18 08:25:47 -0800 | [diff] [blame] | 48 | sp<IMediaExtractor> extractor = MediaExtractorFactory::CreateFromService( |
| 49 | localSource, |
| 50 | mime.get() ? mime.get()->c_str() : nullptr); |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 51 | |
Marco Nelissen | ebab358 | 2015-11-04 09:56:21 -0800 | [diff] [blame] | 52 | ALOGV("extractor service created %p (%s)", |
Dongwon Kang | ba8128f | 2017-08-07 18:51:24 -0700 | [diff] [blame] | 53 | extractor.get(), |
| 54 | extractor == nullptr ? "" : extractor->name()); |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 55 | |
Dongwon Kang | ba8128f | 2017-08-07 18:51:24 -0700 | [diff] [blame] | 56 | if (extractor != nullptr) { |
Marco Nelissen | dab79b3 | 2019-11-18 08:25:47 -0800 | [diff] [blame] | 57 | registerMediaExtractor(extractor, localSource, mime.get() ? mime.get()->c_str() : nullptr); |
Marco Nelissen | a48a51c | 2016-02-25 10:52:54 -0800 | [diff] [blame] | 58 | } |
Marco Nelissen | dab79b3 | 2019-11-18 08:25:47 -0800 | [diff] [blame] | 59 | *_aidl_return = extractor; |
| 60 | return binder::Status::ok(); |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Marco Nelissen | dab79b3 | 2019-11-18 08:25:47 -0800 | [diff] [blame] | 63 | ::android::binder::Status MediaExtractorService::makeIDataSource( |
Jiyong Park | 5120751 | 2019-12-03 16:24:48 +0900 | [diff] [blame] | 64 | base::unique_fd fd, |
Marco Nelissen | dab79b3 | 2019-11-18 08:25:47 -0800 | [diff] [blame] | 65 | int64_t offset, |
| 66 | int64_t length, |
| 67 | ::android::sp<::android::IDataSource>* _aidl_return) { |
Jiyong Park | 5120751 | 2019-12-03 16:24:48 +0900 | [diff] [blame] | 68 | sp<DataSource> source = DataSourceFactory::getInstance()->CreateFromFd(fd.release(), offset, length); |
Marco Nelissen | dab79b3 | 2019-11-18 08:25:47 -0800 | [diff] [blame] | 69 | *_aidl_return = CreateIDataSourceFromDataSource(source); |
| 70 | return binder::Status::ok(); |
Andy Hung | d49dbd6 | 2016-07-07 14:20:35 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Marco Nelissen | dab79b3 | 2019-11-18 08:25:47 -0800 | [diff] [blame] | 73 | ::android::binder::Status MediaExtractorService::getSupportedTypes( |
| 74 | ::std::vector<::std::string>* _aidl_return) { |
| 75 | *_aidl_return = MediaExtractorFactory::getSupportedTypes(); |
| 76 | return binder::Status::ok(); |
Marco Nelissen | 5782209 | 2019-01-07 14:51:32 -0800 | [diff] [blame] | 77 | } |
| 78 | |
Marco Nelissen | a48a51c | 2016-02-25 10:52:54 -0800 | [diff] [blame] | 79 | status_t MediaExtractorService::dump(int fd, const Vector<String16>& args) { |
Marco Nelissen | c96ca43 | 2018-01-19 08:14:40 -0800 | [diff] [blame] | 80 | return MediaExtractorFactory::dump(fd, args) || dumpExtractors(fd, args); |
Marco Nelissen | a48a51c | 2016-02-25 10:52:54 -0800 | [diff] [blame] | 81 | } |
| 82 | |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 83 | } // namespace android |