1 /* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 *     * Redistributions of source code must retain the above copyright
7 *       notice, this list of conditions and the following disclaimer.
8 *     * Redistributions in binary form must reproduce the above
9 *       copyright notice, this list of conditions and the following
10 *       disclaimer in the documentation and/or other materials provided
11 *       with the distribution.
12 *     * Neither the name of The Linux Foundation nor the names of its
13 *       contributors may be used to endorse or promote products derived
14 *       from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29 
30 #define LOG_TAG "QCameraBufferMaps"
31 
32 // System dependencies
33 #include <utils/Errors.h>
34 #include <stdlib.h>
35 #include <string.h>
36 
37 // Camera dependencies
38 #include "QCameraBufferMaps.h"
39 
40 using namespace android;
41 
42 namespace qcamera {
43 
44 /*===========================================================================
45  * FUNCTION   : QCameraBufferMaps
46  *
47  * DESCRIPTION: default constructor of QCameraBufferMaps
48  *
49  * PARAMETERS : None
50  *
51  * RETURN     : None
52  *==========================================================================*/
QCameraBufferMaps()53 QCameraBufferMaps::QCameraBufferMaps()
54 {
55     memset(&mBufMapList, 0, sizeof(mBufMapList));
56 }
57 
58 /*===========================================================================
59  * FUNCTION   : QCameraBufferMaps
60  *
61  * DESCRIPTION: copy constructor of QCameraBufferMaps
62  *
63  * PARAMETERS :
64  *   @pBufferMaps : object to be copied
65  *
66  * RETURN     : None
67  *==========================================================================*/
QCameraBufferMaps(const QCameraBufferMaps & pBufferMaps)68 QCameraBufferMaps::QCameraBufferMaps(const QCameraBufferMaps& pBufferMaps)
69 {
70     memcpy(&mBufMapList, &pBufferMaps.mBufMapList, sizeof(mBufMapList));
71 }
72 
73 /*===========================================================================
74  * FUNCTION   : QCameraBufferMaps
75  *
76  * DESCRIPTION: constructor of QCameraBufferMaps
77  *
78  * PARAMETERS :
79  *   @pBufMapList : list of buffer maps
80  *
81  * RETURN     : None
82  *==========================================================================*/
QCameraBufferMaps(const cam_buf_map_type_list & pBufMapList)83 QCameraBufferMaps::QCameraBufferMaps(const cam_buf_map_type_list& pBufMapList)
84 {
85     memcpy(&mBufMapList, &pBufMapList, sizeof(mBufMapList));
86 }
87 
88 /*===========================================================================
89  * FUNCTION   : QCameraBufferMaps
90  *
91  * DESCRIPTION: constructor of QCameraBufferMaps
92  *
93  * PARAMETERS :
94  *   @pType   : Type of buffer
95  *   @pStreamId : Stream id
96  *   @pFrameIndex : Frame index
97  *   @pPlaneIndex : Plane index
98  *   @pCookie   : Could be job_id to identify mapping job
99  *   @pFd   : Origin file descriptor
100  *   @pSize   : Size of the buffer
101  *
102  * RETURN     : None
103  *==========================================================================*/
QCameraBufferMaps(cam_mapping_buf_type pType,uint32_t pStreamId,uint32_t pFrameIndex,int32_t pPlaneIndex,uint32_t pCookie,int32_t pFd,size_t pSize)104 QCameraBufferMaps::QCameraBufferMaps(cam_mapping_buf_type pType,
105         uint32_t pStreamId,
106         uint32_t pFrameIndex,
107         int32_t pPlaneIndex,
108         uint32_t pCookie,
109         int32_t pFd,
110         size_t pSize)
111 {
112     memset(&mBufMapList, 0, sizeof(mBufMapList));
113     enqueue(pType, pStreamId, pFrameIndex, pPlaneIndex, pCookie, pFd, pSize);
114 }
115 
116 /*===========================================================================
117  * FUNCTION   : ~QCameraBufferMaps
118  *
119  * DESCRIPTION: destructor of QCameraBufferMaps
120  *
121  * PARAMETERS : None
122  *
123  * RETURN     : None
124  *==========================================================================*/
~QCameraBufferMaps()125 QCameraBufferMaps::~QCameraBufferMaps()
126 {
127 }
128 
129 /*===========================================================================
130  * FUNCTION   : operator=
131  *
132  * DESCRIPTION: assignment operator of QCameraBufferMaps
133  *
134  * PARAMETERS :
135  *   @pBufferMaps : object to be copied
136  *
137  * RETURN     : *this, with updated contents
138  *==========================================================================*/
operator =(const QCameraBufferMaps & pBufferMaps)139 QCameraBufferMaps& QCameraBufferMaps::operator=(const QCameraBufferMaps& pBufferMaps)
140 {
141     if (&pBufferMaps != this) {
142         memcpy(&mBufMapList, &pBufferMaps.mBufMapList, sizeof(mBufMapList));
143     }
144     return *this;
145 }
146 
147 /*===========================================================================
148  * FUNCTION   : enqueue
149  *
150  * DESCRIPTION: Add a buffer map
151  *
152  * PARAMETERS :
153  *   @pType   : Type of buffer
154  *   @pStreamId : Stream id
155  *   @pFrameIndex : Frame index
156  *   @pPlaneIndex : Plane index
157  *   @pCookie   : Could be job_id to identify mapping job
158  *   @pFd   : Origin file descriptor
159  *   @pSize   : Size of the buffer
160  *
161  * RETURN     : int32_t type of status
162  *              NO_ERROR  -- success
163  *              none-zero failure code
164  *==========================================================================*/
enqueue(cam_mapping_buf_type pType,uint32_t pStreamId,uint32_t pFrameIndex,int32_t pPlaneIndex,uint32_t pCookie,int32_t pFd,size_t pSize)165 uint32_t QCameraBufferMaps::enqueue(cam_mapping_buf_type pType,
166         uint32_t pStreamId,
167         uint32_t pFrameIndex,
168         int32_t pPlaneIndex,
169         uint32_t pCookie,
170         int32_t pFd,
171         size_t pSize)
172 {
173     uint32_t pos = mBufMapList.length++;
174     mBufMapList.buf_maps[pos].type = pType;
175     mBufMapList.buf_maps[pos].stream_id = pStreamId;
176     mBufMapList.buf_maps[pos].frame_idx = pFrameIndex;
177     mBufMapList.buf_maps[pos].plane_idx = pPlaneIndex;
178     mBufMapList.buf_maps[pos].cookie = pCookie;
179     mBufMapList.buf_maps[pos].fd = pFd;
180     mBufMapList.buf_maps[pos].size = pSize;
181 
182     return NO_ERROR;
183 }
184 
185 /*===========================================================================
186  * FUNCTION   : getCamBufMapList
187  *
188  * DESCRIPTION: Populate the list
189  *
190  * PARAMETERS :
191  *   @pBufMapList : [output] the list of buffer maps
192  *
193  * RETURN     : int32_t type of status
194  *              NO_ERROR  -- success
195  *              none-zero failure code
196  *==========================================================================*/
getCamBufMapList(cam_buf_map_type_list & pBufMapList) const197 uint32_t QCameraBufferMaps::getCamBufMapList(cam_buf_map_type_list& pBufMapList) const
198 {
199     memcpy(&pBufMapList, &mBufMapList, sizeof(pBufMapList));
200 
201     return NO_ERROR;
202 }
203 
204 /*===========================================================================
205  * FUNCTION   : makeSingletonBufMapList
206  *
207  * DESCRIPTION: Create a buffer map list of a single element
208  *
209  * PARAMETERS :
210  *   @pType   : Type of buffer
211  *   @pStreamId : Stream id
212  *   @pFrameIndex : Frame index
213  *   @pPlaneIndex : Plane index
214  *   @pCookie   : Could be job_id to identify mapping job
215  *   @pFd   : Origin file descriptor
216  *   @pSize   : Size of the buffer
217  *   @pBufMapList : [output] the list of buffer maps
218  *
219  * RETURN     : int32_t type of status
220  *              NO_ERROR  -- success
221  *              none-zero failure code
222  *==========================================================================*/
makeSingletonBufMapList(cam_mapping_buf_type pType,uint32_t pStreamId,uint32_t pFrameIndex,int32_t pPlaneIndex,uint32_t pCookie,int32_t pFd,size_t pSize,cam_buf_map_type_list & pBufMapList)223 uint32_t QCameraBufferMaps::makeSingletonBufMapList(cam_mapping_buf_type pType,
224         uint32_t pStreamId,
225         uint32_t pFrameIndex,
226         int32_t pPlaneIndex,
227         uint32_t pCookie,
228         int32_t pFd,
229         size_t pSize,
230         cam_buf_map_type_list& pBufMapList)
231 {
232     uint32_t rc = NO_ERROR;
233 
234     QCameraBufferMaps bufferMaps(pType,
235             pStreamId,
236             pFrameIndex,
237             pPlaneIndex,
238             pCookie,
239             pFd,
240             pSize);
241     rc = bufferMaps.getCamBufMapList(pBufMapList);
242 
243     return rc;
244 }
245 
246 }; // namespace qcamera
247