From: hj kim Date: Tue, 26 Jul 2022 07:35:19 +0000 (+0900) Subject: webrtc_source_mediapacket: move _set_media_format() to webrtc_source_mediapacket.c X-Git-Tag: submit/tizen/20220727.071902~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d20dca2792085a7bac10a991de5d56281aec2bf6;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_source_mediapacket: move _set_media_format() to webrtc_source_mediapacket.c Plus, remove some mediapacket internal APIs from webrtc_private.h and add static keyword. [Version] 0.3.176 [Issue Type] Refactoring Change-Id: I81f958dbc33a600075295ee558ce5a377a9d7045 --- diff --git a/include/webrtc_private.h b/include/webrtc_private.h index 95668b1f..7e988681 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -650,11 +650,9 @@ void _remove_rest_of_elements_for_filesrc_pipeline(webrtc_gst_slot_s *source, bo /* media packet source */ int _build_mediapacketsrc(webrtc_s *webrtc, webrtc_gst_slot_s *source); -int _complete_rest_of_mediapacketsrc(webrtc_gst_slot_s *source, GstPad **src_pad, GstElement *appsrc, GList *element_list); -int _complete_mediapacketsrc_from_encoded_format(webrtc_s *webrtc, webrtc_gst_slot_s *source); GstCaps *_make_mediapacketsrc_raw_caps_from_media_format(webrtc_gst_slot_s *source); int _push_media_packet(webrtc_s *webrtc, unsigned int source_id, media_packet_h packet); -int _set_mediapacketsrc_codec_info(webrtc_s *webrtc, webrtc_gst_slot_s *source, media_format_mimetype_e mime_type); +int _set_media_format(webrtc_s *webrtc, unsigned int source_id, media_format_h format); /* screen source */ int _get_screen_resolution(int *width, int *height); @@ -695,7 +693,6 @@ int _unset_audio_loopback(webrtc_s *webrtc, unsigned int source_id); int _set_video_loopback(webrtc_s *webrtc, unsigned int source_id, unsigned int type, void *display, unsigned int *track_id); int _unset_video_loopback(webrtc_s *webrtc, unsigned int source_id); int _set_sound_stream_info(webrtc_s *webrtc, unsigned int source_id, sound_stream_info_h stream_info); -int _set_media_format(webrtc_s *webrtc, unsigned int source_id, media_format_h format); int _set_media_path(webrtc_s *webrtc, unsigned int source_id, const char *path); /* sink */ diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 6bde943d..03c95751 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.175 +Version: 0.3.176 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_source.c b/src/webrtc_source.c index 4451bac4..b9379815 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -1495,112 +1495,6 @@ int _set_sound_stream_info(webrtc_s *webrtc, unsigned int source_id, sound_strea return _apply_stream_info(element, stream_type, stream_index, aec_ref_device_id); } -static int __complete_mediapacketsrc_from_raw_format(webrtc_s *webrtc, webrtc_gst_slot_s *source) -{ - int ret; - GstPad **src_pad; - GstElement *appsrc; - GList *element_list = NULL; - GstCaps *sink_caps; - - RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); - RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); - RET_VAL_IF(source->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL"); - - src_pad = &source->av[GET_AV_IDX_BY_TYPE(source->media_types)].src_pad; - ret = _add_no_target_ghostpad_to_slot(source, true, src_pad); - RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to _add_no_target_ghostpad_to_slot()"); - - appsrc = _find_element_in_bin(source->bin, "appsrc"); - RET_VAL_IF(appsrc == NULL, WEBRTC_ERROR_INVALID_OPERATION, "appsrc is NULL"); - - source->zerocopy_enabled = _is_hw_encoder_used(webrtc, source->type, source->media_types); - - 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_mediapacketsrc_raw_caps_from_media_format(source))) { - ret = WEBRTC_ERROR_INVALID_OPERATION; - goto exit; - } - PRINT_CAPS(sink_caps, "appsrc"); - g_object_set(G_OBJECT(appsrc), "caps", sink_caps, NULL); - gst_caps_unref(sink_caps); - - if ((ret = _complete_rest_of_mediapacketsrc(source, src_pad, appsrc, element_list)) != WEBRTC_ERROR_NONE) - goto exit; - - SAFE_G_LIST_FREE(element_list); - - return WEBRTC_ERROR_NONE; - -exit: - SAFE_G_LIST_FREE_FULL(element_list, gst_object_unref); - return ret; -} - -int _set_media_format(webrtc_s *webrtc, unsigned int source_id, media_format_h format) -{ - int ret; - webrtc_gst_slot_s *source; - media_format_type_e format_type; - media_format_mimetype_e mime_type; - - RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); - RET_VAL_IF(format == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "format is NULL"); - RET_VAL_IF((source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "could not find source"); - RET_VAL_IF(source->type != WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET, WEBRTC_ERROR_INVALID_PARAMETER, "invalid media source type(%d)", source->type); - RET_VAL_IF(source->media_format != NULL, WEBRTC_ERROR_INVALID_OPERATION, "format is already set to this media packet source"); - - RET_VAL_IF(media_format_get_type(format, &format_type) != MEDIA_FORMAT_ERROR_NONE, WEBRTC_ERROR_INVALID_OPERATION, - "failed to media_format_get_type()"); - - if (format_type == MEDIA_FORMAT_AUDIO) { - source->media_types = MEDIA_TYPE_AUDIO; - RET_VAL_IF(media_format_get_audio_info(format, &mime_type, NULL, NULL, NULL, NULL) != MEDIA_FORMAT_ERROR_NONE, - WEBRTC_ERROR_INVALID_OPERATION, "failed to media_format_get_audio_info()"); - - } else if (format_type == MEDIA_FORMAT_VIDEO) { - source->media_types = MEDIA_TYPE_VIDEO; - RET_VAL_IF(media_format_get_video_info(format, &mime_type, NULL, NULL, NULL, NULL) != MEDIA_FORMAT_ERROR_NONE, - WEBRTC_ERROR_INVALID_OPERATION, "failed to media_format_get_video_info()"); - - } else { - LOG_ERROR("invalid media format type[0x%x]", format_type); - return WEBRTC_ERROR_INVALID_OPERATION; - } - - RET_VAL_IF(!_is_supported_mime_type(mime_type), WEBRTC_ERROR_INVALID_PARAMETER, "mime_type[0x%x] is not supported", mime_type); - - media_format_ref(format); - source->media_format = format; - if((ret = _set_mediapacketsrc_codec_info(webrtc, source, mime_type)) != WEBRTC_ERROR_NONE) - goto error; - - if ((mime_type & MEDIA_FORMAT_RAW) && - !(mime_type == MEDIA_FORMAT_PCMU || mime_type == MEDIA_FORMAT_PCMA)) /* FIXME: media_format.h defined PCMU/PCMA as a raw format, it's a bug. */ - ret = __complete_mediapacketsrc_from_raw_format(webrtc, source); - else - ret = _complete_mediapacketsrc_from_encoded_format(webrtc, source); - if (ret != WEBRTC_ERROR_NONE) { - LOG_ERROR("failed to complete mediapacketsrc"); - goto error; - } - - ret = _link_source_with_webrtcbin(source, webrtc->gst.webrtcbin); - if (ret != WEBRTC_ERROR_NONE) - goto error; - - LOG_INFO("webrtc[%p] source_id[%u] format[%p]", webrtc, source_id, format); - - return WEBRTC_ERROR_NONE; - -error: - media_format_unref(format); - source->media_format = NULL; - return ret; -} - static gboolean __check_format_is_not_set_cb(gpointer key, gpointer value, gpointer user_data) { const webrtc_gst_slot_s *source = (webrtc_gst_slot_s *)value; diff --git a/src/webrtc_source_mediapacket.c b/src/webrtc_source_mediapacket.c index e2da4567..e9e488a4 100644 --- a/src/webrtc_source_mediapacket.c +++ b/src/webrtc_source_mediapacket.c @@ -553,7 +553,7 @@ int _build_mediapacketsrc(webrtc_s *webrtc, webrtc_gst_slot_s *source) return WEBRTC_ERROR_NONE; } -int _complete_rest_of_mediapacketsrc(webrtc_gst_slot_s *source, GstPad **src_pad, GstElement *appsrc, GList *element_list) +static int __complete_rest_of_mediapacketsrc(webrtc_gst_slot_s *source, GstPad **src_pad, GstElement *appsrc, GList *element_list) { int ret; GstElement *capsfilter; @@ -589,7 +589,7 @@ error: } //LCOV_EXCL_START -int _complete_mediapacketsrc_from_encoded_format(webrtc_s *webrtc, webrtc_gst_slot_s *source) +static int __complete_mediapacketsrc_from_encoded_format(webrtc_s *webrtc, webrtc_gst_slot_s *source) { int ret; GstPad **src_pad; @@ -620,7 +620,7 @@ int _complete_mediapacketsrc_from_encoded_format(webrtc_s *webrtc, webrtc_gst_sl g_object_set(G_OBJECT(appsrc), "caps", sink_caps, NULL); gst_caps_unref(sink_caps); - if ((ret = _complete_rest_of_mediapacketsrc(source, src_pad, appsrc, element_list)) != WEBRTC_ERROR_NONE) + if ((ret = __complete_rest_of_mediapacketsrc(source, src_pad, appsrc, element_list)) != WEBRTC_ERROR_NONE) goto exit; SAFE_G_LIST_FREE(element_list); @@ -633,7 +633,7 @@ exit: } //LCOV_EXCL_STOP -int _set_mediapacketsrc_codec_info(webrtc_s *webrtc, webrtc_gst_slot_s *source, media_format_mimetype_e mime_type) +static int __set_mediapacketsrc_codec_info(webrtc_s *webrtc, webrtc_gst_slot_s *source, media_format_mimetype_e mime_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"); @@ -665,3 +665,109 @@ int _set_mediapacketsrc_codec_info(webrtc_s *webrtc, webrtc_gst_slot_s *source, return WEBRTC_ERROR_NONE; } + +static int __complete_mediapacketsrc_from_raw_format(webrtc_s *webrtc, webrtc_gst_slot_s *source) +{ + int ret; + GstPad **src_pad; + GstElement *appsrc; + GList *element_list = NULL; + GstCaps *sink_caps; + + RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); + RET_VAL_IF(source->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL"); + + src_pad = &source->av[GET_AV_IDX_BY_TYPE(source->media_types)].src_pad; + ret = _add_no_target_ghostpad_to_slot(source, true, src_pad); + RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to _add_no_target_ghostpad_to_slot()"); + + appsrc = _find_element_in_bin(source->bin, "appsrc"); + RET_VAL_IF(appsrc == NULL, WEBRTC_ERROR_INVALID_OPERATION, "appsrc is NULL"); + + source->zerocopy_enabled = _is_hw_encoder_used(webrtc, source->type, source->media_types); + + 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_mediapacketsrc_raw_caps_from_media_format(source))) { + ret = WEBRTC_ERROR_INVALID_OPERATION; + goto exit; + } + PRINT_CAPS(sink_caps, "appsrc"); + g_object_set(G_OBJECT(appsrc), "caps", sink_caps, NULL); + gst_caps_unref(sink_caps); + + if ((ret = __complete_rest_of_mediapacketsrc(source, src_pad, appsrc, element_list)) != WEBRTC_ERROR_NONE) + goto exit; + + SAFE_G_LIST_FREE(element_list); + + return WEBRTC_ERROR_NONE; + +exit: + SAFE_G_LIST_FREE_FULL(element_list, gst_object_unref); + return ret; +} + +int _set_media_format(webrtc_s *webrtc, unsigned int source_id, media_format_h format) +{ + int ret; + webrtc_gst_slot_s *source; + media_format_type_e format_type; + media_format_mimetype_e mime_type; + + RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + RET_VAL_IF(format == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "format is NULL"); + RET_VAL_IF((source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "could not find source"); + RET_VAL_IF(source->type != WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET, WEBRTC_ERROR_INVALID_PARAMETER, "invalid media source type(%d)", source->type); + RET_VAL_IF(source->media_format != NULL, WEBRTC_ERROR_INVALID_OPERATION, "format is already set to this media packet source"); + + RET_VAL_IF(media_format_get_type(format, &format_type) != MEDIA_FORMAT_ERROR_NONE, WEBRTC_ERROR_INVALID_OPERATION, + "failed to media_format_get_type()"); + + if (format_type == MEDIA_FORMAT_AUDIO) { + source->media_types = MEDIA_TYPE_AUDIO; + RET_VAL_IF(media_format_get_audio_info(format, &mime_type, NULL, NULL, NULL, NULL) != MEDIA_FORMAT_ERROR_NONE, + WEBRTC_ERROR_INVALID_OPERATION, "failed to media_format_get_audio_info()"); + + } else if (format_type == MEDIA_FORMAT_VIDEO) { + source->media_types = MEDIA_TYPE_VIDEO; + RET_VAL_IF(media_format_get_video_info(format, &mime_type, NULL, NULL, NULL, NULL) != MEDIA_FORMAT_ERROR_NONE, + WEBRTC_ERROR_INVALID_OPERATION, "failed to media_format_get_video_info()"); + + } else { + LOG_ERROR("invalid media format type[0x%x]", format_type); + return WEBRTC_ERROR_INVALID_OPERATION; + } + + RET_VAL_IF(!_is_supported_mime_type(mime_type), WEBRTC_ERROR_INVALID_PARAMETER, "mime_type[0x%x] is not supported", mime_type); + + media_format_ref(format); + source->media_format = format; + if((ret = __set_mediapacketsrc_codec_info(webrtc, source, mime_type)) != WEBRTC_ERROR_NONE) + goto error; + + if ((mime_type & MEDIA_FORMAT_RAW) && + !(mime_type == MEDIA_FORMAT_PCMU || mime_type == MEDIA_FORMAT_PCMA)) /* FIXME: media_format.h defined PCMU/PCMA as a raw format, it's a bug. */ + ret = __complete_mediapacketsrc_from_raw_format(webrtc, source); + else + ret = __complete_mediapacketsrc_from_encoded_format(webrtc, source); + if (ret != WEBRTC_ERROR_NONE) { + LOG_ERROR("failed to complete mediapacketsrc"); + goto error; + } + + ret = _link_source_with_webrtcbin(source, webrtc->gst.webrtcbin); + if (ret != WEBRTC_ERROR_NONE) + goto error; + + LOG_INFO("webrtc[%p] source_id[%u] format[%p]", webrtc, source_id, format); + + return WEBRTC_ERROR_NONE; + +error: + media_format_unref(format); + source->media_format = NULL; + return ret; +}