1 /*
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
27 namespace android {
28
29 enum {
30 MAKE_EXTRACTOR = IBinder::FIRST_CALL_TRANSACTION
31 };
32
33 class BpMediaExtractorService : public BpInterface<IMediaExtractorService>
34 {
35 public:
BpMediaExtractorService(const sp<IBinder> & impl)36 BpMediaExtractorService(const sp<IBinder>& impl)
37 : BpInterface<IMediaExtractorService>(impl)
38 {
39 }
40
makeExtractor(const sp<IDataSource> & source,const char * mime)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
57 IMPLEMENT_META_INTERFACE(MediaExtractorService, "android.media.IMediaExtractorService");
58
59 // ----------------------------------------------------------------------
60
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)61 status_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);
68 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 }
74 sp<IDataSource> source = interface_cast<IDataSource>(b);
75 const char *mime = data.readCString();
76 sp<IMediaExtractor> ex = makeExtractor(source, mime);
77 reply->writeStrongBinder(IInterface::asBinder(ex));
78 return NO_ERROR;
79 }
80 default:
81 return BBinder::onTransact(code, data, reply, flags);
82 }
83 }
84
85 // ----------------------------------------------------------------------------
86
87 } // namespace android
88