<div dir="ltr">Hello guys, <div><br></div><div>I'm doing some code heavily based on the Appsink example in this <a href="http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/section-data-spoof.html">page</a>. 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).</div><div><br></div><div><div>void capture_image(const char * filename)</div><div>{</div><div><span class="" style="white-space:pre">  </span>GstElement *appsink;</div><div><span class="" style="white-space:pre">       </span>GstSample *sample, *jpeg_sample;</div><div><span class="" style="white-space:pre">   </span>GstBuffer *buffer;</div><div><span class="" style="white-space:pre"> </span>GstCaps *caps_old, *caps_new;</div><div><span class="" style="white-space:pre">      </span>GstStructure *caps_s;</div><div><span class="" style="white-space:pre">      </span>gint width, height;</div><div><span class="" style="white-space:pre">        </span>GstMapInfo map;</div><div><span class="" style="white-space:pre">    </span>FILE *fp;</div><div><br></div><div><span class="" style="white-space:pre"> </span>//add and link elements to the pipeline</div><div><span class="" style="white-space:pre">    </span>add_mode(MODE_IMAGE_NOTE);</div><div><br></div><div><span class="" style="white-space:pre">        </span>//Block for sample in appsink</div><div><span class="" style="white-space:pre">      </span>appsink = gst_bin_get_by_name(GST_BIN(pipeline), "image_capture_appsink");</div><div><span class="" style="white-space:pre">       </span>g_signal_emit_by_name (appsink, "pull-sample", &sample, NULL);</div><div><br></div><div><span class="" style="white-space:pre">      </span>//extract size info</div><div><span class="" style="white-space:pre">        </span>caps_old = gst_sample_get_caps (sample);</div><div> <span class="" style="white-space:pre"> </span>caps_s = gst_caps_get_structure (caps_old, 0);</div><div> <span class="" style="white-space:pre">   </span>gst_structure_get_int (caps_s, "width", &width);</div><div>        gst_structure_get_int (caps_s, "height", &height);</div></div><div><div><span class="" style="white-space:pre">   </span>printf("DEBUG: capture_image - our sample is [%dx%d]\n", width, height);</div><div><br></div><div><span class="" style="white-space:pre">        </span>//convert our sample</div><div><span class="" style="white-space:pre">       </span>caps_new = gst_caps_new_simple ("image/jpeg", "width", G_TYPE_INT, width, </div><div><span class="" style="white-space:pre">                                                                                    </span>"height", G_TYPE_INT, height, NULL);</div><div><span class="" style="white-space:pre">     </span>jpeg_sample = gst_video_convert_sample(sample, caps_new, GST_SECOND, NULL);</div><div><span class="" style="white-space:pre">        </span>buffer = gst_sample_get_buffer(jpeg_sample);</div><div><span class="" style="white-space:pre">       </span>gst_buffer_map (buffer, &map, GST_MAP_READ);</div><div><br></div><div><span class="" style="white-space:pre">  </span>//write to disk here</div><div><span class="" style="white-space:pre">       </span>fp = fopen(filename, "w");</div><div><span class="" style="white-space:pre">       </span>fwrite(map.data, 1, map.size, fp);</div><div><span class="" style="white-space:pre"> </span>fclose(fp);</div><div><span class="" style="white-space:pre">        </span></div><div><span class="" style="white-space:pre">   </span>//unlink and elements from the pipeline</div><div><span class="" style="white-space:pre">    </span>remove_mode(MODE_IMAGE_NOTE);</div><div><br></div><div><span class="" style="white-space:pre">     </span>//release resources</div><div><span class="" style="white-space:pre">        </span>gst_caps_unref(caps_old);</div><div><span class="" style="white-space:pre">  </span>gst_caps_unref(caps_new);</div><div><span class="" style="white-space:pre">  </span>gst_buffer_unmap (buffer, &map);</div><div><b><span class="" style="white-space:pre">      </span>printf("releasing sample %d\n", GST_MINI_OBJECT_REFCOUNT_VALUE(sample));</b></div><div><b><span class="" style="white-space:pre">      </span>gst_sample_unref(sample);</b></div><div><b><span class="" style="white-space:pre">       </span>printf("releasing jpeg_sample %d\n", GST_MINI_OBJECT_REFCOUNT_VALUE(jpeg_sample));</b></div><div><b><span class="" style="white-space:pre">    </span>gst_sample_unref(jpeg_sample);</b></div><div><span style="white-space:pre">      </span><br></div><div>}</div></div><div><br></div><div>And this is outputting in the console</div><div><br></div><div><div><b>releasing sample 1</b></div><div><b>(lt-mobimedia:9375): GStreamer-CRITICAL **: gst_mini_object_unref: assertion `mini_object->refcount > 0' failed</b></div><div><b>releasing jpeg_sample 1</b></div></div><div><br></div><div>I'm I reading the wrong refcount value?</div><div><br></div><div>Cheers, </div><div>Sérgio</div><div><div><br></div><div> </div></div></div>