<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:'times new roman', 'new york', times, serif;font-size:12pt"><div>Hi Tim,</div><div>tried and approved, thanks a lot again for your help!</div><div>Regards,</div><div>Al</div><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><br><div style="font-family:arial, helvetica, sans-serif;font-size:13px"><font size="2" face="Tahoma"><hr size="1"><b><span style="font-weight: bold;">De :</span></b> Tim-Philipp Müller &lt;t.i.m@zen.co.uk&gt;<br><b><span style="font-weight: bold;">À :</span></b> gstreamer-devel@lists.sourceforge.net<br><b><span style="font-weight: bold;">Envoyé le :</span></b> Mar 6 juillet 2010, 10h 05min 22s<br><b><span style="font-weight: bold;">Objet&nbsp;:</span></b> Re: [gst-devel] Freeing application data from message<br></font><br>On Mon, 2010-07-05 at 12:11 +0000, Albert Costa wrote:<br><br><br>&gt;&nbsp;
  MyInfo* myinfo = new MyInfo;<br>&gt;&nbsp;  /* do stuff with myinfo, including allocating internal data */<br>&gt;<br>&gt;&nbsp;  structure = gst_structure_new("FILTERMESSAGE",<br>&gt;&nbsp; &nbsp;  "info", G_TYPE_POINTER, (gpointer)myinfo, <br>&gt;&nbsp; &nbsp;  NULL); <br><br>The problem here is that you're using G_TYPE_POINTER. If you use<br>G_TYPE_POINTER, the type system doesn't know how to copy or free your<br>data, so it's up to you to take care of this.<br><br>What you should do is register a 'boxed type' for your structure, like<br>this:<br><br>static MyInfo *<br>my_info_ref (MyInfo * info)<br>{<br>&nbsp; if (info != NULL)<br>&nbsp; &nbsp; g_atomic_int_inc (&amp;info-&gt;refcount);<br><br>&nbsp; return info;<br>}<br><br>static void<br>my_info_unref (MyInfo * info)<br>{<br>&nbsp; /* if we ended up with the refcount at zero, free it */<br>&nbsp; if (g_atomic_int_dec_and_test (&amp;info-&gt;refcount)) {<br>&nbsp; &nbsp;  /* g_free (info-&gt;foo);
 */<br>&nbsp; &nbsp;  /* g_free (info);&nbsp; &nbsp; &nbsp; */<br>&nbsp; }<br>}<br><br>#define MY_TYPE_INFO my_info_get_type()<br><br>static GType<br>my_info_get_type (void)<br>{<br>&nbsp; static volatile gsize type = 0;<br>&nbsp; if (g_once_init_enter (&amp;type)) {<br>&nbsp; &nbsp; GType tmp;<br>&nbsp; &nbsp; tmp = g_boxed_type_register_static ("MyInfo",<br>&nbsp; &nbsp; &nbsp; &nbsp; (GBoxedCopyFunc) my_info_ref,<br>&nbsp; &nbsp; &nbsp; &nbsp; (GBoxedFreeFunc) my_info_unref);<br>&nbsp; &nbsp; g_once_init_leave (&amp;type, tmp);<br>&nbsp; }<br>&nbsp; return type;<br>}<br><br>Then you can use:<br><br>&gt; structure = gst_structure_new("FILTERMESSAGE",<br>&gt;&nbsp; &nbsp;  "info", MY_TYPE_INFO, myinfo, NULL);<br>&gt; my_info_unref (myinfo);<br><br>and the info will be freed automatically with the message later (unless<br>you are still holding refs).<br><br><br>&gt;&nbsp;  gst_bus_post (bus, msg);<br><br>Use gst_element_post_message().<br><br><br>&gt; On
 the other side, I have my application that watches the bus<br>&gt; messages, and gets my info:<br>&gt;&nbsp; &nbsp;  case GST_MESSAGE_APPLICATION:<br>&gt;&nbsp; &nbsp; &nbsp; &nbsp;  const GstStructure *structure =<br>&gt; gst_message_get_structure(message);<br>&gt;&nbsp; &nbsp; &nbsp; &nbsp;  MyInfo* info;<br>&gt;&nbsp; &nbsp; &nbsp; &nbsp;  info =<br>&gt; (MyInfo*)g_value_get_pointer(gst_structure_get_value(structure,<br>&gt; "info"));<br><br>You can then use _get_boxed() here (to just get a pointer to your info<br>structure), or _dup_boxed() (to get a pointer and a reference).<br>&gt; <br>Cheers<br> -Tim<br><br>PS: you still have not filed a bug about that MTS typefind problem from<br>a few days ago. Could you please do that and/or send me the (beginning<br>of the) file?<br><br><br><br><br>------------------------------------------------------------------------------<br>This SF.net email is sponsored by Sprint<br>What will you do first with EVO, the
 first 4G phone?<br>Visit sprint.com/first -- <a href="http://p.sf.net/sfu/sprint-com-first" target="_blank">http://p.sf.net/sfu/sprint-com-first</a><br>_______________________________________________<br>gstreamer-devel mailing list<br><a ymailto="mailto:gstreamer-devel@lists.sourceforge.net" href="mailto:gstreamer-devel@lists.sourceforge.net">gstreamer-devel@lists.sourceforge.net</a><br><a href="https://lists.sourceforge.net/lists/listinfo/gstreamer-devel" target="_blank">https://lists.sourceforge.net/lists/listinfo/gstreamer-devel</a><br></div></div><div style="position:fixed"></div>


</div><br>




      </body></html>