Merge branch 'move_subdir_omx' into tizen_gst_1.19.2_mono
[platform/upstream/gstreamer.git] / subprojects / gst-omx / omx / gstomxallocator.h
1 /*
2  * Copyright (C) 2019, Collabora Ltd.
3  *   Author: George Kiagiadakis <george.kiagiadakis@collabora.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation
8  * version 2.1 of the License.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
18  *
19  */
20
21 #ifndef __GST_OMX_ALLOCATOR_H__
22 #define __GST_OMX_ALLOCATOR_H__
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <gst/gst.h>
29
30 #include "gstomx.h"
31
32 G_BEGIN_DECLS
33
34 #define GST_OMX_MEMORY_QUARK gst_omx_memory_quark ()
35
36 #define GST_TYPE_OMX_ALLOCATOR   (gst_omx_allocator_get_type())
37 #define GST_IS_OMX_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_OMX_ALLOCATOR))
38 #define GST_OMX_ALLOCATOR(obj)    (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_OMX_ALLOCATOR, GstOMXAllocator))
39
40 typedef struct _GstOMXMemory GstOMXMemory;
41 typedef struct _GstOMXAllocator GstOMXAllocator;
42 typedef struct _GstOMXAllocatorClass GstOMXAllocatorClass;
43
44 typedef enum {
45   GST_OMX_ALLOCATOR_FOREIGN_MEM_NONE,
46   GST_OMX_ALLOCATOR_FOREIGN_MEM_DMABUF,
47 #ifdef TIZEN_FEATURE_OMX
48   GST_OMX_ALLOCATOR_FOREIGN_MEM_TBM,
49 #endif
50   GST_OMX_ALLOCATOR_FOREIGN_MEM_OTHER_POOL,
51 } GstOMXAllocatorForeignMemMode;
52
53 struct _GstOMXMemory
54 {
55   GstMemory mem;
56   GstOMXBuffer *buf;
57
58   /* TRUE if the memory is in use outside the allocator */
59   gboolean acquired;
60
61   /* memory allocated from the foreign_allocator
62    * or planted externally when using a foreign buffer pool */
63   GstMemory *foreign_mem;
64
65   /* the original dispose function of foreign_mem */
66   GstMiniObjectDisposeFunction foreign_dispose;
67 };
68
69 struct _GstOMXAllocator
70 {
71   GstAllocator parent;
72
73   GstOMXComponent *component;
74   GstOMXPort *port;
75
76   GstOMXAllocatorForeignMemMode foreign_mode;
77   GstAllocator *foreign_allocator;
78
79   /* array of GstOMXMemory */
80   GPtrArray *memories;
81   guint n_memories;
82
83   guint n_outstanding;
84   gboolean active;
85
86   GMutex lock;
87   GCond cond;
88 #ifdef TIZEN_FEATURE_OMX
89   GstVideoInfo video_info;
90 #endif
91 };
92
93 struct _GstOMXAllocatorClass
94 {
95   GstAllocatorClass parent_class;
96 };
97
98 GType gst_omx_allocator_get_type (void);
99
100 GQuark gst_omx_memory_quark (void);
101
102 GstOMXBuffer * gst_omx_memory_get_omx_buf (GstMemory * mem);
103
104 GstOMXAllocator * gst_omx_allocator_new (GstOMXComponent * component,
105     GstOMXPort * port);
106
107 gboolean gst_omx_allocator_configure (GstOMXAllocator * allocator, guint count,
108     GstOMXAllocatorForeignMemMode mode);
109 gboolean gst_omx_allocator_set_active (GstOMXAllocator * allocator,
110     gboolean active);
111 void gst_omx_allocator_wait_inactive (GstOMXAllocator * allocator);
112
113 GstFlowReturn gst_omx_allocator_acquire (GstOMXAllocator * allocator,
114     GstMemory ** memory, gint index, GstOMXBuffer * omx_buf);
115
116 GstMemory * gst_omx_allocator_allocate (GstOMXAllocator * allocator, gint index,
117     GstMemory * foreign_mem);
118
119 G_END_DECLS
120
121 #endif