waylandsink : Add fakesink function(signal-handoffs) for stream callback of MSL with...
authorHyunil <hyunil46.park@samsung.com>
Mon, 29 Aug 2016 08:20:48 +0000 (17:20 +0900)
committerHyunil <hyunil46.park@samsung.com>
Mon, 29 Aug 2016 08:27:36 +0000 (17:27 +0900)
Change-Id: Id89792bf7827e6292112ef7d177b04cc438ebee0
Signed-off-by: Hyunil <hyunil46.park@samsung.com>
ext/wayland/gstwaylandsink.c
ext/wayland/gstwaylandsink.h
ext/wayland/wlwindow.c

index a526750..66a14a2 100755 (executable)
@@ -135,6 +135,10 @@ gst_waylandsink_flip_get_type (void)
 enum
 {
   SIGNAL_0,
+#ifdef GST_WLSINK_ENHANCEMENT
+  SIGNAL_HANDOFF,
+  SIGNAL_PREROLL_HANDOFF,
+#endif
   LAST_SIGNAL
 };
 
@@ -144,6 +148,7 @@ enum
   PROP_0,
   PROP_DISPLAY,
 #ifdef GST_WLSINK_ENHANCEMENT
+  PROP_SIGNAL_HANDOFFS,
   PROP_USE_GAPLESS,
   PROP_KEEP_CAMERA_PREVIEW,
   PROP_USE_TBM,
@@ -227,6 +232,9 @@ static void gst_wayland_sink_end_geometry_change (GstWaylandVideo * video);
 static gboolean gst_wayland_sink_event (GstBaseSink * bsink, GstEvent * event);
 static void gst_wayland_sink_update_window_geometry (GstWaylandSink * sink);
 static void render_last_buffer (GstWaylandSink * sink);
