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 MediaExtractorFactory::LoadExtractors();
34 }
35
~MediaExtractorService()36 MediaExtractorService::~MediaExtractorService() {
37 ALOGE("should not be in ~MediaExtractorService");
38 }
39
makeExtractor(const::android::sp<::android::IDataSource> & remoteSource,const::std::optional<::std::string> & mime,::android::sp<::android::IMediaExtractor> * _aidl_return)40 ::android::binder::Status MediaExtractorService::makeExtractor(
41 const ::android::sp<::android::IDataSource>& remoteSource,
42 const ::std::optional< ::std::string> &mime,
43 ::android::sp<::android::IMediaExtractor>* _aidl_return) {
44 ALOGV("@@@ MediaExtractorService::makeExtractor for %s", mime ? mime->c_str() : nullptr);
45
46 sp<DataSource> localSource = CreateDataSourceFromIDataSource(remoteSource);
47
48 MediaBuffer::useSharedMemory();
49 sp<IMediaExtractor> extractor = MediaExtractorFactory::CreateFromService(
50 localSource,
51 mime ? mime->c_str() : nullptr);
52
53 ALOGV("extractor service created %p (%s)",
54 extractor.get(),
55 extractor == nullptr ? "" : extractor->name());
56
57 if (extractor != nullptr) {
58 registerMediaExtractor(extractor, localSource, mime ? mime->c_str() : nullptr);
59 }
60 *_aidl_return = extractor;
61 return binder::Status::ok();
62 }
63
makeIDataSource(base::unique_fd fd,int64_t offset,int64_t length,::android::sp<::android::IDataSource> * _aidl_return)64 ::android::binder::Status MediaExtractorService::makeIDataSource(
65 base::unique_fd fd,
66 int64_t offset,
67 int64_t length,
68 ::android::sp<::android::IDataSource>* _aidl_return) {
69 sp<DataSource> source = DataSourceFactory::getInstance()->CreateFromFd(fd.release(), offset, length);
70 *_aidl_return = CreateIDataSourceFromDataSource(source);
71 return binder::Status::ok();
72 }
73
getSupportedTypes(::std::vector<::std::string> * _aidl_return)74 ::android::binder::Status MediaExtractorService::getSupportedTypes(
75 ::std::vector<::std::string>* _aidl_return) {
76 *_aidl_return = MediaExtractorFactory::getSupportedTypes();
77 return binder::Status::ok();
78 }
79
dump(int fd,const Vector<String16> & args)80 status_t MediaExtractorService::dump(int fd, const Vector<String16>& args) {
81 return MediaExtractorFactory::dump(fd, args) || dumpExtractors(fd, args);
82 }
83
84 } // namespace android
85