libvisual: clean dereferences of private structures

https://bugzilla.gnome.org/show_bug.cgi?id=742875
This commit is contained in:
Luis de Bethencourt 2015-06-07 18:49:48 +01:00
parent 380d68fbe5
commit 7423eafa85

View file

@ -1,5 +1,6 @@
/* GStreamer /* GStreamer
* Copyright (C) <2011> Stefan Kost <ensonic@users.sf.net> * Copyright (C) <2011> Stefan Kost <ensonic@users.sf.net>
* Copyright (C) <2015> Luis de Bethencourt <luis@debethencourt.com>
* *
* gstaudiovisualizer.h: base class for audio visualisation elements * gstaudiovisualizer.h: base class for audio visualisation elements
* *
@ -201,9 +202,10 @@ shader_fade (GstAudioVisualizer * scope, const GstVideoFrame * sframe,
GstVideoFrame * dframe) GstVideoFrame * dframe)
{ {
guint i, j; guint i, j;
guint r = (scope->priv->shade_amount >> 16) & 0xff; guint32 shade_amount = scope->priv->shade_amount;
guint g = (scope->priv->shade_amount >> 8) & 0xff; guint r = (shade_amount >> 16) & 0xff;
guint b = (scope->priv->shade_amount >> 0) & 0xff; guint g = (shade_amount >> 8) & 0xff;
guint b = (shade_amount >> 0) & 0xff;
guint8 *s, *d; guint8 *s, *d;
gint ss, ds, width, height; gint ss, ds, width, height;
@ -229,9 +231,10 @@ shader_fade_and_move_up (GstAudioVisualizer * scope,
const GstVideoFrame * sframe, GstVideoFrame * dframe) const GstVideoFrame * sframe, GstVideoFrame * dframe)
{ {
guint i, j; guint i, j;
guint r = (scope->priv->shade_amount >> 16) & 0xff; guint32 shade_amount = scope->priv->shade_amount;
guint g = (scope->priv->shade_amount >> 8) & 0xff; guint r = (shade_amount >> 16) & 0xff;
guint b = (scope->priv->shade_amount >> 0) & 0xff; guint g = (shade_amount >> 8) & 0xff;
guint b = (shade_amount >> 0) & 0xff;
guint8 *s, *d; guint8 *s, *d;
gint ss, ds, width, height; gint ss, ds, width, height;
@ -257,9 +260,10 @@ shader_fade_and_move_down (GstAudioVisualizer * scope,
const GstVideoFrame * sframe, GstVideoFrame * dframe) const GstVideoFrame * sframe, GstVideoFrame * dframe)
{ {
guint i, j; guint i, j;
guint r = (scope->priv->shade_amount >> 16) & 0xff; guint32 shade_amount = scope->priv->shade_amount;
guint g = (scope->priv->shade_amount >> 8) & 0xff; guint r = (shade_amount >> 16) & 0xff;
guint b = (scope->priv->shade_amount >> 0) & 0xff; guint g = (shade_amount >> 8) & 0xff;
guint b = (shade_amount >> 0) & 0xff;
guint8 *s, *d; guint8 *s, *d;
gint ss, ds, width, height; gint ss, ds, width, height;
@ -285,9 +289,10 @@ shader_fade_and_move_left (GstAudioVisualizer * scope,
const GstVideoFrame * sframe, GstVideoFrame * dframe) const GstVideoFrame * sframe, GstVideoFrame * dframe)
{ {
guint i, j; guint i, j;
guint r = (scope->priv->shade_amount >> 16) & 0xff; guint32 shade_amount = scope->priv->shade_amount;
guint g = (scope->priv->shade_amount >> 8) & 0xff; guint r = (shade_amount >> 16) & 0xff;
guint b = (scope->priv->shade_amount >> 0) & 0xff; guint g = (shade_amount >> 8) & 0xff;
guint b = (shade_amount >> 0) & 0xff;
guint8 *s, *d; guint8 *s, *d;
gint ss, ds, width, height; gint ss, ds, width, height;
@ -317,9 +322,10 @@ shader_fade_and_move_right (GstAudioVisualizer * scope,
const GstVideoFrame * sframe, GstVideoFrame * dframe) const GstVideoFrame * sframe, GstVideoFrame * dframe)
{ {
guint i, j; guint i, j;
guint r = (scope->priv->shade_amount >> 16) & 0xff; guint32 shade_amount = scope->priv->shade_amount;
guint g = (scope->priv->shade_amount >> 8) & 0xff; guint r = (shade_amount >> 16) & 0xff;
guint b = (scope->priv->shade_amount >> 0) & 0xff; guint g = (shade_amount >> 8) & 0xff;
guint b = (shade_amount >> 0) & 0xff;
guint8 *s, *d; guint8 *s, *d;
gint ss, ds, width, height; gint ss, ds, width, height;
@ -349,9 +355,10 @@ shader_fade_and_move_horiz_out (GstAudioVisualizer * scope,
const GstVideoFrame * sframe, GstVideoFrame * dframe) const GstVideoFrame * sframe, GstVideoFrame * dframe)
{ {
guint i, j; guint i, j;
guint r = (scope->priv->shade_amount >> 16) & 0xff; guint32 shade_amount = scope->priv->shade_amount;
guint g = (scope->priv->shade_amount >> 8) & 0xff; guint r = (shade_amount >> 16) & 0xff;
guint b = (scope->priv->shade_amount >> 0) & 0xff; guint g = (shade_amount >> 8) & 0xff;
guint b = (shade_amount >> 0) & 0xff;
guint8 *s, *d; guint8 *s, *d;
gint ss, ds, width, height; gint ss, ds, width, height;
@ -386,9 +393,10 @@ shader_fade_and_move_horiz_in (GstAudioVisualizer * scope,
const GstVideoFrame * sframe, GstVideoFrame * dframe) const GstVideoFrame * sframe, GstVideoFrame * dframe)
{ {
guint i, j; guint i, j;
guint r = (scope->priv->shade_amount >> 16) & 0xff; guint32 shade_amount = scope->priv->shade_amount;
guint g = (scope->priv->shade_amount >> 8) & 0xff; guint r = (shade_amount >> 16) & 0xff;
guint b = (scope->priv->shade_amount >> 0) & 0xff; guint g = (shade_amount >> 8) & 0xff;
guint b = (shade_amount >> 0) & 0xff;
guint8 *s, *d; guint8 *s, *d;
gint ss, ds, width, height; gint ss, ds, width, height;
@ -423,9 +431,10 @@ shader_fade_and_move_vert_out (GstAudioVisualizer * scope,
const GstVideoFrame * sframe, GstVideoFrame * dframe) const GstVideoFrame * sframe, GstVideoFrame * dframe)
{ {
guint i, j; guint i, j;
guint r = (scope->priv->shade_amount >> 16) & 0xff; guint32 shade_amount = scope->priv->shade_amount;
guint g = (scope->priv->shade_amount >> 8) & 0xff; guint r = (shade_amount >> 16) & 0xff;
guint b = (scope->priv->shade_amount >> 0) & 0xff; guint g = (shade_amount >> 8) & 0xff;
guint b = (shade_amount >> 0) & 0xff;
guint8 *s, *s1, *d, *d1; guint8 *s, *s1, *d, *d1;
gint ss, ds, width, height; gint ss, ds, width, height;
@ -458,9 +467,10 @@ shader_fade_and_move_vert_in (GstAudioVisualizer * scope,
const GstVideoFrame * sframe, GstVideoFrame * dframe) const GstVideoFrame * sframe, GstVideoFrame * dframe)
{ {
guint i, j; guint i, j;
guint r = (scope->priv->shade_amount >> 16) & 0xff; guint32 shade_amount = scope->priv->shade_amount;
guint g = (scope->priv->shade_amount >> 8) & 0xff; guint r = (shade_amount >> 16) & 0xff;
guint b = (scope->priv->shade_amount >> 0) & 0xff; guint g = (shade_amount >> 8) & 0xff;
guint b = (shade_amount >> 0) & 0xff;
guint8 *s, *s1, *d, *d1; guint8 *s, *s1, *d, *d1;
gint ss, ds, width, height; gint ss, ds, width, height;
@ -491,42 +501,46 @@ shader_fade_and_move_vert_in (GstAudioVisualizer * scope,
static void static void
gst_audio_visualizer_change_shader (GstAudioVisualizer * scope) gst_audio_visualizer_change_shader (GstAudioVisualizer * scope)
{ {
GstAudioVisualizerShaderFunc shader;
switch (scope->priv->shader_type) { switch (scope->priv->shader_type) {
case GST_AUDIO_VISUALIZER_SHADER_NONE: case GST_AUDIO_VISUALIZER_SHADER_NONE:
scope->priv->shader = NULL; shader = NULL;
break; break;
case GST_AUDIO_VISUALIZER_SHADER_FADE: case GST_AUDIO_VISUALIZER_SHADER_FADE:
scope->priv->shader = shader_fade; shader = shader_fade;
break; break;
case GST_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_UP: case GST_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_UP:
scope->priv->shader = shader_fade_and_move_up; shader = shader_fade_and_move_up;
break; break;
case GST_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_DOWN: case GST_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_DOWN:
scope->priv->shader = shader_fade_and_move_down; shader = shader_fade_and_move_down;
break; break;
case GST_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_LEFT: case GST_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_LEFT:
scope->priv->shader = shader_fade_and_move_left; shader = shader_fade_and_move_left;
break; break;
case GST_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_RIGHT: case GST_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_RIGHT:
scope->priv->shader = shader_fade_and_move_right; shader = shader_fade_and_move_right;
break; break;
case GST_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_HORIZ_OUT: case GST_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_HORIZ_OUT:
scope->priv->shader = shader_fade_and_move_horiz_out; shader = shader_fade_and_move_horiz_out;
break; break;
case GST_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_HORIZ_IN: case GST_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_HORIZ_IN:
scope->priv->shader = shader_fade_and_move_horiz_in; shader = shader_fade_and_move_horiz_in;
break; break;
case GST_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_VERT_OUT: case GST_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_VERT_OUT:
scope->priv->shader = shader_fade_and_move_vert_out; shader = shader_fade_and_move_vert_out;
break; break;
case GST_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_VERT_IN: case GST_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_VERT_IN:
scope->priv->shader = shader_fade_and_move_vert_in; shader = shader_fade_and_move_vert_in;
break; break;
default: default:
GST_ERROR ("invalid shader function"); GST_ERROR ("invalid shader function");
scope->priv->shader = NULL; shader = NULL;
break; break;
} }
scope->priv->shader = shader;
} }
/* base class */ /* base class */
@ -685,22 +699,23 @@ static void
gst_audio_visualizer_finalize (GObject * object) gst_audio_visualizer_finalize (GObject * object)
{ {
GstAudioVisualizer *scope = GST_AUDIO_VISUALIZER (object); GstAudioVisualizer *scope = GST_AUDIO_VISUALIZER (object);
GstAudioVisualizerPrivate *priv = scope->priv;
if (scope->priv->adapter) { if (priv->adapter) {
g_object_unref (scope->priv->adapter); g_object_unref (priv->adapter);
scope->priv->adapter = NULL; priv->adapter = NULL;
} }
if (scope->priv->inbuf) { if (priv->inbuf) {
gst_buffer_unref (scope->priv->inbuf); gst_buffer_unref (priv->inbuf);
scope->priv->inbuf = NULL; priv->inbuf = NULL;
} }
if (scope->priv->tempbuf) { if (priv->tempbuf) {
gst_video_frame_unmap (&scope->priv->tempframe); gst_video_frame_unmap (&priv->tempframe);
gst_buffer_unref (scope->priv->tempbuf); gst_buffer_unref (priv->tempbuf);
scope->priv->tempbuf = NULL; priv->tempbuf = NULL;
} }
g_mutex_clear (&scope->priv->config_lock); g_mutex_clear (&priv->config_lock);
G_OBJECT_CLASS (parent_class)->finalize (object); G_OBJECT_CLASS (parent_class)->finalize (object);
} }
@ -708,14 +723,16 @@ gst_audio_visualizer_finalize (GObject * object)
static void static void
gst_audio_visualizer_reset (GstAudioVisualizer * scope) gst_audio_visualizer_reset (GstAudioVisualizer * scope)
{ {
gst_adapter_clear (scope->priv->adapter); GstAudioVisualizerPrivate *priv = scope->priv;
gst_segment_init (&scope->priv->segment, GST_FORMAT_UNDEFINED);
gst_adapter_clear (priv->adapter);
gst_segment_init (&priv->segment, GST_FORMAT_UNDEFINED);
GST_OBJECT_LOCK (scope); GST_OBJECT_LOCK (scope);
scope->priv->proportion = 1.0; priv->proportion = 1.0;
scope->priv->earliest_time = -1; priv->earliest_time = -1;
scope->priv->dropped = 0; priv->dropped = 0;
scope->priv->processed = 0; priv->processed = 0;
GST_OBJECT_UNLOCK (scope); GST_OBJECT_UNLOCK (scope);
} }
@ -756,6 +773,7 @@ gst_audio_visualizer_src_setcaps (GstAudioVisualizer * scope, GstCaps * caps)
{ {
GstVideoInfo info; GstVideoInfo info;
GstAudioVisualizerClass *klass; GstAudioVisualizerClass *klass;
GstAudioVisualizerPrivate *priv;
gboolean res; gboolean res;
if (!gst_video_info_from_caps (&info, caps)) if (!gst_video_info_from_caps (&info, caps))
@ -763,23 +781,24 @@ gst_audio_visualizer_src_setcaps (GstAudioVisualizer * scope, GstCaps * caps)
klass = GST_AUDIO_VISUALIZER_CLASS (G_OBJECT_GET_CLASS (scope)); klass = GST_AUDIO_VISUALIZER_CLASS (G_OBJECT_GET_CLASS (scope));
priv = scope->priv;
scope->vinfo = info; scope->vinfo = info;
scope->priv->frame_duration = gst_util_uint64_scale_int (GST_SECOND, priv->frame_duration = gst_util_uint64_scale_int (GST_SECOND,
GST_VIDEO_INFO_FPS_D (&info), GST_VIDEO_INFO_FPS_N (&info)); GST_VIDEO_INFO_FPS_D (&info), GST_VIDEO_INFO_FPS_N (&info));
scope->priv->spf = priv->spf = gst_util_uint64_scale_int (GST_AUDIO_INFO_RATE (&scope->ainfo),
gst_util_uint64_scale_int (GST_AUDIO_INFO_RATE (&scope->ainfo),
GST_VIDEO_INFO_FPS_D (&info), GST_VIDEO_INFO_FPS_N (&info)); GST_VIDEO_INFO_FPS_D (&info), GST_VIDEO_INFO_FPS_N (&info));
scope->req_spf = scope->priv->spf; scope->req_spf = priv->spf;
if (scope->priv->tempbuf) { if (priv->tempbuf) {
gst_video_frame_unmap (&scope->priv->tempframe); gst_video_frame_unmap (&priv->tempframe);
gst_buffer_unref (scope->priv->tempbuf); gst_buffer_unref (priv->tempbuf);
} }
scope->priv->tempbuf = gst_buffer_new_wrapped (g_malloc0 (scope->vinfo.size), priv->tempbuf = gst_buffer_new_wrapped (g_malloc0 (scope->vinfo.size),
scope->vinfo.size); scope->vinfo.size);
gst_video_frame_map (&scope->priv->tempframe, &scope->vinfo, gst_video_frame_map (&priv->tempframe, &scope->vinfo, priv->tempbuf,
scope->priv->tempbuf, GST_MAP_READWRITE); GST_MAP_READWRITE);
if (klass->setup && !klass->setup (scope)) if (klass->setup && !klass->setup (scope))
goto setup_failed; goto setup_failed;
@ -787,10 +806,10 @@ gst_audio_visualizer_src_setcaps (GstAudioVisualizer * scope, GstCaps * caps)
GST_DEBUG_OBJECT (scope, "video: dimension %dx%d, framerate %d/%d", GST_DEBUG_OBJECT (scope, "video: dimension %dx%d, framerate %d/%d",
GST_VIDEO_INFO_WIDTH (&info), GST_VIDEO_INFO_HEIGHT (&info), GST_VIDEO_INFO_WIDTH (&info), GST_VIDEO_INFO_HEIGHT (&info),
GST_VIDEO_INFO_FPS_N (&info), GST_VIDEO_INFO_FPS_D (&info)); GST_VIDEO_INFO_FPS_N (&info), GST_VIDEO_INFO_FPS_D (&info));
GST_DEBUG_OBJECT (scope, "blocks: spf %u, req_spf %u", GST_DEBUG_OBJECT (scope, "blocks: spf %u, req_spf %u", priv->spf,
scope->priv->spf, scope->req_spf); scope->req_spf);
gst_pad_set_caps (scope->priv->srcpad, caps); gst_pad_set_caps (priv->srcpad, caps);
/* find a pool for the negotiated caps now */ /* find a pool for the negotiated caps now */
res = gst_audio_visualizer_do_bufferpool (scope, caps); res = gst_audio_visualizer_do_bufferpool (scope, caps);
@ -1066,6 +1085,7 @@ gst_audio_visualizer_chain (GstPad * pad, GstObject * parent,
{ {
GstFlowReturn ret = GST_FLOW_OK; GstFlowReturn ret = GST_FLOW_OK;
GstAudioVisualizer *scope; GstAudioVisualizer *scope;
GstAudioVisualizerPrivate *priv;
GstAudioVisualizerClass *klass; GstAudioVisualizerClass *klass;
GstBuffer *inbuf; GstBuffer *inbuf;
guint64 dist, ts; guint64 dist, ts;
@ -1074,19 +1094,20 @@ gst_audio_visualizer_chain (GstPad * pad, GstObject * parent,
gint bps, channels, rate; gint bps, channels, rate;
scope = GST_AUDIO_VISUALIZER (parent); scope = GST_AUDIO_VISUALIZER (parent);
priv = scope->priv;
klass = GST_AUDIO_VISUALIZER_CLASS (G_OBJECT_GET_CLASS (scope)); klass = GST_AUDIO_VISUALIZER_CLASS (G_OBJECT_GET_CLASS (scope));
GST_LOG_OBJECT (scope, "chainfunc called"); GST_LOG_OBJECT (scope, "chainfunc called");
/* resync on DISCONT */ /* resync on DISCONT */
if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT)) { if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT)) {
gst_adapter_clear (scope->priv->adapter); gst_adapter_clear (priv->adapter);
} }
/* Make sure have an output format */ /* Make sure have an output format */
if (gst_pad_check_reconfigure (scope->priv->srcpad)) { if (gst_pad_check_reconfigure (priv->srcpad)) {
if (!gst_audio_visualizer_src_negotiate (scope)) { if (!gst_audio_visualizer_src_negotiate (scope)) {
gst_pad_mark_reconfigure (scope->priv->srcpad); gst_pad_mark_reconfigure (priv->srcpad);
goto not_negotiated; goto not_negotiated;
} }
} }
@ -1100,26 +1121,26 @@ gst_audio_visualizer_chain (GstPad * pad, GstObject * parent,
goto beach; goto beach;
} }
gst_adapter_push (scope->priv->adapter, buffer); gst_adapter_push (priv->adapter, buffer);
g_mutex_lock (&scope->priv->config_lock); g_mutex_lock (&priv->config_lock);
/* this is what we want */ /* this is what we want */
sbpf = scope->req_spf * channels * sizeof (gint16); sbpf = scope->req_spf * channels * sizeof (gint16);
inbuf = scope->priv->inbuf; inbuf = priv->inbuf;
/* FIXME: the timestamp in the adapter would be different */ /* FIXME: the timestamp in the adapter would be different */
gst_buffer_copy_into (inbuf, buffer, GST_BUFFER_COPY_METADATA, 0, -1); gst_buffer_copy_into (inbuf, buffer, GST_BUFFER_COPY_METADATA, 0, -1);
/* this is what we have */ /* this is what we have */
avail = gst_adapter_available (scope->priv->adapter); avail = gst_adapter_available (priv->adapter);
GST_LOG_OBJECT (scope, "avail: %u, bpf: %u", avail, sbpf); GST_LOG_OBJECT (scope, "avail: %u, bpf: %u", avail, sbpf);
while (avail >= sbpf) { while (avail >= sbpf) {
GstBuffer *outbuf; GstBuffer *outbuf;
GstVideoFrame outframe; GstVideoFrame outframe;
/* get timestamp of the current adapter content */ /* get timestamp of the current adapter content */
ts = gst_adapter_prev_pts (scope->priv->adapter, &dist); ts = gst_adapter_prev_pts (priv->adapter, &dist);
if (GST_CLOCK_TIME_IS_VALID (ts)) { if (GST_CLOCK_TIME_IS_VALID (ts)) {
/* convert bytes to time */ /* convert bytes to time */
dist /= bps; dist /= bps;
@ -1133,12 +1154,12 @@ gst_audio_visualizer_chain (GstPad * pad, GstObject * parent,
gint64 qostime; gint64 qostime;
qostime = qostime =
gst_segment_to_running_time (&scope->priv->segment, GST_FORMAT_TIME, gst_segment_to_running_time (&priv->segment, GST_FORMAT_TIME,
ts) + scope->priv->frame_duration; ts) + priv->frame_duration;
GST_OBJECT_LOCK (scope); GST_OBJECT_LOCK (scope);
earliest_time = scope->priv->earliest_time; earliest_time = priv->earliest_time;
proportion = scope->priv->proportion; proportion = priv->proportion;
GST_OBJECT_UNLOCK (scope); GST_OBJECT_UNLOCK (scope);
if (GST_CLOCK_TIME_IS_VALID (earliest_time) && qostime <= earliest_time) { if (GST_CLOCK_TIME_IS_VALID (earliest_time) && qostime <= earliest_time) {
@ -1149,26 +1170,26 @@ gst_audio_visualizer_chain (GstPad * pad, GstObject * parent,
"QoS: skip ts: %" GST_TIME_FORMAT ", earliest: %" GST_TIME_FORMAT, "QoS: skip ts: %" GST_TIME_FORMAT ", earliest: %" GST_TIME_FORMAT,
GST_TIME_ARGS (qostime), GST_TIME_ARGS (earliest_time)); GST_TIME_ARGS (qostime), GST_TIME_ARGS (earliest_time));
++scope->priv->dropped; ++priv->dropped;
stream_time = gst_segment_to_stream_time (&scope->priv->segment, stream_time = gst_segment_to_stream_time (&priv->segment,
GST_FORMAT_TIME, ts); GST_FORMAT_TIME, ts);
jitter = GST_CLOCK_DIFF (qostime, earliest_time); jitter = GST_CLOCK_DIFF (qostime, earliest_time);
qos_msg = gst_message_new_qos (GST_OBJECT (scope), FALSE, qostime, qos_msg = gst_message_new_qos (GST_OBJECT (scope), FALSE, qostime,
stream_time, ts, GST_BUFFER_DURATION (buffer)); stream_time, ts, GST_BUFFER_DURATION (buffer));
gst_message_set_qos_values (qos_msg, jitter, proportion, 1000000); gst_message_set_qos_values (qos_msg, jitter, proportion, 1000000);
gst_message_set_qos_stats (qos_msg, GST_FORMAT_BUFFERS, gst_message_set_qos_stats (qos_msg, GST_FORMAT_BUFFERS,
scope->priv->processed, scope->priv->dropped); priv->processed, priv->dropped);
gst_element_post_message (GST_ELEMENT (scope), qos_msg); gst_element_post_message (GST_ELEMENT (scope), qos_msg);
goto skip; goto skip;
} }
} }
++scope->priv->processed; ++priv->processed;
g_mutex_unlock (&scope->priv->config_lock); g_mutex_unlock (&priv->config_lock);
ret = default_prepare_output_buffer (scope, &outbuf); ret = default_prepare_output_buffer (scope, &outbuf);
g_mutex_lock (&scope->priv->config_lock); g_mutex_lock (&priv->config_lock);
/* recheck as the value could have changed */ /* recheck as the value could have changed */
sbpf = scope->req_spf * channels * sizeof (gint16); sbpf = scope->req_spf * channels * sizeof (gint16);
@ -1181,16 +1202,16 @@ gst_audio_visualizer_chain (GstPad * pad, GstObject * parent,
gst_object_sync_values (GST_OBJECT (scope), ts); gst_object_sync_values (GST_OBJECT (scope), ts);
GST_BUFFER_TIMESTAMP (outbuf) = ts; GST_BUFFER_TIMESTAMP (outbuf) = ts;
GST_BUFFER_DURATION (outbuf) = scope->priv->frame_duration; GST_BUFFER_DURATION (outbuf) = priv->frame_duration;
/* this can fail as the data size we need could have changed */ /* this can fail as the data size we need could have changed */
if (!(adata = (gpointer) gst_adapter_map (scope->priv->adapter, sbpf))) if (!(adata = (gpointer) gst_adapter_map (priv->adapter, sbpf)))
break; break;
gst_video_frame_map (&outframe, &scope->vinfo, outbuf, GST_MAP_READWRITE); gst_video_frame_map (&outframe, &scope->vinfo, outbuf, GST_MAP_READWRITE);
if (scope->priv->shader) { if (priv->shader) {
gst_video_frame_copy (&outframe, &scope->priv->tempframe); gst_video_frame_copy (&outframe, &priv->tempframe);
} else { } else {
/* gst_video_frame_clear() or is output frame already cleared */ /* gst_video_frame_clear() or is output frame already cleared */
gint i; gint i;
@ -1213,18 +1234,17 @@ gst_audio_visualizer_chain (GstPad * pad, GstObject * parent,
} else { } else {
/* run various post processing (shading and geometric transformation) */ /* run various post processing (shading and geometric transformation) */
/* FIXME: SHADER assumes 32bpp */ /* FIXME: SHADER assumes 32bpp */
if (scope->priv->shader && if (priv->shader && GST_VIDEO_INFO_COMP_PSTRIDE (&scope->vinfo, 0) == 4) {
GST_VIDEO_INFO_COMP_PSTRIDE (&scope->vinfo, 0) == 4) { priv->shader (scope, &outframe, &priv->tempframe);
scope->priv->shader (scope, &outframe, &scope->priv->tempframe);
} }
} }
} }
gst_video_frame_unmap (&outframe); gst_video_frame_unmap (&outframe);
g_mutex_unlock (&scope->priv->config_lock); g_mutex_unlock (&priv->config_lock);
ret = gst_pad_push (scope->priv->srcpad, outbuf); ret = gst_pad_push (priv->srcpad, outbuf);
outbuf = NULL; outbuf = NULL;
g_mutex_lock (&scope->priv->config_lock); g_mutex_lock (&priv->config_lock);
skip: skip:
/* recheck as the value could have changed */ /* recheck as the value could have changed */
@ -1232,21 +1252,21 @@ gst_audio_visualizer_chain (GstPad * pad, GstObject * parent,
GST_LOG_OBJECT (scope, "avail: %u, bpf: %u", avail, sbpf); GST_LOG_OBJECT (scope, "avail: %u, bpf: %u", avail, sbpf);
/* we want to take less or more, depending on spf : req_spf */ /* we want to take less or more, depending on spf : req_spf */
if (avail - sbpf >= sbpf) { if (avail - sbpf >= sbpf) {
gst_adapter_flush (scope->priv->adapter, sbpf); gst_adapter_flush (priv->adapter, sbpf);
gst_adapter_unmap (scope->priv->adapter); gst_adapter_unmap (priv->adapter);
} else if (avail >= sbpf) { } else if (avail >= sbpf) {
/* just flush a bit and stop */ /* just flush a bit and stop */
gst_adapter_flush (scope->priv->adapter, (avail - sbpf)); gst_adapter_flush (priv->adapter, (avail - sbpf));
gst_adapter_unmap (scope->priv->adapter); gst_adapter_unmap (priv->adapter);
break; break;
} }
avail = gst_adapter_available (scope->priv->adapter); avail = gst_adapter_available (priv->adapter);
if (ret != GST_FLOW_OK) if (ret != GST_FLOW_OK)
break; break;
} }
g_mutex_unlock (&scope->priv->config_lock); g_mutex_unlock (&priv->config_lock);
beach: beach:
return ret; return ret;
@ -1265,8 +1285,10 @@ gst_audio_visualizer_src_event (GstPad * pad, GstObject * parent,
{ {
gboolean res; gboolean res;
GstAudioVisualizer *scope; GstAudioVisualizer *scope;
GstAudioVisualizerPrivate *priv;
scope = GST_AUDIO_VISUALIZER (parent); scope = GST_AUDIO_VISUALIZER (parent);
priv = scope->priv;
switch (GST_EVENT_TYPE (event)) { switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_QOS: case GST_EVENT_QOS:
@ -1279,17 +1301,16 @@ gst_audio_visualizer_src_event (GstPad * pad, GstObject * parent,
/* save stuff for the _chain() function */ /* save stuff for the _chain() function */
GST_OBJECT_LOCK (scope); GST_OBJECT_LOCK (scope);
scope->priv->proportion = proportion; priv->proportion = proportion;
if (diff >= 0) if (diff >= 0)
/* we're late, this is a good estimate for next displayable /* we're late, this is a good estimate for next displayable
* frame (see part-qos.txt) */ * frame (see part-qos.txt) */
scope->priv->earliest_time = priv->earliest_time = timestamp + 2 * diff + priv->frame_duration;
timestamp + 2 * diff + scope->priv->frame_duration;
else else
scope->priv->earliest_time = timestamp + diff; priv->earliest_time = timestamp + diff;
GST_OBJECT_UNLOCK (scope); GST_OBJECT_UNLOCK (scope);
res = gst_pad_push_event (scope->priv->sinkpad, event); res = gst_pad_push_event (priv->sinkpad, event);
break; break;
} }
case GST_EVENT_RECONFIGURE: case GST_EVENT_RECONFIGURE: