title: Kurento: unable to receive callback from GStreamer element "cutter"
body: <p>I am trying to apply some GStreamer plugins on the kurento <code>mediapipeline</code>, here I expect that the Gstreamer code which is working fine in a standalone program to send callback messages related to <code>cutter</code>.</p>
  
  <p>The following is my code:</p>
  
  <pre><code>namespace kurento
  {
      namespace module
      {
          namespace vadcustomfilter
          {
              std::string Id = "";
  
              void VADCustomFilterImpl::busMessage(GstMessage * message)
              {
                  GST_ERROR("***In BusMessage***");
  
                  if (message-&gt;type == GST_MESSAGE_EOS)
                  {
                      g_object_set(G_OBJECT(valve), "drop", FALSE, NULL);
                  }
  
                  const GstStructure *s = gst_message_get_structure(message);
                  const gchar *name = gst_structure_get_name(s);
                  GST_INFO("Name: %s\n", name);
  
                  if (message-&gt;type == GST_MESSAGE_ELEMENT)
                  {
                      if (strcmp(name, "cutter") == 0)
                      {
                          GstClockTime time = 0;
                          GstClockTime prevsilencetime = 0;
  
                          if (!gst_structure_get_boolean(s, "above", &amp;above))
                          {
                              GST_ERROR("could not parse above");
                          }
  
                          GST_INFO("above: %d", above);
  
                          if (above)
                          {
                              if (isSpeaking == 0)
                              {
                                  revsilencetime = time;                              
                                  g_object_set(G_OBJECT(valve), "drop", FALSE, NULL);
                              }
                              /*Send Voice Detected Event */                          
                              try
                              {
                                  GST_ERROR("Sending Event: VoiceDetected");
                                  VoiceDetected event(shared_from_this(), "voice-detected", Id.c_str());
                                  signalVoiceDetected(event);
                                  GST_ERROR("Sent Event: VoiceDetected");
                              }
                              catch (std::bad_weak_ptr &amp; e)
                              {
                                  GST_ERROR("EXCEPTION: Voice activity detected ");
                              }
                              isSpeaking = 1;
                          }
                          else
                          {
                              if (isSpeaking == 1)
                              {
                                  g_object_set(G_OBJECT(valve), "drop", TRUE, NULL);
                              }
                              isSpeaking = 0;
                          }
                      }
                  }
              }
  
  
              VADCustomFilterImpl::VADCustomFilterImpl(const boost::property_tree::
                  ptree &amp; config,
                  std::shared_ptr &lt;
                  MediaPipeline &gt; mediaPipeline,
                  const std::string &amp;pipelineId) :FilterImpl
                  (config,
                  std::dynamic_pointer_cast &lt;MediaObjectImpl&gt; (mediaPipeline))
              {
  --&gt;Edit Start       
  
                  g_object_set (element, "filter-factory", "audioconvert", NULL);
                  g_object_get (G_OBJECT (element), "filter", &amp;audioconvertfilter, NULL);
  
                  if (audioconvertfilter == NULL) {
                      throw KurentoException (MEDIA_OBJECT_NOT_FOUND, "MediaObject not found: audioconvertfilter");
                  }
  
                  g_object_set (element, "filter-factory", "cutter", NULL);
                  g_object_get (G_OBJECT (element), "filter", &amp;cutterfilter, NULL);
  
                  if (cutterfilter == NULL) {
                      throw KurentoException (MEDIA_OBJECT_NOT_FOUND, "MediaObject not found: cutterfilter");
                  }
  
                  g_object_set (G_OBJECT (cutterfilter), "threshold-dB", -39.0, NULL);
                  g_object_set (G_OBJECT (cutterfilter), "run-length", 400000000, NULL);
  
  
                  g_object_set (element, "filter-factory", "vadcustomfilter", NULL);
  
                  g_object_get (G_OBJECT (element), "filter", &amp;vadCustomFilter, NULL);
  
                  bus_handler_id = 0;
                  GST_ERROR("PipelineId: constructor %s",pipelineId.c_str());
                  Id = pipelineId;
      --&gt;Edit End
  
              }
  
  
              void VADCustomFilterImpl::postConstructor()
              {
                  GstBus *bus;
  
                  std::shared_ptr &lt; MediaPipelineImpl &gt; pipe;
  
                  FilterImpl::postConstructor();
  
                  pipe =
                      std::dynamic_pointer_cast &lt;MediaPipelineImpl&gt;
                      (getMediaPipeline());
                  g_assert(pipe);
  
                  /* #1. Add cutter filter here */
                  create_gst_cutter_filter(pipe);
  
  
                  bus = gst_pipeline_get_bus(GST_PIPELINE(pipe-&gt;getPipeline()));
                  g_assert(bus);
                  bus_handler_id = register_signal_handler(G_OBJECT(bus),
                      "message",
                      std::function &lt;
                      void(GstElement *,
                      GstMessage *) &gt;
                      (std::bind
                      (&amp;VADCustomFilterImpl::
                      busMessage, this,
                      std::placeholders::_2)),
                      std::dynamic_pointer_cast &lt;
                      VADCustomFilterImpl&gt;
                      (shared_from_this()));
  
  
                  GST_ERROR("busMessage added successfully.");
  
                  g_object_unref(bus);
              }
  
              VADCustomFilterImpl::~VADCustomFilterImpl()
              {
                  std::shared_ptr &lt; MediaPipelineImpl &gt; pipe;
  
                  if (bus_handler_id &gt; 0)
                  {
                      pipe =
                          std::dynamic_pointer_cast &lt;MediaPipelineImpl&gt;
                          (getMediaPipeline());
                      GstBus *bus =
                          gst_pipeline_get_bus(GST_PIPELINE(pipe-&gt;getPipeline()));
                      unregister_signal_handler(bus, bus_handler_id);
                      g_object_unref(bus);
                  }
              }
  
              MediaObjectImpl *VADCustomFilterImplFactory::createObject(const boost::
                  property_tree::
                  ptree &amp;
                  config,
                  std::
                  shared_ptr &lt;
                  MediaPipeline
                  &gt;
                  mediaPipeline,
                  const std::string &amp;pipelineId)
                  const
              {
                  GST_ERROR("Pipeline Id createObject %s", pipelineId.c_str());
                  return new VADCustomFilterImpl(config, mediaPipeline, pipelineId.c_str());
              }
  
  
  
  
              VADCustomFilterImpl::StaticConstructor VADCustomFilterImpl::
                  staticConstructor;
  
              VADCustomFilterImpl::StaticConstructor::StaticConstructor()
              {
                  GST_DEBUG_CATEGORY_INIT(GST_CAT_DEFAULT, GST_DEFAULT_NAME, 0,
                      GST_DEFAULT_NAME);
              }
          }/* vadcustomfilter */
      }/* module */
  }/* kurento */
  </code></pre>
  
  <p>overall I have added comments for the questions which I have in the code.</p>
  
  <p>I am getting callback for <code>GstMessageTag</code> which I have printed in the log using <code>gst_structure_get_name(name)</code> but i am not getting any callbacks for <code>cutter</code></p>
  
  <p>Is there anything missing/wrong in the flow of the code ?</p>
  
  <p><strong>Edit:</strong> Removed gstreamer way of adding plugin filters, tried adding <code>audioconvert</code> <code>cutter</code> on <code>element</code></p>
  
  <p>but I am getting error on <code>addIceCandidate</code>:</p>
  
  <pre><code>Req-&gt; {"id":13,"method":"invoke","params":{"object":"ff394885-ff7b-4cd2-ac83-190ab58056c3_kurento.MediaPipeline/4911aa60-27e4-461e-86c0-10532bc30d4f_kurento.WebRtcEndpoint","operation":"addIceCandidate","operationParams":{"candidate":{"sdpMid":"audio","__module__":"kurento","sdpMLineIndex":0,"__type__":"IceCandidate","candidate":"candidate:1226269011 1 udp 2122260223 172.24.9.207 62808 typ host generation 0 ufrag nSC45+9JNTCJm+yr"}},"sessionId":"15daae09-de86-4293-a3de-28f33f2d0b16"},"jsonrpc":"2.0"}
  
  
  Res {"id":13,"error":{"code":40401,"message":"Error adding candidate","data":{"type":"ICE_ADD_CANDIDATE_ERROR"}},"jsonrpc":"2.0"}
  </code></pre>