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