[vlc-devel] [PATCH 2/2] Enable zero-copy support for gstreamer video decoders

Vikram Fugro vikram.fugro at gmail.com
Thu Feb 4 05:47:07 CET 2016


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
---
 modules/codec/Makefile.am                          |   2 +-
 modules/codec/gstreamer/gstdecode.c                | 492 ++++++++++-----------
 .../codec/gstreamer/gstvlcpictureplaneallocator.c  | 320 ++++++++++++++
 .../codec/gstreamer/gstvlcpictureplaneallocator.h  |  91 ++++
 modules/codec/gstreamer/gstvlcvideopool.c          | 239 ++++++++++
 modules/codec/gstreamer/gstvlcvideopool.h          |  68 +++
 modules/codec/gstreamer/gstvlcvideosink.c          | 326 ++++++++++++++
 modules/codec/gstreamer/gstvlcvideosink.h          |  84 ++++
 8 files changed, 1372 insertions(+), 250 deletions(-)
 create mode 100644 modules/codec/gstreamer/gstvlcpictureplaneallocator.c
 create mode 100644 modules/codec/gstreamer/gstvlcpictureplaneallocator.h
 create mode 100644 modules/codec/gstreamer/gstvlcvideopool.c
 create mode 100644 modules/codec/gstreamer/gstvlcvideopool.h
 create mode 100644 modules/codec/gstreamer/gstvlcvideosink.c
 create mode 100644 modules/codec/gstreamer/gstvlcvideosink.h

diff --git a/modules/codec/Makefile.am b/modules/codec/Makefile.am
index e06afad..50d64b9 100644
--- a/modules/codec/Makefile.am
+++ b/modules/codec/Makefile.am
@@ -542,7 +542,7 @@ 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
diff --git a/modules/codec/gstreamer/gstdecode.c b/modules/codec/gstreamer/gstdecode.c
index 0f65ec3..413d5b9 100644
--- a/modules/codec/gstreamer/gstdecode.c
+++ b/modules/codec/gstreamer/gstdecode.c
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * gstdecode.c: Decoder module making use of gstreamer
  *****************************************************************************
- * Copyright (C) 2014 VLC authors and VideoLAN
+ * Copyright (C) 2014-2016 VLC authors and VideoLAN
  * $Id:
  *
  * Author: Vikram Fugro <vikram.fugro at gmail.com>
@@ -35,9 +35,13 @@
 #include <gst/gst.h>
 #include <gst/video/video.h>
 #include <gst/video/gstvideometa.h>
+
 #include <gst/app/gstappsrc.h>
 #include <gst/gstatomicqueue.h>
 
