Add system setting to use ULPFEC and RED 84/250384/13
authorHyunil <hyunil46.park@samsung.com>
Thu, 24 Dec 2020 04:47:47 +0000 (13:47 +0900)
committerHyunil <hyunil46.park@samsung.com>
Wed, 30 Dec 2020 05:04:10 +0000 (14:04 +0900)
- 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 <hyunil46.park@samsung.com>
include/webrtc_private.h
packaging/capi-media-webrtc.spec
src/webrtc_ini.c
src/webrtc_private.c

index 5ddecc979e03fd45c3c9424098e794ebca3b6b37..8f732abe7a1b6671f2a7f1716ca147441e31e1be 100644 (file)
@@ -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 {
index 022a83d0b314bb5d59a3a6a51e361d4a4c0d4aa4..cc97edeb0ca23eb825221709a54007e80e7b3015 100644 (file)
@@ -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
index f884b18718317a4e083d0a28a2ff8258570f458d..94fdd5f7242d52c376f9ec37acf5e76be4901ebd 100644 (file)
@@ -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);
index db91fe687aab0ea667e989b37eb8fd053cd86b6d..0c204a9e91a13a4ffe2574ec6dbee807ea7d815c 100644 (file)
@@ -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
+}