blob: 8b00d850f420f92a0e659eb5278ff43267bb775f [file] [log] [blame]
Marco Nelissenb2487f02015-09-01 13:23:23 -07001/*
2**
3** Copyright 2007, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#define LOG_TAG "IMediaExtractorService"
19//#define LOG_NDEBUG 0
20
21#include <utils/Log.h>
22#include <stdint.h>
23#include <sys/types.h>
24#include <binder/Parcel.h>
25#include <media/IMediaExtractorService.h>
26
27namespace android {
28
29enum {
30 MAKE_EXTRACTOR = IBinder::FIRST_CALL_TRANSACTION
31};
32
33class BpMediaExtractorService : public BpInterface<IMediaExtractorService>
34{
35public:
Chih-Hung Hsieh64a28702016-05-03 09:52:51 -070036 explicit BpMediaExtractorService(const sp<IBinder>& impl)
Marco Nelissenb2487f02015-09-01 13:23:23 -070037 : BpInterface<IMediaExtractorService>(impl)
38 {
39 }
40
41 virtual sp<IMediaExtractor> makeExtractor(const sp<IDataSource> &source, const char *mime) {
42 Parcel data, reply;
43 data.writeInterfaceToken(IMediaExtractorService::getInterfaceDescriptor());
44 data.writeStrongBinder(IInterface::asBinder(source));
45 if (mime != NULL) {
46 data.writeCString(mime);
47 }
48 status_t ret = remote()->transact(MAKE_EXTRACTOR, data, &reply);
49 if (ret == NO_ERROR) {
50 return interface_cast<IMediaExtractor>(reply.readStrongBinder());
51 }
52 return NULL;
53 }
54
55};
56
57IMPLEMENT_META_INTERFACE(MediaExtractorService, "android.media.IMediaExtractorService");
58
59// ----------------------------------------------------------------------
60
61status_t BnMediaExtractorService::onTransact(
62 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
63{
64 switch (code) {
65
66 case MAKE_EXTRACTOR: {
67 CHECK_INTERFACE(IMediaExtractorService, data, reply);
Marco Nelissenc22c00c2015-11-12 10:36:51 -080068 sp<IBinder> b;
69 status_t ret = data.readStrongBinder(&b);
70 if (ret != NO_ERROR || b == NULL) {
71 ALOGE("Error reading source from parcel");
72 return ret;
73 }
Andy Hung4c3d1ee2016-07-29 19:25:07 -070074 // If we make an extractor through Binder, enabled shared memory
75 // for MediaBuffers for this process.
76 MediaBuffer::useSharedMemory();
Marco Nelissenc22c00c2015-11-12 10:36:51 -080077 sp<IDataSource> source = interface_cast<IDataSource>(b);
Marco Nelissenb2487f02015-09-01 13:23:23 -070078 const char *mime = data.readCString();
79 sp<IMediaExtractor> ex = makeExtractor(source, mime);
80 reply->writeStrongBinder(IInterface::asBinder(ex));
81 return NO_ERROR;
82 }
83 default:
84 return BBinder::onTransact(code, data, reply, flags);
85 }
86}
87
88// ----------------------------------------------------------------------------
89
90} // namespace android