Remove duplicate declarations
[platform/upstream/gst-plugins-good.git] / sys / v4l2 / gstv4l2allocator.h
1 /*
2  * Copyright (C) 2014 Collabora Ltd.
3  *     Author: Nicolas Dufresne <nicolas.dufresne@collabora.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
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  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  *
20  */
21
22
23 #ifndef __GST_V4L2_ALLOCATOR_H__
24 #define __GST_V4L2_ALLOCATOR_H__
25
26 #include "ext/videodev2.h"
27 #include <gst/gst.h>
28 #include <gst/gstatomicqueue.h>
29
30 G_BEGIN_DECLS
31
32 #define GST_TYPE_V4L2_ALLOCATOR                 (gst_v4l2_allocator_get_type())
33 #define GST_IS_V4L2_ALLOCATOR(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_V4L2_ALLOCATOR))
34 #define GST_IS_V4L2_ALLOCATOR_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_V4L2_ALLOCATOR))
35 #define GST_V4L2_ALLOCATOR_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_V4L2_ALLOCATOR, GstV4l2AllocatorClass))
36 #define GST_V4L2_ALLOCATOR(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_V4L2_ALLOCATOR, GstV4l2Allocator))
37 #define GST_V4L2_ALLOCATOR_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_V4L2_ALLOCATOR, GstV4l2AllocatorClass))
38 #define GST_V4L2_ALLOCATOR_CAST(obj)            ((GstV4l2Allocator *)(obj))
39
40 #define GST_V4L2_ALLOCATOR_CAN_REQUEST(obj,type) \
41         (GST_OBJECT_FLAG_IS_SET (obj, GST_V4L2_ALLOCATOR_FLAG_ ## type ## _REQBUFS))
42 #define GST_V4L2_ALLOCATOR_CAN_ALLOCATE(obj,type) \
43         (GST_OBJECT_FLAG_IS_SET (obj, GST_V4L2_ALLOCATOR_FLAG_ ## type ## _CREATE_BUFS))
44
45 #define GST_V4L2_MEMORY_QUARK gst_v4l2_memory_quark ()
46
47 typedef struct _GstV4l2Allocator GstV4l2Allocator;
48 typedef struct _GstV4l2AllocatorClass GstV4l2AllocatorClass;
49 typedef struct _GstV4l2MemoryGroup GstV4l2MemoryGroup;
50 typedef struct _GstV4l2Memory GstV4l2Memory;
51 typedef enum _GstV4l2Capabilities GstV4l2Capabilities;
52 typedef enum _GstV4l2Return GstV4l2Return;
53
54 enum _GstV4l2AllocatorFlags
55 {
56   GST_V4L2_ALLOCATOR_FLAG_MMAP_REQBUFS        = (GST_ALLOCATOR_FLAG_LAST << 0),
57   GST_V4L2_ALLOCATOR_FLAG_MMAP_CREATE_BUFS    = (GST_ALLOCATOR_FLAG_LAST << 1),
58   GST_V4L2_ALLOCATOR_FLAG_USERPTR_REQBUFS     = (GST_ALLOCATOR_FLAG_LAST << 2),
59   GST_V4L2_ALLOCATOR_FLAG_USERPTR_CREATE_BUFS = (GST_ALLOCATOR_FLAG_LAST << 3),
60   GST_V4L2_ALLOCATOR_FLAG_DMABUF_REQBUFS      = (GST_ALLOCATOR_FLAG_LAST << 4),
61   GST_V4L2_ALLOCATOR_FLAG_DMABUF_CREATE_BUFS  = (GST_ALLOCATOR_FLAG_LAST << 5),
62 };
63
64 enum _GstV4l2Return
65 {
66   GST_V4L2_OK = 0,
67   GST_V4L2_ERROR = -1,
68   GST_V4L2_BUSY = -2
69 };
70
71 struct _GstV4l2Memory
72 {
73   GstMemory mem;
74   gint plane;
75   GstV4l2MemoryGroup *group;
76   gpointer data;
77   gint dmafd;
78 };
79
80 struct _GstV4l2MemoryGroup
81 {
82   gint n_mem;
83   GstMemory * mem[VIDEO_MAX_PLANES];
84   gint mems_allocated;
85   struct v4l2_buffer buffer;
86   struct v4l2_plane planes[VIDEO_MAX_PLANES];
87 };
88
89 struct _GstV4l2Allocator
90 {
91   GstAllocator parent;
92   GstV4l2Object *obj;
93   guint32 count;
94   guint32 memory;
95   gboolean can_allocate;
96   gboolean active;
97
98   GstV4l2MemoryGroup * groups[VIDEO_MAX_FRAME];
99   GstAtomicQueue *free_queue;
100   GstAtomicQueue *pending_queue;
101
102 };
103
104 struct _GstV4l2AllocatorClass {
105   GstAllocatorClass parent_class;
106 };
107
108 GType gst_v4l2_allocator_get_type(void);
109
110 gboolean             gst_is_v4l2_memory                (GstMemory * mem);
111
112 GQuark               gst_v4l2_memory_quark             (void);
113
114 gboolean             gst_v4l2_allocator_is_active      (GstV4l2Allocator * allocator);
115
116 guint                gst_v4l2_allocator_get_size       (GstV4l2Allocator * allocator);
117
118 GstV4l2Allocator*    gst_v4l2_allocator_new            (GstObject *parent, GstV4l2Object * obj);
119
120 guint                gst_v4l2_allocator_start          (GstV4l2Allocator * allocator,
121                                                         guint32 count, guint32 memory);
122
123 GstV4l2Return        gst_v4l2_allocator_stop           (GstV4l2Allocator * allocator);
124
125 GstV4l2MemoryGroup*  gst_v4l2_allocator_alloc_mmap     (GstV4l2Allocator * allocator);
126
127 GstV4l2MemoryGroup*  gst_v4l2_allocator_alloc_dmabuf   (GstV4l2Allocator * allocator,
128                                                         GstAllocator * dmabuf_allocator);
129
130 GstV4l2MemoryGroup * gst_v4l2_allocator_alloc_dmabufin (GstV4l2Allocator * allocator);
131
132 GstV4l2MemoryGroup * gst_v4l2_allocator_alloc_userptr  (GstV4l2Allocator * allocator);
133
134 gboolean             gst_v4l2_allocator_import_dmabuf  (GstV4l2Allocator * allocator,
135                                                         GstV4l2MemoryGroup *group,
136                                                         gint n_mem, GstMemory ** dma_mem);
137
138 gboolean             gst_v4l2_allocator_import_userptr (GstV4l2Allocator * allocator,
139                                                         GstV4l2MemoryGroup *group,
140                                                         gsize img_size, int n_planes,
141                                                         gpointer * data, gsize * size);
142
143 void                 gst_v4l2_allocator_flush          (GstV4l2Allocator * allocator);
144
145 gboolean             gst_v4l2_allocator_qbuf           (GstV4l2Allocator * allocator,
146                                                         GstV4l2MemoryGroup * group);
147
148 GstFlowReturn        gst_v4l2_allocator_dqbuf          (GstV4l2Allocator * allocator,
149                                                         GstV4l2MemoryGroup ** group);
150
151 void                 gst_v4l2_allocator_reset_group    (GstV4l2Allocator * allocator,
152                                                         GstV4l2MemoryGroup * group);
153
154 G_END_DECLS
155
156 #endif /* __GST_V4L2_ALLOCATOR_H__ */