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
21 #include <utils/Vector.h>
22
23 #include <datasource/DataSourceFactory.h>
24 #include <media/DataSource.h>
25 #include <media/stagefright/InterfaceUtils.h>
26 #include <media/stagefright/MediaExtractorFactory.h>
27 #include <media/stagefright/RemoteDataSource.h>
28 #include "MediaExtractorService.h"
29
30 namespace android {
31
MediaExtractorService()32 MediaExtractorService::MediaExtractorService()
33 : BnMediaExtractorService() {
34 MediaExtractorFactory::LoadExtractors();
35 }
36
makeExtractor(const sp<IDataSource> & remoteSource,const char * mime)37 sp<IMediaExtractor> MediaExtractorService::makeExtractor(
38 const sp<IDataSource> &remoteSource, const char *mime) {
39 ALOGV("@@@ MediaExtractorService::makeExtractor for %s", mime);
40
41 sp<DataSource> localSource = CreateDataSourceFromIDataSource(remoteSource);
42
43 sp<IMediaExtractor> extractor = MediaExtractorFactory::CreateFromService(localSource, mime);
44
45 ALOGV("extractor service created %p (%s)",
46 extractor.get(),
47 extractor == nullptr ? "" : extractor->name());
48
49 if (extractor != nullptr) {
50 registerMediaExtractor(extractor, localSource, mime);
51 return extractor;
52 }
53 return nullptr;
54 }
55
makeIDataSource(int fd,int64_t offset,int64_t length)56 sp<IDataSource> MediaExtractorService::makeIDataSource(int fd, int64_t offset, int64_t length)
57 {
58 sp<DataSource> source = DataSourceFactory::getInstance()->CreateFromFd(fd, offset, length);
59 return CreateIDataSourceFromDataSource(source);
60 }
61
getSupportedTypes()62 std::unordered_set<std::string> MediaExtractorService::getSupportedTypes() {
63 return MediaExtractorFactory::getSupportedTypes();
64 }
65
dump(int fd,const Vector<String16> & args)66 status_t MediaExtractorService::dump(int fd, const Vector<String16>& args) {
67 return MediaExtractorFactory::dump(fd, args) || dumpExtractors(fd, args);
68 }
69
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)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
77