summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim-Philipp Müller <tim@centricular.net>2013-08-14 18:17:51 +0100
committerTim-Philipp Müller <tim@centricular.net>2013-08-28 22:46:31 +0100
commit25521d48188ebf09832b697ede5810cdb24c31c3 (patch)
tree4041626dcefafc047a583b48390855d11325e49d
parent652ef187f5d5e8baaf1a3d0ac528aa93a7b0c398 (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.c22
-rw-r--r--gst/inter/gstinteraudiosrc.h3
2 files changed, 20 insertions, 5 deletions
diff --git a/gst/inter/gstinteraudiosrc.c b/gst/inter/gstinteraudiosrc.c
index 3e55be260..d800e960d 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;
}
@@ -284,17 +290,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 4ccc7f5c5..2c46f8302 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