Merge branch 'upstream/1.22.7' into tizen_gst_1.22.7
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-good / sys / v4l2 / gstv4l2bufferpool.h
1 /* GStreamer
2  *
3  * Copyright (C) 2001-2002 Ronald Bultje <rbultje@ronald.bitfreak.net>
4  *               2006 Edgard Lima <edgard.lima@gmail.com>
5  *               2009 Texas Instruments, Inc - http://www.ti.com/
6  *
7  * gstv4l2bufferpool.h V4L2 buffer pool class
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public
20  * License along with this library; if not, write to the
21  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
22  * Boston, MA 02110-1301, USA.
23  */
24
25 #ifndef __GST_V4L2_BUFFER_POOL_H__
26 #define __GST_V4L2_BUFFER_POOL_H__
27
28 #include <gst/gst.h>
29
30 typedef struct _GstV4l2BufferPool GstV4l2BufferPool;
31 typedef struct _GstV4l2BufferPoolClass GstV4l2BufferPoolClass;
32 typedef struct _GstV4l2Meta GstV4l2Meta;
33
34 #include "gstv4l2object.h"
35 #include "gstv4l2allocator.h"
36
37 G_BEGIN_DECLS
38
39 #define GST_TYPE_V4L2_BUFFER_POOL      (gst_v4l2_buffer_pool_get_type())
40 #define GST_IS_V4L2_BUFFER_POOL(obj)   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_V4L2_BUFFER_POOL))
41 #define GST_V4L2_BUFFER_POOL(obj)      (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_V4L2_BUFFER_POOL, GstV4l2BufferPool))
42 #define GST_V4L2_BUFFER_POOL_CAST(obj) ((GstV4l2BufferPool*)(obj))
43
44 /* Returns true if the pool is streaming. Must be called with stream lock
45  * held. */
46 #define GST_V4L2_BUFFER_POOL_IS_STREAMING(obj) (GST_V4L2_BUFFER_POOL (obj)->streaming)
47
48 /* This flow return is used to indicate that the last buffer has been dequeued
49  * during draining. This should normally only occur for mem-2-mem devices. */
50 #define GST_V4L2_FLOW_LAST_BUFFER GST_FLOW_CUSTOM_SUCCESS
51
52 /* This flow return is used to indicated that the returned buffer was marked
53  * with the error flag and had no payload. This error should be recovered by
54  * simply waiting for next buffer. */
55 #define GST_V4L2_FLOW_CORRUPTED_BUFFER GST_FLOW_CUSTOM_SUCCESS_1
56
57 /* This flow return is used to indicate that a SOURCE_CHANGE event with the
58  * resolution change flag set was received. */
59 #define GST_V4L2_FLOW_RESOLUTION_CHANGE GST_FLOW_CUSTOM_SUCCESS_2
60
61 struct _GstV4l2BufferPool
62 {
63   GstBufferPool parent;
64
65   GstV4l2Object *obj;        /* the v4l2 object */
66   gint video_fd;             /* a dup(2) of the v4l2object's video_fd */
67
68   gboolean empty;
69   GCond empty_cond;
70
71   gboolean orphaned;
72
73   GstV4l2Allocator *vallocator;
74   GstAllocator *allocator;
75 #ifdef TIZEN_FEATURE_V4L2_TBM_SUPPORT
76   GstAllocator *tallocator;
77   gint live_buffer_count;
78   GMutex buffer_lock;
79   GCond buffer_cond;
80   gboolean tbm_output_dump;
81 #endif /* TIZEN_FEATURE_V4L2_TBM_SUPPORT */
82   GstAllocationParams params;
83   GstBufferPool *other_pool;
84   guint size;
85   GstVideoInfo caps_info;   /* Default video information */
86
87   gboolean add_videometa;    /* set if video meta should be added */
88   gboolean enable_copy_threshold; /* If copy_threshold should be set */
89
90   guint min_latency;         /* number of buffers we will hold */
91   guint max_latency;         /* number of buffers we can hold */
92   guint num_queued;          /* number of buffers queued in the driver */
93   guint num_allocated;       /* number of buffers allocated */
94   guint copy_threshold;      /* when our pool runs lower, start handing out copies */
95
96   gboolean streaming;
97   gboolean flushing;
98
99   GstBuffer *buffers[VIDEO_MAX_FRAME];
100   volatile gint buffer_state[VIDEO_MAX_FRAME];
101
102   /* signal handlers */
103   gulong group_released_handler;
104
105   /* Control to warn only once on buggy feild driver bug */
106   gboolean has_warned_on_buggy_field;
107 };
108
109 struct _GstV4l2BufferPoolClass
110 {
111   GstBufferPoolClass parent_class;
112 };
113
114 GType gst_v4l2_buffer_pool_get_type (void);
115
116 GstBufferPool *     gst_v4l2_buffer_pool_new     (GstV4l2Object *obj, GstCaps *caps);
117
118 GstFlowReturn       gst_v4l2_buffer_pool_process (GstV4l2BufferPool * bpool, GstBuffer ** buf, guint32 * frame_number);
119
120 void                gst_v4l2_buffer_pool_set_other_pool (GstV4l2BufferPool * pool,
121                                                          GstBufferPool * other_pool);
122 void                gst_v4l2_buffer_pool_copy_at_threshold (GstV4l2BufferPool * pool,
123                                                             gboolean copy);
124
125 GstFlowReturn       gst_v4l2_buffer_pool_flush   (GstV4l2Object * v4l2object);
126
127 gboolean            gst_v4l2_buffer_pool_orphan  (GstV4l2Object * v4l2object);
128
129 void                gst_v4l2_buffer_pool_enable_resolution_change (GstV4l2BufferPool *self);
130
131 G_END_DECLS
132
133 #endif /*__GST_V4L2_BUFFER_POOL_H__ */