1/*
2 * cl_video_buffer.h - cl video buffer
3 *
4 *  Copyright (c) 2017 Intel Corporation
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *      http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * Author: Yinhang Liu <yinhangx.liu@intel.com>
19 * Author: Wind Yuan <feng.yuan@intel.com>
20 */
21#ifndef XCAM_CL_VIDEO_BUFFER_H
22#define XCAM_CL_VIDEO_BUFFER_H
23
24#include <xcam_std.h>
25#include <safe_list.h>
26#include <xcam_mutex.h>
27#include <buffer_pool.h>
28#include <x3a_stats_pool.h>
29#include <ocl/cl_context.h>
30
31namespace XCam {
32
33class CLBuffer;
34class CLVideoBufferPool;
35
36class CLVideoBufferData
37    : public BufferData
38{
39    friend class CLVideoBufferPool;
40
41public:
42    ~CLVideoBufferData ();
43
44    cl_mem &get_mem_id ();
45    SmartPtr<CLBuffer> get_cl_buffer () {
46        return _buf;
47    }
48
49    //derived from BufferData
50    virtual uint8_t *map ();
51    virtual bool unmap ();
52
53protected:
54    explicit CLVideoBufferData (SmartPtr<CLBuffer> &body);
55
56private:
57    XCAM_DEAD_COPY (CLVideoBufferData);
58
59private:
60    uint8_t                *_buf_ptr;
61    SmartPtr<CLBuffer>      _buf;
62};
63
64class CLVideoBuffer
65    : public BufferProxy
66    , public CLBuffer
67{
68    friend class CLVideoBufferPool;
69
70public:
71    explicit CLVideoBuffer (
72        const SmartPtr<CLContext> &context, const VideoBufferInfo &info, const SmartPtr<CLVideoBufferData> &data);
73    virtual ~CLVideoBuffer () {}
74
75    SmartPtr<CLBuffer> get_cl_buffer ();
76    SmartPtr<X3aStats> find_3a_stats ();
77
78protected:
79    CLVideoBuffer (const VideoBufferInfo &info, const SmartPtr<CLVideoBufferData> &data);
80
81private:
82    XCAM_DEAD_COPY (CLVideoBuffer);
83};
84
85class CLVideoBufferPool
86    : public BufferPool
87{
88    friend class CLVideoBuffer;
89
90public:
91    explicit CLVideoBufferPool () {}
92    ~CLVideoBufferPool () {}
93
94protected:
95    // derived from BufferPool
96    virtual bool fixate_video_info (VideoBufferInfo &info);
97    virtual SmartPtr<BufferData> allocate_data (const VideoBufferInfo &buffer_info);
98    virtual SmartPtr<BufferProxy> create_buffer_from_data (SmartPtr<BufferData> &data);
99
100private:
101    XCAM_DEAD_COPY (CLVideoBufferPool);
102};
103
104};
105
106#endif // XCAM_CL_VIDEO_BUFFER_H
107