1 /* Copyright (c) 2012-2015, The Linux Foundataion. 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 #ifndef __QCAMERA3_STREAMMEM_H__ 31 #define __QCAMERA3_STREAMMEM_H__ 32 33 #include <hardware/camera3.h> 34 #include <utils/Mutex.h> 35 #include "QCamera3Mem.h" 36 37 extern "C" { 38 #include <sys/types.h> 39 #include <linux/msm_ion.h> 40 #include <mm_camera_interface.h> 41 } 42 43 using namespace android; 44 45 namespace qcamera { 46 47 class QCamera3StreamMem { 48 public: 49 QCamera3StreamMem(uint32_t maxHeapBuffer, bool queueAll = true); 50 virtual ~QCamera3StreamMem(); 51 52 uint32_t getCnt(); 53 int getRegFlags(uint8_t *regFlags); 54 55 // Helper function to access individual QCamera3Buffer object 56 int getFd(uint32_t index); 57 ssize_t getSize(uint32_t index); 58 int invalidateCache(uint32_t index); 59 int cleanInvalidateCache(uint32_t index); 60 int32_t getBufDef(const cam_frame_len_offset_t &offset, 61 mm_camera_buf_def_t &bufDef, uint32_t index); 62 void *getPtr(uint32_t index); 63 64 bool valid(uint32_t index); 65 66 // Gralloc buffer related functions 67 int registerBuffer(buffer_handle_t *buffer, cam_stream_type_t type); 68 int unregisterBuffer(uint32_t index); 69 int getMatchBufIndex(void *object); 70 void *getBufferHandle(uint32_t index); 71 void unregisterBuffers(); //TODO: relace with unififed clear() function? 72 73 // Heap buffer related functions 74 int allocateAll(size_t size); 75 int allocateOne(size_t size); 76 void deallocate(); //TODO: replace with unified clear() function? 77 78 // Clear function: unregister for gralloc buffer, and deallocate for heap buffer 79 void clear() {unregisterBuffers(); deallocate(); } 80 81 // Frame number getter and setter 82 int32_t markFrameNumber(uint32_t index, uint32_t frameNumber); 83 int32_t getFrameNumber(uint32_t index); 84 int32_t getGrallocBufferIndex(uint32_t frameNumber); 85 int32_t getHeapBufferIndex(uint32_t frameNumber); 86 87 private: 88 //variables 89 QCamera3HeapMemory mHeapMem; 90 QCamera3GrallocMemory mGrallocMem; 91 uint32_t mMaxHeapBuffers; 92 Mutex mLock; 93 bool mQueueHeapBuffers; 94 }; 95 96 }; 97 #endif // __QCAMERA3_STREAMMEM_H__ 98