+#include "gstvlcpictureplaneallocator.h"
+#include "gstvlcvideosink.h"
+
 struct decoder_sys_t
 {
     GstElement *p_decoder;
@@ -45,6 +49,8 @@ struct decoder_sys_t
     GstElement *p_decode_in;
     GstElement *p_decode_out;
 
+    GstVlcPicturePlaneAllocator *p_allocator;
+
     GstBus *p_bus;
 
     GstVideoInfo vinfo;
@@ -89,105 +95,37 @@ vlc_module_begin( )
     set_capability( "decoder", 50 )
     set_section( N_( "Decoding" ) , NULL )
     set_callbacks( OpenDecoder, CloseDecoder )
-    add_bool( "use-decodebin", false, USEDECODEBIN_TEXT,
+    add_bool( "use-decodebin", true, USEDECODEBIN_TEXT,
         USEDECODEBIN_LONGTEXT, false )
 vlc_module_end( )
 
-/* gst_init( ) is not thread-safe, hence a thread-safe wrapper */
-static void vlc_gst_init( void )
+void gst_vlc_dec_ensure_empty_queue( decoder_t *p_dec )
 {
-    static vlc_mutex_t init_lock = VLC_STATIC_MUTEX;
-
-    vlc_mutex_lock( &init_lock );
-    gst_init( NULL, NULL );
-    vlc_mutex_unlock( &init_lock );
-}
+    decoder_sys_t *p_sys = p_dec->p_sys;
+    int i_count = 0;
 
-static GstStructure* vlc_to_gst_fmt( const es_format_t *p_fmt )
-{
-    const video_format_t *p_vfmt = &p_fmt->video;
-    GstStructure *p_str = NULL;
+    msg_Dbg( p_dec, "Ensuring the decoder queue is empty");
 
-    switch( p_fmt->i_codec ){
-    case VLC_CODEC_H264:
-        p_str = gst_structure_new_empty( "video/x-h264" );
-        gst_structure_set( p_str, "alignment", G_TYPE_STRING, "au", NULL );
-        break;
-    case VLC_CODEC_MP4V:
-        p_str = gst_structure_new_empty( "video/mpeg" );
-        gst_structure_set( p_str, "mpegversion", G_TYPE_INT, 4,
-                "systemstream", G_TYPE_BOOLEAN, FALSE, NULL );
-        break;
-    case VLC_CODEC_VP8:
-        p_str = gst_structure_new_empty( "video/x-vp8" );
-        break;
-    case VLC_CODEC_MPGV:
-        p_str = gst_structure_new_empty( "video/mpeg" );
-        gst_structure_set( p_str, "mpegversion", G_TYPE_INT, 2,
-                "systemstream", G_TYPE_BOOLEAN, FALSE, NULL );
-        break;
-    case VLC_CODEC_FLV1:
-        p_str = gst_structure_new_empty( "video/x-flash-video" );
-        gst_structure_set( p_str, "flvversion", G_TYPE_INT, 1, NULL );
-        break;
-    case VLC_CODEC_WMV1:
-        p_str = gst_structure_new_empty( "video/x-wmv" );
-        gst_structure_set( p_str, "wmvversion", G_TYPE_INT, 1,
-                "format", G_TYPE_STRING, "WMV1", NULL );
-        break;
-    case VLC_CODEC_WMV2:
-        p_str = gst_structure_new_empty( "video/x-wmv" );
-        gst_structure_set( p_str, "wmvversion", G_TYPE_INT, 2,
-                "format", G_TYPE_STRING, "WMV2", NULL );
-        break;
-    case VLC_CODEC_WMV3:
-        p_str = gst_structure_new_empty( "video/x-wmv" );
-        gst_structure_set( p_str, "wmvversion", G_TYPE_INT, 3,
-                "format", G_TYPE_STRING, "WMV3", NULL );
-        break;
-    case VLC_CODEC_VC1:
-        p_str = gst_structure_new_empty( "video/x-wmv" );
-        gst_structure_set( p_str, "wmvversion", G_TYPE_INT, 3,
-                "format", G_TYPE_STRING, "WVC1", NULL );
-        break;
-    default:
-        /* unsupported codec */
-        return NULL;
+    /* Busy wait with sleep; As this is rare case and the
+     * wait might at max go for 3-4 iterations, preferred to not
+     * to throw in a cond/lock here. */
+    while( p_sys->b_running && i_count < 60 &&
+            gst_atomic_queue_length( p_sys->p_que ))
+    {
+        msleep ( 15000 );
+        i_count++;
     }
 
-    if( p_vfmt->i_width && p_vfmt->i_height )
-        gst_structure_set( p_str,
-                "width", G_TYPE_INT, p_vfmt->i_width,
-                "height", G_TYPE_INT, p_vfmt->i_height, NULL );
-
-    if( p_vfmt->i_frame_rate && p_vfmt->i_frame_rate_base )
-        gst_structure_set( p_str, "framerate", GST_TYPE_FRACTION,
-                p_vfmt->i_frame_rate,
-                p_vfmt->i_frame_rate_base, NULL );
-
-    if( p_vfmt->i_sar_num && p_vfmt->i_sar_den )
-        gst_structure_set( p_str, "pixel-aspect-ratio", GST_TYPE_FRACTION,
-                p_vfmt->i_sar_num,
-                p_vfmt->i_sar_den, NULL );
-
-    if( p_fmt->i_extra )
+    if( p_sys->b_running )
     {
-        GstBuffer *p_buf;
-
-        p_buf = gst_buffer_new_wrapped_full( GST_MEMORY_FLAG_READONLY,
-                p_fmt->p_extra, p_fmt->i_extra, 0,
-                p_fmt->i_extra, NULL, NULL );
-        if( p_buf == NULL )
-        {
-            gst_structure_free( p_str );
-            return NULL;
-        }
-
-        gst_structure_set( p_str, "codec_data", GST_TYPE_BUFFER, p_buf, NULL );
-        gst_buffer_unref( p_buf );
+        if( !gst_atomic_queue_length( p_sys->p_que ))
+            msg_Dbg( p_dec, "Ensured the decoder queue is empty" );
+        else
+            msg_Warn( p_dec, "Timed out when ensuring an empty queue" );
     }
-
-    return p_str;
+    else
+        msg_Dbg( p_dec, "Ensuring empty decoder queue not required; decoder \
+                not running" );
 }
 
 /* Emitted by appsrc when serving a seek request.
@@ -203,110 +141,6 @@ static gboolean seek_data_cb( GstAppSrc *p_src, guint64 l_offset,
     return TRUE;
 }
 
-/* Emitted by decodebin when there are no more
- * outputs.This signal is not really necessary
- * to be connected. It is connected here for sanity
- * check only, just in-case something unexpected
- * happens inside decodebin in finding the appropriate
- * decoder, and it fails to emit PAD_ADDED signal */
-static void no_more_pads_cb( GstElement *p_ele, gpointer p_data )
-{
-    VLC_UNUSED( p_ele );
-    decoder_t *p_dec = p_data;
-    decoder_sys_t *p_sys = p_dec->p_sys;
-    GstPad *p_pad;
-
-    msg_Dbg( p_dec, "no more pads" );
-
-    p_pad = gst_element_get_static_pad( p_sys->p_decode_out,
-            "sink" );
-    if( !gst_pad_is_linked( p_pad ) )
-    {
-        msg_Err( p_dec, "failed to link decode out pad" );
-        GST_ELEMENT_ERROR( p_sys->p_decoder, STREAM, FAILED,
-                ( "vlc stream error" ), NULL );
-    }
-
-    gst_object_unref( p_pad );
-}
-
-/* Sets the video output format */
-static bool set_vout_format( GstStructure* p_str,
-        const es_format_t *restrict p_infmt, es_format_t *restrict p_outfmt )
-{
-    video_format_t *p_voutfmt = &p_outfmt->video;
-    const video_format_t *p_vinfmt = &p_infmt->video;
-    gboolean b_ret;
-
-    /* We are interested in system memory raw buffers for now,
-     * but support for opaque data formats can also be added.
-     * For eg. when using HW decoders for zero-copy */
-    p_outfmt->i_codec = vlc_fourcc_GetCodecFromString(
-            VIDEO_ES,
-            gst_structure_get_string( p_str, "format" ) );
-    if( !p_outfmt->i_codec )
-        return false;
-
-    gst_structure_get_int( p_str, "width", &p_voutfmt->i_width );
-    gst_structure_get_int( p_str, "height", &p_voutfmt->i_height );
-
-    b_ret = gst_structure_get_fraction( p_str,
-            "pixel-aspect-ratio",
-            &p_voutfmt->i_sar_num,
-            &p_voutfmt->i_sar_den );
-
-    if( !b_ret || !p_voutfmt->i_sar_num ||
-            !p_voutfmt->i_sar_den )
-    {
-        p_voutfmt->i_sar_num = 1;
-        p_voutfmt->i_sar_den = 1;
-    }
-
-    b_ret = gst_structure_get_fraction( p_str, "framerate",
-            &p_voutfmt->i_frame_rate,
-            &p_voutfmt->i_frame_rate_base );
-
-    if( !b_ret || !p_voutfmt->i_frame_rate ||
-            !p_voutfmt->i_frame_rate_base )
-    {
-        p_voutfmt->i_frame_rate = p_vinfmt->i_frame_rate;
-        p_voutfmt->i_frame_rate_base = p_vinfmt->i_frame_rate_base;
-    }
-
-    return true;
-}
-
-static bool set_out_fmt( decoder_t *p_dec, GstPad *p_pad )
-{
-    GstCaps *p_caps = gst_pad_get_current_caps( p_pad );
-    decoder_sys_t *p_sys = p_dec->p_sys;
-    GstStructure *p_str;
-
-    if( !gst_video_info_from_caps( &p_sys->vinfo,
-                p_caps ) )
-    {
-        msg_Err( p_dec, "failed to get video info from caps" );
-        gst_caps_unref( p_caps );
-        GST_ELEMENT_ERROR( p_sys->p_decoder, STREAM, FAILED,
-                ( "vlc stream error" ), NULL );
-        return false;
-    }
-
-    p_str = gst_caps_get_structure( p_caps, 0 );
-
-    if( !set_vout_format( p_str, &p_dec->fmt_in, &p_dec->fmt_out ) )
-    {
-        msg_Err( p_dec, "failed to set out format" );
-        gst_caps_unref( p_caps );
-        GST_ELEMENT_ERROR( p_sys->p_decoder, STREAM, FAILED,
-                ( "vlc stream error" ), NULL );
-        return false;
-    }
-
-    gst_caps_unref( p_caps );
-    return true;
-}
-
 /* Emitted by decodebin and links decodebin to fakesink.
  * Since only one elementary codec stream is fed to decodebin,
  * this signal cannot be emitted more than once. */
@@ -318,14 +152,17 @@ static void pad_added_cb( GstElement *p_ele, GstPad *p_pad, gpointer p_data )
 
     if( likely( gst_pad_has_current_caps( p_pad ) ) )
     {
+        GstPadLinkReturn ret;
         GstPad *p_sinkpad;
 
-        if( !set_out_fmt( p_dec, p_pad ) )
-            return;
+        msg_Dbg( p_dec, "linking the decoder with the vsink");
 
         p_sinkpad = gst_element_get_static_pad(
                 p_sys->p_decode_out, "sink" );
-        gst_pad_link( p_pad, p_sinkpad );
+        ret = gst_pad_link( p_pad, p_sinkpad );
+        if( ret != GST_PAD_LINK_OK )
+            msg_Warn( p_dec, "failed to link decoder with vsink");
+
         gst_object_unref( p_sinkpad );
     }
     else
@@ -336,36 +173,42 @@ static void pad_added_cb( GstElement *p_ele, GstPad *p_pad, gpointer p_data )
     }
 }
 
-/* Emitted by fakesink for every buffer and sets the
- * output format (if not set). Adds the buffer to the queue */
-static void frame_handoff_cb( GstElement *p_ele, GstBuffer *p_buf,
-        GstPad *p_pad, gpointer p_data )
+static gboolean caps_handoff_cb( GstElement* p_ele, GstCaps *p_caps,
+        gpointer p_data )
 {
     VLC_UNUSED( p_ele );
     decoder_t *p_dec = p_data;
     decoder_sys_t *p_sys = p_dec->p_sys;
 
-    if( unlikely( p_dec->fmt_out.i_codec == 0 ) )
-    {
-        if( !gst_pad_has_current_caps( p_pad ) )
-        {
-            msg_Err( p_dec, "fakesink pad has no caps" );
-            GST_ELEMENT_ERROR( p_sys->p_decoder, STREAM, FAILED,
-                    ( "vlc stream error" ), NULL );
-            return;
-        }
+    msg_Info( p_dec, "got new caps %s", gst_caps_to_string( p_caps ));
 
-        if( !set_out_fmt( p_dec, p_pad ) )
-            return;
+    if( !gst_video_info_from_caps( &p_sys->vinfo, p_caps ))
+    {
+        msg_Warn( p_dec, "failed to negotiate" );
+        return FALSE;
     }
 
+    gst_vlc_dec_ensure_empty_queue( p_dec );
+
+    return gst_vlc_set_vout_fmt( &p_sys->vinfo, p_caps, p_dec );
+}
+
+/* Emitted by fakesink for every buffer and sets the
+ * Adds the buffer to the queue */
+static void frame_handoff_cb( GstElement *p_ele, GstBuffer *p_buf,
+        gpointer p_data )
+{
+    VLC_UNUSED( p_ele );
+    decoder_t *p_dec = p_data;
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
     /* Push the buffer to the queue */
     gst_atomic_queue_push( p_sys->p_que, gst_buffer_ref( p_buf ) );
 }
 
 /* Copy the frame data from the GstBuffer (from decoder)
  * to the picture obtained from downstream in VLC.
- * TODO(Zero-Copy): This function should be avoided as much
+ * This function should be avoided as much
  * as possible, since it involves a complete frame copy. */
 static void gst_CopyPicture( picture_t *p_pic, GstVideoFrame *p_frame )
 {
@@ -408,7 +251,7 @@ static gint find_decoder_func( gconstpointer p_p1, gconstpointer p_p2 )
     return !( gst_element_factory_can_sink_any_caps( p_factory,
                 p_caps->p_sinkcaps ) &&
             gst_element_factory_can_src_any_caps( p_factory,
-                p_caps->p_srccaps ) );
+                p_caps->p_srccaps ));
 }
 
 static bool default_msg_handler( decoder_t *p_dec, GstMessage *p_msg )
