webrtc_source_private: move _set_payload_type() to webrtc_source_private.c 71/278471/4
authorhj kim <backto.kim@samsung.com>
Thu, 21 Jul 2022 02:20:25 +0000 (11:20 +0900)
committerhj kim <backto.kim@samsung.com>
Mon, 25 Jul 2022 04:57:10 +0000 (13:57 +0900)
[Version] 0.3.165
[Issue Type] Refactoring

Change-Id: If44d7add0f791f6cd2889a7a84c9d409d47aba78

include/webrtc_source_private.h
packaging/capi-media-webrtc.spec
src/webrtc_source.c
src/webrtc_source_mediapacket.c
src/webrtc_source_private.c

index 5c2401dbf319e751b4d1d6ab6fda4bf7b715e819..48ec08e2ad18d6f52e99e68522e3bb7e6c9e5d8d 100644 (file)
@@ -84,10 +84,10 @@ bool _is_supported_mime_type(media_format_mimetype_e mime_type);
 bool _is_encoded_format_supported(webrtc_media_source_type_e type, webrtc_ini_s *ini);
 GstCaps *_get_caps_from_encoded_audio_media_type(const char *media_type, int channels, int samplerate);
 GstCaps *_get_caps_from_encoded_video_media_type(const char *media_type, int width, int height);
-unsigned int _get_available_payload_type(webrtc_s *webrtc);
 GstCaps *_make_rtp_caps(const gchar *media_type, unsigned int payload_type, webrtc_gst_slot_s *source);
 int _set_mediapacketsrc_codec_info(webrtc_s *webrtc, webrtc_gst_slot_s *source, media_format_mimetype_e mime_type);
 int _get_screen_resolution(int *width, int *height);
 const char *_get_element_name(int av_idx, gst_element_e element);
+int _set_payload_type(webrtc_s *webrtc, webrtc_gst_slot_s *source, int av_idx, const gchar *media_type);
 
 #endif /* __TIZEN_MEDIA_WEBRTC_SOURCE_COMMON_H__ */
index b2e3a2e774611e607bcc6dcd781dcfdbb156b9d2..506acd6d229d4dc403bbb584482c0a76bd4bbeec 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.3.164
+Version:    0.3.165
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 464b19ad3b9ce6a47b755cacb88a2d9e02da2dc1..19c9ac1cf809d577903b107a764def5c6f8857dc 100644 (file)
@@ -298,19 +298,6 @@ static GstElement *__get_hw_encoder_element(webrtc_s *webrtc, webrtc_gst_slot_s
 }
 //LCOV_EXCL_STOP
 
