blob: 0be53c9add55c03b15afe20bdcd1f968d55ee2f0 [file] [log] [blame]
Chris Watkins99f31602015-03-20 13:06:33 -07001/*
2 * Copyright 2015 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_NDEBUG 0
18#define LOG_TAG "IDataSource"
19#include <utils/Log.h>
20#include <utils/Timers.h>
21
22#include <media/IDataSource.h>
23
24#include <binder/IMemory.h>
25#include <binder/Parcel.h>
26#include <media/stagefright/foundation/ADebug.h>
27
28namespace android {
29
30enum {
31 GET_IMEMORY = IBinder::FIRST_CALL_TRANSACTION,
32 READ_AT,
33 GET_SIZE,
34 CLOSE,
35};
36
37struct BpDataSource : public BpInterface<IDataSource> {
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -070038 explicit BpDataSource(const sp<IBinder>& impl)
39 : BpInterface<IDataSource>(impl) {}
Chris Watkins99f31602015-03-20 13:06:33 -070040
41 virtual sp<IMemory> getIMemory() {
42 Parcel data, reply;
43 data.writeInterfaceToken(IDataSource::getInterfaceDescriptor());
44 remote()->transact(GET_IMEMORY, data, &reply);
45 sp<IBinder> binder = reply.readStrongBinder();
46 return interface_cast<IMemory>(binder);
47 }
48
49 virtual ssize_t readAt(off64_t offset, size_t size) {
50 Parcel data, reply;
51 data.writeInterfaceToken(IDataSource::getInterfaceDescriptor());
52 data.writeInt64(offset);
53 data.writeInt64(size);
54 remote()->transact(READ_AT, data, &reply);
55 return reply.readInt64();
56 }
57
58 virtual status_t getSize(off64_t* size) {
59 Parcel data, reply;
60 data.writeInterfaceToken(IDataSource::getInterfaceDescriptor());
61 remote()->transact(GET_SIZE, data, &reply);
62 status_t err = reply.readInt32();
63 *size = reply.readInt64();
64 return err;
65 }
66
67 virtual void close() {
68 Parcel data, reply;
69 data.writeInterfaceToken(IDataSource::getInterfaceDescriptor());
70 remote()->transact(CLOSE, data, &reply);
71 }
72};
73
74IMPLEMENT_META_INTERFACE(DataSource, "android.media.IDataSource");
75
76status_t BnDataSource::onTransact(
77 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) {
78 switch (code) {
79 case GET_IMEMORY: {
80 CHECK_INTERFACE(IDataSource, data, reply);
81 reply->writeStrongBinder(IInterface::asBinder(getIMemory()));
82 return NO_ERROR;
83 } break;
84 case READ_AT: {
85 CHECK_INTERFACE(IDataSource, data, reply);
86 off64_t offset = (off64_t) data.readInt64();
87 size_t size = (size_t) data.readInt64();
88 reply->writeInt64(readAt(offset, size));
89 return NO_ERROR;
90 } break;
91 case GET_SIZE: {
92 CHECK_INTERFACE(IDataSource, data, reply);
93 off64_t size;
94 status_t err = getSize(&size);
95 reply->writeInt32(err);
96 reply->writeInt64(size);
97 return NO_ERROR;
98 } break;
99 case CLOSE: {
100 CHECK_INTERFACE(IDataSource, data, reply);
101 close();
102 return NO_ERROR;
103 } break;
104 default:
105 return BBinder::onTransact(code, data, reply, flags);
106 }
107}
108
109} // namespace android