• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
28 namespace android {
29 
30 enum {
31     GET_IMEMORY = IBinder::FIRST_CALL_TRANSACTION,
32     READ_AT,
33     GET_SIZE,
34     CLOSE,
35 };
36 
37 struct BpDataSource : public BpInterface<IDataSource> {
BpDataSourceandroid::BpDataSource38     BpDataSource(const sp<IBinder>& impl) : BpInterface<IDataSource>(impl) {}
39 
getIMemoryandroid::BpDataSource40     virtual sp<IMemory> getIMemory() {
41         Parcel data, reply;
42         data.writeInterfaceToken(IDataSource::getInterfaceDescriptor());
43         remote()->transact(GET_IMEMORY, data, &reply);
44         sp<IBinder> binder = reply.readStrongBinder();
45         return interface_cast<IMemory>(binder);
46     }
47 
readAtandroid::BpDataSource48     virtual ssize_t readAt(off64_t offset, size_t size) {
49         Parcel data, reply;
50         data.writeInterfaceToken(IDataSource::getInterfaceDescriptor());
51         data.writeInt64(offset);
52         data.writeInt64(size);
53         remote()->transact(READ_AT, data, &reply);
54         return reply.readInt64();
55     }
56 
getSizeandroid::BpDataSource57     virtual status_t getSize(off64_t* size) {
58         Parcel data, reply;
59         data.writeInterfaceToken(IDataSource::getInterfaceDescriptor());
60         remote()->transact(GET_SIZE, data, &reply);
61         status_t err = reply.readInt32();
62         *size = reply.readInt64();
63         return err;
64     }
65 
closeandroid::BpDataSource66     virtual void close() {
67         Parcel data, reply;
68         data.writeInterfaceToken(IDataSource::getInterfaceDescriptor());
69         remote()->transact(CLOSE, data, &reply);
70     }
71 };
72 
73 IMPLEMENT_META_INTERFACE(DataSource, "android.media.IDataSource");
74 
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)75 status_t BnDataSource::onTransact(
76     uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) {
77     switch (code) {
78         case GET_IMEMORY: {
79             CHECK_INTERFACE(IDataSource, data, reply);
80             reply->writeStrongBinder(IInterface::asBinder(getIMemory()));
81             return NO_ERROR;
82         } break;
83         case READ_AT: {
84             CHECK_INTERFACE(IDataSource, data, reply);
85             off64_t offset = (off64_t) data.readInt64();
86             size_t size = (size_t) data.readInt64();
87             reply->writeInt64(readAt(offset, size));
88             return NO_ERROR;
89         } break;
90         case GET_SIZE: {
91             CHECK_INTERFACE(IDataSource, data, reply);
92             off64_t size;
93             status_t err = getSize(&size);
94             reply->writeInt32(err);
95             reply->writeInt64(size);
96             return NO_ERROR;
97         } break;
98         case CLOSE: {
99             CHECK_INTERFACE(IDataSource, data, reply);
100             close();
101             return NO_ERROR;
102         } break;
103         default:
104             return BBinder::onTransact(code, data, reply, flags);
105     }
106 }
107 
108 }  // namespace android
109