v4l2: Fix SIGSEGV on 'change state' during 'format change'
[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   GstPoll *poll;             /* a poll for video_fd */
68   GstPollFD pollfd;
69   gboolean can_poll_device;
70
71   gboolean empty;
72   GCond empty_cond;
73
74   gboolean orphaned;
75
76   GstV4l2Allocator *vallocator;
77   GstAllocator *allocator;
78   GstAllocationParams params;
79   GstBufferPool *other_pool;
80   guint size;
81   GstVideoInfo caps_info;   /* Default video information */
82
83   gboolean add_videometa;    /* set if video meta should be added */
84   gboolean enable_copy_threshold; /* If copy_threshold should be set */
85
86   guint min_latency;         /* number of buffers we will hold */
87   guint max_latency;         /* number of buffers we can hold */
88   guint num_queued;          /* number of buffers queued in the driver */
89   guint num_allocated;       /* number of buffers allocated */
90   guint copy_threshold;      /* when our pool runs lower, start handing out copies */
91
92   gboolean streaming;
93   gboolean flushing;
94
95   GstBuffer *buffers[VIDEO_MAX_FRAME];
96   volatile gint buffer_state[VIDEO_MAX_FRAME];
97
98   /* signal handlers */
99   gulong group_released_handler;
100
101   /* Control to warn only once on buggy feild driver bug */
102   gboolean has_warned_on_buggy_field;
103 };
104
105 struct _GstV4l2BufferPoolClass
106 {
107   GstBufferPoolClass parent_class;
108 };
109
110 GType gst_v4l2_buffer_pool_get_type (void);
111
112 GstBufferPool *     gst_v4l2_buffer_pool_new     (GstV4l2Object *obj, GstCaps *caps);
113
114 GstFlowReturn       gst_v4l2_buffer_pool_process (GstV4l2BufferPool * bpool, GstBuffer ** buf, guint32 * frame_number);
115
116 void                gst_v4l2_buffer_pool_set_other_pool (GstV4l2BufferPool * pool,
117                                                          GstBufferPool * other_pool);
118 void                gst_v4l2_buffer_pool_copy_at_threshold (GstV4l2BufferPool * pool,
119                                                             gboolean copy);
120
121 gboolean            gst_v4l2_buffer_pool_flush   (GstV4l2Object * v4l2object);
122
123 gboolean            gst_v4l2_buffer_pool_orphan  (GstV4l2Object * v4l2object);
124
125 void                gst_v4l2_buffer_pool_enable_resolution_change (GstV4l2BufferPool *self);
126
127 G_END_DECLS
128
129 #endif /*__GST_V4L2_BUFFER_POOL_H__ */