interaudiosrc: make silence memory actually contain silence

instead of random data. Reported by Marco Micheletti on
gstreamer-devel.
This commit is contained in:
Tim-Philipp Müller 2013-08-14 18:17:51 +01:00
parent 9d92aaabe7
commit e861c72efc
2 changed files with 20 additions and 5 deletions

View file

@ -187,6 +187,7 @@ gst_inter_audio_src_set_caps (GstBaseSrc * src, GstCaps * caps)
{ {
GstInterAudioSrc *interaudiosrc = GST_INTER_AUDIO_SRC (src); GstInterAudioSrc *interaudiosrc = GST_INTER_AUDIO_SRC (src);
const GstStructure *structure; const GstStructure *structure;
GstAudioInfo info;
gboolean ret; gboolean ret;
int sample_rate; 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); ret = gst_pad_set_caps (src->srcpad, caps);
} }
if (gst_audio_info_from_caps (&info, caps)) {
interaudiosrc->finfo = info.finfo;
}
return ret; return ret;
} }
@ -226,6 +231,7 @@ gst_inter_audio_src_stop (GstBaseSrc * src)
gst_inter_surface_unref (interaudiosrc->surface); gst_inter_surface_unref (interaudiosrc->surface);
interaudiosrc->surface = NULL; interaudiosrc->surface = NULL;
interaudiosrc->finfo = NULL;
return TRUE; return TRUE;
} }
@ -282,17 +288,23 @@ gst_inter_audio_src_create (GstBaseSrc * src, guint64 offset, guint size,
if (n > 0) { if (n > 0) {
buffer = gst_adapter_take_buffer (interaudiosrc->surface->audio_adapter, buffer = gst_adapter_take_buffer (interaudiosrc->surface->audio_adapter,
n * 4); n * 4);
} else {
buffer = gst_buffer_new ();
} }
g_mutex_unlock (&interaudiosrc->surface->mutex); g_mutex_unlock (&interaudiosrc->surface->mutex);
if (n < SIZE) { 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); GST_WARNING ("creating %d samples of silence", SIZE - n);
mem = gst_allocator_alloc (NULL, (SIZE - n) * 4, NULL);
if (buffer) if (gst_memory_map (mem, &map, GST_MAP_WRITE)) {
newbuf = gst_buffer_append (newbuf, buffer); gst_audio_format_fill_silence (interaudiosrc->finfo, map.data, map.size);
buffer = newbuf; gst_memory_unmap (mem, &map);
}
buffer = gst_buffer_make_writable (buffer);
gst_buffer_prepend_memory (buffer, mem);
} }
n = SIZE; n = SIZE;

View file

@ -21,6 +21,7 @@
#define _GST_INTER_AUDIO_SRC_H_ #define _GST_INTER_AUDIO_SRC_H_
#include <gst/base/gstbasesrc.h> #include <gst/base/gstbasesrc.h>
#include <gst/audio/audio.h>
#include "gstintersurface.h" #include "gstintersurface.h"
G_BEGIN_DECLS G_BEGIN_DECLS
@ -43,6 +44,8 @@ struct _GstInterAudioSrc
guint64 n_samples; guint64 n_samples;
int sample_rate; int sample_rate;
const GstAudioFormatInfo *finfo;
}; };
struct _GstInterAudioSrcClass struct _GstInterAudioSrcClass