@@ -466,6 +309,129 @@ static bool default_msg_handler( decoder_t *p_dec, GstMessage *p_msg )
     return err;
 }
 
+static gboolean vlc_gst_plugin_init( GstPlugin *p_plugin )
+{
+    if( !gst_element_register( p_plugin, "vlcvideosink", GST_RANK_NONE,
+                GST_TYPE_VLC_VIDEO_SINK ))
+        return FALSE;
+
+    return TRUE;
+}
+
+/* gst_init( ) is not thread-safe, hence a thread-safe wrapper */
+static bool vlc_gst_init( void )
+{
+    static vlc_mutex_t init_lock = VLC_STATIC_MUTEX;
+    static bool b_registered = false;
+    bool b_ret = true;
+
+    vlc_mutex_lock( &init_lock );
+    gst_init( NULL, NULL );
+    if ( !b_registered )
+    {
+        b_ret = gst_plugin_register_static( 1, 0, "videolan",
+                "VLC Gstreamer plugins", vlc_gst_plugin_init,
+                "1.0.0", "LGPL", "NA", "vlc", "NA" );
+        b_registered = b_ret;
+    }
+    vlc_mutex_unlock( &init_lock );
+
+    return b_ret;
+}
+
+static GstStructure* vlc_to_gst_fmt( const es_format_t *p_fmt )
+{
+    const video_format_t *p_vfmt = &p_fmt->video;
+    GstStructure *p_str = NULL;
+
+    switch( p_fmt->i_codec ){
+    case VLC_CODEC_H264:
+        p_str = gst_structure_new_empty( "video/x-h264" );
+        gst_structure_set( p_str, "alignment", G_TYPE_STRING, "au", NULL );
+        if( p_fmt->i_extra )
+            gst_structure_set( p_str, "stream-format", G_TYPE_STRING, "avc",
+                    NULL );
+        else
+            gst_structure_set( p_str, "stream-format", G_TYPE_STRING,
+                    "byte-stream", NULL );
+        break;
+    case VLC_CODEC_MP4V:
+        p_str = gst_structure_new_empty( "video/mpeg" );
+        gst_structure_set( p_str, "mpegversion", G_TYPE_INT, 4,
+                "systemstream", G_TYPE_BOOLEAN, FALSE, NULL );
+        break;
+    case VLC_CODEC_VP8:
+        p_str = gst_structure_new_empty( "video/x-vp8" );
+        break;
+    case VLC_CODEC_MPGV:
+        p_str = gst_structure_new_empty( "video/mpeg" );
+        gst_structure_set( p_str, "mpegversion", G_TYPE_INT, 2,
+                "systemstream", G_TYPE_BOOLEAN, FALSE, NULL );
+        break;
+    case VLC_CODEC_FLV1:
+        p_str = gst_structure_new_empty( "video/x-flash-video" );
+        gst_structure_set( p_str, "flvversion", G_TYPE_INT, 1, NULL );
+        break;
+    case VLC_CODEC_WMV1:
+        p_str = gst_structure_new_empty( "video/x-wmv" );
+        gst_structure_set( p_str, "wmvversion", G_TYPE_INT, 1,
+                "format", G_TYPE_STRING, "WMV1", NULL );
+        break;
+    case VLC_CODEC_WMV2:
+        p_str = gst_structure_new_empty( "video/x-wmv" );
+        gst_structure_set( p_str, "wmvversion", G_TYPE_INT, 2,
+                "format", G_TYPE_STRING, "WMV2", NULL );
+        break;
+    case VLC_CODEC_WMV3:
+        p_str = gst_structure_new_empty( "video/x-wmv" );
+        gst_structure_set( p_str, "wmvversion", G_TYPE_INT, 3,
+                "format", G_TYPE_STRING, "WMV3", NULL );
+        break;
+    case VLC_CODEC_VC1:
+        p_str = gst_structure_new_empty( "video/x-wmv" );
+        gst_structure_set( p_str, "wmvversion", G_TYPE_INT, 3,
+                "format", G_TYPE_STRING, "WVC1", NULL );
+        break;
+    default:
+        /* unsupported codec */
+        return NULL;
+    }
+
+    if( p_vfmt->i_width && p_vfmt->i_height )
+        gst_structure_set( p_str,
+                "width", G_TYPE_INT, p_vfmt->i_width,
+                "height", G_TYPE_INT, p_vfmt->i_height, NULL );
+
+    if( p_vfmt->i_frame_rate && p_vfmt->i_frame_rate_base )
+        gst_structure_set( p_str, "framerate", GST_TYPE_FRACTION,
+                p_vfmt->i_frame_rate,
+                p_vfmt->i_frame_rate_base, NULL );
+
+    if( p_vfmt->i_sar_num && p_vfmt->i_sar_den )
+        gst_structure_set( p_str, "pixel-aspect-ratio", GST_TYPE_FRACTION,
+                p_vfmt->i_sar_num,
+                p_vfmt->i_sar_den, NULL );
+
+    if( p_fmt->i_extra )
+    {
+        GstBuffer *p_buf;
+
+        p_buf = gst_buffer_new_wrapped_full( GST_MEMORY_FLAG_READONLY,
+                p_fmt->p_extra, p_fmt->i_extra, 0,
+                p_fmt->i_extra, NULL, NULL );
+        if( p_buf == NULL )
+        {
+            gst_structure_free( p_str );
+            return NULL;
+        }
+
+        gst_structure_set( p_str, "codec_data", GST_TYPE_BUFFER, p_buf, NULL );
+        gst_buffer_unref( p_buf );
+    }
+
+    return p_str;
+}
+
 /*****************************************************************************
  * OpenDecoder: probe the decoder and return score
  *****************************************************************************/
