Commit aa1ec5c9 authored by Vikram Fugro's avatar Vikram Fugro Committed by Jean-Baptiste Kempf

Enable zero-copy support for gstreamer video decoders

Implements the interface to provide the VLC pictures
from vout mapped to GstBuffers, along with per video
plane stride/offsets info, to the upstream gstreamer
video decoder. If the stride/offsets info of the vlc
pictures (created by vout) matches the video decoder's
expectations, the decoder will directly decode into
the vout allocated pictures, enabling zero-copy. Else
it will continue to use it's own bufferpool
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent c4a18376
......@@ -542,7 +542,10 @@ libquicktime_plugin_la_LIBADD = $(LIBM)
EXTRA_LTLIBRARIES += libquicktime_plugin.la
codec_LTLIBRARIES += $(LTLIBquicktime)
libgstdecode_plugin_la_SOURCES = codec/gstreamer/gstdecode.c
libgstdecode_plugin_la_SOURCES = codec/gstreamer/gstdecode.c \
codec/gstreamer/gstvlcpictureplaneallocator.c \
codec/gstreamer/gstvlcvideopool.c \
codec/gstreamer/gstvlcvideosink.c
libgstdecode_plugin_la_CFLAGS = $(AM_CFLAGS) $(GST_VIDEO_CFLAGS) $(GST_APP_CFLAGS)
libgstdecode_plugin_la_LIBADD = $(GST_VIDEO_LIBS) $(GST_APP_LIBS)
if HAVE_GST_DECODE
......
This diff is collapsed.
This diff is collapsed.
/*****************************************************************************
* gstvlcpictureplaneallocator.h: VLC pictures wrapped by GstAllocator
*****************************************************************************
* Copyright (C) 2016 VLC authors and VideoLAN
* $Id:
*
* Author: Vikram Fugro <vikram.fugro@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#ifndef VLC_GST_PICTURE_PLANE_ALLOCATOR_H_
#define VLC_GST_PICTURE_PLANE_ALLOCATOR_H_
#include <gst/gst.h>
#include <gst/video/video.h>
#include <gst/video/gstvideometa.h>
#include <vlc_common.h>
#include <vlc_codec.h>
typedef struct _GstVlcPicturePlane GstVlcPicturePlane;
typedef struct _GstVlcPicturePlaneAllocator GstVlcPicturePlaneAllocator;
typedef struct _GstVlcPicturePlaneAllocatorClass \
GstVlcPicturePlaneAllocatorClass;
/* allocator functions */
#define GST_TYPE_VLC_PICTURE_PLANE_ALLOCATOR \
(gst_vlc_picture_plane_allocator_get_type())
#define GST_IS_VLC_PICTURE_PLANE_ALLOCATOR(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_VLC_PICTURE_PLANE_ALLOCATOR))
#define GST_VLC_PICTURE_PLANE_ALLOCATOR(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_VLC_PICTURE_PLANE_ALLOCATOR, \
GstVlcPicturePlaneAllocator))
#define GST_VLC_PICTURE_PLANE_ALLOCATOR_CAST(obj) \
((GstVlcPicturePlaneAllocator*)(obj))
struct _GstVlcPicturePlane
{
GstMemory parent;
decoder_t *p_dec;
picture_t *p_pic;
plane_t *p_plane;
};
struct _GstVlcPicturePlaneAllocator
{
GstAllocator parent;
picture_t pic_info;;
decoder_t *p_dec;
};
struct _GstVlcPicturePlaneAllocatorClass
{
GstAllocatorClass parent_class;
};
GType gst_vlc_picture_plane_allocator_get_type( void );
GstVlcPicturePlaneAllocator* gst_vlc_picture_plane_allocator_new(
decoder_t *p_dec );
bool gst_vlc_picture_plane_allocator_query_format(
GstVlcPicturePlaneAllocator *p_gallocator, GstVideoInfo *p_info,
GstCaps *p_caps );
bool gst_vlc_set_vout_fmt( GstVideoInfo *p_info, GstCaps *p_caps,
decoder_t *p_dec );
void gst_vlc_dec_ensure_empty_queue( decoder_t* p_dec );
bool gst_vlc_picture_plane_allocator_hold( GstVlcPicturePlaneAllocator
*p_allocator, GstBuffer *p_buffer );
void gst_vlc_picture_plane_allocator_release(
GstVlcPicturePlaneAllocator *p_allocator, GstBuffer *p_buffer );
bool gst_vlc_picture_plane_allocator_alloc(
GstVlcPicturePlaneAllocator *p_allocator,
GstBuffer *p_buffer );
#endif
/*****************************************************************************
* gstvlcvideopool.c: VLC pictures managed by GstBufferPool
*****************************************************************************
* Copyright (C) 2016 VLC authors and VideoLAN
* $Id:
*
* Author: Vikram Fugro <vikram.fugro@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#include "gstvlcvideopool.h"
#include <vlc_common.h>
/* bufferpool */
static void gst_vlc_video_pool_finalize( GObject *p_object );
#define gst_vlc_video_pool_parent_class parent_class
G_DEFINE_TYPE (GstVlcVideoPool, gst_vlc_video_pool,
GST_TYPE_BUFFER_POOL);
static const gchar** gst_vlc_video_pool_get_options (GstBufferPool *p_pool)
{
static const gchar *options[] = { GST_BUFFER_POOL_OPTION_VIDEO_META,
NULL
};
return options;
}
static gboolean gst_vlc_video_pool_set_config( GstBufferPool *p_pool,
GstStructure *p_config )
{
GstVlcVideoPool *p_vpool = GST_VLC_VIDEO_POOL_CAST( p_pool );
GstCaps *p_caps;
GstVideoInfo info;
guint size, min_buffers, max_buffers;
GstAllocator *p_allocator;
GstAllocationParams params;
if( !gst_buffer_pool_config_get_params( p_config, &p_caps, &size,
&min_buffers, &max_buffers ))
goto wrong_config;
if( p_caps == NULL )
goto no_caps;
gst_buffer_pool_config_get_allocator( p_config, &p_allocator, &params );
if( p_allocator )
{
if( !GST_IS_VLC_PICTURE_PLANE_ALLOCATOR( p_allocator ))
goto unsupported_allocator;
else
{
if( p_vpool->p_allocator )
gst_object_unref( p_vpool->p_allocator );
p_vpool->p_allocator = gst_object_ref ( p_allocator );
}
}
/* now parse the caps from the config */
if ( !gst_video_info_from_caps( &info, p_caps ))
goto wrong_caps;
/* enable metadata based on config of the pool */
p_vpool->b_add_metavideo =
gst_buffer_pool_config_has_option( p_config,
GST_BUFFER_POOL_OPTION_VIDEO_META );
if( !gst_vlc_picture_plane_allocator_query_format( p_vpool->p_allocator,
&info, p_caps))
goto unknown_format;
if( p_vpool->p_caps )
gst_caps_unref( p_vpool->p_caps );
p_vpool->p_caps = gst_caps_ref( p_caps );
p_vpool->info = info;
gst_buffer_pool_config_set_params( p_config, p_caps, info.size,
min_buffers, max_buffers );
return GST_BUFFER_POOL_CLASS (parent_class)->set_config( p_pool, p_config );
/* ERRORS */
wrong_config:
{
msg_Err(p_vpool->p_dec, "wrong pool config" );
return FALSE;
}
no_caps:
{
msg_Err(p_vpool->p_dec, "no input caps in config" );
return FALSE;
}
wrong_caps:
{
msg_Err(p_vpool->p_dec, "invalid caps" );
return FALSE;
}
unknown_format:
{
msg_Err(p_vpool->p_dec, "format unsupported" );
return FALSE;
}
unsupported_allocator:
{
msg_Err(p_vpool->p_dec, "allocator unsupported" );
return FALSE;
}
}
static GstFlowReturn gst_vlc_video_pool_acquire_buffer( GstBufferPool *p_pool,
GstBuffer **p_buffer, GstBufferPoolAcquireParams *p_params )
{
GstVlcVideoPool *p_vpool = GST_VLC_VIDEO_POOL_CAST( p_pool );
GstVideoInfo *p_info;
GstFlowReturn result;
result = GST_BUFFER_POOL_CLASS( parent_class)->acquire_buffer( p_pool,
p_buffer, p_params );
if( result == GST_FLOW_OK &&
!gst_vlc_picture_plane_allocator_hold( p_vpool->p_allocator,
*p_buffer ))
result = GST_FLOW_EOS;
return result;
}
static void gst_vlc_video_pool_release_buffer( GstBufferPool *p_pool,
GstBuffer *p_buffer )
{
GstVlcVideoPool* p_vpool = GST_VLC_VIDEO_POOL_CAST( p_pool );
gst_vlc_picture_plane_allocator_release( p_vpool->p_allocator, p_buffer );
GST_BUFFER_POOL_CLASS( parent_class )->release_buffer( p_pool, p_buffer );
return;
}
static void gst_vlc_video_pool_free_buffer( GstBufferPool *p_pool,
GstBuffer *p_buffer )
{
GstVlcVideoPool* p_vpool = GST_VLC_VIDEO_POOL_CAST( p_pool );
gst_vlc_picture_plane_allocator_release( p_vpool->p_allocator, p_buffer );
GST_BUFFER_POOL_CLASS( parent_class )->free_buffer( p_pool, p_buffer );
return;
}
static GstFlowReturn gst_vlc_video_pool_alloc_buffer( GstBufferPool *p_pool,
GstBuffer **p_buffer, GstBufferPoolAcquireParams *p_params)
{
GstVlcVideoPool *p_vpool = GST_VLC_VIDEO_POOL_CAST( p_pool );
GstVideoInfo *p_info = &p_vpool->info;
*p_buffer = gst_buffer_new( );
if( !gst_vlc_picture_plane_allocator_alloc( p_vpool->p_allocator,
*p_buffer ))
return GST_FLOW_EOS;
if( p_vpool->b_add_metavideo )
{
msg_Dbg( p_vpool->p_dec, "meta video enabled" );
gst_buffer_add_video_meta_full( *p_buffer, GST_VIDEO_FRAME_FLAG_NONE,
GST_VIDEO_INFO_FORMAT( p_info ), GST_VIDEO_INFO_WIDTH( p_info ),
GST_VIDEO_INFO_HEIGHT( p_info ),
GST_VIDEO_INFO_N_PLANES( p_info ),
p_info->offset, p_info->stride );
}
return GST_FLOW_OK;
}
static void gst_vlc_video_pool_class_init( GstVlcVideoPoolClass *p_klass )
{
GObjectClass *p_gobject_class = ( GObjectClass* )p_klass;
GstBufferPoolClass *p_gstbufferpool_class = ( GstBufferPoolClass* )p_klass;
p_gobject_class->finalize = gst_vlc_video_pool_finalize;
p_gstbufferpool_class->get_options = gst_vlc_video_pool_get_options;
p_gstbufferpool_class->set_config = gst_vlc_video_pool_set_config;
p_gstbufferpool_class->alloc_buffer = gst_vlc_video_pool_alloc_buffer;
p_gstbufferpool_class->free_buffer = gst_vlc_video_pool_free_buffer;
p_gstbufferpool_class->acquire_buffer = gst_vlc_video_pool_acquire_buffer;
p_gstbufferpool_class->release_buffer = gst_vlc_video_pool_release_buffer;
}
static void gst_vlc_video_pool_init( GstVlcVideoPool *p_pool )
{
}
static void gst_vlc_video_pool_finalize( GObject *p_object )
{
GstVlcVideoPool *p_pool = GST_VLC_VIDEO_POOL_CAST( p_object );
gst_object_unref( p_pool->p_allocator );
G_OBJECT_CLASS( parent_class )->finalize( p_object );
}
GstVlcVideoPool* gst_vlc_video_pool_new(
GstAllocator *p_allocator, decoder_t *p_dec )
{
GstVlcVideoPool *p_pool;
if( !GST_IS_VLC_PICTURE_PLANE_ALLOCATOR( p_allocator ))
{
msg_Err( p_pool->p_dec, "unspported allocator for pool" );
return NULL;
}
p_pool = g_object_new( GST_TYPE_VLC_VIDEO_POOL, NULL );
p_pool->p_allocator = gst_object_ref( p_allocator );
p_pool->p_dec = p_dec;
return p_pool;
}
/*****************************************************************************
* gstvlcvideopool.h: VLC pictures managed by GstBufferPool
*****************************************************************************
* Copyright (C) 2016 VLC authors and VideoLAN
* $Id:
*
* Author: Vikram Fugro <vikram.fugro@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#ifndef VLC_GST_VIDEO_POOL_H
#define VLC_GST_VIDEO_POOL_H
#include <gst/gstbufferpool.h>
#include <gst/video/gstvideopool.h>
#include "gstvlcpictureplaneallocator.h"
typedef struct _GstVlcVideoPool GstVlcVideoPool;
typedef struct _GstVlcVideoPoolClass GstVlcVideoPoolClass;
/* buffer pool functions */
#define GST_TYPE_VLC_VIDEO_POOL (gst_vlc_video_pool_get_type())
#define GST_IS_VLC_VIDEO_POOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
GST_TYPE_VLC_VIDEO_POOL))
#define GST_VLC_VIDEO_POOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
GST_TYPE_VLC_VIDEO_POOL, \
GstVlcVideoPool))
#define GST_VLC_VIDEO_POOL_CAST(obj) ((GstVlcVideoPool*)(obj))
struct _GstVlcVideoPool
{
GstBufferPool bufferpool;
GstVlcPicturePlaneAllocator *p_allocator;
GstCaps *p_caps;
GstVideoInfo info;
bool b_add_metavideo;
decoder_t *p_dec;
};
struct _GstVlcVideoPoolClass
{
GstBufferPoolClass parent_class;
};
GType gst_vlc_video_pool_get_type( void );
GstVlcVideoPool* gst_vlc_video_pool_new(
GstAllocator *p_allocator, decoder_t *p_dec );
#endif /*__GST_VLC_VIDEO_POOL_H__*/
This diff is collapsed.
/*****************************************************************************
* gstvlcvideosink.h: VLC gstreamer video sink
*****************************************************************************
* Copyright (C) 2016 VLC authors and VideoLAN
* $Id:
*
* Author: Vikram Fugro <vikram.fugro@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#ifndef VLC_GST_VIDEO_SINK_H
#define VLC_GST_VIDEO_SINK_H
#include <gst/gst.h>
#include <gst/gstallocator.h>
#include <gst/video/video.h>
#include <gst/video/gstvideometa.h>
#include <gst/base/gstbasesink.h>
#include <vlc_codec.h>
typedef struct _GstVlcVideoSink GstVlcVideoSink;
typedef struct _GstVlcVideoSinkClass GstVlcVideoSinkClass;
#define GST_TYPE_VLC_VIDEO_SINK \
(gst_vlc_video_sink_get_type())
#define GST_VLC_VIDEO_SINK(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_VLC_VIDEO_SINK, \
GstVlcVideoSink))
#define GST_VLC_VIDEO_SINK_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_VLC_VIDEO_SINK, \
GstVlcVideoSinkClass))
#define GST_IS_VLC_VIDEO_SINK(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_VLC_VIDEO_SINK))
#define GST_IS_VLC_VIDEO_SINK_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_VLC_VIDEO_SINK))
struct _GstVlcVideoSink
{
GstBaseSink parent;
GstAllocator *p_allocator;
GstVideoInfo vinfo;
decoder_t *p_dec;
//FIXME: caps_signal
gboolean (*new_caps) ( GstElement *p_ele, GstCaps *p_caps,
gpointer p_data );
};
struct _GstVlcVideoSinkClass
{
GstBaseSinkClass parent_class;
//FIXME: caps_signal
#if 0
gboolean (*new_caps) ( GstElement *p_ele, GstCaps *p_caps,
gpointer p_data );
#endif
void (*new_buffer) ( GstElement *p_ele, GstBuffer *p_buffer,
gpointer p_data );
};
GType gst_vlc_video_sink_get_type (void);
#endif /* __GST_VLC_VIDEO_SINK_H__ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment