From ba009c7ed46f8f5c0679a38d0b8b692d10315cdc Mon Sep 17 00:00:00 2001 From: Sangchul Lee Date: Fri, 22 Apr 2022 18:42:27 +0900 Subject: [PATCH] webrtc_source: Rename functions and replace codes with the function [Version] 0.3.95 [Issue Type] Refactoring Change-Id: I517b4ade896132e5a25f5a91f0ad422ae7ca9abd Signed-off-by: Sangchul Lee --- packaging/capi-media-webrtc.spec | 2 +- src/webrtc_source.c | 142 +++++++++++-------------------- 2 files changed, 53 insertions(+), 91 deletions(-) diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 88c68b0d..529f3714 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.3.94 +Version: 0.3.95 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_source.c b/src/webrtc_source.c index c4b005a0..36da3e62 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -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; } -- 2.34.1