gdkpixbufsink: port to 0.11

This commit is contained in:
Mark Nauwelaerts 2012-02-29 22:28:01 +01:00
parent 84881b5399
commit 06bf7481b1
3 changed files with 43 additions and 39 deletions

View file

@ -314,7 +314,7 @@ dnl Make sure you have a space before and after all plugins
GST_PLUGINS_NONPORTED="deinterlace interleave flx \ GST_PLUGINS_NONPORTED="deinterlace interleave flx \
imagefreeze smpte \ imagefreeze smpte \
videobox \ videobox \
cairo cairo_gobject dv1394 gdk_pixbuf \ cairo cairo_gobject dv1394 \
oss oss4 \ oss oss4 \
wavpack \ wavpack \
osx_video osx_audio " osx_video osx_audio "

View file

@ -110,8 +110,7 @@ enum
}; };
GST_BOILERPLATE (GstGdkPixbufSink, gst_gdk_pixbuf_sink, GstVideoSink, G_DEFINE_TYPE (GstGdkPixbufSink, gst_gdk_pixbuf_sink, GST_TYPE_VIDEO_SINK);
GST_TYPE_VIDEO_SINK);
static void gst_gdk_pixbuf_sink_set_property (GObject * object, guint prop_id, static void gst_gdk_pixbuf_sink_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec); const GValue * value, GParamSpec * pspec);
@ -129,18 +128,20 @@ static GstFlowReturn gst_gdk_pixbuf_sink_preroll (GstBaseSink * bsink,
static GdkPixbuf *gst_gdk_pixbuf_sink_get_pixbuf_from_buffer (GstGdkPixbufSink * static GdkPixbuf *gst_gdk_pixbuf_sink_get_pixbuf_from_buffer (GstGdkPixbufSink *
sink, GstBuffer * buf); sink, GstBuffer * buf);
#define WxH ", width = (int) [ 16, 4096 ], height = (int) [ 16, 4096 ]"
static GstStaticPadTemplate pixbufsink_sink_factory = static GstStaticPadTemplate pixbufsink_sink_factory =
GST_STATIC_PAD_TEMPLATE ("sink", GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK, GST_PAD_SINK,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB WxH ";" GST_VIDEO_CAPS_RGBA WxH)); GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("RGB") ";"
GST_VIDEO_CAPS_MAKE ("RGBA"))
);
static void static void
gst_gdk_pixbuf_sink_base_init (gpointer g_class) gst_gdk_pixbuf_sink_class_init (GstGdkPixbufSinkClass * klass)
{ {
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); GstBaseSinkClass *basesink_class = GST_BASE_SINK_CLASS (klass);
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gst_element_class_set_details_simple (element_class, "GdkPixbuf sink", gst_element_class_set_details_simple (element_class, "GdkPixbuf sink",
"Sink/Video", "Output images as GdkPixbuf objects in bus messages", "Sink/Video", "Output images as GdkPixbuf objects in bus messages",
@ -148,13 +149,6 @@ gst_gdk_pixbuf_sink_base_init (gpointer g_class)
gst_element_class_add_pad_template (element_class, gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&pixbufsink_sink_factory)); gst_static_pad_template_get (&pixbufsink_sink_factory));
}
static void
gst_gdk_pixbuf_sink_class_init (GstGdkPixbufSinkClass * klass)
{
GstBaseSinkClass *basesink_class = GST_BASE_SINK_CLASS (klass);
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->set_property = gst_gdk_pixbuf_sink_set_property; gobject_class->set_property = gst_gdk_pixbuf_sink_set_property;
gobject_class->get_property = gst_gdk_pixbuf_sink_get_property; gobject_class->get_property = gst_gdk_pixbuf_sink_get_property;
@ -190,8 +184,7 @@ gst_gdk_pixbuf_sink_class_init (GstGdkPixbufSinkClass * klass)
} }
static void static void
gst_gdk_pixbuf_sink_init (GstGdkPixbufSink * sink, gst_gdk_pixbuf_sink_init (GstGdkPixbufSink * sink)
GstGdkPixbufSinkClass * klass)
{ {
sink->par_n = 0; sink->par_n = 0;
sink->par_d = 0; sink->par_d = 0;
@ -240,46 +233,51 @@ static gboolean
gst_gdk_pixbuf_sink_set_caps (GstBaseSink * basesink, GstCaps * caps) gst_gdk_pixbuf_sink_set_caps (GstBaseSink * basesink, GstCaps * caps)
{ {
GstGdkPixbufSink *sink = GST_GDK_PIXBUF_SINK (basesink); GstGdkPixbufSink *sink = GST_GDK_PIXBUF_SINK (basesink);
GstVideoInfo info;
GstVideoFormat fmt; GstVideoFormat fmt;
gint w, h, par_n, par_d; gint w, h, s, par_n, par_d;
GST_LOG_OBJECT (sink, "caps: %" GST_PTR_FORMAT, caps); GST_LOG_OBJECT (sink, "caps: %" GST_PTR_FORMAT, caps);
if (!gst_video_format_parse_caps (caps, &fmt, &w, &h)) { if (!gst_video_info_from_caps (&info, caps)) {
GST_WARNING_OBJECT (sink, "parse_caps failed"); GST_WARNING_OBJECT (sink, "parse_caps failed");
return FALSE; return FALSE;
} }
if (!gst_video_parse_caps_pixel_aspect_ratio (caps, &par_n, &par_d)) { fmt = GST_VIDEO_INFO_FORMAT (&info);
GST_LOG_OBJECT (sink, "no pixel aspect ratio"); w = GST_VIDEO_INFO_WIDTH (&info);
return FALSE; h = GST_VIDEO_INFO_HEIGHT (&info);
} s = GST_VIDEO_INFO_COMP_PSTRIDE (&info, 0);
par_n = GST_VIDEO_INFO_PAR_N (&info);
par_d = GST_VIDEO_INFO_PAR_N (&info);
g_assert ((fmt == GST_VIDEO_FORMAT_RGB && g_assert ((fmt == GST_VIDEO_FORMAT_RGB && s == 3) ||
gst_video_format_get_pixel_stride (fmt, 0) == 3) || (fmt == GST_VIDEO_FORMAT_RGBA && s == 4));
(fmt == GST_VIDEO_FORMAT_RGBA &&
gst_video_format_get_pixel_stride (fmt, 0) == 4));
GST_VIDEO_SINK_WIDTH (sink) = w; GST_VIDEO_SINK_WIDTH (sink) = w;
GST_VIDEO_SINK_HEIGHT (sink) = h; GST_VIDEO_SINK_HEIGHT (sink) = h;
sink->rowstride = gst_video_format_get_row_stride (fmt, 0, w);
sink->has_alpha = (fmt == GST_VIDEO_FORMAT_RGBA);
sink->par_n = par_n; sink->par_n = par_n;
sink->par_d = par_d; sink->par_d = par_d;
sink->has_alpha = GST_VIDEO_INFO_HAS_ALPHA (&info);
GST_INFO_OBJECT (sink, "format : %d", fmt); GST_INFO_OBJECT (sink, "format : %d", fmt);
GST_INFO_OBJECT (sink, "width x height : %d x %d", w, h); GST_INFO_OBJECT (sink, "width x height : %d x %d", w, h);
GST_INFO_OBJECT (sink, "pixel-aspect-ratio : %d/%d", par_n, par_d); GST_INFO_OBJECT (sink, "pixel-aspect-ratio : %d/%d", par_n, par_d);
sink->info = info;
return TRUE; return TRUE;
} }
static void static void
gst_gdk_pixbuf_sink_pixbuf_destroy_notify (guchar * pixels, GstBuffer * buf) gst_gdk_pixbuf_sink_pixbuf_destroy_notify (guchar * pixels,
GstVideoFrame * frame)
{ {
gst_buffer_unref (buf); gst_video_frame_unmap (frame);
gst_buffer_unref (frame->buffer);
g_slice_free (GstVideoFrame, frame);
} }
static GdkPixbuf * static GdkPixbuf *
@ -287,24 +285,30 @@ gst_gdk_pixbuf_sink_get_pixbuf_from_buffer (GstGdkPixbufSink * sink,
GstBuffer * buf) GstBuffer * buf)
{ {
GdkPixbuf *pix = NULL; GdkPixbuf *pix = NULL;
GstVideoFrame *frame;
gint minsize, bytes_per_pixel; gint minsize, bytes_per_pixel;
g_return_val_if_fail (GST_VIDEO_SINK_WIDTH (sink) > 0, NULL); g_return_val_if_fail (GST_VIDEO_SINK_WIDTH (sink) > 0, NULL);
g_return_val_if_fail (GST_VIDEO_SINK_HEIGHT (sink) > 0, NULL); g_return_val_if_fail (GST_VIDEO_SINK_HEIGHT (sink) > 0, NULL);
frame = g_slice_new0 (GstVideoFrame);
gst_video_frame_map (frame, &sink->info, buf, GST_MAP_READ);
bytes_per_pixel = (sink->has_alpha) ? 4 : 3; bytes_per_pixel = (sink->has_alpha) ? 4 : 3;
/* last row needn't have row padding */ /* last row needn't have row padding */
minsize = (sink->rowstride * (GST_VIDEO_SINK_HEIGHT (sink) - 1)) + minsize = (GST_VIDEO_FRAME_COMP_STRIDE (frame, 0) *
(GST_VIDEO_SINK_HEIGHT (sink) - 1)) +
(bytes_per_pixel * GST_VIDEO_SINK_WIDTH (sink)); (bytes_per_pixel * GST_VIDEO_SINK_WIDTH (sink));
g_return_val_if_fail (GST_BUFFER_SIZE (buf) >= minsize, NULL); g_return_val_if_fail (gst_buffer_get_size (buf) >= minsize, NULL);
pix = gdk_pixbuf_new_from_data (GST_BUFFER_DATA (buf), gst_buffer_ref (buf);
pix = gdk_pixbuf_new_from_data (GST_VIDEO_FRAME_COMP_DATA (frame, 0),
GDK_COLORSPACE_RGB, sink->has_alpha, 8, GST_VIDEO_SINK_WIDTH (sink), GDK_COLORSPACE_RGB, sink->has_alpha, 8, GST_VIDEO_SINK_WIDTH (sink),
GST_VIDEO_SINK_HEIGHT (sink), sink->rowstride, GST_VIDEO_SINK_HEIGHT (sink), GST_VIDEO_FRAME_COMP_STRIDE (frame, 0),
(GdkPixbufDestroyNotify) gst_gdk_pixbuf_sink_pixbuf_destroy_notify, (GdkPixbufDestroyNotify) gst_gdk_pixbuf_sink_pixbuf_destroy_notify,
gst_buffer_ref (buf)); frame);
return pix; return pix;
} }

View file

@ -21,7 +21,7 @@
#define GST_GDK_PIXBUF_SINK_H #define GST_GDK_PIXBUF_SINK_H
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/video/video.h>
#include <gst/video/gstvideosink.h> #include <gst/video/gstvideosink.h>
#include <gdk-pixbuf/gdk-pixbuf.h> #include <gdk-pixbuf/gdk-pixbuf.h>
@ -47,9 +47,9 @@ struct _GstGdkPixbufSink
/*< private >*/ /*< private >*/
/* current caps */ /* current caps */
GstVideoInfo info;
gint width; gint width;
gint height; gint height;
gint rowstride;
gint par_n; gint par_n;
gint par_d; gint par_d;
gboolean has_alpha; gboolean has_alpha;