PointerDetectorFilterImpl::~PointerDetectorFilterImpl()
{
  std::shared_ptr<MediaPipelineImpl> pipe;

  pipe = std::dynamic_pointer_cast<MediaPipelineImpl> (getMediaPipeline() );
  GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (pipe->getPipeline() ) );
  g_signal_handler_disconnect (bus, bus_handler_id);
  g_object_unref (bus);
}
Exemplo n.º 2
0
HubImpl::~HubImpl()
{
  std::shared_ptr<MediaPipelineImpl> pipe;

  pipe = std::dynamic_pointer_cast<MediaPipelineImpl> (getMediaPipeline() );

  gst_bin_remove (GST_BIN ( pipe->getPipeline() ), element);
  gst_element_set_state (element, GST_STATE_NULL);
  g_object_unref (element);
}
Exemplo n.º 3
0
ZBarFilterImpl::~ZBarFilterImpl()
{
  std::shared_ptr<MediaPipelineImpl> pipe;

  if (bus_handler_id > 0) {
    pipe = std::dynamic_pointer_cast<MediaPipelineImpl> (getMediaPipeline() );
    GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (pipe->getPipeline() ) );
    unregister_signal_handler (bus, bus_handler_id);
    g_object_unref (bus);
  }
}
Exemplo n.º 4
0
HubImpl::HubImpl (const boost::property_tree::ptree &config,
                  std::shared_ptr<MediaObjectImpl> parent,
                  const std::string &factoryName) : MediaObjectImpl (config, parent)
{
  std::shared_ptr<MediaPipelineImpl> pipe;

  pipe = std::dynamic_pointer_cast<MediaPipelineImpl> (getMediaPipeline() );

  element = gst_element_factory_make (factoryName.c_str(), NULL);

  g_object_ref (element);
  pipe->addElement (element);
}
MediaElementImpl::MediaElementImpl (const std::string &factoryName,
                                    std::shared_ptr<MediaObjectImpl> parent) :
  MediaObjectImpl (parent)
{
  std::shared_ptr<MediaPipelineImpl> pipe;

  pipe = std::dynamic_pointer_cast<MediaPipelineImpl> (getMediaPipeline() );

  element = gst_element_factory_make (factoryName.c_str(), NULL);

  g_object_ref (element);
  gst_bin_add (GST_BIN ( pipe->getPipeline() ), element);
  gst_element_sync_state_with_parent (element);
}
Exemplo n.º 6
0
void ZBarFilterImpl::postConstructor ()
{
  GstBus *bus;
  std::shared_ptr<MediaPipelineImpl> pipe;

  FilterImpl::postConstructor ();

  pipe = std::dynamic_pointer_cast<MediaPipelineImpl> (getMediaPipeline() );

  bus = gst_pipeline_get_bus (GST_PIPELINE (pipe->getPipeline() ) );

  bus_handler_id = register_signal_handler (G_OBJECT (bus),
                   "message",
                   std::function <void (GstElement *, GstMessage *) >
                   (std::bind (&ZBarFilterImpl::busMessage, this,
                               std::placeholders::_2) ),
                   std::dynamic_pointer_cast<ZBarFilterImpl>
                   (shared_from_this() ) );
  g_object_unref (bus);
}
PointerDetectorFilterImpl::PointerDetectorFilterImpl (
  const std::vector<std::shared_ptr<PointerDetectorWindowMediaParam>> &windows,
  std::shared_ptr< MediaObjectImpl > parent) :
  FilterImpl (parent)
{
  GstBus *bus;
  std::shared_ptr<MediaPipelineImpl> pipe;
  GstStructure *buttonsLayout;

  pipe = std::dynamic_pointer_cast<MediaPipelineImpl> (getMediaPipeline() );

  g_object_set (element, "filter-factory", "pointerdetector", NULL);

  bus = gst_pipeline_get_bus (GST_PIPELINE (pipe->getPipeline() ) );

  g_object_get (G_OBJECT (element), "filter", &pointerDetector, NULL);

  if (pointerDetector == NULL) {
    g_object_unref (bus);
    throw KurentoException (MEDIA_OBJECT_NOT_AVAILABLE,
                            "Media Object not available");
  }

  buttonsLayout = gst_structure_new_empty  ("windowsLayout");

  for (auto window : windows) {
    GstStructure *buttonsLayoutAux = get_structure_from_window (window);

    gst_structure_set (buttonsLayout,
                       window->getId().c_str(), GST_TYPE_STRUCTURE,
                       buttonsLayoutAux,
                       NULL);

    gst_structure_free (buttonsLayoutAux);
  }

  g_object_set (G_OBJECT (pointerDetector), WINDOWS_LAYOUT, buttonsLayout,
                NULL);
  gst_structure_free (buttonsLayout);

  busMessageLambda = [&] (GstMessage * message) {
    const GstStructure *st;
    gchar *windowID;
    const gchar *type;
    std::string windowIDStr, typeStr;

    if (GST_MESSAGE_SRC (message) != GST_OBJECT (pointerDetector) ||
        GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT) {
      return;
    }

    st = gst_message_get_structure (message);
    type = gst_structure_get_name (st);

    if ( (g_strcmp0 (type, "window-out") != 0) &&
         (g_strcmp0 (type, "window-in") != 0) ) {
      GST_WARNING ("The message does not have the correct name");
      return;
    }

    if (!gst_structure_get (st, "window", G_TYPE_STRING , &windowID, NULL) ) {
      GST_WARNING ("The message does not contain the window ID");
      return;
    }

    windowIDStr = windowID;
    typeStr = type;

    g_free (windowID);

    if (typeStr == "window-in") {
      try {
        WindowIn event (windowIDStr, shared_from_this(), WindowIn::getName() );

        signalWindowIn (event);
      } catch (std::bad_weak_ptr &e) {
      }
    } else if (typeStr == "window-out") {
      try {
        WindowOut event (windowIDStr, shared_from_this(), WindowOut::getName() );

        signalWindowOut (event);
      } catch (std::bad_weak_ptr &e) {
      }
    }
  };

  bus_handler_id = g_signal_connect (bus, "message",
                                     G_CALLBACK (bus_message_adaptor),
                                     &busMessageLambda);
  g_object_unref (bus);
  // There is no need to reference pointerdetector because its life cycle is the same as the filter life cycle
  g_object_unref (pointerDetector);
}
CrowdDetectorFilterImpl::CrowdDetectorFilterImpl (
  const std::vector<std::shared_ptr<RegionOfInterest>> &rois,
  std::shared_ptr< MediaObjectImpl > parent) :
  FilterImpl (parent)
{
  GstBus *bus;
  std::shared_ptr<MediaPipelineImpl> pipe;
  GstStructure *roisStructure;

  pipe = std::dynamic_pointer_cast<MediaPipelineImpl> (getMediaPipeline() );

  g_object_set (element, "filter-factory", "crowddetector", NULL);

  bus = gst_pipeline_get_bus (GST_PIPELINE (pipe->getPipeline() ) );

  g_object_get (G_OBJECT (element), "filter", &crowdDetector, NULL);

  if (crowdDetector == NULL) {
    g_object_unref (bus);
    throw KurentoException (MEDIA_OBJECT_NOT_AVAILABLE,
                            "Media Object not available");
  }

  roisStructure = gst_structure_new_empty  ("Rois");

  for (auto roi : rois) {
    GstStructure *roiStructureAux = get_structure_from_roi (roi);

    gst_structure_set (roisStructure,
                       roi->getId().c_str(), GST_TYPE_STRUCTURE,
                       roiStructureAux,
                       NULL);

    gst_structure_free (roiStructureAux);
  }

  g_object_set (G_OBJECT (crowdDetector), ROIS_PARAM, roisStructure, NULL);
  gst_structure_free (roisStructure);

  busMessageLambda = [&] (GstMessage * message) {
    const GstStructure *st;
    gchar *roiID;
    const gchar *type;
    std::string roiIDStr, typeStr;

    if (GST_MESSAGE_SRC (message) != GST_OBJECT (crowdDetector) ||
        GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT) {
      return;
    }

    st = gst_message_get_structure (message);
    type = gst_structure_get_name (st);

    if (!gst_structure_get (st, "roi", G_TYPE_STRING , &roiID, NULL) ) {
      GST_WARNING ("The message does not contain the roi ID");
      return;
    }

    roiIDStr = roiID;
    typeStr = type;

    g_free (roiID);

    if (typeStr == "fluidity-event") {

      double fluidity_percentage;
      int fluidity_level;

      if (! (gst_structure_get (st, "fluidity_percentage", G_TYPE_DOUBLE,
                                &fluidity_percentage, NULL) ) ) {
        GST_WARNING ("The message does not contain the fluidity percentage");
        return;
      }

      if (! (gst_structure_get (st, "fluidity_level", G_TYPE_INT,
                                &fluidity_level, NULL) ) ) {
        GST_WARNING ("The message does not contain the fluidity level");
        return;
      }

      try {
        CrowdDetectorFluidity event (fluidity_percentage, fluidity_level, roiIDStr,
                                     shared_from_this(),
                                     CrowdDetectorFluidity::getName() );
        signalCrowdDetectorFluidity (event);
      } catch (std::bad_weak_ptr &e) {
      }
    } else if (typeStr == "occupancy-event") {

      double occupancy_percentage;
      int occupancy_level;

      if (! (gst_structure_get (st, "occupancy_percentage", G_TYPE_DOUBLE,
                                &occupancy_percentage, NULL) ) ) {
        GST_WARNING ("The message does not contain the occupancy percentage");
        return;
      }

      if (! (gst_structure_get (st, "occupancy_level", G_TYPE_INT,
                                &occupancy_level, NULL) ) ) {
        GST_WARNING ("The message does not contain the occupancy level");
        return;
      }

      try {
        CrowdDetectorOccupancy event (occupancy_level, occupancy_percentage,
                                      roiIDStr, shared_from_this(),
                                      CrowdDetectorOccupancy::getName() );
        signalCrowdDetectorOccupancy (event);
      } catch (std::bad_weak_ptr &e) {
      }
    } else if (typeStr == "direction-event") {

      double direction_angle;

      if (! (gst_structure_get (st, "direction_angle", G_TYPE_DOUBLE,
                                &direction_angle, NULL) ) ) {
        GST_WARNING ("The message does not contain the direction angle");
        return;
      }

      try {
        CrowdDetectorDirection event (direction_angle, roiIDStr, shared_from_this(),
                                      CrowdDetectorDirection::getName() );
        signalCrowdDetectorDirection (event);
      } catch (std::bad_weak_ptr &e) {
      }
    } else {
      GST_WARNING ("The message does not have the correct name");
    }
  };

  bus_handler_id = g_signal_connect (bus, "message",
                                     G_CALLBACK (bus_message_adaptor),
                                     &busMessageLambda);
  g_object_unref (bus);

  // There is no need to reference crowddetector because its life cycle is the same as the filter life cycle
  g_object_unref (crowdDetector);
}