From: Sangchul Lee Date: Thu, 26 Nov 2020 11:23:53 +0000 (+0900) Subject: Add infrastructure for setting display object X-Git-Tag: submit/tizen/20210729.023123~179 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ae742a15457a31a645fc925fe6e38f7020bae131;p=platform%2Fcore%2Fapi%2Fwebrtc.git Add infrastructure for setting display object 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 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f3e106b..63b37530 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/include/webrtc.h b/include/webrtc.h index df4ecfa2..c290beb8 100644 --- a/include/webrtc.h +++ b/include/webrtc.h @@ -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 diff --git a/include/webrtc_private.h b/include/webrtc_private.h index d8dfc407..dc5087c9 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -25,6 +25,7 @@ #include #endif #include +#include #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); diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 1150d782..837b3f0b 100644 --- a/packaging/capi-media-webrtc.spec +++ b/packaging/capi-media-webrtc.spec @@ -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. diff --git a/src/webrtc.c b/src/webrtc.c index ad090854..581a38f3 100644 --- a/src/webrtc.c +++ b/src/webrtc.c @@ -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 index 00000000..4b82b4f4 --- /dev/null +++ b/src/webrtc_display.c @@ -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 + +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 diff --git a/src/webrtc_sink.c b/src/webrtc_sink.c index c26d111b..2ba01e7c 100644 --- a/src/webrtc_sink.c +++ b/src/webrtc_sink.c @@ -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