blob: a2b35f6775ddec2d61d968699734daf721464f32 [file] [log] [blame]
Marco Nelissenb2487f02015-09-01 13:23:23 -07001/*
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 Nelissena48a51c2016-02-25 10:52:54 -080021#include <utils/Vector.h>
22
Marco Nelissenb2487f02015-09-01 13:23:23 -070023#include <media/stagefright/DataSource.h>
24#include <media/stagefright/MediaExtractor.h>
25#include "MediaExtractorService.h"
26
27namespace android {
28
Marco Nelissena48a51c2016-02-25 10:52:54 -080029typedef struct {
30 String8 mime;
31 String8 name;
32 pid_t owner;
33 wp<MediaExtractor> extractor;
34 String8 toString() {
35 String8 str = name;
36 str.append(" for mime ");
37 str.append(mime);
38 str.append(String8::format(", pid %d: ", owner));
39 if (extractor.promote() == NULL) {
40 str.append("deleted");
41 } else {
42 str.append("active");
43 }
44 return str;
45 }
46} ExtractorInstance;
47
48static Vector<ExtractorInstance> extractors;
49
Marco Nelissenb2487f02015-09-01 13:23:23 -070050sp<IMediaExtractor> MediaExtractorService::makeExtractor(
51 const sp<IDataSource> &remoteSource, const char *mime) {
Marco Nelissenebab3582015-11-04 09:56:21 -080052 ALOGV("@@@ MediaExtractorService::makeExtractor for %s", mime);
Marco Nelissenb2487f02015-09-01 13:23:23 -070053
54 sp<DataSource> localSource = DataSource::CreateFromIDataSource(remoteSource);
55
56 sp<MediaExtractor> ret = MediaExtractor::CreateFromService(localSource, mime);
57
Marco Nelissenebab3582015-11-04 09:56:21 -080058 ALOGV("extractor service created %p (%s)",
Marco Nelissenb2487f02015-09-01 13:23:23 -070059 ret.get(),
60 ret == NULL ? "" : ret->name());
61
Marco Nelissena48a51c2016-02-25 10:52:54 -080062 if (ret != NULL) {
63 ExtractorInstance ex;
64 ex.mime = mime == NULL ? "NULL" : mime;
65 ex.name = ret->name();
66 ex.owner = IPCThreadState::self()->getCallingPid();
67 ex.extractor = ret;
68
69 if (extractors.size() > 10) {
70 extractors.resize(10);
71 }
72 extractors.push_front(ex);
73 }
74
Marco Nelissenb2487f02015-09-01 13:23:23 -070075 return ret;
76}
77
Marco Nelissena48a51c2016-02-25 10:52:54 -080078status_t MediaExtractorService::dump(int fd, const Vector<String16>& args) {
79 String8 out;
80 out.append("Recent extractors, most recent first:\n");
81 for (size_t i = 0; i < extractors.size(); i++) {
82 ExtractorInstance ex = extractors.itemAt(i);
83 out.append(" ");
84 out.append(ex.toString());
85 out.append("\n");
86 }
87 write(fd, out.string(), out.size());
88 return OK;
89}
90
Marco Nelissenb2487f02015-09-01 13:23:23 -070091
92status_t MediaExtractorService::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
93 uint32_t flags)
94{
95 return BnMediaExtractorService::onTransact(code, data, reply, flags);
96}
97
98} // namespace android