+
+static guint gst_waylandsink_signals[LAST_SIGNAL] = { 0 };
+
 #endif
 #define gst_wayland_sink_parent_class parent_class
 G_DEFINE_TYPE_WITH_CODE (GstWaylandSink, gst_wayland_sink, GST_TYPE_VIDEO_SINK,
@@ -412,18 +420,36 @@ gst_wayland_sink_class_init (GstWaylandSinkClass * klass)
 
   g_object_class_install_property (gobject_class, PROP_ALIGN_WIDTH,
       g_param_spec_double ("align-w", "align width",
-          "Align with, Left: 0.0, Middle: 0.5, Right: 1.0 \n"
+          "Align with, Left: 0.0, Middle: 0.5, Right: 1.0"
           "Please set align-w and align-h togethrer"
           "Function is not supported in DISP_GEO_METHOD_CUSTOM_ROI. ", 0.0,
           1.0, 0.5, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
   g_object_class_install_property (gobject_class, PROP_ALIGN_HEIGHT,
       g_param_spec_double ("align-h", "align height",
-          "Align height, Left: 0.0, Middle: 0.5, Right: 1.0 \n"
+          "Align height, Left: 0.0, Middle: 0.5, Right: 1.0"
           "Please set align-w and align-h togethrer"
           "Function is not supported in DISP_GEO_METHOD_CUSTOM_ROI. ", 0.0,
           1.0, 0.5, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
+  /* fakesink function for stream callback of MSL with browser */
+  g_object_class_install_property (gobject_class, PROP_SIGNAL_HANDOFFS,
+      g_param_spec_boolean ("signal-handoffs", "Signal handoffs",
+          "Send a signal before unreffing the buffer", FALSE,
+          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+  gst_waylandsink_signals[SIGNAL_HANDOFF] =
+      g_signal_new ("handoff", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
+      G_STRUCT_OFFSET (GstWaylandSinkClass, handoff), NULL, NULL,
+      g_cclosure_marshal_generic, G_TYPE_NONE, 2,
+      GST_TYPE_BUFFER | G_SIGNAL_TYPE_STATIC_SCOPE, GST_TYPE_PAD);
+
+  gst_waylandsink_signals[SIGNAL_PREROLL_HANDOFF] =
+      g_signal_new ("preroll-handoff", G_TYPE_FROM_CLASS (klass),
+      G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstWaylandSinkClass, preroll_handoff),
+      NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2,
+      GST_TYPE_BUFFER | G_SIGNAL_TYPE_STATIC_SCOPE, GST_TYPE_PAD);
+
 #endif
 }
 
@@ -448,6 +474,7 @@ gst_wayland_sink_init (GstWaylandSink * sink)
 {
   FUNCTION;
 #ifdef GST_WLSINK_ENHANCEMENT
+  sink->signal_handoffs = FALSE;
   sink->keep_camera_preview = FALSE;
   sink->got_costum_event = FALSE;
   sink->USE_TBM = TRUE;
@@ -771,6 +798,9 @@ gst_wayland_sink_get_property (GObject * object,
     case PROP_KEEP_CAMERA_PREVIEW:
       g_value_set_boolean (value, sink->keep_camera_preview);
       break;
+    case PROP_SIGNAL_HANDOFFS:
+      g_value_set_boolean (value, sink->signal_handoffs);
+      break;
     case PROP_USE_TBM:
       g_value_set_boolean (value, sink->USE_TBM);
       break;
@@ -822,7 +852,7 @@ gst_wayland_sink_get_property (GObject * object,
     case PROP_OFFSET_WIDTH:
       g_value_set_uint (value, sink->offset_w);
       break;
-     case PROP_OFFSET_HEIGHT:
+    case PROP_OFFSET_HEIGHT:
       g_value_set_uint (value, sink->offset_h);
       break;
     case PROP_ALIGN_WIDTH:
@@ -853,6 +883,14 @@ gst_wayland_sink_set_property (GObject * object,
       GST_OBJECT_UNLOCK (sink);
       break;
 #ifdef GST_WLSINK_ENHANCEMENT
+    case PROP_SIGNAL_HANDOFFS:
+      sink->signal_handoffs = g_value_get_boolean (value);
+      GST_LOG ("set signal_handoffs(%d)", sink->signal_handoffs);
+      if (sink->signal_handoffs && sink->window) {
+        /* overlay -> hand-off */
+        gst_wayland_sink_stop_video (sink);
+      }
+      break;
     case PROP_KEEP_CAMERA_PREVIEW:
       sink->keep_camera_preview = g_value_get_boolean (value);
       GST_LOG ("keep_camera_preview (%d)", sink->keep_camera_preview);
@@ -1621,8 +1659,21 @@ gst_wayland_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
 static GstFlowReturn
 gst_wayland_sink_preroll (GstBaseSink * bsink, GstBuffer * buffer)
 {
+#ifdef GST_WLSINK_ENHANCEMENT
+  GstWaylandSink *sink = GST_WAYLAND_SINK (bsink);
   FUNCTION;
+
   GST_DEBUG_OBJECT (bsink, "preroll buffer %p", buffer);
+
+  if (sink->signal_handoffs) {
+    GST_LOG ("g_signal_emit: preroll-handoff");
+    g_signal_emit (sink,
+        gst_waylandsink_signals[SIGNAL_PREROLL_HANDOFF], 0, buffer,
+        bsink->sinkpad);
+
+    return GST_FLOW_OK;
+  }
+#endif
   return gst_wayland_sink_render (bsink, buffer);
 }
 
@@ -1745,6 +1796,14 @@ gst_wayland_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
     gst_wayland_sink_update_window_geometry (sink);
 #endif
   }
+
+  if (sink->signal_handoffs) {
+    GST_LOG ("g_signal_emit: hand-off ");
+    g_signal_emit (sink, gst_waylandsink_signals[SIGNAL_HANDOFF], 0, buffer,
+        bsink->sinkpad);
+    goto done;
+  }
+
   /* drop buffers until we get a frame callback */
   if (g_atomic_int_get (&sink->redraw_pending) == TRUE
       && !gst_wayland_sink_check_use_gapless (sink))
index 8e43c53..702ec4e 100644 (file)
@@ -97,7 +97,10 @@ struct _GstWaylandSink
   gboolean redraw_pending;
   GMutex render_lock;
   GstBuffer *last_buffer;
+
 #ifdef GST_WLSINK_ENHANCEMENT
+  gboolean signal_handoffs;
+
   gboolean keep_camera_preview;
   gboolean got_costum_event;
   gboolean visible;
@@ -117,6 +120,11 @@ struct _GstWaylandSink
 struct _GstWaylandSinkClass
 {
   GstVideoSinkClass parent;
+#ifdef GST_WLSINK_ENHANCEMENT
+  /* signals */
+  void (*handoff) (GstElement *element, GstBuffer *buf, GstPad *pad);
+  void (*preroll_handoff) (GstElement *element, GstBuffer *buf, GstPad *pad);
+#endif
 };
 
 GType
index e925888..e416c8b 100644 (file)
@@ -790,23 +790,6 @@ done:
     GST_INFO ("wl_surface_commit (video_surface@%p)", window->video_surface);
     wl_surface_commit (window->video_surface);
   }
-
-  if (gst_wl_window_is_toplevel (window)) {
-    struct wl_region *region;
-
-    region = wl_compositor_create_region (window->display->compositor);
-    GST_INFO ("wl_region@%p = wl_compositor_create_region (wl_compositor@%p)",
-        region, window->display->compositor);
-    GST_INFO ("wl_region_add (wl_region@%p, x@%d, y@%d, w@%d, h@%d)", region, 0,
-        0, window->render_rectangle.w, window->render_rectangle.h);
-    wl_region_add (region, 0, 0, window->render_rectangle.w,
-        window->render_rectangle.h);
-    GST_INFO ("wl_surface_set_input_region (area_surface@%p, wl_region@%p)",
-        window->area_surface, region);
-    wl_surface_set_input_region (window->area_surface, region);
-    GST_INFO ("wl_region_destroy (wl_region@%p)", region);
-    wl_region_destroy (region);
-  }
 }
 #else
 static void
@@ -950,15 +933,10 @@ gst_wl_window_set_render_rectangle (GstWlWindow * window, gint x, gint y,
 #if GST_WLSINK_ENHANCEMENT
   FUNCTION;
   g_return_if_fail (window != NULL);
-  if (gst_wl_window_is_toplevel (window)) {
-    /* let's set windwo size for convenient gst-launch test */
-    x = 0, y = 0, w = 720, h = 1280;
-    window->render_rectangle.x = x;
-    window->render_rectangle.y = y;
-    window->render_rectangle.w = w;
-    window->render_rectangle.h = h;
-  } else {
-    /* we already set area surface size, ignore call by app, app need to remove call */
+
+  if (window->disp_geo_method.value != DISP_GEO_METHOD_CUSTOM_ROI) {
+    GST_ERROR
+        ("must be set display-geometry-method to DISP_GEO_METHOD_CUSTOM_ROI before setting render rectangle()");
     return;
   }