Strange behavior from gst_sample_unref

Sérgio Agostinho sergio.r.agostinho at
Tue Dec 2 05:00:44 PST 2014

Hello guys,

I'm doing some code heavily based on the Appsink example in this page
And I'm getting a strange behavior when I try to unref the samples I'm
working on. I request a sample from appsink, convert it to jpeg, dump it to
the harddrive and then unref everything. Here's a snippet of the code (a
useful one for anyone trying to get and image dumped into the harddrive
from a raw video live stream).

void capture_image(const char * filename)
GstElement *appsink;
GstSample *sample, *jpeg_sample;
GstBuffer *buffer;
GstCaps *caps_old, *caps_new;
GstStructure *caps_s;
gint width, height;
GstMapInfo map;
FILE *fp;

//add and link elements to the pipeline

//Block for sample in appsink
appsink = gst_bin_get_by_name(GST_BIN(pipeline), "image_capture_appsink");
g_signal_emit_by_name (appsink, "pull-sample", &sample, NULL);

//extract size info
caps_old = gst_sample_get_caps (sample);
  caps_s = gst_caps_get_structure (caps_old, 0);
  gst_structure_get_int (caps_s, "width", &width);
        gst_structure_get_int (caps_s, "height", &height);
printf("DEBUG: capture_image - our sample is [%dx%d]\n", width, height);

//convert our sample
caps_new = gst_caps_new_simple ("image/jpeg", "width", G_TYPE_INT, width,
"height", G_TYPE_INT, height, NULL);
jpeg_sample = gst_video_convert_sample(sample, caps_new, GST_SECOND, NULL);
buffer = gst_sample_get_buffer(jpeg_sample);
gst_buffer_map (buffer, &map, GST_MAP_READ);

//write to disk here
fp = fopen(filename, "w");
fwrite(, 1, map.size, fp);
 //unlink and elements from the pipeline

//release resources
gst_buffer_unmap (buffer, &map);
* printf("releasing sample %d\n", GST_MINI_OBJECT_REFCOUNT_VALUE(sample));*
* gst_sample_unref(sample);*
* printf("releasing jpeg_sample %d\n",
* gst_sample_unref(jpeg_sample);*


And this is outputting in the console

*releasing sample 1*
*(lt-mobimedia:9375): GStreamer-CRITICAL **: gst_mini_object_unref:
assertion `mini_object->refcount > 0' failed*
*releasing jpeg_sample 1*

I'm I reading the wrong refcount value?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the gstreamer-devel mailing list