diff options
author | Tim-Philipp Müller <tim@centricular.net> | 2013-08-14 18:17:51 +0100 |
---|---|---|
committer | Tim-Philipp Müller <tim@centricular.net> | 2013-08-14 18:19:21 +0100 |
commit | e861c72efc3c1c31c82040a5f65a1f315301d121 (patch) | |
tree | 0a1ca9b8b066a9cd7526ce705fcafedabfb39591 | |
parent | 9d92aaabe7f55f3476e8e70b31342afa7f2a2bee (diff) |
interaudiosrc: make silence memory actually contain silence
instead of random data. Reported by Marco Micheletti on
gstreamer-devel.
-rw-r--r-- | gst/inter/gstinteraudiosrc.c | 22 | ||||
-rw-r--r-- | gst/inter/gstinteraudiosrc.h | 3 |
2 files changed, 20 insertions, 5 deletions
diff --git a/gst/inter/gstinteraudiosrc.c b/gst/inter/gstinteraudiosrc.c index d1d2ea6fd..ee8786e98 100644 --- a/gst/inter/gstinteraudiosrc.c +++ b/gst/inter/gstinteraudiosrc.c @@ -187,6 +187,7 @@ gst_inter_audio_src_set_caps (GstBaseSrc * src, GstCaps * caps) { GstInterAudioSrc *interaudiosrc = GST_INTER_AUDIO_SRC (src); const GstStructure *structure; + GstAudioInfo info; gboolean ret; int sample_rate; @@ -201,6 +202,10 @@ gst_inter_audio_src_set_caps (GstBaseSrc * src, GstCaps * caps) ret = gst_pad_set_caps (src->srcpad, caps); } + if (gst_audio_info_from_caps (&info, caps)) { + interaudiosrc->finfo = info.finfo; + } + return ret; } @@ -226,6 +231,7 @@ gst_inter_audio_src_stop (GstBaseSrc * src) gst_inter_surface_unref (interaudiosrc->surface); interaudiosrc->surface = NULL; + interaudiosrc->finfo = NULL; return TRUE; } @@ -282,17 +288,23 @@ gst_inter_audio_src_create (GstBaseSrc * src, guint64 offset, guint size, if (n > 0) { buffer = gst_adapter_take_buffer (interaudiosrc->surface->audio_adapter, n * 4); + } else { + buffer = gst_buffer_new (); } g_mutex_unlock (&interaudiosrc->surface->mutex); if (n < SIZE) { - GstBuffer *newbuf = gst_buffer_new_and_alloc ((SIZE - n) * 4); + GstMapInfo map; + GstMemory *mem; GST_WARNING ("creating %d samples of silence", SIZE - n); - - if (buffer) - newbuf = gst_buffer_append (newbuf, buffer); - buffer = newbuf; + mem = gst_allocator_alloc (NULL, (SIZE - n) * 4, NULL); + if (gst_memory_map (mem, &map, GST_MAP_WRITE)) { + gst_audio_format_fill_silence (interaudiosrc->finfo, map.data, map.size); + gst_memory_unmap (mem, &map); + } + buffer = gst_buffer_make_writable (buffer); + gst_buffer_prepend_memory (buffer, mem); } n = SIZE; diff --git a/gst/inter/gstinteraudiosrc.h b/gst/inter/gstinteraudiosrc.h index a86d5c025..318bb39de 100644 --- a/gst/inter/gstinteraudiosrc.h +++ b/gst/inter/gstinteraudiosrc.h @@ -21,6 +21,7 @@ #define _GST_INTER_AUDIO_SRC_H_ #include <gst/base/gstbasesrc.h> +#include <gst/audio/audio.h> #include "gstintersurface.h" G_BEGIN_DECLS @@ -43,6 +44,8 @@ struct _GstInterAudioSrc guint64 n_samples; int sample_rate; + + const GstAudioFormatInfo *finfo; }; struct _GstInterAudioSrcClass |