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 | |
Dongwon Kang | 7fa7c86 | 2018-12-06 09:07:58 -0800 | [diff] [blame] | 32 | MediaExtractorService::MediaExtractorService() |
Dongwon Kang | c728a42 | 2019-05-08 11:17:01 -0700 | [diff] [blame] | 33 | : BnMediaExtractorService() { |
| 34 | MediaExtractorFactory::LoadExtractors(); |
| 35 | } |
Dongwon Kang | 7fa7c86 | 2018-12-06 09:07:58 -0800 | [diff] [blame] | 36 | |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 37 | sp<IMediaExtractor> MediaExtractorService::makeExtractor( |
| 38 | const sp<IDataSource> &remoteSource, const char *mime) { |
Marco Nelissen | ebab358 | 2015-11-04 09:56:21 -0800 | [diff] [blame] | 39 | ALOGV("@@@ MediaExtractorService::makeExtractor for %s", mime); |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 40 | |
Dongwon Kang | d91dc5a | 2017-10-10 00:07:09 -0700 | [diff] [blame] | 41 | sp<DataSource> localSource = CreateDataSourceFromIDataSource(remoteSource); |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 42 | |
Dongwon Kang | 5e1897b | 2017-06-29 15:21:53 -0700 | [diff] [blame] | 43 | sp<IMediaExtractor> extractor = MediaExtractorFactory::CreateFromService(localSource, mime); |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 44 | |
Marco Nelissen | ebab358 | 2015-11-04 09:56:21 -0800 | [diff] [blame] | 45 | ALOGV("extractor service created %p (%s)", |
Dongwon Kang | ba8128f | 2017-08-07 18:51:24 -0700 | [diff] [blame] | 46 | extractor.get(), |
| 47 | extractor == nullptr ? "" : extractor->name()); |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 48 | |
Dongwon Kang | ba8128f | 2017-08-07 18:51:24 -0700 | [diff] [blame] | 49 | if (extractor != nullptr) { |
Dongwon Kang | 5e1897b | 2017-06-29 15:21:53 -0700 | [diff] [blame] | 50 | registerMediaExtractor(extractor, localSource, mime); |
| 51 | return extractor; |
Marco Nelissen | a48a51c | 2016-02-25 10:52:54 -0800 | [diff] [blame] | 52 | } |
Dongwon Kang | ba8128f | 2017-08-07 18:51:24 -0700 | [diff] [blame] | 53 | return nullptr; |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Andy Hung | d49dbd6 | 2016-07-07 14:20:35 -0700 | [diff] [blame] | 56 | sp<IDataSource> MediaExtractorService::makeIDataSource(int fd, int64_t offset, int64_t length) |
| 57 | { |
Dongwon Kang | 79b0c24 | 2019-10-13 08:17:34 -0700 | [diff] [blame] | 58 | sp<DataSource> source = DataSourceFactory::getInstance()->CreateFromFd(fd, offset, length); |
Dongwon Kang | d91dc5a | 2017-10-10 00:07:09 -0700 | [diff] [blame] | 59 | return CreateIDataSourceFromDataSource(source); |
Andy Hung | d49dbd6 | 2016-07-07 14:20:35 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Marco Nelissen | 5782209 | 2019-01-07 14:51:32 -0800 | [diff] [blame] | 62 | std::unordered_set<std::string> MediaExtractorService::getSupportedTypes() { |
| 63 | return MediaExtractorFactory::getSupportedTypes(); |
| 64 | } |
| 65 | |
Marco Nelissen | a48a51c | 2016-02-25 10:52:54 -0800 | [diff] [blame] | 66 | status_t MediaExtractorService::dump(int fd, const Vector<String16>& args) { |
Marco Nelissen | c96ca43 | 2018-01-19 08:14:40 -0800 | [diff] [blame] | 67 | return MediaExtractorFactory::dump(fd, args) || dumpExtractors(fd, args); |
Marco Nelissen | a48a51c | 2016-02-25 10:52:54 -0800 | [diff] [blame] | 68 | } |
| 69 | |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 70 | status_t MediaExtractorService::onTransact(uint32_t code, const Parcel& data, Parcel* reply, |
| 71 | uint32_t flags) |
| 72 | { |
| 73 | return BnMediaExtractorService::onTransact(code, data, reply, flags); |
| 74 | } |
| 75 | |
| 76 | } // namespace android |