title: interfacing gobject with C++
body: <p>I’m trying to create a custom audio sink plugin for gstreamer using the Gst::AudioSink as a base class. For me this involves multiple learning curves as I’m new to gstreamer, gstreamermm and gobject. Also I have no background or real interest in gtkmm as I’m not working on GUI code at present.</p>
  
  <p>I am trying to create a class along the lines of:</p>
  
  <pre><code>class MyAudioSink: public Gst::AudioSink
  {
  public:
      explicit MyAudioSink(KantarAudioSink *gobj);
      virtual ~MyAudioSink();
  
      static void class_init(Gst::ElementClass&lt;MyAudioSink&gt; *klass);
  
      virtual int write_vfunc(gpointer data, guint length) override;
      virtual void reset_vfunc();
  };
  </code></pre>
  
  <p>I seem to missing some magic in the <em>class_init()</em> function that should link the base class functions to the virtual functions in MyAudioSink.
  In C we would do something like:</p>
  
  <pre><code>  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
    GstAudioSinkClass *audio_sink_class = GST_AUDIO_SINK_CLASS (klass);
    audio_sink_class-&gt;write = GST_DEBUG_FUNCPTR (myaudiosink_write);
  </code></pre>
  
  <p>I don’t really grok the C++ binding to gobject.
  What is the equivalent for linking to the C++ virtual function hierarchy?</p>
  
  <p>I got the impression from Marcin’s video <a href="https://gstconf.ubicast.tv/videos/gstreamermm-c-way-of-doing-gstreamer-based-applications/" rel="nofollow noreferrer">https://gstconf.ubicast.tv/videos/gstreamermm-c-way-of-doing-gstreamer-based-applications/</a> that the virtual functions should be invoked automatically.</p>
  
  <p>I can create a half usable (doesn’t handle things like EOS) plugin by adding:</p>
  
  <pre><code>   add_pad(sinkpad = Gst::Pad::create(get_pad_template("sink"), "sink"));
     sinkpad-&gt;set_chain_function(sigc::mem_fun(*this, &amp;MyAudioSink::chain));
  </code></pre>
  
  <p>But I don't think a sink should have a chain function.</p>
  
  <p>I've also asked this question on the gtkmm mailing list. If I get an answer there I will post it here.</p>
  
  <p>For MyAudioSink I get a class hierarchy of:</p>
  
  <blockquote>
    <p>GObject  +----GInitiallyUnowned
           +----GstObject
                 +----GstElement
                       +----myaudiosink</p>
  </blockquote>
  
  <p>Rather than:</p>
  
  <blockquote>
    <p>GObject  +----GInitiallyUnowned
           +----GstObject
                 +----GstElement
                       +----GstBaseAudioSink
                            +----GstAudioSink
                                 +----myaudiosink</p>
  </blockquote>
  
  <p>I suspect this is the essence of my problem.</p>
  
  <p>For the audiofilter example Marcin mentions <a href="https://stackoverflow.com/a/49997751/1569204">here</a> I get a class hierachy of:</p>
  
  <blockquote>
    <p>GObject  +----GInitiallyUnowned
           +----GstObject
                 +----GstElement
                       +----GstBaseTransform
                             +----GstAudioFilter
                                   +----myaudiofilter</p>
  </blockquote>