Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 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: |
Chih-Hung Hsieh | 64a2870 | 2016-05-03 09:52:51 -0700 | [diff] [blame] | 36 | explicit BpMediaExtractorService(const sp<IBinder>& impl) |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 37 | : 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 | |
| 57 | IMPLEMENT_META_INTERFACE(MediaExtractorService, "android.media.IMediaExtractorService"); |
| 58 | |
| 59 | // ---------------------------------------------------------------------- |
| 60 | |
| 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); |
Marco Nelissen | c22c00c | 2015-11-12 10:36:51 -0800 | [diff] [blame] | 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 | } |
Andy Hung | 4c3d1ee | 2016-07-29 19:25:07 -0700 | [diff] [blame] | 74 | // If we make an extractor through Binder, enabled shared memory |
| 75 | // for MediaBuffers for this process. |
| 76 | MediaBuffer::useSharedMemory(); |
Marco Nelissen | c22c00c | 2015-11-12 10:36:51 -0800 | [diff] [blame] | 77 | sp<IDataSource> source = interface_cast<IDataSource>(b); |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 78 | 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 |