1 /* Copyright (c) 2012-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 #ifndef __QCAMERA3_STREAMMEM_H__ 31 #define __QCAMERA3_STREAMMEM_H__ 32 33 // System dependencies 34 #include <utils/Mutex.h> 35 36 // Camera dependencies 37 #include "QCamera3Mem.h" 38 39 extern "C" { 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 int cleanCache(uint32_t index); 61 int32_t getBufDef(const cam_frame_len_offset_t &offset, 62 mm_camera_buf_def_t &bufDef, uint32_t index); 63 void *getPtr(uint32_t index); 64 65 bool valid(uint32_t index); 66 67 // Gralloc buffer related functions 68 int registerBuffer(buffer_handle_t *buffer, cam_stream_type_t type); 69 int unregisterBuffer(uint32_t index); 70 int getMatchBufIndex(void *object); 71 void *getBufferHandle(uint32_t index); 72 void unregisterBuffers(); //TODO: relace with unififed clear() function? 73 74 // Heap buffer related functions 75 int allocateAll(size_t size); 76 int allocateOne(size_t size); 77 void deallocate(); //TODO: replace with unified clear() function? 78 79 // Clear function: unregister for gralloc buffer, and deallocate for heap buffer clear()80 void clear() {unregisterBuffers(); deallocate(); } 81 82 // Frame number getter and setter 83 int32_t markFrameNumber(uint32_t index, uint32_t frameNumber); 84 int32_t getFrameNumber(uint32_t index); 85 int32_t getOldestFrameNumber(uint32_t &index); 86 int32_t getGrallocBufferIndex(uint32_t frameNumber); 87 int32_t getHeapBufferIndex(uint32_t frameNumber); 88 int32_t getBufferIndex(uint32_t frameNumber); 89 90 private: 91 //variables 92 QCamera3HeapMemory mHeapMem; 93 QCamera3GrallocMemory mGrallocMem; 94 uint32_t mMaxHeapBuffers; 95 Mutex mLock; 96 bool mQueueHeapBuffers; 97 }; 98 99 }; 100 #endif // __QCAMERA3_STREAMMEM_H__ 101