From f9293f1a48e2e5d23f15ece4d67d8880d5e9eac8 Mon Sep 17 00:00:00 2001 From: Hyunil Date: Thu, 24 Dec 2020 13:47:47 +0900 Subject: [PATCH] Add system setting to use ULPFEC and RED - ULPFEC: Generic Forward Error Correction(FEC) using Uneven Level Protection(ULP) as described in RFC 5109(https://tools.ietf.org/html/rfc5109) - RED: Encoded Redundant Audio Data (RED) as per RFC 2198(https://tools.ietf.org/html/rfc2198) - Apply only to video with a large amount of RTP packet such as Chrome [Version] 0.1.73 [Issue Type] New feature Change-Id: If3fce2c16a626c1d4196a25209d9670396a9bb77 Signed-off-by: Hyunil --- include/webrtc_private.h | 2 ++ packaging/capi-media-webrtc.spec | 2 +- src/webrtc_ini.c | 6 ++++++ src/webrtc_private.c | 29 ++++++++++++++++++++++++++++- 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/include/webrtc_private.h b/include/webrtc_private.h index 5ddecc97..8f732abe 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -175,6 +175,8 @@ typedef struct _ini_item_general_s { gchar **gst_excluded_elements; const char *stun_server; int jitterbuffer_latency; + bool use_ulpfec_red; + int fec_percentage; } ini_item_general_s; typedef struct _ini_item_media_source_s { diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 022a83d0..cc97edeb 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.72 +Version: 0.1.73 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_ini.c b/src/webrtc_ini.c index f884b187..94fdd5f7 100644 --- a/src/webrtc_ini.c +++ b/src/webrtc_ini.c @@ -21,6 +21,8 @@ #define DEFAULT_GENERATE_DOT true #define DEFAULT_DOT_PATH "/tmp" #define DEFAULT_JITTERBUFFER_LATENCY 200 /* ms */ +#define DEFAULT_USE_ULPFEC_RED true +#define DEFAULT_FEC_PERCENTAGE 100 /* FEC overhead percentage for the whole stream */ /* categories */ #define INI_CATEGORY_GENERAL "general" @@ -38,6 +40,8 @@ #define INI_ITEM_GST_EXCLUDED_ELEMENTS "gstreamer excluded elements" #define INI_ITEM_STUN_SERVER "stun server" #define INI_ITEM_RTP_JITTERBUFFER_LATENCY "rtp jitterbuffer latency" +#define INI_ITEM_USE_ULPFEC_RED "use ulpfec red" +#define INI_ITEM_FEC_PERCENTAGE "fec percentage" /* items for media source */ #define INI_ITEM_SOURCE_ELEMENT "source element" @@ -341,6 +345,8 @@ int _load_ini(webrtc_s *webrtc) __ini_read_list(ini->dict, INI_CATEGORY_GENERAL, INI_ITEM_GST_EXCLUDED_ELEMENTS, &ini->general.gst_excluded_elements); ini->general.stun_server = __ini_get_string(ini->dict, INI_CATEGORY_GENERAL, INI_ITEM_STUN_SERVER, NULL); ini->general.jitterbuffer_latency = __ini_get_int(ini->dict, INI_CATEGORY_GENERAL, INI_ITEM_RTP_JITTERBUFFER_LATENCY, DEFAULT_JITTERBUFFER_LATENCY); + ini->general.use_ulpfec_red = __ini_get_boolean(webrtc->ini.dict, INI_CATEGORY_GENERAL, INI_ITEM_USE_ULPFEC_RED, DEFAULT_USE_ULPFEC_RED); + ini->general.fec_percentage = __ini_get_int(webrtc->ini.dict, INI_CATEGORY_GENERAL, INI_ITEM_FEC_PERCENTAGE, DEFAULT_FEC_PERCENTAGE); /* default setting for a media source */ __apply_media_source_setting(ini, &ini->media_source, INI_CATEGORY_MEDIA_SOURCE); diff --git a/src/webrtc_private.c b/src/webrtc_private.c index db91fe68..0c204a9e 100644 --- a/src/webrtc_private.c +++ b/src/webrtc_private.c @@ -745,6 +745,31 @@ int _set_ghost_pad_target(GstPad *ghost_pad, GstElement *target_element, bool is return WEBRTC_ERROR_NONE; } +static void __webrtcbin_transceiver_set_ulpfec_red(webrtc_s *webrtc, GstWebRTCRTPTransceiver *transceiver) +{ + GstElement *rtpbin; + + RET_IF(webrtc == NULL, "webrtc is NULL"); + RET_IF(transceiver == NULL, "transceiver is NULL"); + + if (!webrtc->ini.general.use_ulpfec_red) { + LOG_DEBUG("skip setting ULPFEC/RED"); + return; + } + + g_object_set(transceiver, "fec-type", GST_WEBRTC_FEC_TYPE_ULP_RED, + "fec-percentage", webrtc->ini.general.fec_percentage, NULL); + LOG_DEBUG("set ULPFEC/RED, fec-percentage: %d", webrtc->ini.general.fec_percentage); + + if (!(rtpbin = gst_bin_get_by_name(GST_BIN(webrtc->gst.webrtcbin), "rtpbin"))) { + LOG_ERROR("failed to get rtpbin"); + return; + } + LOG_INFO("Set do-lost, ULPFEC recovers a lost packet when do-lost event occurs"); + g_object_set(G_OBJECT(rtpbin), "do-lost", true, NULL); + gst_object_unref(rtpbin); +} + static void __webrtcbin_pad_added_cb(GstElement *webrtcbin, GstPad *new_pad, gpointer user_data) { int ret = WEBRTC_ERROR_NONE; @@ -798,6 +823,8 @@ static void __webrtcbin_on_new_transceiver_cb(GstElement *webrtcbin, GstWebRTCRT source->mlines[i] = transceiver->mline; LOG_DEBUG("source[%s, id:%u, mline:%d for %s]", (gchar*)key, source->id, source->mlines[i], i == MLINES_IDX_AUDIO ? "AUDIO" : "VIDEO"); + if (i == MLINES_IDX_VIDEO) + __webrtcbin_transceiver_set_ulpfec_red(webrtc, transceiver); } } } @@ -1405,4 +1432,4 @@ bool _webrtcbin_have_remote_offer(webrtc_s *webrtc) g_object_get(webrtc->gst.webrtcbin, "signaling-state", &signaling_state, NULL); return (signaling_state == GST_WEBRTC_SIGNALING_STATE_HAVE_REMOTE_OFFER); -} \ No newline at end of file +} -- 2.34.1