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