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 40using namespace android; 41 42namespace qcamera { 43 44/*=========================================================================== 45 * FUNCTION : QCameraBufferMaps 46 * 47 * DESCRIPTION: default constructor of QCameraBufferMaps 48 * 49 * PARAMETERS : None 50 * 51 * RETURN : None 52 *==========================================================================*/ 53QCameraBufferMaps::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 *==========================================================================*/ 68QCameraBufferMaps::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 *==========================================================================*/ 83QCameraBufferMaps::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 *==========================================================================*/ 104QCameraBufferMaps::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 void *buffer) 112{ 113 memset(&mBufMapList, 0, sizeof(mBufMapList)); 114 enqueue(pType, pStreamId, pFrameIndex, pPlaneIndex, pCookie, pFd, pSize, buffer); 115} 116 117/*=========================================================================== 118 * FUNCTION : ~QCameraBufferMaps 119 * 120 * DESCRIPTION: destructor of QCameraBufferMaps 121 * 122 * PARAMETERS : None 123 * 124 * RETURN : None 125 *==========================================================================*/ 126QCameraBufferMaps::~QCameraBufferMaps() 127{ 128} 129 130/*=========================================================================== 131 * FUNCTION : operator= 132 * 133 * DESCRIPTION: assignment operator of QCameraBufferMaps 134 * 135 * PARAMETERS : 136 * @pBufferMaps : object to be copied 137 * 138 * RETURN : *this, with updated contents 139 *==========================================================================*/ 140QCameraBufferMaps& QCameraBufferMaps::operator=(const QCameraBufferMaps& pBufferMaps) 141{ 142 if (&pBufferMaps != this) { 143 memcpy(&mBufMapList, &pBufferMaps.mBufMapList, sizeof(mBufMapList)); 144 } 145 return *this; 146} 147 148/*=========================================================================== 149 * FUNCTION : enqueue 150 * 151 * DESCRIPTION: Add a buffer map 152 * 153 * PARAMETERS : 154 * @pType : Type of buffer 155 * @pStreamId : Stream id 156 * @pFrameIndex : Frame index 157 * @pPlaneIndex : Plane index 158 * @pCookie : Could be job_id to identify mapping job 159 * @pFd : Origin file descriptor 160 * @pSize : Size of the buffer 161 * 162 * RETURN : int32_t type of status 163 * NO_ERROR -- success 164 * none-zero failure code 165 *==========================================================================*/ 166uint32_t QCameraBufferMaps::enqueue(cam_mapping_buf_type pType, 167 uint32_t pStreamId, 168 uint32_t pFrameIndex, 169 int32_t pPlaneIndex, 170 uint32_t pCookie, 171 int32_t pFd, 172 size_t pSize, 173 void *buffer) 174{ 175 uint32_t pos = mBufMapList.length++; 176 mBufMapList.buf_maps[pos].type = pType; 177 mBufMapList.buf_maps[pos].stream_id = pStreamId; 178 mBufMapList.buf_maps[pos].frame_idx = pFrameIndex; 179 mBufMapList.buf_maps[pos].plane_idx = pPlaneIndex; 180 mBufMapList.buf_maps[pos].cookie = pCookie; 181 mBufMapList.buf_maps[pos].fd = pFd; 182 mBufMapList.buf_maps[pos].size = pSize; 183 mBufMapList.buf_maps[pos].buffer = buffer; 184 185 return NO_ERROR; 186} 187 188/*=========================================================================== 189 * FUNCTION : getCamBufMapList 190 * 191 * DESCRIPTION: Populate the list 192 * 193 * PARAMETERS : 194 * @pBufMapList : [output] the list of buffer maps 195 * 196 * RETURN : int32_t type of status 197 * NO_ERROR -- success 198 * none-zero failure code 199 *==========================================================================*/ 200uint32_t QCameraBufferMaps::getCamBufMapList(cam_buf_map_type_list& pBufMapList) const 201{ 202 memcpy(&pBufMapList, &mBufMapList, sizeof(pBufMapList)); 203 204 return NO_ERROR; 205} 206 207/*=========================================================================== 208 * FUNCTION : makeSingletonBufMapList 209 * 210 * DESCRIPTION: Create a buffer map list of a single element 211 * 212 * PARAMETERS : 213 * @pType : Type of buffer 214 * @pStreamId : Stream id 215 * @pFrameIndex : Frame index 216 * @pPlaneIndex : Plane index 217 * @pCookie : Could be job_id to identify mapping job 218 * @pFd : Origin file descriptor 219 * @pSize : Size of the buffer 220 * @pBufMapList : [output] the list of buffer maps 221 * 222 * RETURN : int32_t type of status 223 * NO_ERROR -- success 224 * none-zero failure code 225 *==========================================================================*/ 226uint32_t QCameraBufferMaps::makeSingletonBufMapList(cam_mapping_buf_type pType, 227 uint32_t pStreamId, 228 uint32_t pFrameIndex, 229 int32_t pPlaneIndex, 230 uint32_t pCookie, 231 int32_t pFd, 232 size_t pSize, 233 cam_buf_map_type_list& pBufMapList, 234 void *buffer) 235{ 236 uint32_t rc = NO_ERROR; 237 238 QCameraBufferMaps bufferMaps(pType, 239 pStreamId, 240 pFrameIndex, 241 pPlaneIndex, 242 pCookie, 243 pFd, 244 pSize, 245 buffer); 246 rc = bufferMaps.getCamBufMapList(pBufMapList); 247 248 return rc; 249} 250 251}; // namespace qcamera 252