omxvideodec: support interlace-mode=interleaved input
[platform/upstream/gstreamer.git] / 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   GST_OMX_ALLOCATOR_FOREIGN_MEM_OTHER_POOL,
48 } GstOMXAllocatorForeignMemMode;
49
50 struct _GstOMXMemory
51 {
52   GstMemory mem;
53   GstOMXBuffer *buf;
54
55   /* TRUE if the memory is in use outside the allocator */
56   gboolean acquired;
57
58   /* memory allocated from the foreign_allocator
59    * or planted externally when using a foreign buffer pool */
60   GstMemory *foreign_mem;
61   /* the original dispose function of foreign_mem */
62   GstMiniObjectDisposeFunction foreign_dispose;
63 };
64
65 struct _GstOMXAllocator
66 {
67   GstAllocator parent;
68
69   GstOMXComponent *component;
70   GstOMXPort *port;
71
72   GstOMXAllocatorForeignMemMode foreign_mode;
73   GstAllocator *foreign_allocator;
74
75   /* array of GstOMXMemory */
76   GPtrArray *memories;
77   guint n_memories;
78
79   guint n_outstanding;
80   gboolean active;
81
82   GMutex lock;
83   GCond cond;
84 };
85
86 struct _GstOMXAllocatorClass
87 {
88   GstAllocatorClass parent_class;
89 };
90
91 GType gst_omx_allocator_get_type (void);
92
93 GQuark gst_omx_memory_quark (void);
94
95 GstOMXBuffer * gst_omx_memory_get_omx_buf (GstMemory * mem);
96
97 GstOMXAllocator * gst_omx_allocator_new (GstOMXComponent * component,
98     GstOMXPort * port);
99
100 gboolean gst_omx_allocator_configure (GstOMXAllocator * allocator, guint count,
101     GstOMXAllocatorForeignMemMode mode);
102 gboolean gst_omx_allocator_set_active (GstOMXAllocator * allocator,
103     gboolean active);
104 void gst_omx_allocator_wait_inactive (GstOMXAllocator * allocator);
105
106 GstFlowReturn gst_omx_allocator_acquire (GstOMXAllocator * allocator,
107     GstMemory ** memory, gint index, GstOMXBuffer * omx_buf);
108
109 GstMemory * gst_omx_allocator_allocate (GstOMXAllocator * allocator, gint index,
110     GstMemory * foreign_mem);
111
112 G_END_DECLS
113
114 #endif