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
39extern "C" {
40#include "mm_camera_interface.h"
41}
42
43using namespace android;
44
45namespace qcamera {
46
47class QCamera3StreamMem {
48public:
49    QCamera3StreamMem(uint32_t maxHeapBuffer);
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            bool virtualAddr);
64    void *getPtr(uint32_t index);
65
66    bool valid(uint32_t index);
67
68    // Gralloc buffer related functions
69    int registerBuffer(buffer_handle_t *buffer, cam_stream_type_t type);
70    int unregisterBuffer(uint32_t index);
71    int getMatchBufIndex(void *object);
72    void *getBufferHandle(uint32_t index);
73    void unregisterBuffers(); //TODO: relace with unififed clear() function?
74
75    // Heap buffer related functions
76    int allocateAll(size_t size);
77    int allocateOne(size_t size, bool isCached = true);
78    void deallocate(); //TODO: replace with unified clear() function?
79
80    // Clear function: unregister for gralloc buffer, and deallocate for heap buffer
81    void clear() {unregisterBuffers(); deallocate(); }
82
83    // Frame number getter and setter
84    int32_t markFrameNumber(uint32_t index, uint32_t frameNumber);
85    int32_t getFrameNumber(uint32_t index);
86    int32_t getOldestFrameNumber(uint32_t &index);
87    int32_t getGrallocBufferIndex(uint32_t frameNumber);
88    int32_t getHeapBufferIndex(uint32_t frameNumber);
89    int32_t getBufferIndex(uint32_t frameNumber);
90
91private:
92    //variables
93    QCamera3HeapMemory mHeapMem;
94    QCamera3GrallocMemory mGrallocMem;
95    uint32_t mMaxHeapBuffers;
96    Mutex mLock;
97};
98
99};
100#endif // __QCAMERA3_STREAMMEM_H__
101