new-buffer signal in appsink

Tim-Philipp Müller t.i.m at zen.co.uk
Sun Aug 25 08:20:06 PDT 2013


On Fri, 2013-08-23 at 12:10 +0530, jyoti kulkarni wrote:

Hi,

> Now new-buffer signal is removed in gstreamer1.0 how can we access the
> buffers.

You use the "new-sample" signal instead.


> Now i am using "new-sample" and writing it to a file. (the samples
> what i get is decoded video/audio buffers of huge size)
> 
> 
> since GstSample can hold only small amount of data iam able to write
> only single sample. how should i write all the samples to the files.

a GstSample is just a little helper structure that contains a GstBuffer
along with the GstCaps and the GstSegment that it goes with. As such, it
can hold just as much data as a GstBuffer can/could.

> I am doing it in following way for audio buffer and similarly for
> video buffer.
> 
>  g_signal_emit_by_name (sink, "pull-sample", &sample,NULL);

That's fine of course, just want to point out that there's a little
utility library called libgstapp-1.0 in gst-plugins-base which provides
proper API for this.

>   if (sample) {
> 
>        buffer = gst_sample_get_buffer (sample);

Note that this does not return a reference to the buffer.

>        gst_buffer_map (buffer, &map, GST_MAP_READ);
>        g_print("\n size=%d\n",map.size);
> 
> fwrite(map.data, 1, map.size,data->audio_file);

Shouldn't it be fwrite(data, size, 1, file) to make sure you either
write all of the data or none of the data? (Assuming that's what you
want)

>     gst_sample_unref(sample);
>     gst_buffer_unmap (buffer,&map);

Here's the problem. gst_sample_unref() will unref the buffer, to which
you didn't get a ref. This might free the buffer, and gst_buffer_unmap()
then operates on a free buffer.

First unmap the buffer, then unref the sample.

> 
> If i simply use GstBuffer i get below critical warnings and some junk
> data is written into file.

Junk being written to the file sounds like a different issue.

> g_signal_emit_by_name (sink, "pull-sample", &buffer,NULL);
> 
> GStreamer-CRITICAL **: gst_buffer_map_range: assertion `GST_IS_BUFFER
> (buffer)' failed

Cheers
 -Tim




More information about the gstreamer-devel mailing list