#include <sys/mman.h>
#include <string.h>
#include <unistd.h>
+#if HAVE_DECL_V4L2_MEMORY_DMABUF
+#include <fcntl.h>
+#endif
#include "gst/video/video.h"
#include "gst/video/gstvideometa.h"
#include "gst/video/gstvideopool.h"
+#include "gst/allocators/gstdmabuf.h"
#include <gstv4l2bufferpool.h>
-#include "gstv4l2src.h"
-#include "gstv4l2sink.h"
#include "v4l2_calls.h"
#include "gst/gst-i18n-plugin.h"
#include <gst/glib-compat-private.h>
switch (obj->mode) {
case GST_V4L2_IO_RW:
+ case GST_V4L2_IO_DMABUF:
break;
case GST_V4L2_IO_MMAP:
{
break;
}
case GST_V4L2_IO_MMAP:
+ case GST_V4L2_IO_DMABUF:
{
newbuf = gst_buffer_new ();
meta = GST_V4L2_META_ADD (newbuf);
GST_LOG_OBJECT (pool, " memory: %d", meta->vbuffer.memory);
if (meta->vbuffer.memory == V4L2_MEMORY_MMAP)
GST_LOG_OBJECT (pool, " MMAP offset: %u", meta->vbuffer.m.offset);
- GST_LOG_OBJECT (pool, " length: %u", meta->vbuffer.length);
-
- meta->mem = v4l2_mmap (0, meta->vbuffer.length,
- PROT_READ | PROT_WRITE, MAP_SHARED, pool->video_fd,
- meta->vbuffer.m.offset);
- if (meta->mem == MAP_FAILED)
- goto mmap_failed;
-
- gst_buffer_append_memory (newbuf,
- gst_memory_new_wrapped (GST_MEMORY_FLAG_NO_SHARE,
- meta->mem, meta->vbuffer.length, 0, meta->vbuffer.length, NULL,
- NULL));
+ if (obj->mode == GST_V4L2_IO_MMAP) {
+ meta->mem = v4l2_mmap (0, meta->vbuffer.length,
+ PROT_READ | PROT_WRITE, MAP_SHARED, pool->video_fd,
+ meta->vbuffer.m.offset);
+ if (meta->mem == MAP_FAILED)
+ goto mmap_failed;
+
+ gst_buffer_append_memory (newbuf,
+ gst_memory_new_wrapped (GST_MEMORY_FLAG_NO_SHARE,
+ meta->mem, meta->vbuffer.length, 0, meta->vbuffer.length, NULL,
+ NULL));
+ }
+#if HAVE_DECL_V4L2_MEMORY_DMABUF
+ if (obj->mode == GST_V4L2_IO_DMABUF) {
+ struct v4l2_exportbuffer expbuf;
+
+ expbuf.type = meta->vbuffer.type;
+ expbuf.index = meta->vbuffer.index;
+ expbuf.flags = O_CLOEXEC;
+ if (v4l2_ioctl (pool->video_fd, VIDIOC_EXPBUF, &expbuf) < 0)
+ goto mmap_failed;
+
+ meta->vbuffer.memory = V4L2_MEMORY_DMABUF;
+ gst_buffer_append_memory (newbuf,
+ gst_dmabuf_allocator_alloc (pool->allocator, expbuf.fd,
+ meta->vbuffer.length));
+ }
+#endif
/* add metadata to raw video buffers */
if (pool->add_videometa && info->finfo) {
const GstVideoFormatInfo *finfo = info->finfo;
gst_buffer_pool_config_has_option (config,
GST_BUFFER_POOL_OPTION_VIDEO_META);
- if (!pool->add_videometa) {
+ if (!pool->add_videometa &&
+ GST_VIDEO_INFO_FORMAT (&obj->info) != GST_VIDEO_FORMAT_ENCODED) {
gint stride;
- /* we don't have video metadata, see if the strides are compatible */
+ /* we don't have video metadata, and we are not dealing with raw video,
+ * see if the strides are compatible */
stride = GST_VIDEO_INFO_PLANE_STRIDE (&obj->info, 0);
GST_DEBUG_OBJECT (pool, "no videometadata, checking strides %d and %u",
num_buffers = 1;
copy_threshold = 0;
break;
+ case GST_V4L2_IO_DMABUF:
case GST_V4L2_IO_MMAP:
{
/* request a reasonable number of buffers when no max specified. We will
pool->size = size;
pool->num_buffers = num_buffers;
pool->copy_threshold = copy_threshold;
+
+ if (obj->mode == GST_V4L2_IO_DMABUF)
+ allocator = gst_dmabuf_allocator_obtain ();
+
if (pool->allocator)
gst_object_unref (pool->allocator);
if ((pool->allocator = allocator))
break;
case GST_V4L2_IO_MMAP:
case GST_V4L2_IO_USERPTR:
+ case GST_V4L2_IO_DMABUF:
GST_DEBUG_OBJECT (pool, "STREAMON");
if (v4l2_ioctl (pool->video_fd, VIDIOC_STREAMON, &obj->type) < 0)
goto start_failed;
break;
case GST_V4L2_IO_MMAP:
case GST_V4L2_IO_USERPTR:
+ case GST_V4L2_IO_DMABUF:
/* we actually need to sync on all queued buffers but not
* on the non-queued ones */
GST_DEBUG_OBJECT (pool, "STREAMOFF");
ret = GST_BUFFER_POOL_CLASS (parent_class)->stop (bpool);
/* then free the remaining buffers */
- for (n = 0; n < pool->num_queued; n++) {
- gst_v4l2_buffer_pool_free_buffer (bpool, pool->buffers[n]);
+ for (n = 0; n < pool->num_buffers; n++) {
+ if (pool->buffers[n])
+ gst_v4l2_buffer_pool_free_buffer (bpool, pool->buffers[n]);
}
pool->num_queued = 0;
g_free (pool->buffers);
memset (&vbuffer, 0x00, sizeof (vbuffer));
vbuffer.type = obj->type;
- vbuffer.memory = V4L2_MEMORY_MMAP;
+#if HAVE_DECL_V4L2_MEMORY_DMABUF
+ if (obj->mode == GST_V4L2_IO_DMABUF)
+ vbuffer.memory = V4L2_MEMORY_DMABUF;
+ else
+#endif
+ vbuffer.memory = V4L2_MEMORY_MMAP;
GST_LOG_OBJECT (pool, "doing DQBUF");
if (v4l2_ioctl (pool->video_fd, VIDIOC_DQBUF, &vbuffer) < 0)
/* this can change at every frame, esp. with jpeg */
if (obj->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
gst_buffer_resize (outbuf, 0, vbuffer.bytesused);
- else
- gst_buffer_resize (outbuf, 0, vbuffer.length);
GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
ret = GST_BUFFER_POOL_CLASS (parent_class)->acquire_buffer (bpool,
buffer, params);
break;
-
+ case GST_V4L2_IO_DMABUF:
case GST_V4L2_IO_MMAP:
/* just dequeue a buffer, we basically use the queue of v4l2 as the
* storage for our buffers. This function does poll first so we can
GST_BUFFER_POOL_CLASS (parent_class)->release_buffer (bpool, buffer);
break;
+ case GST_V4L2_IO_DMABUF:
case GST_V4L2_IO_MMAP:
/* queue back in the device */
gst_v4l2_buffer_pool_qbuf (pool, buffer);
case GST_V4L2_IO_MMAP:
{
GstV4l2Meta *meta;
+ guint index;
meta = GST_V4L2_META_GET (buffer);
g_assert (meta != NULL);
- if (pool->buffers[meta->vbuffer.index] == NULL) {
- GST_LOG_OBJECT (pool, "buffer not queued, putting on free list");
+ index = meta->vbuffer.index;
+
+ if (pool->buffers[index] == NULL) {
+ GST_LOG_OBJECT (pool, "buffer %u not queued, putting on free list",
+ index);
+
+ /* reset to the full length, in case it was changed */
+ gst_buffer_resize (buffer, 0, meta->vbuffer.length);
+
/* playback, put the buffer back in the queue to refill later. */
GST_BUFFER_POOL_CLASS (parent_class)->release_buffer (bpool,
buffer);
/* the buffer is queued in the device but maybe not played yet. We just
* leave it there and not make it available for future calls to acquire
* for now. The buffer will be dequeued and reused later. */
- GST_LOG_OBJECT (pool, "buffer is queued");
+ GST_LOG_OBJECT (pool, "buffer %u is queued", index);
}
break;
}
/* FIXME, do write() */
GST_WARNING_OBJECT (pool, "implement write()");
break;
-
+ case GST_V4L2_IO_DMABUF:
case GST_V4L2_IO_MMAP:
{
GstBuffer *to_queue;