From c6e19d5df2740aa7f940af1ff255166e619c5b00 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 13 Aug 2012 13:47:01 +0200 Subject: [PATCH] visual: add support for GstVideoFrame Add support for GstVideoMeta and GstVideoFrame. Remove some redundant fields that are also in GstVideoInfo Disable the shader code, it looks broken. Fixes https://bugzilla.gnome.org/show_bug.cgi?id=681719 --- ext/libvisual/gstaudiovisualizer.c | 399 ++++++++++++++++++++++--------------- ext/libvisual/gstaudiovisualizer.h | 13 +- ext/libvisual/visual.c | 31 +-- 3 files changed, 260 insertions(+), 183 deletions(-) diff --git a/ext/libvisual/gstaudiovisualizer.c b/ext/libvisual/gstaudiovisualizer.c index e5c188f..2a941c6 100644 --- a/ext/libvisual/gstaudiovisualizer.c +++ b/ext/libvisual/gstaudiovisualizer.c @@ -39,6 +39,10 @@ #include +#include +#include +#include + #include "gstaudiovisualizer.h" GST_DEBUG_CATEGORY_STATIC (audio_visualizer_debug); @@ -129,232 +133,315 @@ gst_audio_visualizer_shader_get_type (void) /* we're only supporting GST_VIDEO_FORMAT_xRGB right now) */ #if G_BYTE_ORDER == G_LITTLE_ENDIAN -#define SHADE1(_d, _s, _i, _r, _g, _b) \ -G_STMT_START { \ - _d[_i] = (_s[_i] > _b) ? _s[_i] - _b : 0; \ - _i++; \ - _d[_i] = (_s[_i] > _g) ? _s[_i] - _g : 0; \ - _i++; \ - _d[_i] = (_s[_i] > _r) ? _s[_i] - _r : 0; \ - _i++; \ - _d[_i++] = 0; \ -} G_STMT_END - -#define SHADE2(_d, _s, _j, _i, _r, _g, _b) \ -G_STMT_START { \ - _d[_j++] = (_s[_i] > _b) ? _s[_i] - _b : 0; \ - _i++; \ - _d[_j++] = (_s[_i] > _g) ? _s[_i] - _g : 0; \ - _i++; \ - _d[_j++] = (_s[_i] > _r) ? _s[_i] - _r : 0; \ - _i++; \ - _d[_j++] = 0; \ - _i++; \ +#define SHADE(_d, _s, _i, _r, _g, _b) \ +G_STMT_START { \ + _d[_i * 4 + 0] = (_s[_i * 4 + 0] > _b) ? _s[_i * 4 + 0] - _b : 0; \ + _d[_i * 4 + 1] = (_s[_i * 4 + 1] > _g) ? _s[_i * 4 + 1] - _g : 0; \ + _d[_i * 4 + 2] = (_s[_i * 4 + 2] > _r) ? _s[_i * 4 + 2] - _r : 0; \ + _d[_i * 4 + 3] = 0; \ } G_STMT_END -#else - -#define SHADE1(_d, _s, _i, _r, _g, _b) \ -G_STMT_START { \ - _d[_i++] = 0; \ - _d[_i] = (_s[_i] > _r) ? _s[_i] - _r : 0; \ - _i++; \ - _d[_i] = (_s[_i] > _g) ? _s[_i] - _g : 0; \ - _i++; \ - _d[_i] = (_s[_i] > _b) ? _s[_i] - _b : 0; \ - _i++; \ -} G_STMT_END +#else /* G_BYTE_ORDER == G_LITTLE_ENDIAN */ -#define SHADE2(_d, _s, _j, _i, _r, _g, _b) \ -G_STMT_START { \ - _d[_j++] = 0; \ - _i++; \ - _d[_j++] = (_s[_i] > _r) ? _s[_i] - _r : 0; \ - _i++; \ - _d[_j++] = (_s[_i] > _g) ? _s[_i] - _g : 0; \ - _i++; \ - _d[_j++] = (_s[_i] > _b) ? _s[_i] - _b : 0; \ - _i++; \ +#define SHADE(_d, _s, _i, _r, _g, _b) \ +G_STMT_START { \ + _d[_i * 4 + 0] = 0; \ + _d[_i * 4 + 1] = (_s[_i * 4 + 1] > _r) ? _s[_i * 4 + 1] - _r : 0; \ + _d[_i * 4 + 2] = (_s[_i * 4 + 2] > _g) ? _s[_i * 4 + 2] - _g : 0; \ + _d[_i * 4 + 3] = (_s[_i * 4 + 3] > _b) ? _s[_i * 4 + 3] - _b : 0; \ } G_STMT_END #endif static void -shader_fade (GstAudioVisualizer * scope, const guint8 * s, guint8 * d) +shader_fade (GstAudioVisualizer * scope, const GstVideoFrame * sframe, + GstVideoFrame * dframe) { - guint i, bpf = scope->bpf; + guint i, j; guint r = (scope->shade_amount >> 16) & 0xff; guint g = (scope->shade_amount >> 8) & 0xff; guint b = (scope->shade_amount >> 0) & 0xff; + guint8 *s, *d; + gint ss, ds, width, height; - for (i = 0; i < bpf;) { - SHADE1 (d, s, i, r, g, b); + s = GST_VIDEO_FRAME_PLANE_DATA (sframe, 0); + ss = GST_VIDEO_FRAME_PLANE_STRIDE (sframe, 0); + d = GST_VIDEO_FRAME_PLANE_DATA (dframe, 0); + ds = GST_VIDEO_FRAME_PLANE_STRIDE (dframe, 0); + + width = GST_VIDEO_FRAME_WIDTH (sframe); + height = GST_VIDEO_FRAME_HEIGHT (sframe); + + for (j = 0; j < height; j++) { + for (i = 0; i < width; i++) { + SHADE (d, s, i, r, g, b); + } + s += ss; + d += ds; } } static void -shader_fade_and_move_up (GstAudioVisualizer * scope, const guint8 * s, - guint8 * d) +shader_fade_and_move_up (GstAudioVisualizer * scope, + const GstVideoFrame * sframe, GstVideoFrame * dframe) { - guint i, j, bpf = scope->bpf; - guint bpl = 4 * scope->width; + guint i, j; guint r = (scope->shade_amount >> 16) & 0xff; guint g = (scope->shade_amount >> 8) & 0xff; guint b = (scope->shade_amount >> 0) & 0xff; + guint8 *s, *d; + gint ss, ds, width, height; - for (j = 0, i = bpl; i < bpf;) { - SHADE2 (d, s, j, i, r, g, b); + s = GST_VIDEO_FRAME_PLANE_DATA (sframe, 0); + ss = GST_VIDEO_FRAME_PLANE_STRIDE (sframe, 0); + d = GST_VIDEO_FRAME_PLANE_DATA (dframe, 0); + ds = GST_VIDEO_FRAME_PLANE_STRIDE (dframe, 0); + + width = GST_VIDEO_FRAME_WIDTH (sframe); + height = GST_VIDEO_FRAME_HEIGHT (sframe); + + for (j = 1; j < height; j++) { + s += ss; + for (i = 0; i < width; i++) { + SHADE (d, s, i, r, g, b); + } + d += ds; } } static void -shader_fade_and_move_down (GstAudioVisualizer * scope, const guint8 * s, - guint8 * d) +shader_fade_and_move_down (GstAudioVisualizer * scope, + const GstVideoFrame * sframe, GstVideoFrame * dframe) { - guint i, j, bpf = scope->bpf; - guint bpl = 4 * scope->width; + guint i, j; guint r = (scope->shade_amount >> 16) & 0xff; guint g = (scope->shade_amount >> 8) & 0xff; guint b = (scope->shade_amount >> 0) & 0xff; + guint8 *s, *d; + gint ss, ds, width, height; - for (j = bpl, i = 0; j < bpf;) { - SHADE2 (d, s, j, i, r, g, b); + s = GST_VIDEO_FRAME_PLANE_DATA (sframe, 0); + ss = GST_VIDEO_FRAME_PLANE_STRIDE (sframe, 0); + d = GST_VIDEO_FRAME_PLANE_DATA (dframe, 0); + ds = GST_VIDEO_FRAME_PLANE_STRIDE (dframe, 0); + + width = GST_VIDEO_FRAME_WIDTH (sframe); + height = GST_VIDEO_FRAME_HEIGHT (sframe); + + for (j = 1; j < height; j++) { + d += ds; + for (i = 0; i < width; i++) { + SHADE (d, s, i, r, g, b); + } + s += ss; } } static void shader_fade_and_move_left (GstAudioVisualizer * scope, - const guint8 * s, guint8 * d) + const GstVideoFrame * sframe, GstVideoFrame * dframe) { - guint i, j, k, bpf = scope->bpf; - guint w = scope->width; + guint i, j; guint r = (scope->shade_amount >> 16) & 0xff; guint g = (scope->shade_amount >> 8) & 0xff; guint b = (scope->shade_amount >> 0) & 0xff; + guint8 *s, *d; + gint ss, ds, width, height; + + s = GST_VIDEO_FRAME_PLANE_DATA (sframe, 0); + ss = GST_VIDEO_FRAME_PLANE_STRIDE (sframe, 0); + d = GST_VIDEO_FRAME_PLANE_DATA (dframe, 0); + ds = GST_VIDEO_FRAME_PLANE_STRIDE (dframe, 0); + + width = GST_VIDEO_FRAME_WIDTH (sframe); + height = GST_VIDEO_FRAME_HEIGHT (sframe); + + width -= 1; + s += 4; /* move to the left */ - for (j = 0, i = 4; i < bpf;) { - for (k = 0; k < w - 1; k++) { - SHADE2 (d, s, j, i, r, g, b); + for (j = 0; j < height; j++) { + for (i = 0; i < width; i++) { + SHADE (d, s, i, r, g, b); } - i += 4; - j += 4; + d += ds; + s += ss; } } static void shader_fade_and_move_right (GstAudioVisualizer * scope, - const guint8 * s, guint8 * d) + const GstVideoFrame * sframe, GstVideoFrame * dframe) { - guint i, j, k, bpf = scope->bpf; - guint w = scope->width; + guint i, j; guint r = (scope->shade_amount >> 16) & 0xff; guint g = (scope->shade_amount >> 8) & 0xff; guint b = (scope->shade_amount >> 0) & 0xff; + guint8 *s, *d; + gint ss, ds, width, height; - /* move to the left */ - for (j = 4, i = 0; i < bpf;) { - for (k = 0; k < w - 1; k++) { - SHADE2 (d, s, j, i, r, g, b); + s = GST_VIDEO_FRAME_PLANE_DATA (sframe, 0); + ss = GST_VIDEO_FRAME_PLANE_STRIDE (sframe, 0); + d = GST_VIDEO_FRAME_PLANE_DATA (dframe, 0); + ds = GST_VIDEO_FRAME_PLANE_STRIDE (dframe, 0); + + width = GST_VIDEO_FRAME_WIDTH (sframe); + height = GST_VIDEO_FRAME_HEIGHT (sframe); + + width -= 1; + d += 4; + + /* move to the right */ + for (j = 0; j < height; j++) { + for (i = 0; i < width; i++) { + SHADE (d, s, i, r, g, b); } - i += 4; - j += 4; + d += ds; + s += ss; } } static void shader_fade_and_move_horiz_out (GstAudioVisualizer * scope, - const guint8 * s, guint8 * d) + const GstVideoFrame * sframe, GstVideoFrame * dframe) { - guint i, j, bpf = scope->bpf / 2; - guint bpl = 4 * scope->width; + guint i, j; guint r = (scope->shade_amount >> 16) & 0xff; guint g = (scope->shade_amount >> 8) & 0xff; guint b = (scope->shade_amount >> 0) & 0xff; + guint8 *s, *d; + gint ss, ds, width, height; + + s = GST_VIDEO_FRAME_PLANE_DATA (sframe, 0); + ss = GST_VIDEO_FRAME_PLANE_STRIDE (sframe, 0); + d = GST_VIDEO_FRAME_PLANE_DATA (dframe, 0); + ds = GST_VIDEO_FRAME_PLANE_STRIDE (dframe, 0); + + width = GST_VIDEO_FRAME_WIDTH (sframe); + height = GST_VIDEO_FRAME_HEIGHT (sframe); /* move upper half up */ - for (j = 0, i = bpl; i < bpf;) { - SHADE2 (d, s, j, i, r, g, b); + for (j = 0; j < height / 2; j++) { + s += ss; + for (i = 0; i < width; i++) { + SHADE (d, s, i, r, g, b); + } + d += ds; } /* move lower half down */ - for (j = bpf + bpl, i = bpf; j < bpf + bpf;) { - SHADE2 (d, s, j, i, r, g, b); + for (j = 0; j < height / 2; j++) { + d += ds; + for (i = 0; i < width; i++) { + SHADE (d, s, i, r, g, b); + } + s += ss; } } static void shader_fade_and_move_horiz_in (GstAudioVisualizer * scope, - const guint8 * s, guint8 * d) + const GstVideoFrame * sframe, GstVideoFrame * dframe) { - guint i, j, bpf = scope->bpf / 2; - guint bpl = 4 * scope->width; + guint i, j; guint r = (scope->shade_amount >> 16) & 0xff; guint g = (scope->shade_amount >> 8) & 0xff; guint b = (scope->shade_amount >> 0) & 0xff; + guint8 *s, *d; + gint ss, ds, width, height; + + s = GST_VIDEO_FRAME_PLANE_DATA (sframe, 0); + ss = GST_VIDEO_FRAME_PLANE_STRIDE (sframe, 0); + d = GST_VIDEO_FRAME_PLANE_DATA (dframe, 0); + ds = GST_VIDEO_FRAME_PLANE_STRIDE (dframe, 0); + + width = GST_VIDEO_FRAME_WIDTH (sframe); + height = GST_VIDEO_FRAME_HEIGHT (sframe); /* move upper half down */ - for (i = 0, j = bpl; i < bpf;) { - SHADE2 (d, s, j, i, r, g, b); + for (j = 0; j < height / 2; j++) { + d += ds; + for (i = 0; i < width; i++) { + SHADE (d, s, i, r, g, b); + } + s += ss; } /* move lower half up */ - for (i = bpf + bpl, j = bpf; i < bpf + bpf;) { - SHADE2 (d, s, j, i, r, g, b); + for (j = 0; j < height / 2; j++) { + s += ss; + for (i = 0; i < width; i++) { + SHADE (d, s, i, r, g, b); + } + d += ds; } } static void shader_fade_and_move_vert_out (GstAudioVisualizer * scope, - const guint8 * s, guint8 * d) + const GstVideoFrame * sframe, GstVideoFrame * dframe) { - guint i, j, k, bpf = scope->bpf; - guint m = scope->width / 2; + guint i, j; guint r = (scope->shade_amount >> 16) & 0xff; guint g = (scope->shade_amount >> 8) & 0xff; guint b = (scope->shade_amount >> 0) & 0xff; - - /* move left half to the left */ - for (j = 0, i = 4; i < bpf;) { - for (k = 0; k < m; k++) { - SHADE2 (d, s, j, i, r, g, b); + guint8 *s, *s1, *d, *d1; + gint ss, ds, width, height; + + s = GST_VIDEO_FRAME_PLANE_DATA (sframe, 0); + ss = GST_VIDEO_FRAME_PLANE_STRIDE (sframe, 0); + d = GST_VIDEO_FRAME_PLANE_DATA (dframe, 0); + ds = GST_VIDEO_FRAME_PLANE_STRIDE (dframe, 0); + + width = GST_VIDEO_FRAME_WIDTH (sframe); + height = GST_VIDEO_FRAME_HEIGHT (sframe); + + for (j = 0; j < height; j++) { + /* move left half to the left */ + s1 = s + 1; + for (i = 0; i < width / 2; i++) { + SHADE (d, s1, i, r, g, b); } - j += 4 * m; - i += 4 * m; - } - /* move right half to the right */ - for (j = 4 * (m + 1), i = 4 * m; j < bpf;) { - for (k = 0; k < m; k++) { - SHADE2 (d, s, j, i, r, g, b); + /* move right half to the right */ + d1 = d + 1; + for (; i < width - 1; i++) { + SHADE (d1, s, i, r, g, b); } - j += 4 * m; - i += 4 * m; + s += ss; + d += ds; } } static void shader_fade_and_move_vert_in (GstAudioVisualizer * scope, - const guint8 * s, guint8 * d) + const GstVideoFrame * sframe, GstVideoFrame * dframe) { - guint i, j, k, bpf = scope->bpf; - guint m = scope->width / 2; + guint i, j; guint r = (scope->shade_amount >> 16) & 0xff; guint g = (scope->shade_amount >> 8) & 0xff; guint b = (scope->shade_amount >> 0) & 0xff; - - /* move left half to the right */ - for (j = 4, i = 0; j < bpf;) { - for (k = 0; k < m; k++) { - SHADE2 (d, s, j, i, r, g, b); + guint8 *s, *s1, *d, *d1; + gint ss, ds, width, height; + + s = GST_VIDEO_FRAME_PLANE_DATA (sframe, 0); + ss = GST_VIDEO_FRAME_PLANE_STRIDE (sframe, 0); + d = GST_VIDEO_FRAME_PLANE_DATA (dframe, 0); + ds = GST_VIDEO_FRAME_PLANE_STRIDE (dframe, 0); + + width = GST_VIDEO_FRAME_WIDTH (sframe); + height = GST_VIDEO_FRAME_HEIGHT (sframe); + + for (j = 0; j < height; j++) { + /* move left half to the right */ + d1 = d + 1; + for (i = 0; i < width / 2; i++) { + SHADE (d1, s, i, r, g, b); } - j += 4 * m; - i += 4 * m; - } - /* move right half to the left */ - for (j = 4 * m, i = 4 * (m + 1); i < bpf;) { - for (k = 0; k < m; k++) { - SHADE2 (d, s, j, i, r, g, b); + /* move right half to the left */ + s1 = s + 1; + for (; i < width - 1; i++) { + SHADE (d, s1, i, r, g, b); } - j += 4 * m; - i += 4 * m; + s += ss; + d += ds; } } @@ -497,10 +584,7 @@ gst_audio_visualizer_init (GstAudioVisualizer * scope, scope->shade_amount = DEFAULT_SHADE_AMOUNT; /* reset the initial video state */ - scope->width = 320; - scope->height = 200; - scope->fps_n = 25; /* desired frame rate */ - scope->fps_d = 1; + gst_video_info_init (&scope->vinfo); scope->frame_duration = GST_CLOCK_TIME_NONE; /* reset the initial state */ @@ -616,41 +700,31 @@ gst_audio_visualizer_src_setcaps (GstAudioVisualizer * scope, GstCaps * caps) { GstVideoInfo info; GstAudioVisualizerClass *klass; - GstStructure *structure; gboolean res; if (!gst_video_info_from_caps (&info, caps)) goto wrong_caps; - structure = gst_caps_get_structure (caps, 0); - if (!gst_structure_get_int (structure, "width", &scope->width) || - !gst_structure_get_int (structure, "height", &scope->height) || - !gst_structure_get_fraction (structure, "framerate", &scope->fps_n, - &scope->fps_d)) - goto wrong_caps; - klass = GST_AUDIO_VISUALIZER_CLASS (G_OBJECT_GET_CLASS (scope)); scope->vinfo = info; - scope->video_format = info.finfo->format; scope->frame_duration = gst_util_uint64_scale_int (GST_SECOND, - scope->fps_d, scope->fps_n); + GST_VIDEO_INFO_FPS_D (&info), GST_VIDEO_INFO_FPS_N (&info)); scope->spf = gst_util_uint64_scale_int (GST_AUDIO_INFO_RATE (&scope->ainfo), - scope->fps_d, scope->fps_n); + GST_VIDEO_INFO_FPS_D (&info), GST_VIDEO_INFO_FPS_N (&info)); scope->req_spf = scope->spf; - scope->bpf = scope->width * scope->height * 4; - if (scope->pixelbuf) g_free (scope->pixelbuf); - scope->pixelbuf = g_malloc0 (scope->bpf); + scope->pixelbuf = g_malloc0 (info.size); if (klass->setup) res = klass->setup (scope); GST_DEBUG_OBJECT (scope, "video: dimension %dx%d, framerate %d/%d", - scope->width, scope->height, scope->fps_n, scope->fps_d); + GST_VIDEO_INFO_WIDTH (&info), GST_VIDEO_INFO_HEIGHT (&info), + GST_VIDEO_INFO_FPS_N (&info), GST_VIDEO_INFO_FPS_D (&info)); GST_DEBUG_OBJECT (scope, "blocks: spf %u, req_spf %u", scope->spf, scope->req_spf); @@ -698,10 +772,9 @@ gst_audio_visualizer_src_negotiate (GstAudioVisualizer * scope) target = gst_caps_make_writable (target); structure = gst_caps_get_structure (target, 0); - gst_structure_fixate_field_nearest_int (structure, "width", scope->width); - gst_structure_fixate_field_nearest_int (structure, "height", scope->height); - gst_structure_fixate_field_nearest_fraction (structure, "framerate", - scope->fps_n, scope->fps_d); + gst_structure_fixate_field_nearest_int (structure, "width", 320); + gst_structure_fixate_field_nearest_int (structure, "height", 200); + gst_structure_fixate_field_nearest_fraction (structure, "framerate", 25, 1); target = gst_caps_fixate (target); @@ -723,16 +796,17 @@ gst_audio_visualizer_src_negotiate (GstAudioVisualizer * scope) gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max); } else { pool = NULL; - size = scope->bpf; + size = 0; min = max = 0; } if (pool == NULL) { /* we did not get a pool, make one ourselves then */ - pool = gst_buffer_pool_new (); + pool = gst_video_buffer_pool_new (); } config = gst_buffer_pool_get_config (pool); + gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META); gst_buffer_pool_config_set_params (config, target, size, min, max); gst_buffer_pool_set_config (pool, config); @@ -826,7 +900,7 @@ gst_audio_visualizer_chain (GstPad * pad, GstObject * parent, GST_LOG_OBJECT (scope, "avail: %u, bpf: %u", avail, sbpf); while (avail >= sbpf) { GstBuffer *outbuf; - GstMapInfo map; + GstVideoFrame outframe; /* get timestamp of the current adapter content */ ts = gst_adapter_prev_timestamp (scope->adapter, &dist); @@ -873,16 +947,20 @@ gst_audio_visualizer_chain (GstPad * pad, GstObject * parent, GST_BUFFER_TIMESTAMP (outbuf) = ts; GST_BUFFER_DURATION (outbuf) = scope->frame_duration; - gst_buffer_map (outbuf, &map, GST_MAP_WRITE); + /* this can fail as the data size we need could have changed */ + if (!(adata = (gpointer) gst_adapter_map (scope->adapter, sbpf))) + break; + + gst_video_frame_map (&outframe, &scope->vinfo, outbuf, GST_MAP_READWRITE); + +#if 0 + /* FIXME? copy uninitialized memory into the destination buffer? */ if (scope->shader) { memcpy (map.data, scope->pixelbuf, scope->bpf); } else { memset (map.data, 0, scope->bpf); } - - /* this can fail as the data size we need could have changed */ - if (!(adata = (gpointer) gst_adapter_map (scope->adapter, sbpf))) - break; +#endif gst_buffer_replace_all_memory (inbuf, gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY, adata, sbpf, 0, @@ -890,18 +968,19 @@ gst_audio_visualizer_chain (GstPad * pad, GstObject * parent, /* call class->render() vmethod */ if (klass->render) { - if (!klass->render (scope, inbuf, outbuf)) { + if (!klass->render (scope, inbuf, &outframe)) { ret = GST_FLOW_ERROR; } else { +#if 0 + /* FIXME, dest and source reversed? */ /* run various post processing (shading and geometri transformation */ if (scope->shader) { - scope->shader (scope, map.data, scope->pixelbuf); + scope->shader (scope, outframe, scope->pixelbuf); } +#endif } } - - gst_buffer_unmap (outbuf, &map); - gst_buffer_resize (outbuf, 0, scope->bpf); + gst_video_frame_unmap (&outframe); g_mutex_unlock (&scope->config_lock); ret = gst_pad_push (scope->srcpad, outbuf); diff --git a/ext/libvisual/gstaudiovisualizer.h b/ext/libvisual/gstaudiovisualizer.h index efe3a8c..7c32b85 100644 --- a/ext/libvisual/gstaudiovisualizer.h +++ b/ext/libvisual/gstaudiovisualizer.h @@ -37,7 +37,7 @@ G_BEGIN_DECLS typedef struct _GstAudioVisualizer GstAudioVisualizer; typedef struct _GstAudioVisualizerClass GstAudioVisualizerClass; -typedef void (*GstAudioVisualizerShaderFunc)(GstAudioVisualizer *scope, const guint8 *s, guint8 *d); +typedef void (*GstAudioVisualizerShaderFunc)(GstAudioVisualizer *scope, const GstVideoFrame *s, GstVideoFrame *d); /** * GstAudioVisualizerShader: @@ -88,23 +88,18 @@ struct _GstAudioVisualizer /* video state */ GstVideoInfo vinfo; - GstVideoFormat video_format; - gint fps_n, fps_d; - gint width; - gint height; guint64 frame_duration; - guint bpf; /* bytes per frame */ /* audio state */ GstAudioInfo ainfo; /* configuration mutex */ GMutex config_lock; - + /* QoS stuff *//* with LOCK */ gdouble proportion; GstClockTime earliest_time; - + GstSegment segment; }; @@ -116,7 +111,7 @@ struct _GstAudioVisualizerClass gboolean (*setup) (GstAudioVisualizer * scope); /* virtual function for rendering a frame */ - gboolean (*render) (GstAudioVisualizer * scope, GstBuffer * audio, GstBuffer * video); + gboolean (*render) (GstAudioVisualizer * scope, GstBuffer * audio, GstVideoFrame * video); }; GType gst_audio_visualizer_get_type (void); diff --git a/ext/libvisual/visual.c b/ext/libvisual/visual.c index 5afa774..c928b8d 100644 --- a/ext/libvisual/visual.c +++ b/ext/libvisual/visual.c @@ -62,7 +62,7 @@ static void gst_visual_finalize (GObject * object); static gboolean gst_visual_setup (GstAudioVisualizer * bscope); static gboolean gst_visual_render (GstAudioVisualizer * bscope, - GstBuffer * audio, GstBuffer * video); + GstBuffer * audio, GstVideoFrame * video); static GstElementClass *parent_class = NULL; @@ -163,7 +163,7 @@ static gboolean gst_visual_setup (GstAudioVisualizer * bscope) { GstVisual *visual = GST_VISUAL (bscope); - gint pitch, depth; + gint depth; gst_visual_clear_actors (visual); @@ -188,13 +188,14 @@ gst_visual_setup (GstAudioVisualizer * bscope) visual_video_set_depth (visual->video, visual_video_depth_enum_from_value (depth)); - visual_video_set_dimension (visual->video, bscope->width, bscope->height); - pitch = GST_ROUND_UP_4 (bscope->width * visual->video->bpp); - visual_video_set_pitch (visual->video, pitch); + visual_video_set_dimension (visual->video, + GST_VIDEO_INFO_WIDTH (&bscope->vinfo), + GST_VIDEO_INFO_HEIGHT (&bscope->vinfo)); visual_actor_video_negotiate (visual->actor, 0, FALSE, FALSE); - GST_DEBUG_OBJECT (visual, "WxH: %dx%d, bpp: %d, pitch: %d, depth: %d", - bscope->width, bscope->height, visual->video->bpp, pitch, depth); + GST_DEBUG_OBJECT (visual, "WxH: %dx%d, bpp: %d, depth: %d", + GST_VIDEO_INFO_WIDTH (&bscope->vinfo), + GST_VIDEO_INFO_HEIGHT (&bscope->vinfo), visual->video->bpp, depth); return TRUE; /* ERRORS */ @@ -216,20 +217,22 @@ no_realize: static gboolean gst_visual_render (GstAudioVisualizer * bscope, GstBuffer * audio, - GstBuffer * video) + GstVideoFrame * video) { GstVisual *visual = GST_VISUAL (bscope); - GstMapInfo amap, vmap; + GstMapInfo amap; const guint16 *adata; gint i, channels; gboolean res = TRUE; - gst_buffer_map (audio, &amap, GST_MAP_READ); - gst_buffer_map (video, &vmap, GST_MAP_WRITE); - - visual_video_set_buffer (visual->video, vmap.data); + visual_video_set_buffer (visual->video, GST_VIDEO_FRAME_PLANE_DATA (video, + 0)); + visual_video_set_pitch (visual->video, GST_VIDEO_FRAME_PLANE_STRIDE (video, + 0)); channels = GST_AUDIO_INFO_CHANNELS (&bscope->ainfo); + + gst_buffer_map (audio, &amap, GST_MAP_READ); adata = (const guint16 *) amap.data; #if defined(VISUAL_API_VERSION) && VISUAL_API_VERSION >= 4000 && VISUAL_API_VERSION < 5000 @@ -318,7 +321,7 @@ gst_visual_render (GstAudioVisualizer * bscope, GstBuffer * audio, GST_DEBUG_OBJECT (visual, "rendered one frame"); done: - gst_buffer_unmap (video, &vmap); gst_buffer_unmap (audio, &amap); + return res; } -- 2.7.4