-static int __get_fixed_payload_type(const gchar *media_type)
-{
-       RET_VAL_IF(media_type == NULL, -1, "media_type is NULL");
-
-       if (!g_strcmp0(media_type, MEDIA_TYPE_AUDIO_MULAW))
-               return 0;
-       if (!g_strcmp0(media_type, MEDIA_TYPE_AUDIO_ALAW))
-               return 8;
-
-       LOG_DEBUG("%s might need to use dynamic id", media_type);
-       return -1;
-}
-
 static void __return_payload_type(webrtc_s *webrtc, unsigned int payload_type)
 {
        int i;
@@ -462,26 +449,6 @@ static GstElement * __prepare_encoder(webrtc_s *webrtc, webrtc_gst_slot_s *sourc
        return encoder;
 }
 
-static int __set_payload_type(webrtc_s *webrtc, webrtc_gst_slot_s *source, int av_idx, const gchar *media_type)
-{
-       int payload_type = -1;
-
-       RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
-       RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
-
-       if (media_type)
-               if ((payload_type = __get_fixed_payload_type(media_type)) != -1)
-                       goto out;
-
-       if ((payload_type = _get_available_payload_type(webrtc)) == 0)
-               return WEBRTC_ERROR_INVALID_OPERATION;
-
-out:
-       source->av[av_idx].pt = payload_type;
-
-       return WEBRTC_ERROR_NONE;
-}
-
 static GstPadProbeReturn __payloaded_data_probe_cb(GstPad *pad, GstPadProbeInfo *info, gpointer user_data)
 {
        probe_userdata_s *probe_data = (probe_userdata_s *)user_data;
@@ -751,7 +718,6 @@ int __create_rest_of_elements(webrtc_s *webrtc, webrtc_gst_slot_s *source, bool
        GstCaps *sink_caps;
        element_info_s elem_info;
        gchar *media_type = NULL;
-       int payload_type;
        int idx;
 
        RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
@@ -825,13 +791,10 @@ skip_encoder:
                goto error;
        APPEND_ELEMENT(*element_list, capsfilter2);
 
-       if ((payload_type = __get_fixed_payload_type(media_type)) == -1)
-               if ((payload_type = _get_available_payload_type(webrtc)) == 0)
-                       goto error;
-
-       source->av[idx].pt = payload_type;
+       if(_set_payload_type(webrtc, source, idx, media_type) != WEBRTC_ERROR_NONE)
+               goto error;
 
-       if ((sink_caps = _make_rtp_caps(media_type, payload_type, source))) {
+       if ((sink_caps = _make_rtp_caps(media_type, source->av[idx].pt, source))) {
                g_object_set(G_OBJECT(capsfilter2), "caps", sink_caps, NULL);
                gst_caps_unref(sink_caps);
        }
@@ -1505,7 +1468,7 @@ static GstElement * __prepare_capsfilter_for_filesrc_pipeline(webrtc_gst_slot_s
        if (!(capsfilter = _create_element(DEFAULT_ELEMENT_CAPSFILTER, _get_element_name(GET_AV_IDX(is_audio), ELEMENT_CAPSFILTER))))
                return NULL;
 
-       if(__set_payload_type(source->webrtc, source, GET_AV_IDX(is_audio), NULL) != WEBRTC_ERROR_NONE) {
+       if(_set_payload_type(source->webrtc, source, GET_AV_IDX(is_audio), NULL) != WEBRTC_ERROR_NONE) {
                SAFE_GST_OBJECT_UNREF(capsfilter);
                return NULL;
        }
@@ -2490,7 +2453,7 @@ int _set_transceiver_codec(webrtc_s *webrtc, unsigned int source_id, webrtc_medi
                if (source->av[av_idx].pt >= MIN_DYNAMIC_PAYLOAD_TYPE)
                        __return_payload_type(webrtc, source->av[av_idx].pt);
 
-               if((ret = __set_payload_type(webrtc, source, av_idx, payload_info->gst_media_type)) != WEBRTC_ERROR_NONE)
+               if((ret = _set_payload_type(webrtc, source, av_idx, payload_info->gst_media_type)) != WEBRTC_ERROR_NONE)
                        return ret;
        }
 
index 79b46038da3121807dc46ed151895dbb761296ba..e905848a0a2b8f38345fb3b0496c782199aa36c6 100644 (file)
@@ -319,7 +319,6 @@ static int __create_rest_of_elements_for_encoded_format(webrtc_s *webrtc, webrtc
        GstElement *payloader;
        GstElement *queue;
        GstElement *capsfilter;
-       unsigned int payload_type;
 
        RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
        RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
@@ -342,13 +341,10 @@ static int __create_rest_of_elements_for_encoded_format(webrtc_s *webrtc, webrtc
                goto error;
        APPEND_ELEMENT(*element_list, capsfilter);
 
-       payload_type = _get_available_payload_type(webrtc);
-       if (payload_type == 0)
+       if(_set_payload_type(webrtc, source, GET_AV_IDX_BY_TYPE(source->media_types), NULL) != WEBRTC_ERROR_NONE)
                goto error;
 
-       source->av[GET_AV_IDX_BY_TYPE(source->media_types)].pt = payload_type;
-
-       if ((sink_caps = _make_rtp_caps(media_type, payload_type, source))) {
+       if ((sink_caps = _make_rtp_caps(media_type, source->av[GET_AV_IDX_BY_TYPE(source->media_types)].pt, source))) {
                g_object_set(G_OBJECT(capsfilter), "caps", sink_caps, NULL);
                gst_caps_unref(sink_caps);
        }
index dc8fab31692d5a3b709df9da00834bda6620ba68..2560d940ff958cbde2b9c91bcf3e8d7d9a3749e4 100644 (file)
@@ -311,27 +311,6 @@ bool _is_supported_mime_type(media_format_mimetype_e mime_type)
        }
 }
 
-unsigned int _get_available_payload_type(webrtc_s *webrtc)
-{
-       int bitmask = 0x1;
-       int count = 0;
-
-       RET_VAL_IF(webrtc == NULL, 0, "webrtc is NULL");
-
-       while (count++ < PAYLOAD_TYPE_BITS) {
-               if (webrtc->payload_types & bitmask) {
-                       bitmask <<= 1;
-                       continue;
-               }
-               webrtc->payload_types |= bitmask;
-               LOG_DEBUG("found available payload type[%d]", count + 95);
-               return count + 95; /* 96 ~ 127 */
-       }
-
-       LOG_ERROR("could not assign payload type");
-       return 0;
-}
-
 GstCaps *_make_rtp_caps(const gchar *media_type, unsigned int payload_type, webrtc_gst_slot_s *source)
 {
        GstCaps *caps;
@@ -377,4 +356,60 @@ const char *_get_element_name(int av_idx, gst_element_e element)
        RET_VAL_IF((element > ELEMENT_FAKESINK), NULL, "invalid element [%d]", element);
 
        return _av_element_tbl[av_idx][element];
-}
\ No newline at end of file
+}
+
+static int __get_fixed_payload_type(const gchar *media_type)
+{
+       RET_VAL_IF(media_type == NULL, -1, "media_type is NULL");
+
+       if (!g_strcmp0(media_type, MEDIA_TYPE_AUDIO_MULAW))
+               return 0;
+       if (!g_strcmp0(media_type, MEDIA_TYPE_AUDIO_ALAW))
+               return 8;
+
+       LOG_DEBUG("%s might need to use dynamic id", media_type);
+
+       return -1;
+}
+
+static int __get_available_payload_type(webrtc_s *webrtc)
+{
+       int bitmask = 0x1;
+       int count = 0;
+
+       RET_VAL_IF(webrtc == NULL, 0, "webrtc is NULL");
+
+       while (count++ < PAYLOAD_TYPE_BITS) {
+               if (webrtc->payload_types & bitmask) {
+                       bitmask <<= 1;
+                       continue;
+               }
+               webrtc->payload_types |= bitmask;
+               LOG_DEBUG("found available payload type[%d]", count + 95);
+               return count + 95; /* 96 ~ 127 */
+       }
+
+       LOG_ERROR("could not assign payload type");
+
+       return -1;
+}
+
+int _set_payload_type(webrtc_s *webrtc, webrtc_gst_slot_s *source, int av_idx, const gchar *media_type)
+{
+       int payload_type = -1;
+
+       RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
+       RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
+
+       if (media_type)
+               if ((payload_type = __get_fixed_payload_type(media_type)) != -1)
+                       goto out;
+
+       if ((payload_type = __get_available_payload_type(webrtc)) == -1)
+               return WEBRTC_ERROR_INVALID_OPERATION;
+
+out:
+       source->av[av_idx].pt = payload_type;
+
+       return WEBRTC_ERROR_NONE;
+}