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/
7 * gstv4l2bufferpool.h V4L2 buffer pool class
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.
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.
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.
25 #ifndef __GST_V4L2_BUFFER_POOL_H__
26 #define __GST_V4L2_BUFFER_POOL_H__
30 typedef struct _GstV4l2BufferPool GstV4l2BufferPool;
31 typedef struct _GstV4l2BufferPoolClass GstV4l2BufferPoolClass;
32 typedef struct _GstV4l2Meta GstV4l2Meta;
34 #include "gstv4l2object.h"
35 #include "gstv4l2allocator.h"
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))
44 /* Returns true if the pool is streaming. Must be called with stream lock
46 #define GST_V4L2_BUFFER_POOL_IS_STREAMING(obj) (GST_V4L2_BUFFER_POOL (obj)->streaming)
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
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
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
61 struct _GstV4l2BufferPool
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 */
69 gboolean can_poll_device;
76 GstV4l2Allocator *vallocator;
77 GstAllocator *allocator;
78 GstAllocationParams params;
79 GstBufferPool *other_pool;
81 GstVideoInfo caps_info; /* Default video information */
83 gboolean add_videometa; /* set if video meta should be added */
84 gboolean enable_copy_threshold; /* If copy_threshold should be set */
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 */
95 GstBuffer *buffers[VIDEO_MAX_FRAME];
96 volatile gint buffer_state[VIDEO_MAX_FRAME];
99 gulong group_released_handler;
101 /* Control to warn only once on buggy feild driver bug */
102 gboolean has_warned_on_buggy_field;
105 struct _GstV4l2BufferPoolClass
107 GstBufferPoolClass parent_class;
110 GType gst_v4l2_buffer_pool_get_type (void);
112 GstBufferPool * gst_v4l2_buffer_pool_new (GstV4l2Object *obj, GstCaps *caps);
114 GstFlowReturn gst_v4l2_buffer_pool_process (GstV4l2BufferPool * bpool, GstBuffer ** buf, guint32 * frame_number);
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,
121 gboolean gst_v4l2_buffer_pool_flush (GstV4l2Object * v4l2object);
123 gboolean gst_v4l2_buffer_pool_orphan (GstV4l2Object * v4l2object);
125 void gst_v4l2_buffer_pool_enable_resolution_change (GstV4l2BufferPool *self);
129 #endif /*__GST_V4L2_BUFFER_POOL_H__ */