Add infrastructure for setting display object 81/248581/1
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 26 Nov 2020 11:23:53 +0000 (20:23 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 26 Nov 2020 11:30:33 +0000 (20:30 +0900)
Display type and object can be set to each video sink pipeline.
Now it has a dependency on mm-display-interface.

[Version] 0.1.63
[Issue Type] New feature

Change-Id: I856457101cc858acec86f68a86651bac116e8fdf
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
CMakeLists.txt
include/webrtc.h
include/webrtc_private.h
packaging/capi-media-webrtc.spec
src/webrtc.c
src/webrtc_display.c [new file with mode: 0644]
src/webrtc_sink.c

index 3f3e106b570ca971efb7007e24a285350e436e48..63b375306d1b7524eedaa3fba28d2c0a77e6845f 100644 (file)
@@ -11,7 +11,7 @@ SET(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib")
 SET(INC_DIR include)
 INCLUDE_DIRECTORIES(${INC_DIR})
 
-SET(dependents "dlog glib-2.0 gstreamer-1.0 gstreamer-webrtc-1.0 json-glib-1.0 iniparser")
+SET(dependents "dlog glib-2.0 gstreamer-1.0 gstreamer-webrtc-1.0 json-glib-1.0 iniparser mm-common mm-display-interface")
 SET(pc_dependents "capi-base-common" )
 
 INCLUDE(FindPkgConfig)
index df4ecfa2fed0044ef3b7cff0388fdfc8929997a1..c290beb855041002e3984046e9cc7c3438d62ebc 100644 (file)
@@ -55,6 +55,12 @@ typedef void *webrtc_data_channel_h;
  */
 typedef void *webrtc_bytes_data_h;
 
+/**
+ * @brief WebRTC display handle type.
+ * @since_tizen 6.5
+ */
+typedef void *webrtc_display_h;
+
 /**
  * @brief Enumeration for WebRTC error.
  * @since_tizen 6.5
@@ -124,6 +130,16 @@ typedef enum
        WEBRTC_DATA_CHANNEL_TYPE_BYTES,   /**<  Bytes data */
 } webrtc_data_channel_type_e;
 
+/**
+ * @brief Enumeration for WebRTC display type.
+ * @since_tizen 6.5
+ */
+typedef enum
+{
+       WEBRTC_DISPLAY_TYPE_OVERLAY,      /**< Overlay */
+       WEBRTC_DISPLAY_TYPE_EVAS,         /**< Evas image object */
+} webrtc_display_type_e;
+
 /**
  * @brief Called when an error occurs.
  * @details The following error codes can be received:\n
index d8dfc407cc415bd31d1698a04b34d1fbc984e3a0..dc5087c91f3039cd613f40efa905605064ba867d 100644 (file)
@@ -25,6 +25,7 @@
 #include <gst/webrtc/webrtc.h>
 #endif
 #include <iniparser.h>
+#include <mm_display_interface.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -194,12 +195,24 @@ typedef struct _webrtc_ini_s {
        GHashTable *sources;
 } webrtc_ini_s;
 
+typedef struct _webrtc_callbacks {
+       void *callback;
+       void *user_data;
+} webrtc_callbacks_s;
+
+typedef struct _webrtc_display {
+       void *object;
+       int type;
+       webrtc_callbacks_s video_frame_decoded_cb;
+} webrtc_display_s;
+
 typedef struct _webrtc_gst_slot_s {
        unsigned int id;
        GstElement *bin;
        int media_types;    /* values of media_type_e combined with bitwise 'or' */
        int mlines[2];      /* index 0 for audio, 1 for video */
        GstElement *webrtcbin;
+       webrtc_display_s display;
 } webrtc_gst_slot_s;
 
 typedef struct _webrtc_gst_s {
@@ -211,11 +224,6 @@ typedef struct _webrtc_gst_s {
        GHashTable *sink_slots;
 } webrtc_gst_s;
 
-typedef struct _webrtc_callbacks {
-       void *callback;
-       void *user_data;
-} webrtc_callbacks_s;
-
 typedef struct _webrtc_s {
        webrtc_ini_s ini;
 
@@ -225,6 +233,8 @@ typedef struct _webrtc_s {
 
        webrtc_gst_s gst;
 
+       mm_display_interface_h mm_display;
+
        gchar *stun_server_url;
        gchar *desc_offer;
        gchar *desc_answer;
@@ -295,10 +305,15 @@ GstElement *_create_element_from_registry(element_info_s *elem_info);
 int _add_no_target_ghostpad_to_slot(webrtc_gst_slot_s *slot, bool is_src, GstPad **new_pad);
 int _set_ghost_pad_target(GstPad *ghost_pad, GstElement *target_element, bool is_src);
 int _add_rendering_sink_bin(webrtc_s *webrtc, GstPad *src_pad);
+int _set_display_to_sink(webrtc_s *webrtc, unsigned int track_id, unsigned int type, void *display);
 void _sink_slot_destroy_cb(gpointer data);
 void _source_slot_destroy_cb(gpointer data);
 void _generate_dot(webrtc_s *webrtc, const gchar *name);
 
+void _init_display(webrtc_s *webrtc);
+void _deinit_display(webrtc_s *webrtc);
+int _apply_display(webrtc_s *webrtc, webrtc_display_s *display);
+
 int _webrtcbin_create_offer(webrtc_s *webrtc, char **offer);
 int _webrtcbin_create_answer(webrtc_s *webrtc, char **answer);
 int _webrtcbin_set_session_description(webrtc_s *webrtc, const char *description, bool is_remote);
index 1150d782b7e8d1bdf1ab34b5daee3a265acda472..837b3f0b0587d98c74e14f6e27e1417d89253fe8 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.1.62
+Version:    0.1.63
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
@@ -18,6 +18,8 @@ BuildRequires:  pkgconfig(elementary)
 BuildRequires:  pkgconfig(json-glib-1.0)
 BuildRequires:  pkgconfig(libsoup-2.4)
 BuildRequires:  pkgconfig(iniparser)
+BuildRequires:  pkgconfig(mm-display-interface)
+BuildRequires:  pkgconfig(mm-common)
 
 %description
 A WebRTC library in Tizen Native API.
index ad0908548eb055e95e82ae47a5f4a7e40c7e607a..581a38f39073c979de0cf3dd530201e39c788dfd 100644 (file)
@@ -120,6 +120,7 @@ int webrtc_create(webrtc_h *webrtc)
        _gst_init(_webrtc);
        _gst_build_pipeline(_webrtc);
        _init_data_channels(_webrtc);
+       _init_display(_webrtc);
 
        _webrtc->pend_state = WEBRTC_STATE_IDLE;
        _webrtc->state = _webrtc->pend_state;
@@ -146,6 +147,7 @@ int webrtc_destroy(webrtc_h webrtc)
        _webrtc->pend_state = WEBRTC_STATE_IDLE;
        _webrtc->state = _webrtc->pend_state;
 
+       _deinit_display(_webrtc);
        _destroy_data_channels(_webrtc);
        _gst_destroy_pipeline(_webrtc);
        _unload_ini(_webrtc);
diff --git a/src/webrtc_display.c b/src/webrtc_display.c
new file mode 100644 (file)
index 0000000..4b82b4f
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "webrtc.h"
+#include "webrtc_private.h"
+#include <mm_error.h>
+
+int _apply_display(webrtc_s *webrtc, webrtc_display_s *display)
+{
+       RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
+       RET_VAL_IF(display == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "sink is NULL");
+
+       switch (display->type) {
+       case WEBRTC_DISPLAY_TYPE_OVERLAY:
+               /* TODO: Implemenation */
+               LOG_DEBUG("it's OVERLAY type");
+               break;
+
+       case WEBRTC_DISPLAY_TYPE_EVAS:
+               /* TODO: Implemenation */
+               LOG_DEBUG("it's EVAS type");
+               break;
+
+       default:
+               LOG_ERROR_IF_REACHED("type(%d)", display->type);
+               return WEBRTC_ERROR_INVALID_OPERATION;
+       }
+
+       return WEBRTC_ERROR_NONE;
+}
+
+void _init_display(webrtc_s *webrtc)
+{
+       RET_IF(webrtc == NULL, "webrtc is NULL");
+
+       if (mm_display_interface_init(&webrtc->mm_display) != MM_ERROR_NONE)
+               LOG_WARNING("failed to mm_display_interface_init()");
+}
+
+void _deinit_display(webrtc_s *webrtc)
+{
+       RET_IF(webrtc == NULL, "webrtc is NULL");
+
+       if (webrtc->mm_display) {
+               mm_display_interface_deinit(webrtc->mm_display);
+               webrtc->mm_display = NULL;
+       }
+}
\ No newline at end of file
index c26d111b7ab6c0622afadc7bf18d4491d8697e92..2ba01e7ca43287d68c6f1445b88a5613f7b6ecae 100644 (file)
@@ -36,6 +36,7 @@ static int __build_videosink(webrtc_s *webrtc, GstElement *decodebin, GstPad *sr
        webrtc_gst_slot_s *sink;
        GstElement *videoconvert;
        GstElement *videosink;
+       const char *videosink_factory_name = DEFAULT_ELEMENT_VIDEOSINK;
 
        RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
        RET_VAL_IF(decodebin == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "decodebin is NULL");
@@ -52,8 +53,9 @@ static int __build_videosink(webrtc_s *webrtc, GstElement *decodebin, GstPad *sr
                return WEBRTC_ERROR_INVALID_OPERATION;
        }
 
+       /* TODO: Implemenation per sink->display.type */
        /* FIXME: get factory name from ini */
-       if (!(videosink = _create_element(DEFAULT_ELEMENT_VIDEOSINK, NULL))) {
+       if (!(videosink = _create_element(videosink_factory_name, NULL))) {
                LOG_ERROR("failed to create videosink");
                return WEBRTC_ERROR_INVALID_OPERATION;
        }
@@ -336,3 +338,33 @@ error_before_insert:
 
        return WEBRTC_ERROR_INVALID_OPERATION;
 }
+
+int _set_display_to_sink(webrtc_s *webrtc, unsigned int track_id, unsigned int type, void *display)
+{
+       webrtc_gst_slot_s *sink;
+       gchar *decodebin_name;
+
+       RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
+       RET_VAL_IF(track_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "track id is 0");
+       RET_VAL_IF(display == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "display is NULL");
+
+       decodebin_name = g_strdup_printf("track_%u", track_id);
+
+       sink = __find_sink_slot(webrtc, decodebin_name);
+       if (sink == NULL) {
+               LOG_ERROR("could not find an item by [%s] in sink slots", decodebin_name);
+               g_free(decodebin_name);
+               return WEBRTC_ERROR_INVALID_PARAMETER;
+       }
+       g_free(decodebin_name);
+
+       RET_VAL_IF(sink->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL");
+       RET_VAL_IF((sink->media_types & MEDIA_TYPE_VIDEO) == 0x0, WEBRTC_ERROR_INVALID_OPERATION, "it's not a video track");
+
+       sink->display.type = type;
+       sink->display.object = display;
+
+       LOG_INFO("type[%d] object[%p]", type, display);
+
+       return _apply_display(webrtc, &sink->display);
+}
\ No newline at end of file