blob: 9da1a709bd4191cf6e10d72a405e9f25994d8a17 [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,
Wei Jia10551fc2016-01-27 14:26:51 -080035 GET_FLAGS,
Marco Nelissen69d3d8a2016-03-07 13:20:01 -080036 TO_STRING,
Chris Watkins99f31602015-03-20 13:06:33 -070037};
38
39struct BpDataSource : public BpInterface<IDataSource> {
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -070040 explicit BpDataSource(const sp<IBinder>& impl)
41 : BpInterface<IDataSource>(impl) {}
Chris Watkins99f31602015-03-20 13:06:33 -070042
43 virtual sp<IMemory> getIMemory() {
44 Parcel data, reply;
45 data.writeInterfaceToken(IDataSource::getInterfaceDescriptor());
46 remote()->transact(GET_IMEMORY, data, &reply);
47 sp<IBinder> binder = reply.readStrongBinder();
48 return interface_cast<IMemory>(binder);
49 }
50
51 virtual ssize_t readAt(off64_t offset, size_t size) {
52 Parcel data, reply;
53 data.writeInterfaceToken(IDataSource::getInterfaceDescriptor());
54 data.writeInt64(offset);
55 data.writeInt64(size);
56 remote()->transact(READ_AT, data, &reply);
57 return reply.readInt64();
58 }
59
60 virtual status_t getSize(off64_t* size) {
61 Parcel data, reply;
62 data.writeInterfaceToken(IDataSource::getInterfaceDescriptor());
63 remote()->transact(GET_SIZE, data, &reply);
64 status_t err = reply.readInt32();
65 *size = reply.readInt64();
66 return err;
67 }
68
69 virtual void close() {
70 Parcel data, reply;
71 data.writeInterfaceToken(IDataSource::getInterfaceDescriptor());
72 remote()->transact(CLOSE, data, &reply);
73 }
Wei Jia10551fc2016-01-27 14:26:51 -080074
75 virtual uint32_t getFlags() {
76 Parcel data, reply;
77 data.writeInterfaceToken(IDataSource::getInterfaceDescriptor());
78 remote()->transact(GET_FLAGS, data, &reply);
79 return reply.readUint32();
80 }
Marco Nelissen69d3d8a2016-03-07 13:20:01 -080081
82 virtual String8 toString() {
83 Parcel data, reply;
84 data.writeInterfaceToken(IDataSource::getInterfaceDescriptor());
85 remote()->transact(TO_STRING, data, &reply);
86 return reply.readString8();
87 }
Chris Watkins99f31602015-03-20 13:06:33 -070088};
89
90IMPLEMENT_META_INTERFACE(DataSource, "android.media.IDataSource");
91
92status_t BnDataSource::onTransact(
93 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) {
94 switch (code) {
95 case GET_IMEMORY: {
96 CHECK_INTERFACE(IDataSource, data, reply);
97 reply->writeStrongBinder(IInterface::asBinder(getIMemory()));
98 return NO_ERROR;
99 } break;
100 case READ_AT: {
101 CHECK_INTERFACE(IDataSource, data, reply);
102 off64_t offset = (off64_t) data.readInt64();
103 size_t size = (size_t) data.readInt64();
104 reply->writeInt64(readAt(offset, size));
105 return NO_ERROR;
106 } break;
107 case GET_SIZE: {
108 CHECK_INTERFACE(IDataSource, data, reply);
109 off64_t size;
110 status_t err = getSize(&size);
111 reply->writeInt32(err);
112 reply->writeInt64(size);
113 return NO_ERROR;
114 } break;
115 case CLOSE: {
116 CHECK_INTERFACE(IDataSource, data, reply);
117 close();
118 return NO_ERROR;
119 } break;
Wei Jia10551fc2016-01-27 14:26:51 -0800120 case GET_FLAGS: {
121 CHECK_INTERFACE(IDataSource, data, reply);
122 reply->writeUint32(getFlags());
123 return NO_ERROR;
124 } break;
Marco Nelissen69d3d8a2016-03-07 13:20:01 -0800125 case TO_STRING: {
126 CHECK_INTERFACE(IDataSource, data, reply);
127 reply->writeString8(toString());
128 return NO_ERROR;
129 } break;
130
Chris Watkins99f31602015-03-20 13:06:33 -0700131 default:
132 return BBinder::onTransact(code, data, reply, flags);
133 }
134}
135
136} // namespace android