libxcoder 5.6.0
Loading...
Searching...
No Matches
ISharedBuffer.cpp
Go to the documentation of this file.
1/*******************************************************************************
2 *
3 * Copyright (C) 2022 NETINT Technologies
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18 * SOFTWARE.
19 *
20 ******************************************************************************/
21
22/*!*****************************************************************************
23 * \file ISharedBuffer.cpp
24 *
25 * \brief Public definitions related to resource management of NETINT video
26 * processing devices on Android
27 *******************************************************************************/
28
29#define LOG_TAG "ISharedBuffer"
30
31#include <cutils/properties.h>
32#include "ISharedBuffer.h"
33
34using namespace android;
35using namespace std;
36
37enum
38{
39 GET_BUFFER = IBinder::FIRST_CALL_TRANSACTION,
42};
43
44class BpSharedBuffer : public BpInterface<ISharedBuffer> {
45 public:
46 explicit BpSharedBuffer(const sp<IBinder> &impl)
47 : BpInterface<ISharedBuffer>(impl)
48 {
49 }
50
51 /*!*************************************************************************
52 * \brief Get file descripter by using android net.int.SharedBuffer service.
53 *
54 * \param[in] name The name of the share mem
55 *
56 * \return Get fd (> 0) , < 0 otherwise
57 *
58 **************************************************************************/
59 int getFd(String8 &param)
60 {
61 Parcel data;
62 data.writeInterfaceToken(ISharedBuffer::getInterfaceDescriptor());
63
64 Parcel reply;
65 data.writeString8(param);
66
67 remote()->transact(GET_FD, data, &reply);
68
69 if (reply.readInt32() == 1)
70 {
71 int fd = reply.readFileDescriptor();
72 int fd2 = dup(fd);
73 return fd2;
74 } else
75 {
76 return -1;
77 }
78 }
79
80 /*!*************************************************************************
81 * \brief Set file descripter with the name of the share mem by using android net.int.SharedBuffer service.
82 *
83 * \param[in] name The name of the share mem
84 *
85 * \return Get fd (> 0) , < 0 otherwise
86 *
87 **************************************************************************/
88 int setFd(String8 &param, int32_t fd)
89 {
90 Parcel data;
91 data.writeInterfaceToken(ISharedBuffer::getInterfaceDescriptor());
92
93 Parcel reply;
94 data.writeString8(param);
95 data.writeFileDescriptor(fd);
96
97 remote()->transact(SET_FD, data, &reply);
98 status_t res = reply.readInt32();
99 return res;
100 }
101};
102
103// NOLINTNEXTLINE
104IMPLEMENT_META_INTERFACE(SharedBuffer, "net.int.ISharedBuffer");
105
106/*!*****************************************************************************
107 * \brief transmit the data between binder clint and server.
108 *
109 * \param[in] code The funtion identify
110 * \param[in] data The parcel take the data of the shm
111 * \param[in] reply The parcel take the return data of the shm
112 * \param[in] flags always 0
113 *
114 * \return success status_t (> 0) , < 0 otherwise
115 *
116 ******************************************************************************/
117status_t BnSharedBuffer::onTransact(uint32_t code, const Parcel &data,
118 Parcel *reply, uint32_t flags)
119{
120 switch (code)
121 {
122 case GET_FD:
123 {
124 CHECK_INTERFACE(ISharedBuffer, data, reply);
125 String8 parma = data.readString8();
126 int fd = getFd(parma);
127 if (fd < 0)
128 {
129 reply->writeInt32(0);
130 return NO_ERROR;
131 }
132 reply->writeInt32(1);
133 reply->writeFileDescriptor(fd);
134 return NO_ERROR;
135 }
136 case SET_FD:
137 {
138 CHECK_INTERFACE(ISharedBuffer, data, reply);
139 String8 parma = data.readString8();
140 int32_t fd = data.readFileDescriptor();
141 int fd2 = dup(fd);
142 setFd(parma, fd2);
143 reply->writeInt32(0);
144 return NO_ERROR;
145 }
146 default:
147 {
148 return BBinder::onTransact(code, data, reply, flags);
149 }
150 }
151}
@ GET_BUFFER
@ SET_FD
@ GET_FD
IMPLEMENT_META_INTERFACE(SharedBuffer, "net.int.ISharedBuffer")
Public definitions related to resource management of NETINT video processing devices on Android.
virtual status_t onTransact(uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags=0)
transmit the data between binder clint and server.
int getFd(String8 &param)
Get file descripter by using android net.int.SharedBuffer service.
BpSharedBuffer(const sp< IBinder > &impl)
int setFd(String8 &param, int32_t fd)
Set file descripter with the name of the share mem by using android net.int.SharedBuffer service.