webrtc_source: Rename functions and replace codes with the function 69/274169/2 accepted/tizen/unified/20220426.132039 submit/tizen/20220426.020921
authorSangchul Lee <sc11.lee@samsung.com>
Fri, 22 Apr 2022 09:42:27 +0000 (18:42 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Mon, 25 Apr 2022 03:07:43 +0000 (12:07 +0900)
[Version] 0.3.95
[Issue Type] Refactoring

Change-Id: I517b4ade896132e5a25f5a91f0ad422ae7ca9abd
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
packaging/capi-media-webrtc.spec
src/webrtc_source.c

index 88c68b0d70ca160b033bd20e0459aeffacce6681..529f3714f83c7763e0eac6cb0675850c640fc08d 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.3.94
+Version:    0.3.95
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index c4b005a0ca47ed214db05c675930bc34261ea9af..36da3e62b3d025aa15bd2aa9776640feb8122c09 100644 (file)
@@ -229,7 +229,7 @@ static GstAudioFormat __get_gst_audio_format(media_format_mimetype_e mime_type)
        }
 }
 
-static GstAudioFormat __get_gst_audio_format_from_string(const char *format)
+static GstAudioFormat __get_gst_audio_raw_format_from_string(const char *format)
 {
        RET_VAL_IF(format == NULL, GST_AUDIO_FORMAT_UNKNOWN, "format is NULL");
 
@@ -339,6 +339,54 @@ static GstCaps *__make_video_raw_caps_with_framerate(webrtc_gst_slot_s *source,
        return caps;
 }
 
+static GstCaps *__make_mediapacketsrc_raw_caps_from_media_format(webrtc_gst_slot_s *source)
+{
+       GstCaps *caps = NULL;
+       media_format_mimetype_e mime_type;
+
+       RET_VAL_IF(source == NULL, NULL, "source is NULL");
+       RET_VAL_IF(source->media_format == NULL, NULL, "media_format is NULL");
+       RET_VAL_IF(source->type != WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET, NULL,
+               "type(%d) is not for media packet source", source->type);
+
+       if (source->media_types == MEDIA_TYPE_AUDIO) {
+               int channels;
+               int samplerate;
+               GstAudioInfo info;
+               GstAudioFormat format;
+
+               RET_VAL_IF(media_format_get_audio_info(source->media_format, &mime_type, &channels, &samplerate, NULL, NULL) != MEDIA_FORMAT_ERROR_NONE,
+                       NULL, "failed to media_format_get_audio_info()");
+
+               format = __get_gst_audio_format(mime_type);
+               RET_VAL_IF(format == GST_AUDIO_FORMAT_ENCODED || format == GST_AUDIO_FORMAT_UNKNOWN, NULL, "could not get valid GstAudioFormat for PCM");
+
+               gst_audio_info_set_format(&info, format, samplerate, channels, NULL);
+               caps = gst_audio_info_to_caps(&info);
+
+       } else if (source->media_types == MEDIA_TYPE_VIDEO) {
+               int width;
+               int height;
+               int framerate;
+
+               RET_VAL_IF(media_format_get_video_info(source->media_format, &mime_type, &width, &height, NULL, NULL) != MEDIA_FORMAT_ERROR_NONE,
+                       NULL, "failed to media_format_get_video_info()");
+               RET_VAL_IF(media_format_get_video_frame_rate(source->media_format, &framerate) != MEDIA_FORMAT_ERROR_NONE,
+                       NULL, "failed to media_format_get_video_frame_rate()");
+               caps = gst_caps_new_simple(MEDIA_TYPE_VIDEO_RAW,
+                                               "format", G_TYPE_STRING, __get_video_format_name(mime_type, source->zerocopy_enabled),
+                                               "framerate", GST_TYPE_FRACTION, framerate, 1,
+                                               "width", G_TYPE_INT, width,
+                                               "height", G_TYPE_INT, height,
+                                               NULL);
+
+       } else {
+               LOG_ERROR_IF_REACHED("source->media_types(0x%x)", source->media_types);
+       }
+
+       return caps;
+}
+
 static GstCaps *__make_default_raw_caps(webrtc_gst_slot_s *source, webrtc_ini_s *ini)
 {
        GstCaps *caps = NULL;
@@ -372,7 +420,7 @@ static GstCaps *__make_default_raw_caps(webrtc_gst_slot_s *source, webrtc_ini_s
        case WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST:
        case WEBRTC_MEDIA_SOURCE_TYPE_MIC:
        case WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_AUDIO:
-               format = __get_gst_audio_format_from_string(ini_source->a_raw_format);
+               format = __get_gst_audio_raw_format_from_string(ini_source->a_raw_format);
                RET_VAL_IF(format == GST_AUDIO_FORMAT_UNKNOWN, NULL, "not supported raw format");
 
                gst_audio_info_set_format(&info, format, ini_source->a_samplerate, ini_source->a_channels, NULL);
@@ -380,47 +428,9 @@ static GstCaps *__make_default_raw_caps(webrtc_gst_slot_s *source, webrtc_ini_s
                break;
 
        case WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET: {
-               media_format_mimetype_e mime_type;
-
                RET_VAL_IF(source->media_format == NULL, NULL, "media_format is NULL");
 
-               if (source->media_types == MEDIA_TYPE_AUDIO) {
-                       int channels;
-                       int samplerate;
-                       const char *format_name;
-
-                       RET_VAL_IF(media_format_get_audio_info(source->media_format, &mime_type, &channels, &samplerate, NULL, NULL) != MEDIA_FORMAT_ERROR_NONE,
-                               NULL, "failed to media_format_get_audio_info()");
-
-                       format_name = __get_audio_format_name(mime_type);
-                       RET_VAL_IF(format_name == NULL, NULL, "not supported mime_type");
-
-                       format = __get_gst_audio_format_from_string(format_name);
-                       RET_VAL_IF(format == GST_AUDIO_FORMAT_UNKNOWN, NULL, "not supported raw format");
-
-                       gst_audio_info_set_format(&info, format, samplerate, channels, NULL);
-                       caps = gst_audio_info_to_caps(&info);
-
-               } else if (source->media_types == MEDIA_TYPE_VIDEO) {
-                       int width;
-                       int height;
-                       int framerate;
-
-                       RET_VAL_IF(media_format_get_video_info(source->media_format, &mime_type, &width, &height, NULL, NULL) != MEDIA_FORMAT_ERROR_NONE,
-                               NULL, "failed to media_format_get_video_info()");
-                       RET_VAL_IF(media_format_get_video_frame_rate(source->media_format, &framerate) != MEDIA_FORMAT_ERROR_NONE,
-                               NULL, "failed to media_format_get_video_frame_rate()");
-
-                       caps = gst_caps_new_simple(MEDIA_TYPE_VIDEO_RAW,
-                                                       "format", G_TYPE_STRING, __get_video_format_name(mime_type, source->zerocopy_enabled),
-                                                       "framerate", GST_TYPE_FRACTION, framerate, 1,
-                                                       "width", G_TYPE_INT, width,
-                                                       "height", G_TYPE_INT, height,
-                                                       NULL);
-
-               } else {
-                       LOG_ERROR_IF_REACHED("source->media_types(0x%x)", source->media_types);
-               }
+               caps = __make_mediapacketsrc_raw_caps_from_media_format(source);
                break;
        }
        default:
@@ -431,54 +441,6 @@ static GstCaps *__make_default_raw_caps(webrtc_gst_slot_s *source, webrtc_ini_s
        return caps;
 }
 
-static GstCaps *__make_raw_caps_from_media_format(webrtc_gst_slot_s *source)
-{
-       GstCaps *caps = NULL;
-       media_format_mimetype_e mime_type;
-
-       RET_VAL_IF(source == NULL, NULL, "source is NULL");
-       RET_VAL_IF(source->media_format == NULL, NULL, "media_format is NULL");
-       RET_VAL_IF(source->type != WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET, NULL,
-               "type(%d) is not for media packet source", source->type);
-
-       if (source->media_types == MEDIA_TYPE_AUDIO) {
-               int channels;
-               int samplerate;
-               GstAudioInfo info;
-               GstAudioFormat format;
-
-               RET_VAL_IF(media_format_get_audio_info(source->media_format, &mime_type, &channels, &samplerate, NULL, NULL) != MEDIA_FORMAT_ERROR_NONE,
-                       NULL, "failed to media_format_get_audio_info()");
-
-               format = __get_gst_audio_format(mime_type);
-               RET_VAL_IF(format == GST_AUDIO_FORMAT_ENCODED || format == GST_AUDIO_FORMAT_UNKNOWN, NULL, "could not get valid GstAudioFormat for PCM");
-
-               gst_audio_info_set_format(&info, format, samplerate, channels, NULL);
-               caps = gst_audio_info_to_caps(&info);
-
-       } else if (source->media_types == MEDIA_TYPE_VIDEO) {
-               int width;
-               int height;
-               int framerate;
-
-               RET_VAL_IF(media_format_get_video_info(source->media_format, &mime_type, &width, &height, NULL, NULL) != MEDIA_FORMAT_ERROR_NONE,
-                       NULL, "failed to media_format_get_video_info()");
-               RET_VAL_IF(media_format_get_video_frame_rate(source->media_format, &framerate) != MEDIA_FORMAT_ERROR_NONE,
-                       NULL, "failed to media_format_get_video_frame_rate()");
-               caps = gst_caps_new_simple(MEDIA_TYPE_VIDEO_RAW,
-                                               "format", G_TYPE_STRING, __get_video_format_name(mime_type, source->zerocopy_enabled),
-                                               "framerate", GST_TYPE_FRACTION, framerate, 1,
-                                               "width", G_TYPE_INT, width,
-                                               "height", G_TYPE_INT, height,
-                                               NULL);
-
-       } else {
-               LOG_ERROR_IF_REACHED("source->media_types(0x%x)", source->media_types);
-       }
-
-       return caps;
-}
-
 static GstCaps *__get_caps_from_encoded_audio_media_type(const char *media_type, int channels, int samplerate)
 {
        RET_VAL_IF(media_type == NULL, NULL, "media_type is NULL");
@@ -2377,7 +2339,7 @@ static int __complete_mediapacketsrc_from_raw_format(webrtc_s *webrtc, webrtc_gs
        if ((ret = __create_rest_of_elements(webrtc, source, false, &element_list, (source->media_types == MEDIA_TYPE_AUDIO))) != WEBRTC_ERROR_NONE)
                goto exit;
 
-       if (!(sink_caps = __make_raw_caps_from_media_format(source))) {
+       if (!(sink_caps = __make_mediapacketsrc_raw_caps_from_media_format(source))) {
                ret = WEBRTC_ERROR_INVALID_OPERATION;
                goto exit;
        }