@@ -485,7 +451,11 @@ static int OpenDecoder( vlc_object_t *p_this )
 #define VLC_GST_CHECK( r, v, s, t ) \
     { if( r == v ){ msg_Err( p_dec, s ); i_rval = t; goto fail; } }
 
-    vlc_gst_init( );
+    if( !vlc_gst_init( ))
+    {
+        msg_Err( p_dec, "failed to register vlcvideosink" );
+        return VLC_EGENERIC;
+    }
 
     p_str = vlc_to_gst_fmt( &p_dec->fmt_in );
     if( !p_str )
@@ -554,7 +524,7 @@ static int OpenDecoder( vlc_object_t *p_this )
     VLC_GST_CHECK( p_sys->p_decode_src, NULL, "appsrc not found",
             VLC_ENOMOD );
     g_object_set( G_OBJECT( p_sys->p_decode_src ), "caps", caps.p_sinkcaps,
-            "block", FALSE, "emit-signals", TRUE, "format", GST_FORMAT_BYTES,
+            "emit-signals", TRUE, "format", GST_FORMAT_BYTES,
             "stream-type", GST_APP_STREAM_TYPE_SEEKABLE,
             /* Making DecodeBlock() to block on appsrc with max queue size of 1 byte.
              * This will make the push_buffer() tightly coupled with the buffer
@@ -576,22 +546,32 @@ static int OpenDecoder( vlc_object_t *p_this )
                 VLC_ENOMOD );
         //g_object_set( G_OBJECT( p_sys->p_decode_in ),
         //"max-size-buffers", 2, NULL );
+        //g_signal_connect( G_OBJECT( p_sys->p_decode_in ), "no-more-pads",
+                //G_CALLBACK( no_more_pads_cb ), p_dec );
         g_signal_connect( G_OBJECT( p_sys->p_decode_in ), "pad-added",
                 G_CALLBACK( pad_added_cb ), p_dec );
-        g_signal_connect( G_OBJECT( p_sys->p_decode_in ), "no-more-pads",
-                G_CALLBACK( no_more_pads_cb ), p_dec );
+
     }
 
-    /* fakesink: will emit signal for every available buffer */
-    p_sys->p_decode_out = gst_element_factory_make( "fakesink", NULL );
-    VLC_GST_CHECK( p_sys->p_decode_out, NULL, "fakesink not found",
+    /* videosink: will emit signal for every available buffer */
+    p_sys->p_decode_out = gst_element_factory_make( "vlcvideosink", NULL );
+    VLC_GST_CHECK( p_sys->p_decode_out, NULL, "vlcvideosink not found",
             VLC_ENOMOD );
-    /* connect to the signal with the callback */
-    g_object_set( G_OBJECT( p_sys->p_decode_out ), "sync", FALSE,
-            "enable-last-sample", FALSE, "signal-handoffs", TRUE, NULL );
-    g_signal_connect( G_OBJECT( p_sys->p_decode_out ), "handoff",
+    p_sys->p_allocator = gst_vlc_picture_plane_allocator_new(
+            (gpointer) p_dec );
+    g_object_set( G_OBJECT( p_sys->p_decode_out ), "sync", FALSE, "allocator",
+            p_sys->p_allocator, "id", (gpointer) p_dec, NULL );
+    g_signal_connect( G_OBJECT( p_sys->p_decode_out ), "new-buffer",
             G_CALLBACK( frame_handoff_cb ), p_dec );
 
+    //FIXME: caps_signal
+#if 0
+    g_signal_connect( G_OBJECT( p_sys->p_decode_out ), "new-caps",
+            G_CALLBACK( caps_handoff_cb ), p_dec );
+#else
+    GST_VLC_VIDEO_SINK( p_sys->p_decode_out )->new_caps = caps_handoff_cb;
+#endif
+
     p_sys->p_decoder = GST_ELEMENT( gst_bin_new( "decoder" ) );
     VLC_GST_CHECK( p_sys->p_decoder, NULL, "bin not found", VLC_ENOMOD );
     p_sys->p_bus = gst_bus_new( );
@@ -736,7 +716,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
          *     \                        /
          *   ___v____GSTREAMER BIN_____/____
          *  |                               |
-         *  |   appsrc-->decode-->fakesink  |
+         *  |   appsrc-->decode-->vlcsink   |
          *  |_______________________________|
          *
          * * * * * * * * * * * * * * * * * * * * */
@@ -788,33 +768,43 @@ check_messages:
     /* Look for any output buffers in the queue */
     if( gst_atomic_queue_peek( p_sys->p_que ) )
     {
-        GstVideoFrame frame;
+        GstBuffer *p_buf = GST_BUFFER_CAST(
+                gst_atomic_queue_pop( p_sys->p_que ));
+        GstMemory *p_mem;
 
-        /* Get a new picture */
-        p_pic = decoder_NewPicture( p_dec );
-        if( !p_pic )
-            goto done;
+        if(( p_mem = gst_buffer_peek_memory( p_buf, 0 )) &&
+            GST_IS_VLC_PICTURE_PLANE_ALLOCATOR( p_mem->allocator ))
+        {
+            p_pic = picture_Hold(( (GstVlcPicturePlane*) p_mem )->p_pic );
+        }
+        else
+        {
+            GstVideoFrame frame;
 
-        p_buf = GST_BUFFER_CAST(
-                gst_atomic_queue_pop( p_sys->p_que ) );
+            /* Get a new picture */
+            p_pic = decoder_NewPicture( p_dec );
+            if( !p_pic )
+                goto done;
+
+            if( unlikely( !gst_video_frame_map( &frame,
+                            &p_sys->vinfo, p_buf, GST_MAP_READ ) ) )
+            {
+                msg_Err( p_dec, "failed to map gst video frame" );
+                gst_buffer_unref( p_buf );
+                p_dec->b_error = true;
+                goto done;
+            }
+
+            gst_CopyPicture( p_pic, &frame );
+            gst_video_frame_unmap( &frame );
+        }
 
         if( likely( GST_BUFFER_PTS_IS_VALID( p_buf ) ) )
             p_pic->date = gst_util_uint64_scale(
-                    GST_BUFFER_PTS( p_buf ), GST_MSECOND, GST_SECOND );
+                GST_BUFFER_PTS( p_buf ), GST_MSECOND, GST_SECOND );
         else
             msg_Warn( p_dec, "Gst Buffer has no timestamp" );
 
-        if( unlikely( !gst_video_frame_map( &frame,
-                        &p_sys->vinfo, p_buf, GST_MAP_READ ) ) )
-        {
-            msg_Err( p_dec, "failed to map gst video frame" );
-            gst_buffer_unref( p_buf );
-            p_dec->b_error = true;
-            goto done;
-        }
-
-        gst_CopyPicture( p_pic, &frame );
-        gst_video_frame_unmap( &frame );
         gst_buffer_unref( p_buf );
     }
 
@@ -828,15 +818,18 @@ static void CloseDecoder( vlc_object_t *p_this )
 {
     decoder_t *p_dec = ( decoder_t* )p_this;
     decoder_sys_t *p_sys = p_dec->p_sys;
+    gboolean b_running = p_sys->b_running;
 
-    if( p_sys->b_running )
+    if( b_running )
     {
         GstMessage *p_msg;
         GstFlowReturn i_ret;
 
+        p_sys->b_running = false;
+
         /* Send EOS to the pipeline */
         i_ret = gst_app_src_end_of_stream(
-                GST_APP_SRC_CAST( p_sys->p_decode_src ) );
+                GST_APP_SRC_CAST( p_sys->p_decode_src ));
         msg_Dbg( p_dec, "app src eos: %s", gst_flow_get_name( i_ret ) );
 
         /* and catch it on the bus with a timeout */
@@ -872,13 +865,14 @@ static void CloseDecoder( vlc_object_t *p_this )
         gst_atomic_queue_unref( p_sys->p_que );
     }
 
-    if( p_sys->b_running &&
-            gst_element_set_state( p_sys->p_decoder, GST_STATE_NULL )
+    if( b_running && gst_element_set_state( p_sys->p_decoder, GST_STATE_NULL )
             != GST_STATE_CHANGE_SUCCESS )
         msg_Warn( p_dec,
                 "failed to change the state to NULL," \
                 "pipeline may not close gracefully" );
 
+    if( p_sys->p_allocator )
+        gst_object_unref( p_sys->p_allocator );
     if( p_sys->p_bus )
         gst_object_unref( p_sys->p_bus );
     if( p_sys->p_decode_src )
diff --git a/modules/codec/gstreamer/gstvlcpictureplaneallocator.c b/modules/codec/gstreamer/gstvlcpictureplaneallocator.c
new file mode 100644
index 0000000..2d9776f
--- /dev/null
+++ b/modules/codec/gstreamer/gstvlcpictureplaneallocator.c
@@ -0,0 +1,320 @@
+/*****************************************************************************
+ * gstvlcpictureplaneallocator.c: VLC pictures wrapped by GstAllocator
+ *****************************************************************************
+ * Copyright (C) 2016 VLC authors and VideoLAN
+ * $Id:
+ *
+ * Author: Vikram Fugro <vikram.fugro at 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 <gst/gstallocator.h>
+
+#include "gstvlcpictureplaneallocator.h"
+
+#include <vlc_common.h>
+
+#define gst_vlc_picture_plane_allocator_parent_class parent_class
+G_DEFINE_TYPE (GstVlcPicturePlaneAllocator, gst_vlc_picture_plane_allocator, \
+        GST_TYPE_ALLOCATOR);
+
+static void gst_vlc_picture_plane_allocator_finalize( GObject *p_object );
+static GstMemory* gst_vlc_picture_plane_allocator_dummy_alloc(
+        GstAllocator* p_allocator, gsize i_size,
+        GstAllocationParams *p_params );
+static void gst_vlc_picture_plane_allocator_free( GstAllocator *p_allocator,
+        GstMemory *p_gmem);
+static gpointer gst_vlc_picture_plane_map( GstMemory *p_gmem,
+        gsize i_maxsize, GstMapFlags flags );
+static gboolean gst_vlc_picture_plane_unmap( GstVlcPicturePlane *p_mem );
+static GstMemory* gst_vlc_picture_plane_copy(
+        GstVlcPicturePlane *p_mem, gssize i_offset, gssize i_size );
+
+#define GST_VLC_PICTURE_PLANE_ALLOCATOR_NAME "vlcpictureplane"
+
+static void gst_vlc_picture_plane_allocator_class_init(
+    GstVlcPicturePlaneAllocatorClass *p_klass )
+{
+    GObjectClass *p_gobject_class;
+    GstAllocatorClass *p_allocator_class;
+
+    p_gobject_class = (GObjectClass*) p_klass;
+    p_allocator_class = (GstAllocatorClass*) p_klass;
+
+    p_gobject_class->finalize = gst_vlc_picture_plane_allocator_finalize;
+
+    p_allocator_class->alloc = gst_vlc_picture_plane_allocator_dummy_alloc;
+    p_allocator_class->free = gst_vlc_picture_plane_allocator_free;
+}
+
+static void gst_vlc_picture_plane_allocator_init(
+        GstVlcPicturePlaneAllocator *p_allocator )
+{
+    GstAllocator *p_alloc = GST_ALLOCATOR_CAST( p_allocator );
+
+    p_alloc->mem_type = GST_VLC_PICTURE_PLANE_ALLOCATOR_NAME;
+    p_alloc->mem_map = (GstMemoryMapFunction) gst_vlc_picture_plane_map;
+    p_alloc->mem_unmap = (GstMemoryUnmapFunction) gst_vlc_picture_plane_unmap;
+    p_alloc->mem_copy = (GstMemoryShareFunction) gst_vlc_picture_plane_copy;
+    /* fallback is_span */
+
+    GST_OBJECT_FLAG_SET( p_allocator, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC );
+}
+
+static void gst_vlc_picture_plane_allocator_finalize( GObject *p_object )
+{
+    GstVlcPicturePlaneAllocator *p_alloc = GST_VLC_PICTURE_PLANE_ALLOCATOR(
+            p_object );
+    VLC_UNUSED( p_alloc );
+
+    G_OBJECT_CLASS (parent_class)->finalize( p_object );
+}
+
+static GstMemory* gst_vlc_picture_plane_allocator_dummy_alloc(
+        GstAllocator* p_allocator, gsize i_size, GstAllocationParams *p_params )
+{
+    VLC_UNUSED( p_allocator );
+    VLC_UNUSED( i_size );
+    VLC_UNUSED( p_params );
+    return NULL;
+}
+
+static void gst_vlc_picture_plane_allocator_free( GstAllocator *p_allocator,
+        GstMemory *p_gmem)
+{
+    VLC_UNUSED( p_allocator );
+    GstVlcPicturePlane *p_mem = (GstVlcPicturePlane*) p_gmem;
+    g_slice_free( GstVlcPicturePlane, p_mem );
+}
+
+static gpointer gst_vlc_picture_plane_map( GstMemory *p_gmem,
+    gsize i_maxsize, GstMapFlags flags )
+{
+    VLC_UNUSED( i_maxsize );
+    VLC_UNUSED( flags );
+    GstVlcPicturePlane* p_mem = (GstVlcPicturePlane*) p_gmem;
+
+    if( p_mem->p_pic )
+        return (gpointer) (p_mem->p_plane->p_pixels + p_mem->parent.offset);
+    else
+        return NULL;
+}
+
+static gboolean gst_vlc_picture_plane_unmap(
+        GstVlcPicturePlane *p_mem )
+{
+    VLC_UNUSED( p_mem );
+    return TRUE;
+}
+
+static GstMemory* gst_vlc_picture_plane_copy(
+        GstVlcPicturePlane *p_mem, gssize i_offset, gssize i_size )
+{
+    VLC_UNUSED( p_mem );
+    VLC_UNUSED( i_offset );
+    VLC_UNUSED( i_size );
+    return NULL;
+}
+
+void gst_vlc_picture_plane_allocator_release(
+    GstVlcPicturePlaneAllocator *p_allocator, GstBuffer *p_buffer )
+{
+    GstVlcPicturePlane* p_mem =
+        (GstVlcPicturePlane*) gst_buffer_peek_memory( p_buffer, 0 );
+    guint i_plane;
+
+    if( p_mem->p_pic )
+        picture_Release( p_mem->p_pic );
+    else
+        msg_Warn( p_allocator->p_dec, "pic null inside the plane -> buffer" );
+
+    for( i_plane = 0; i_plane < gst_buffer_n_memory( p_buffer ); i_plane++ )
+    {
+        p_mem = (GstVlcPicturePlane*) gst_buffer_peek_memory ( p_buffer,
+                i_plane );
+        p_mem->p_pic = NULL;
+        p_mem->p_plane = NULL;
+    }
+}
+
+bool gst_vlc_picture_plane_allocator_hold(
+    GstVlcPicturePlaneAllocator *p_allocator, GstBuffer *p_buffer )
+{
+    picture_t* p_pic;
+    decoder_t* p_dec = p_allocator->p_dec;
+    GstVlcPicturePlane *p_mem;
+    int i_plane;
+
+    p_pic = decoder_NewPicture( p_dec );
+    if( !p_pic )
+    {
+        msg_Err( p_allocator->p_dec, "failed to acquire picture from vout" );
+        return false;
+    }
+
+    for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
+    {
+        p_mem = (GstVlcPicturePlane*) gst_buffer_peek_memory ( p_buffer,
+                i_plane );
+        p_mem->p_pic = p_pic;
+        p_mem->p_plane = &p_pic->p[ i_plane ];
+    }
+
+    return true;
+}
+
+bool gst_vlc_picture_plane_allocator_alloc(
+        GstVlcPicturePlaneAllocator *p_allocator,
+        GstBuffer *p_buffer )
+{
+    int i_plane;
+    gsize i_max_size, i_align, i_offset, i_size;
+    picture_t *p_pic;
+
+    p_pic = &p_allocator->pic_info;
+
+    for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
+    {
+        GstVlcPicturePlane *p_mem =
+            (GstVlcPicturePlane*) g_slice_new0( GstVlcPicturePlane );
+
+        i_size = p_pic->p[ i_plane ].i_visible_pitch *
+            p_pic->p[ i_plane ].i_visible_lines;
+        i_max_size = p_pic->p[ i_plane ].i_pitch *
+            p_pic->p[ i_plane ].i_lines;
+        i_align = 0;
+        i_offset = 0;
+
+        gst_memory_init( GST_MEMORY_CAST( p_mem ), GST_MEMORY_FLAG_NO_SHARE,
+                GST_ALLOCATOR_CAST( p_allocator ), NULL, i_max_size,
+                i_align, i_offset, i_size );
+        gst_buffer_append_memory( p_buffer, (GstMemory*) p_mem );
+    }
+
+    return true;
+}
+
+bool gst_vlc_set_vout_fmt( GstVideoInfo *p_info, GstCaps *p_caps,
+        decoder_t *p_dec )
+{
+    es_format_t *p_outfmt = &p_dec->fmt_out;
+    video_format_t *p_voutfmt = &p_dec->fmt_out.video;
+    GstStructure *p_str = gst_caps_get_structure( p_caps, 0 );
+    vlc_fourcc_t i_chroma;
+
+    i_chroma = p_outfmt->i_codec = vlc_fourcc_GetCodecFromString(
+            VIDEO_ES,
+            gst_structure_get_string( p_str, "format" ) );
+    if( !i_chroma )
+    {
+        msg_Err( p_dec, "video chroma type not supported" );
+        return false;
+    }
+
+    video_format_Setup( &p_dec->fmt_out.video, i_chroma,
+            GST_VIDEO_INFO_WIDTH( p_info ), GST_VIDEO_INFO_HEIGHT( p_info ),
+            GST_VIDEO_INFO_WIDTH( p_info ), GST_VIDEO_INFO_HEIGHT( p_info ),
+            GST_VIDEO_INFO_PAR_N( p_info ), GST_VIDEO_INFO_PAR_D( p_info ));
+
+    p_voutfmt->i_frame_rate = GST_VIDEO_INFO_FPS_N( p_info );
+    p_voutfmt->i_frame_rate_base = GST_VIDEO_INFO_FPS_D( p_info );
+
+    return true;
+}
+
+static bool gst_vlc_video_info_from_vout( GstVideoInfo *p_info, GstCaps *p_caps,
+        decoder_t *p_dec, picture_t *p_pic_info )
+{
+    picture_t *p_pic;
+
+    /* Ensure the queue is empty */
+    gst_vlc_dec_ensure_empty_queue( p_dec );
+
+    if( !gst_vlc_set_vout_fmt( p_info, p_caps, p_dec ))
+    {
+        msg_Err( p_dec, "failed to set output format to vout" );
+        return false;
+    }
+
+    /* Acquire a picture and release it. This is to get the picture
+     * stride/offsets info for the Gstreamer decoder looking to use
+     * downstream bufferpool directly; Zero-Copy */
+    p_pic = decoder_NewPicture( p_dec );
+    if( !p_pic )
+    {
+        msg_Err( p_dec, "failed to acquire picture from vout; for pic info" );
+        return false;
+    }
+
+    memcpy( p_pic_info, p_pic, sizeof( picture_t ));
+    picture_Release( p_pic );
+
+    return true;
+}
+
+bool gst_vlc_picture_plane_allocator_query_format(
+        GstVlcPicturePlaneAllocator *p_allocator,
+        GstVideoInfo *p_info, GstCaps *p_caps )
+{
+    decoder_t *p_dec = p_allocator->p_dec;
+    video_format_t v_fmt;
+    picture_t *p_pic_info = &p_allocator->pic_info;
+    int i_plane, i_offset = 0, i_size = 0;
+
+    /* Back up the original format; as this is just a query  */
+    memcpy( &v_fmt, &p_dec->fmt_out.video, sizeof( video_format_t ));
+
+    if( !gst_vlc_video_info_from_vout( p_info, p_caps, p_dec, p_pic_info ))
+    {
+        msg_Err( p_allocator->p_dec, "failed to get the vout info" );
+        return false;
+    }
+
+    //GST_VIDEO_INFO_N_PLANES( p_info ) = p_pic_info->i_planes;
+    for( i_plane = 0; i_plane < p_pic_info->i_planes; i_plane++ )
+    {
+        GST_VIDEO_INFO_PLANE_STRIDE( p_info, i_plane ) =
+            p_pic_info->p[ i_plane ].i_pitch;
+        GST_VIDEO_INFO_PLANE_OFFSET( p_info, i_plane ) = i_offset;
+        //i_offset += p_pic_info->p[ i_plane ].i_pitch *
+            //p_pic_info->p[ i_plane ].i_lines;
+        i_offset += p_pic_info->p[ i_plane ].i_visible_pitch *
+            p_pic_info->p[ i_plane ].i_visible_lines;
+        i_size += p_pic_info->p[ i_plane ].i_visible_pitch *
+            p_pic_info->p[ i_plane ].i_visible_lines;
+    }
+    GST_VIDEO_INFO_SIZE( p_info ) = i_size;
+
+    /* Restore the original format; as this was just a query  */
+    memcpy( &p_dec->fmt_out.video, &v_fmt, sizeof( video_format_t ));
+
+    return true;
+}
+
+
+GstVlcPicturePlaneAllocator* gst_vlc_picture_plane_allocator_new(
+        decoder_t *p_dec )
+{
+    GstVlcPicturePlaneAllocator *p_allocator;
+
+    p_allocator = g_object_new( GST_TYPE_VLC_PICTURE_PLANE_ALLOCATOR, NULL);
+    p_allocator->p_dec = p_dec;
+
+    return p_allocator;
+}
diff --git a/modules/codec/gstreamer/gstvlcpictureplaneallocator.h b/modules/codec/gstreamer/gstvlcpictureplaneallocator.h
new file mode 100644
index 0000000..e693e0e
--- /dev/null
+++ b/modules/codec/gstreamer/gstvlcpictureplaneallocator.h
@@ -0,0 +1,91 @@
+/*****************************************************************************
+ * gstvlcpictureplaneallocator.h: VLC pictures wrapped by GstAllocator
+ *****************************************************************************
+ * Copyright (C) 2016 VLC authors and VideoLAN
+ * $Id:
+ *
+ * Author: Vikram Fugro <vikram.fugro at 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 __GST_VLC_PICTURE_PLANE_ALLOCATOR_H_
+#define __GST_VLC_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
diff --git a/modules/codec/gstreamer/gstvlcvideopool.c b/modules/codec/gstreamer/gstvlcvideopool.c
new file mode 100644
index 0000000..35229a3
--- /dev/null
+++ b/modules/codec/gstreamer/gstvlcvideopool.c
@@ -0,0 +1,239 @@
+/*****************************************************************************
+ * gstvlcvideopool.c: VLC pictures managed by GstBufferPool
+ *****************************************************************************
+ * Copyright (C) 2016 VLC authors and VideoLAN
+ * $Id:
+ *
+ * Author: Vikram Fugro <vikram.fugro at 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;
+}
diff --git a/modules/codec/gstreamer/gstvlcvideopool.h b/modules/codec/gstreamer/gstvlcvideopool.h
new file mode 100644
index 0000000..add2dd9
--- /dev/null
+++ b/modules/codec/gstreamer/gstvlcvideopool.h
@@ -0,0 +1,68 @@
+/*****************************************************************************
+ * gstvlcvideopool.h: VLC pictures managed by GstBufferPool
+ *****************************************************************************
+ * Copyright (C) 2016 VLC authors and VideoLAN
+ * $Id:
+ *
+ * Author: Vikram Fugro <vikram.fugro at 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 __GST_VLC_VIDEO_POOL_H__
+#define __GST_VLC_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__*/
diff --git a/modules/codec/gstreamer/gstvlcvideosink.c b/modules/codec/gstreamer/gstvlcvideosink.c
new file mode 100644
index 0000000..49ac12b
--- /dev/null
+++ b/modules/codec/gstreamer/gstvlcvideosink.c
@@ -0,0 +1,326 @@
+/*****************************************************************************
+ * gstvlcvideosink.c: VLC gstreamer video sink
+ *****************************************************************************
+ * Copyright (C) 2016 VLC authors and VideoLAN
+ * $Id:
+ *
+ * Author: Vikram Fugro <vikram.fugro at 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 "gstvlcvideosink.h"
+
+#include <vlc_common.h>
+
+enum
+{
+    SIGNAL_NEW_CAPS,
+    SIGNAL_NEW_BUFFER,
+    LAST_SIGNAL
+};
+
+enum
+{
+    PROP_0,
+    PROP_ALLOCATOR,
+    PROP_ID
+};
+
+static guint gst_vlc_video_sink_signals[ LAST_SIGNAL ] = { 0 };
+
+static GstStaticPadTemplate sink_template =
+    GST_STATIC_PAD_TEMPLATE ("sink",
+        GST_PAD_SINK,
+        GST_PAD_ALWAYS,
+        GST_STATIC_CAPS ("video/x-raw, "
+            "framerate = (fraction) [ 0, MAX ], "
+            "width = (int) [ 1, MAX ], " "height = (int) [ 1, MAX ]")
+    );
+
+static gboolean gst_vlc_video_sink_setcaps( GstBaseSink *p_bsink,
+        GstCaps *p_caps );
+static gboolean gst_vlc_video_sink_propose_allocation( GstBaseSink *p_bsink,
+        GstQuery *p_query);
+static GstFlowReturn gst_vlc_video_sink_chain( GstBaseSink *p_vsink,
+        GstBuffer *p_buffer );
+
+static void gst_vlc_video_sink_set_property( GObject *p_object, guint prop_id,
+        const GValue *p_value, GParamSpec *p_pspec );
+static void gst_vlc_video_sink_get_property( GObject *p_object, guint prop_id,
+        GValue *p_value, GParamSpec *p_pspec );
+static void gst_vlc_video_sink_finalize( GObject *p_obj );
+
+#define gst_vlc_video_sink_parent_class parent_class
+G_DEFINE_TYPE( GstVlcVideoSink, gst_vlc_video_sink, GST_TYPE_BASE_SINK );
+
+static void gst_vlc_video_sink_class_init( GstVlcVideoSinkClass *p_klass )
+{
+    GObjectClass *p_gobject_class;
+    GstElementClass *p_gstelement_class;
+    GstBaseSinkClass *p_gstbasesink_class;
+
+    p_gobject_class = (GObjectClass*) p_klass;
+    p_gstelement_class = (GstElementClass*) p_klass;
+    p_gstbasesink_class = (GstBaseSinkClass*) p_klass;
+
+    p_gobject_class->set_property = gst_vlc_video_sink_set_property;
+    p_gobject_class->get_property = gst_vlc_video_sink_get_property;
+    p_gobject_class->finalize = gst_vlc_video_sink_finalize;
+
+    g_object_class_install_property( G_OBJECT_CLASS( p_klass ), PROP_ALLOCATOR,
+            g_param_spec_pointer( "allocator", "Allocator", "VlcPictureAllocator",
+                G_PARAM_READWRITE | GST_PARAM_MUTABLE_READY |
+                G_PARAM_STATIC_STRINGS ));
+
+    g_object_class_install_property( G_OBJECT_CLASS( p_klass ), PROP_ID,
+            g_param_spec_pointer( "id", "Id", "ID",
+                G_PARAM_WRITABLE | GST_PARAM_MUTABLE_READY |
+                G_PARAM_STATIC_STRINGS ));
+
+   //FIXME caps_signal: GObject signal didn't seem to work when return
+   //value is expected, so went with the native callback mechanism here.
+#if 0
+    gst_vlc_video_sink_signals[ SIGNAL_NEW_CAPS ] =
+        g_signal_new( "new-caps", G_TYPE_FROM_CLASS( p_klass ),
+                G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET( GstVlcVideoSinkClass,
+                    new_caps ), g_signal_accumulator_true_handled,
+                NULL, g_cclosure_marshal_generic,
+                G_TYPE_BOOLEAN, 1, GST_TYPE_CAPS );
+#endif
+    gst_vlc_video_sink_signals[ SIGNAL_NEW_BUFFER ] =
+        g_signal_new( "new-buffer", G_TYPE_FROM_CLASS( p_klass ),
+                G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET( GstVlcVideoSinkClass,
+                    new_buffer ), NULL, NULL, g_cclosure_marshal_generic,
+                G_TYPE_NONE, 1, GST_TYPE_BUFFER );
+
+    gst_element_class_add_pad_template( p_gstelement_class,
+            gst_static_pad_template_get( &sink_template ));
+
+    gst_element_class_set_static_metadata( p_gstelement_class,
+            "VLC Video Sink", "Sink/Video",
+            "Video Sink for VLC video decoders",
+            "Vikram Fugro <vikram.fugro at gmail.com>" );
+
+    p_gstbasesink_class->set_caps = gst_vlc_video_sink_setcaps;
+    p_gstbasesink_class->propose_allocation =
+        gst_vlc_video_sink_propose_allocation;
+
+    p_gstbasesink_class->render = gst_vlc_video_sink_chain;
+}
+
+static gboolean gst_vlc_video_sink_setcaps( GstBaseSink *p_basesink,
+        GstCaps *p_caps )
+{
+    GstVlcVideoSink *p_vsink = GST_VLC_VIDEO_SINK( p_basesink );
+    GstVideoInfo info;
+    gboolean b_ret = FALSE;
+
+   //FIXME caps_signal
+#if 0
+    GValue ret = { 0 };
+    GValue args[2] = { {0}, {0} };
+#endif
+
+    if( !gst_video_info_from_caps( &info, p_caps ))
+        return FALSE;
+
+    p_vsink->vinfo = info;
+
+    //FIXME caps_signal
+#if 0
+    g_value_init( &args[0], GST_TYPE_ELEMENT );
+    g_value_set_object( &args[0], p_vsink );
+    g_value_init( &args[1], GST_TYPE_CAPS );
+    g_value_set_boxed( &args[1], p_caps );
+
+    g_signal_emitv( args, gst_vlc_video_sink_signals[ SIGNAL_NEW_CAPS ],
+            0, &b_ret );
+#else
+    b_ret = p_vsink->new_caps( GST_ELEMENT_CAST( p_vsink ), p_caps,
+            (gpointer) p_vsink->p_dec );
+#endif
+
+    return b_ret;
+}
+
+static void gst_vlc_video_sink_init( GstVlcVideoSink *p_vlc_video_sink )
+{
+    gst_base_sink_set_sync( GST_BASE_SINK( p_vlc_video_sink), FALSE );
+}
+
+static void gst_vlc_video_sink_finalize( GObject *p_obj )
+{
+    GstVlcVideoSink *p_vsink = GST_VLC_VIDEO_SINK( p_obj );
+
+    if( p_vsink->p_allocator )
+        gst_object_unref( p_vsink->p_allocator );
+
+    G_OBJECT_CLASS( parent_class)->finalize( p_obj );
+}
+
+static GstVlcVideoPool* gst_vlc_video_sink_create_pool(
+        GstVlcVideoSink *p_vsink, GstCaps *p_caps, gsize i_size, gint i_min )
+{
+    GstVlcVideoPool *p_pool;
+    GstStructure *p_config;
+
+    p_pool = gst_vlc_video_pool_new( p_vsink->p_allocator, p_vsink->p_dec );
+
+    p_config = gst_buffer_pool_get_config( GST_BUFFER_POOL_CAST( p_pool ));
+    gst_buffer_pool_config_set_params( p_config, p_caps, i_size, i_min, 0);
+
+    if( !gst_buffer_pool_set_config( GST_BUFFER_POOL_CAST( p_pool ), p_config ))
+        goto config_failed;
+
+    return p_pool;
+
+config_failed:
+    {
+        gst_object_unref (p_pool);
+        return NULL;
+    }
+}
+
+static gboolean gst_vlc_video_sink_propose_allocation( GstBaseSink* p_bsink,
+        GstQuery* p_query )
+{
+    GstVlcVideoSink *p_vsink = GST_VLC_VIDEO_SINK( p_bsink );
+    GstCaps *p_caps;
+    gboolean b_need_pool;
+    GstBufferPool* p_pool = NULL;
+    gsize i_size;
+
+    gst_query_parse_allocation (p_query, &p_caps, &b_need_pool);
+
+    if( p_caps == NULL )
+        goto no_caps;
+
+    if( b_need_pool )
+    {
+        GstVideoInfo info;
+
+        if( !gst_video_info_from_caps( &info, p_caps ))
+            goto invalid_caps;
+
+        if( !gst_vlc_picture_plane_allocator_query_format(
+                    (GstVlcPicturePlaneAllocator*) p_vsink->p_allocator,
+                    &info, p_caps ))
+            goto invalid_format;
+
+        p_pool = (GstBufferPool*) gst_vlc_video_sink_create_pool( p_vsink,
+                p_caps, info.size, 0 );
+
+        if( p_pool == NULL )
+            goto no_pool;
+
+        i_size = info.size;
+    }
+
+    if( p_pool )
+    {
+        /* we need at least 2 buffer because we hold on to the last one */
+        gst_query_add_allocation_pool( p_query, p_pool, i_size, 2, 0);
+        gst_object_unref (p_pool);
+    }
+
+    /* we support various metadata */
+    gst_query_add_allocation_meta( p_query, GST_VIDEO_META_API_TYPE, NULL );
+
+    return TRUE;
+
+    /* ERRORS */
+no_pool:
+    {
+        msg_Err( p_vsink->p_dec, "failed to create the pool" );
+        return FALSE;
+    }
+no_caps:
+    {
+        msg_Err( p_vsink->p_dec, "no caps in allocation query" );
+        return FALSE;
+    }
+invalid_caps:
+    {
+        msg_Err( p_vsink->p_dec, "invalid caps in allocation query" );
+        return FALSE;
+    }
+invalid_format:
+    {
+        msg_Err( p_vsink->p_dec, "vout query returned invalid format" );
+        return FALSE;
+    }
+}
+
+static GstFlowReturn gst_vlc_video_sink_chain( GstBaseSink *p_bsink,
+        GstBuffer *p_buffer )
+{
+    g_signal_emit( p_bsink,
+        gst_vlc_video_sink_signals[ SIGNAL_NEW_BUFFER ], 0, p_buffer );
+
+    return GST_FLOW_OK;
+}
+
+static void gst_vlc_video_sink_set_property( GObject *p_object, guint i_prop_id,
+        const GValue *p_value, GParamSpec *p_pspec )
+{
+    GstVlcVideoSink *p_vsink = GST_VLC_VIDEO_SINK( p_object );
+
+    switch( i_prop_id )
+    {
+        case PROP_ALLOCATOR:
+        {
+            GstAllocator *p_allocator = (GstAllocator*) g_value_get_pointer(
+                    p_value );
+            if( GST_IS_VLC_PICTURE_PLANE_ALLOCATOR( p_allocator ))
+            {
+                if( p_vsink->p_allocator )
+                    gst_object_unref( p_vsink->p_allocator );
+                p_vsink->p_allocator = gst_object_ref( p_allocator );
+            } else
+                msg_Warn( p_vsink->p_dec, "Invalid Allocator set");
+        }
+        break;
+
+        case PROP_ID:
+        {
+            p_vsink->p_dec = (decoder_t*) g_value_get_pointer( p_value );
+        }
+        break;
+
+        default:
+        break;
+    }
+}
+
+static void gst_vlc_video_sink_get_property( GObject *p_object, guint i_prop_id,
+    GValue *p_value, GParamSpec *p_pspec )
+{
+    GstVlcVideoSink *p_vsink = GST_VLC_VIDEO_SINK( p_object );
+
+    switch( i_prop_id )
+    {
+        case PROP_ALLOCATOR:
+            g_value_set_pointer( p_value, p_vsink->p_allocator );
+        break;
+
+        default:
+        break;
+   }
+}
diff --git a/modules/codec/gstreamer/gstvlcvideosink.h b/modules/codec/gstreamer/gstvlcvideosink.h
new file mode 100644
index 0000000..ce0afb0
--- /dev/null
+++ b/modules/codec/gstreamer/gstvlcvideosink.h
@@ -0,0 +1,84 @@
+/*****************************************************************************
+ * gstvlcvideosink.h: VLC gstreamer video sink
+ *****************************************************************************
+ * Copyright (C) 2016 VLC authors and VideoLAN
+ * $Id:
+ *
+ * Author: Vikram Fugro <vikram.fugro at 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 __GST_VLC_VIDEO_SINK_H__
+#define __GST_VLC_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__ */
-- 
2.5.0



More information about the vlc-devel mailing list