v4l2: mark v4l2sink as experimental and build only if --enable-experimental is passed
[platform/upstream/gst-plugins-good.git] / sys / v4l2 / gstv4l2bufferpool.c
1 /* GStreamer
2  *
3  * Copyright (C) 2001-2002 Ronald Bultje <rbultje@ronald.bitfreak.net>
4  *               2006 Edgard Lima <edgard.lima@indt.org.br>
5  *               2009 Texas Instruments, Inc - http://www.ti.com/
6  *
7  * gstv4l2bufferpool.c 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., 59 Temple Place - Suite 330,
22  * Boston, MA 02111-1307, USA.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 #  include <config.h>
27 #endif
28
29 #include <sys/mman.h>
30 #include <string.h>
31 #include <unistd.h>
32
33 #include "gst/video/video.h"
34
35 #include <gstv4l2bufferpool.h>
36 #include "gstv4l2src.h"
37 #ifdef HAVE_EXPERIMENTAL
38 #include "gstv4l2sink.h"
39 #endif
40 #include "v4l2_calls.h"
41 #include "gst/gst-i18n-plugin.h"
42
43
44 GST_DEBUG_CATEGORY_EXTERN (v4l2_debug);
45 #define GST_CAT_DEFAULT v4l2_debug
46
47
48 /*
49  * GstV4l2Buffer:
50  */
51
52 static GstBufferClass *v4l2buffer_parent_class = NULL;
53
54 static void
55 gst_v4l2_buffer_finalize (GstV4l2Buffer * buffer)
56 {
57   GstV4l2BufferPool *pool;
58   gboolean resuscitated = FALSE;
59   gint index;
60
61   pool = buffer->pool;
62
63   index = buffer->vbuffer.index;
64
65   GST_LOG_OBJECT (pool->v4l2elem, "finalizing buffer %p %d", buffer, index);
66
67   GST_V4L2_BUFFER_POOL_LOCK (pool);
68   if (pool->running) {
69     if (pool->requeuebuf) {
70       if (!gst_v4l2_buffer_pool_qbuf (pool, buffer)) {
71         GST_WARNING ("could not requeue buffer %p %d", buffer, index);
72       } else {
73         resuscitated = TRUE;
74       }
75     } else {
76       resuscitated = TRUE;
77       /* XXX double check this... I think it is ok to not synchronize this
78        * w.r.t. destruction of the pool, since the buffer is still live and
79        * the buffer holds a ref to the pool..
80        */
81       g_async_queue_push (pool->avail_buffers, buffer);
82     }
83   } else {
84     GST_LOG_OBJECT (pool->v4l2elem, "the pool is shutting down");
85   }
86
87   if (resuscitated) {
88     /* FIXME: check that the caps didn't change */
89     GST_LOG_OBJECT (pool->v4l2elem, "reviving buffer %p, %d", buffer, index);
90     gst_buffer_ref (GST_BUFFER (buffer));
91     GST_BUFFER_SIZE (buffer) = 0;
92     pool->buffers[index] = buffer;
93   }
94
95   GST_V4L2_BUFFER_POOL_UNLOCK (pool);
96
97   if (!resuscitated) {
98     GST_LOG_OBJECT (pool->v4l2elem,
99         "buffer %p (data %p, len %u) not recovered, unmapping",
100         buffer, GST_BUFFER_DATA (buffer), buffer->vbuffer.length);
101     gst_mini_object_unref (GST_MINI_OBJECT (pool));
102     v4l2_munmap ((void *) GST_BUFFER_DATA (buffer), buffer->vbuffer.length);
103
104     GST_MINI_OBJECT_CLASS (v4l2buffer_parent_class)->finalize (GST_MINI_OBJECT
105         (buffer));
106   }
107 }
108
109 static void
110 gst_v4l2_buffer_class_init (gpointer g_class, gpointer class_data)
111 {
112   GstMiniObjectClass *mini_object_class = GST_MINI_OBJECT_CLASS (g_class);
113
114   v4l2buffer_parent_class = g_type_class_peek_parent (g_class);
115
116   mini_object_class->finalize = (GstMiniObjectFinalizeFunction)
117       gst_v4l2_buffer_finalize;
118 }
119
120 GType
121 gst_v4l2_buffer_get_type (void)
122 {
123   static GType _gst_v4l2_buffer_type;
124
125   if (G_UNLIKELY (_gst_v4l2_buffer_type == 0)) {
126     static const GTypeInfo v4l2_buffer_info = {
127       sizeof (GstBufferClass),
128       NULL,
129       NULL,
130       gst_v4l2_buffer_class_init,
131       NULL,
132       NULL,
133       sizeof (GstV4l2Buffer),
134       0,
135       NULL,
136       NULL
137     };
138     _gst_v4l2_buffer_type = g_type_register_static (GST_TYPE_BUFFER,
139         "GstV4l2Buffer", &v4l2_buffer_info, 0);
140   }
141   return _gst_v4l2_buffer_type;
142 }
143
144 static GstV4l2Buffer *
145 gst_v4l2_buffer_new (GstV4l2BufferPool * pool, guint index, GstCaps * caps)
146 {
147   GstV4l2Buffer *ret;
148   guint8 *data;
149
150   ret = (GstV4l2Buffer *) gst_mini_object_new (GST_TYPE_V4L2_BUFFER);
151
152   GST_LOG_OBJECT (pool->v4l2elem, "creating buffer %u, %p in pool %p", index,
153       ret, pool);
154
155   ret->pool =
156       (GstV4l2BufferPool *) gst_mini_object_ref (GST_MINI_OBJECT (pool));
157
158   ret->vbuffer.index = index;
159   ret->vbuffer.type = pool->type;
160   ret->vbuffer.memory = V4L2_MEMORY_MMAP;
161
162   if (v4l2_ioctl (pool->video_fd, VIDIOC_QUERYBUF, &ret->vbuffer) < 0)
163     goto querybuf_failed;
164
165   GST_LOG_OBJECT (pool->v4l2elem, "  index:     %u", ret->vbuffer.index);
166   GST_LOG_OBJECT (pool->v4l2elem, "  type:      %d", ret->vbuffer.type);
167   GST_LOG_OBJECT (pool->v4l2elem, "  bytesused: %u", ret->vbuffer.bytesused);
168   GST_LOG_OBJECT (pool->v4l2elem, "  flags:     %08x", ret->vbuffer.flags);
169   GST_LOG_OBJECT (pool->v4l2elem, "  field:     %d", ret->vbuffer.field);
170   GST_LOG_OBJECT (pool->v4l2elem, "  memory:    %d", ret->vbuffer.memory);
171   if (ret->vbuffer.memory == V4L2_MEMORY_MMAP)
172     GST_LOG_OBJECT (pool->v4l2elem, "  MMAP offset:  %u",
173         ret->vbuffer.m.offset);
174   GST_LOG_OBJECT (pool->v4l2elem, "  length:    %u", ret->vbuffer.length);
175   GST_LOG_OBJECT (pool->v4l2elem, "  input:     %u", ret->vbuffer.input);
176
177   data = (guint8 *) v4l2_mmap (0, ret->vbuffer.length,
178       PROT_READ | PROT_WRITE, MAP_SHARED, pool->video_fd,
179       ret->vbuffer.m.offset);
180
181   if (data == MAP_FAILED)
182     goto mmap_failed;
183
184   GST_BUFFER_DATA (ret) = data;
185   GST_BUFFER_SIZE (ret) = ret->vbuffer.length;
186
187   GST_BUFFER_FLAG_SET (ret, GST_BUFFER_FLAG_READONLY);
188
189   gst_buffer_set_caps (GST_BUFFER (ret), caps);
190
191   return ret;
192
193   /* ERRORS */
194 querybuf_failed:
195   {
196     gint errnosave = errno;
197
198     GST_WARNING ("Failed QUERYBUF: %s", g_strerror (errnosave));
199     gst_buffer_unref (GST_BUFFER (ret));
200     errno = errnosave;
201     return NULL;
202   }
203 mmap_failed:
204   {
205     gint errnosave = errno;
206
207     GST_WARNING ("Failed to mmap: %s", g_strerror (errnosave));
208     gst_buffer_unref (GST_BUFFER (ret));
209     errno = errnosave;
210     return NULL;
211   }
212 }
213
214
215 /*
216  * GstV4l2BufferPool:
217  */
218
219 static GstMiniObjectClass *buffer_pool_parent_class = NULL;
220
221 static void
222 gst_v4l2_buffer_pool_finalize (GstV4l2BufferPool * pool)
223 {
224   g_mutex_free (pool->lock);
225   pool->lock = NULL;
226
227   g_async_queue_unref (pool->avail_buffers);
228   pool->avail_buffers = NULL;
229
230   if (pool->video_fd >= 0)
231     v4l2_close (pool->video_fd);
232
233   if (pool->buffers) {
234     g_free (pool->buffers);
235     pool->buffers = NULL;
236   }
237
238   GST_MINI_OBJECT_CLASS (buffer_pool_parent_class)->finalize (GST_MINI_OBJECT
239       (pool));
240 }
241
242 static void
243 gst_v4l2_buffer_pool_init (GstV4l2BufferPool * pool, gpointer g_class)
244 {
245   pool->lock = g_mutex_new ();
246   pool->running = FALSE;
247   pool->num_live_buffers = 0;
248 }
249
250 static void
251 gst_v4l2_buffer_pool_class_init (gpointer g_class, gpointer class_data)
252 {
253   GstMiniObjectClass *mini_object_class = GST_MINI_OBJECT_CLASS (g_class);
254
255   buffer_pool_parent_class = g_type_class_peek_parent (g_class);
256
257   mini_object_class->finalize = (GstMiniObjectFinalizeFunction)
258       gst_v4l2_buffer_pool_finalize;
259 }
260
261 GType
262 gst_v4l2_buffer_pool_get_type (void)
263 {
264   static GType _gst_v4l2_buffer_pool_type;
265
266   if (G_UNLIKELY (_gst_v4l2_buffer_pool_type == 0)) {
267     static const GTypeInfo v4l2_buffer_pool_info = {
268       sizeof (GstMiniObjectClass),
269       NULL,
270       NULL,
271       gst_v4l2_buffer_pool_class_init,
272       NULL,
273       NULL,
274       sizeof (GstV4l2BufferPool),
275       0,
276       (GInstanceInitFunc) gst_v4l2_buffer_pool_init,
277       NULL
278     };
279     _gst_v4l2_buffer_pool_type = g_type_register_static (GST_TYPE_MINI_OBJECT,
280         "GstV4l2BufferPool", &v4l2_buffer_pool_info, 0);
281   }
282   return _gst_v4l2_buffer_pool_type;
283 }
284
285
286 /* this is somewhat of a hack.. but better to keep the hack in
287  * one place than copy/pasting it around..
288  */
289 static GstV4l2Object *
290 get_v4l2_object (GstElement * v4l2elem)
291 {
292   GstV4l2Object *v4l2object = NULL;
293   if (GST_IS_V4L2SRC (v4l2elem)) {
294     v4l2object = (GST_V4L2SRC (v4l2elem))->v4l2object;
295 #ifdef HAVE_EXPERIMENTAL
296   } else if (GST_IS_V4L2SINK (v4l2elem)) {
297     v4l2object = (GST_V4L2SINK (v4l2elem))->v4l2object;
298 #endif
299   } else {
300     GST_ERROR_OBJECT (v4l2elem, "unknown v4l2 element");
301   }
302   return v4l2object;
303 }
304
305
306
307 /**
308  * gst_v4l2_buffer_pool_new:
309  * @v4l2elem:  the v4l2 element (src or sink) that owns this pool
310  * @fd:   the video device file descriptor
311  * @num_buffers:  the requested number of buffers in the pool
312  * @caps:  the caps to set on the buffer
313  * @requeuebuf: if %TRUE, and if the pool is still in the running state, a
314  *  buffer with no remaining references is immediately passed back to v4l2
315  *  (VIDIOC_QBUF), otherwise it is returned to the pool of available buffers
316  *  (which can be accessed via gst_v4l2_buffer_pool_get().
317  *
318  * Construct a new buffer pool.
319  *
320  * Returns: the new pool, use gst_v4l2_buffer_pool_destroy() to free resources
321  */
322 GstV4l2BufferPool *
323 gst_v4l2_buffer_pool_new (GstElement * v4l2elem, gint fd, gint num_buffers,
324     GstCaps * caps, gboolean requeuebuf, enum v4l2_buf_type type)
325 {
326   GstV4l2BufferPool *pool;
327   gint n;
328   struct v4l2_requestbuffers breq;
329
330   pool = (GstV4l2BufferPool *) gst_mini_object_new (GST_TYPE_V4L2_BUFFER_POOL);
331
332   pool->video_fd = v4l2_dup (fd);
333   if (pool->video_fd < 0)
334     goto dup_failed;
335
336
337   /* first, lets request buffers, and see how many we can get: */
338   GST_DEBUG_OBJECT (v4l2elem, "STREAMING, requesting %d MMAP buffers",
339       num_buffers);
340
341   memset (&breq, 0, sizeof (struct v4l2_requestbuffers));
342   breq.type = type;
343   breq.count = num_buffers;
344   breq.memory = V4L2_MEMORY_MMAP;
345
346   if (v4l2_ioctl (fd, VIDIOC_REQBUFS, &breq) < 0)
347     goto reqbufs_failed;
348
349   GST_LOG_OBJECT (v4l2elem, " count:  %u", breq.count);
350   GST_LOG_OBJECT (v4l2elem, " type:   %d", breq.type);
351   GST_LOG_OBJECT (v4l2elem, " memory: %d", breq.memory);
352
353   if (breq.count < GST_V4L2_MIN_BUFFERS)
354     goto no_buffers;
355
356   if (num_buffers != breq.count) {
357     GST_WARNING_OBJECT (v4l2elem, "using %u buffers instead", breq.count);
358     num_buffers = breq.count;
359   }
360
361   pool->v4l2elem = v4l2elem;
362   pool->requeuebuf = requeuebuf;
363   pool->type = type;
364   pool->buffer_count = num_buffers;
365   pool->buffers = g_new0 (GstV4l2Buffer *, num_buffers);
366   pool->avail_buffers = g_async_queue_new ();
367
368   /* now, map the buffers: */
369   for (n = 0; n < num_buffers; n++) {
370     pool->buffers[n] = gst_v4l2_buffer_new (pool, n, caps);
371     if (!pool->buffers[n])
372       goto buffer_new_failed;
373     pool->num_live_buffers++;
374     g_async_queue_push (pool->avail_buffers, pool->buffers[n]);
375   }
376
377   return pool;
378
379   /* ERRORS */
380 dup_failed:
381   {
382     gint errnosave = errno;
383
384     gst_mini_object_unref (GST_MINI_OBJECT (pool));
385
386     errno = errnosave;
387
388     return NULL;
389   }
390 reqbufs_failed:
391   {
392     GstV4l2Object *v4l2object = get_v4l2_object (v4l2elem);
393     GST_ELEMENT_ERROR (v4l2elem, RESOURCE, READ,
394         (_("Could not get buffers from device '%s'."),
395             v4l2object->videodev),
396         ("error requesting %d buffers: %s", num_buffers, g_strerror (errno)));
397     return NULL;
398   }
399 no_buffers:
400   {
401     GstV4l2Object *v4l2object = get_v4l2_object (v4l2elem);
402     GST_ELEMENT_ERROR (v4l2elem, RESOURCE, READ,
403         (_("Could not get enough buffers from device '%s'."),
404             v4l2object->videodev),
405         ("we received %d from device '%s', we want at least %d",
406             breq.count, v4l2object->videodev, GST_V4L2_MIN_BUFFERS));
407     return NULL;
408   }
409 buffer_new_failed:
410   {
411     gint errnosave = errno;
412
413     gst_v4l2_buffer_pool_destroy (pool);
414
415     errno = errnosave;
416
417     return NULL;
418   }
419 }
420
421 /**
422  * gst_v4l2_buffer_pool_destroy:
423  * @pool: the pool
424  *
425  * Free all resources in the pool and the pool itself.
426  */
427 void
428 gst_v4l2_buffer_pool_destroy (GstV4l2BufferPool * pool)
429 {
430   gint n;
431
432   GST_V4L2_BUFFER_POOL_LOCK (pool);
433   pool->running = FALSE;
434   GST_V4L2_BUFFER_POOL_UNLOCK (pool);
435
436   GST_DEBUG_OBJECT (pool->v4l2elem, "destroy pool");
437
438   /* after this point, no more buffers will be queued or dequeued; no buffer
439    * from pool->buffers that is NULL will be set to a buffer, and no buffer that
440    * is not NULL will be pushed out. */
441
442   /* miniobjects have no dispose, so they can't break ref-cycles, as buffers ref
443    * the pool, we need to unref the buffer to properly finalize te pool */
444   for (n = 0; n < pool->buffer_count; n++) {
445     GstBuffer *buf;
446
447     GST_V4L2_BUFFER_POOL_LOCK (pool);
448     buf = GST_BUFFER (pool->buffers[n]);
449     GST_V4L2_BUFFER_POOL_UNLOCK (pool);
450
451     if (buf)
452       /* we own the ref if the buffer is in pool->buffers; drop it. */
453       gst_buffer_unref (buf);
454   }
455
456   gst_mini_object_unref (GST_MINI_OBJECT (pool));
457 }
458
459 /**
460  * gst_v4l2_buffer_pool_get:
461  * @pool:   the "this" object
462  * @blocking:  should this call suspend until there is a buffer available
463  *    in the buffer pool?
464  *
465  * Get an available buffer in the pool
466  */
467 GstV4l2Buffer *
468 gst_v4l2_buffer_pool_get (GstV4l2BufferPool * pool, gboolean blocking)
469 {
470   GstV4l2Buffer *buf;
471
472   if (blocking) {
473     buf = g_async_queue_pop (pool->avail_buffers);
474   } else {
475     buf = g_async_queue_try_pop (pool->avail_buffers);
476   }
477
478   if (buf) {
479     GST_V4L2_BUFFER_POOL_LOCK (pool);
480     GST_BUFFER_SIZE (buf) = buf->vbuffer.length;
481     GST_BUFFER_FLAG_UNSET (buf, 0xffffffff);
482     GST_V4L2_BUFFER_POOL_UNLOCK (pool);
483   }
484
485   pool->running = TRUE;
486
487   return buf;
488 }
489
490
491 /**
492  * gst_v4l2_buffer_pool_qbuf:
493  * @pool: the pool
494  * @buf: the buffer to queue
495  *
496  * Queue a buffer to the driver
497  *
498  * Returns: %TRUE for success
499  */
500 gboolean
501 gst_v4l2_buffer_pool_qbuf (GstV4l2BufferPool * pool, GstV4l2Buffer * buf)
502 {
503   GST_LOG_OBJECT (pool->v4l2elem, "enqueue pool buffer %d", buf->vbuffer.index);
504
505   if (v4l2_ioctl (pool->video_fd, VIDIOC_QBUF, &buf->vbuffer) < 0)
506     return FALSE;
507
508   pool->num_live_buffers--;
509   GST_DEBUG_OBJECT (pool->v4l2elem, "num_live_buffers--: %d",
510       pool->num_live_buffers);
511
512   return TRUE;
513 }
514
515 /**
516  * gst_v4l2_buffer_pool_dqbuf:
517  * @pool: the pool
518  *
519  * Dequeue a buffer from the driver.  Some generic error handling is done in
520  * this function, but any error handling specific to v4l2src (capture) or
521  * v4l2sink (output) can be done outside this function by checking 'errno'
522  *
523  * Returns: a buffer
524  */
525 GstV4l2Buffer *
526 gst_v4l2_buffer_pool_dqbuf (GstV4l2BufferPool * pool)
527 {
528   GstV4l2Object *v4l2object = get_v4l2_object (pool->v4l2elem);
529   GstV4l2Buffer *pool_buffer;
530   struct v4l2_buffer buffer;
531
532   memset (&buffer, 0x00, sizeof (buffer));
533   buffer.type = pool->type;
534   buffer.memory = V4L2_MEMORY_MMAP;
535
536
537   if (v4l2_ioctl (pool->video_fd, VIDIOC_DQBUF, &buffer) >= 0) {
538
539     GST_V4L2_BUFFER_POOL_LOCK (pool);
540
541     /* get our GstBuffer with that index from the pool, if the buffer was
542      * outstanding we have a serious problem.
543      */
544     pool_buffer = pool->buffers[buffer.index];
545
546     if (pool_buffer == NULL) {
547       GST_ELEMENT_ERROR (pool->v4l2elem, RESOURCE, FAILED,
548           (_("Failed trying to get video frames from device '%s'."),
549               v4l2object->videodev),
550           (_("No free buffers found in the pool at index %d."), buffer.index));
551       GST_V4L2_BUFFER_POOL_UNLOCK (pool);
552       return NULL;
553     }
554
555     GST_LOG_OBJECT (pool->v4l2elem,
556         "grabbed frame %d (ix=%d), flags %08x, pool-ct=%d, buffer=%p",
557         buffer.sequence, buffer.index, buffer.flags, pool->num_live_buffers,
558         pool_buffer);
559
560     pool->num_live_buffers++;
561     GST_DEBUG_OBJECT (pool->v4l2elem, "num_live_buffers++: %d",
562         pool->num_live_buffers);
563
564     /* set top/bottom field first if v4l2_buffer has the information */
565     if (buffer.field == V4L2_FIELD_INTERLACED_TB)
566       GST_BUFFER_FLAG_SET (pool_buffer, GST_VIDEO_BUFFER_TFF);
567     if (buffer.field == V4L2_FIELD_INTERLACED_BT)
568       GST_BUFFER_FLAG_UNSET (pool_buffer, GST_VIDEO_BUFFER_TFF);
569
570     /* this can change at every frame, esp. with jpeg */
571     GST_BUFFER_SIZE (pool_buffer) = buffer.bytesused;
572
573     GST_V4L2_BUFFER_POOL_UNLOCK (pool);
574
575     return pool_buffer;
576   }
577
578
579   GST_WARNING_OBJECT (pool->v4l2elem,
580       "problem grabbing frame %d (ix=%d), pool-ct=%d, buf.flags=%d",
581       buffer.sequence, buffer.index,
582       GST_MINI_OBJECT_REFCOUNT (pool), buffer.flags);
583
584   switch (errno) {
585     case EAGAIN:
586       GST_WARNING_OBJECT (pool->v4l2elem,
587           "Non-blocking I/O has been selected using O_NONBLOCK and"
588           " no buffer was in the outgoing queue. device %s",
589           v4l2object->videodev);
590       break;
591     case EINVAL:
592       GST_ELEMENT_ERROR (pool->v4l2elem, RESOURCE, FAILED,
593           (_("Failed trying to get video frames from device '%s'."),
594               v4l2object->videodev),
595           (_("The buffer type is not supported, or the index is out of bounds,"
596                   " or no buffers have been allocated yet, or the userptr"
597                   " or length are invalid. device %s"), v4l2object->videodev));
598       break;
599     case ENOMEM:
600       GST_ELEMENT_ERROR (pool->v4l2elem, RESOURCE, FAILED,
601           (_("Failed trying to get video frames from device '%s'. Not enough memory."), v4l2object->videodev), (_("insufficient memory to enqueue a user pointer buffer. device %s."), v4l2object->videodev));
602       break;
603     case EIO:
604       GST_INFO_OBJECT (pool->v4l2elem,
605           "VIDIOC_DQBUF failed due to an internal error."
606           " Can also indicate temporary problems like signal loss."
607           " Note the driver might dequeue an (empty) buffer despite"
608           " returning an error, or even stop capturing."
609           " device %s", v4l2object->videodev);
610       /* have we de-queued a buffer ? */
611       if (!(buffer.flags & (V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE))) {
612         GST_DEBUG_OBJECT (pool->v4l2elem, "reenqueing buffer");
613         /* FIXME ... should we do something here? */
614       }
615       break;
616     case EINTR:
617       GST_WARNING_OBJECT (pool->v4l2elem,
618           "could not sync on a buffer on device %s", v4l2object->videodev);
619       break;
620     default:
621       GST_WARNING_OBJECT (pool->v4l2elem,
622           "Grabbing frame got interrupted on %s unexpectedly. %d: %s.",
623           v4l2object->videodev, errno, g_strerror (errno));
624       break;
625   }
626
627   return NULL;
628 }
629
630 /**
631  * gst_v4l2_buffer_pool_available_buffers:
632  * @pool: the pool
633  *
634  * Check the number of buffers available to the driver, ie. buffers that
635  * have been QBUF'd but not yet DQBUF'd.
636  *
637  * Returns: the number of buffers available.
638  */
639 gint
640 gst_v4l2_buffer_pool_available_buffers (GstV4l2BufferPool * pool)
641 {
642   return pool->buffer_count - pool->num_live_buffers;
643 }