From: hj kim Date: Mon, 29 Aug 2022 07:14:03 +0000 (+0900) Subject: webrtc_ini: Add functions to get value from ini X-Git-Tag: submit/tizen/20220902.031026~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2e206d9c026cd01275839828e774bb1e94f933a8;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_ini: Add functions to get value from ini [Version] 0.3.226 [Issue Type] Refactoring Change-Id: I78e4fb36d6562ed0395a7c9b6bf26cdd4ad35e2f --- diff --git a/include/webrtc_private.h b/include/webrtc_private.h index 07ad0744..b7504c7a 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -673,6 +673,17 @@ void _unload_ini(webrtc_s *webrtc); const ini_item_media_source_s* _ini_get_source_by_type(webrtc_ini_s *ini, int type); bool _is_resource_required(webrtc_ini_s *ini); bool _is_verbose_log(void); +void _get_drc_support_from_ini(webrtc_ini_s *ini, int src_type, bool *drc_support); +void _get_use_ulpfec_red_from_ini(webrtc_ini_s *ini, int src_type, bool *use_ulpfec_red); +void _get_audio_info_from_ini(webrtc_ini_s *ini, int src_type, int *channels, int *samplerate); +void _get_video_encoded_support_from_ini(webrtc_ini_s *ini, int src_type, bool *encoded_support); +void _get_video_resolution_from_ini(webrtc_ini_s *ini, int src_type, int *width, int *height); +int _get_fec_percentage_from_ini(webrtc_ini_s *ini, int src_type); +const char *_get_source_element_from_ini(webrtc_ini_s *ini, int src_type); +const char *_get_raw_format_from_ini(webrtc_ini_s *ini, int src_type, media_type_e media_type); +const char *_get_first_codec_from_ini(webrtc_ini_s *ini, int src_type, media_type_e media_type); +const char *_get_hw_encoder_from_ini(webrtc_ini_s *ini, int src_type, media_type_e media_type); +GStrv _get_supported_codecs_from_ini(webrtc_ini_s *ini, int src_type, media_type_e media_type); /* file source */ int _gst_filesrc_pipeline_set_state(webrtc_s *webrtc, GstState state); diff --git a/include/webrtc_source_private.h b/include/webrtc_source_private.h index 8ac60972..0a5c9551 100644 --- a/include/webrtc_source_private.h +++ b/include/webrtc_source_private.h @@ -89,7 +89,6 @@ GstElement *_find_element_in_bin(GstBin *bin, const gchar *name); bool _is_hw_encoder_used(webrtc_s *webrtc, webrtc_media_source_type_e source_type, media_type_e media_type); GstAudioFormat _get_gst_audio_raw_format_from_string(const char *format); 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); GstCaps *_make_rtp_caps(const gchar *media_type, unsigned int payload_type, webrtc_gst_slot_s *source, GstElement *encoder); diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index ae99a937..68729978 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.225 +Version: 0.3.226 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_ini.c b/src/webrtc_ini.c index 39c30b80..28181520 100644 --- a/src/webrtc_ini.c +++ b/src/webrtc_ini.c @@ -571,6 +571,175 @@ bool _is_resource_required(webrtc_ini_s *ini) ini->resource_acquisition.video_overlay); } +void _get_drc_support_from_ini(webrtc_ini_s *ini, int src_type, bool *drc_support) +{ + const ini_item_media_source_s *ini_source; + + RET_IF(ini == NULL, "ini is NULL"); + RET_IF(drc_support == NULL, "drc_support is NULL"); + + ini_source = _ini_get_source_by_type(ini, src_type); + if (ini_source == NULL) + ini_source = &ini->media_source; + + *drc_support = ini_source->v_drc_support; +} + +void _get_use_ulpfec_red_from_ini(webrtc_ini_s *ini, int src_type, bool *use_ulpfec_red) +{ + const ini_item_media_source_s *ini_source; + + RET_IF(ini == NULL, "ini is NULL"); + RET_IF(use_ulpfec_red == NULL, "use_ulpfec_red is NULL"); + + ini_source = _ini_get_source_by_type(ini, src_type); + if (ini_source == NULL) + ini_source = &ini->media_source; + + *use_ulpfec_red = ini_source->use_ulpfec_red; +} + +void _get_audio_info_from_ini(webrtc_ini_s *ini, int src_type, int *channels, int *samplerate) +{ + const ini_item_media_source_s *ini_source; + + RET_IF(ini == NULL, "ini is NULL"); + RET_IF(channels == NULL, "channels is NULL"); + RET_IF(samplerate == NULL, "samplerate is NULL"); + + ini_source = _ini_get_source_by_type(ini, src_type); + if (ini_source == NULL) + ini_source = &ini->media_source; + + *channels = ini_source->a_channels; + *samplerate = ini_source->a_samplerate; +} + +void _get_video_encoded_support_from_ini(webrtc_ini_s *ini, int src_type, bool *encoded_support) +{ + const ini_item_media_source_s *ini_source; + + RET_IF(ini == NULL, "ini is NULL"); + RET_IF(encoded_support == NULL, "encoded_support is NULL"); + + ini_source = _ini_get_source_by_type(ini, src_type); + if (ini_source == NULL) + ini_source = &ini->media_source; + + LOG_DEBUG("type[%d], v_encoded_fmt_support[%d]", src_type, ini_source->v_encoded_fmt_support); + + *encoded_support = ini_source->v_encoded_fmt_support; +} + +void _get_video_resolution_from_ini(webrtc_ini_s *ini, int src_type, int *width, int *height) +{ + const ini_item_media_source_s *ini_source; + + RET_IF(ini == NULL, "ini is NULL"); + RET_IF(width == NULL, "width is NULL"); + RET_IF(height == NULL, "height is NULL"); + + ini_source = _ini_get_source_by_type(ini, src_type); + if (ini_source == NULL) + ini_source = &ini->media_source; + + *width = ini_source->v_width; + *height = ini_source->v_height; +} + +int _get_fec_percentage_from_ini(webrtc_ini_s *ini, int src_type) +{ + const ini_item_media_source_s *ini_source; + + RET_VAL_IF(ini == NULL, 0, "ini is NULL"); + + ini_source = _ini_get_source_by_type(ini, src_type); + if (ini_source == NULL) + ini_source = &ini->media_source; + + return ini_source->fec_percentage; +} + +const char *_get_source_element_from_ini(webrtc_ini_s *ini, int src_type) +{ + const ini_item_media_source_s *ini_source; + + RET_VAL_IF(ini == NULL, NULL, "ini is NULL"); + + ini_source = _ini_get_source_by_type(ini, src_type); + RET_VAL_IF(ini_source == NULL, NULL, "ini_source is NULL"); + + return ini_source->source_element; +} + +const char *_get_raw_format_from_ini(webrtc_ini_s *ini, int src_type, media_type_e media_type) +{ + const ini_item_media_source_s *ini_source; + + RET_VAL_IF(ini == NULL, NULL, "ini is NULL"); + RET_VAL_IF((media_type != MEDIA_TYPE_AUDIO) && (media_type != MEDIA_TYPE_VIDEO), NULL, "invalid media_type[%d]", media_type); + + ini_source = _ini_get_source_by_type(ini, src_type); + + if (ini_source == NULL) + ini_source = &ini->media_source; + + if (media_type == MEDIA_TYPE_AUDIO) + return ini_source->a_raw_format; + else + return ini_source->v_raw_format; +} + +const char *_get_first_codec_from_ini(webrtc_ini_s *ini, int src_type, media_type_e media_type) +{ + const ini_item_media_source_s *ini_source; + + RET_VAL_IF(ini == NULL, NULL, "ini is NULL"); + RET_VAL_IF((media_type != MEDIA_TYPE_AUDIO) && (media_type != MEDIA_TYPE_VIDEO), NULL, "invalid media_type[%d]", media_type); + + ini_source = _ini_get_source_by_type(ini, src_type); + if (ini_source == NULL) + ini_source = &ini->media_source; + + if (media_type == MEDIA_TYPE_AUDIO) + return ini_source->a_codecs[0]; + else + return ini_source->v_codecs[0]; +} + +const char *_get_hw_encoder_from_ini(webrtc_ini_s *ini, int src_type, media_type_e media_type) +{ + const ini_item_media_source_s *ini_source; + + RET_VAL_IF(ini == NULL, NULL, "ini is NULL"); + RET_VAL_IF((media_type != MEDIA_TYPE_AUDIO) && (media_type != MEDIA_TYPE_VIDEO), NULL, "invalid media_type[%d]", media_type); + + ini_source = _ini_get_source_by_type(ini, src_type); + if (ini_source == NULL) + ini_source = &ini->media_source; + + if (media_type == MEDIA_TYPE_AUDIO) + return ini_source->a_hw_encoder_element; + else + return ini_source->v_hw_encoder_element; +} + +GStrv _get_supported_codecs_from_ini(webrtc_ini_s *ini, int src_type, media_type_e media_type) +{ + const ini_item_media_source_s *ini_source; + + RET_VAL_IF(ini == NULL, NULL, "ini is NULL"); + RET_VAL_IF((media_type != MEDIA_TYPE_AUDIO) && (media_type != MEDIA_TYPE_VIDEO), NULL, "invalid media_type[%d]", media_type); + + ini_source = _ini_get_source_by_type(ini, src_type); + if (ini_source == NULL) + ini_source = &ini->media_source; + + if (media_type == MEDIA_TYPE_AUDIO) + return ini_source->a_codecs; + else + return ini_source->v_codecs; +} void _unload_ini(webrtc_s *webrtc) { RET_IF(webrtc == NULL, "webrtc is NULL"); diff --git a/src/webrtc_private.c b/src/webrtc_private.c index db6057c9..b852d44a 100644 --- a/src/webrtc_private.c +++ b/src/webrtc_private.c @@ -1553,7 +1553,6 @@ static void __webrtcbin_on_new_transceiver_cb(GstElement *webrtcbin, GstWebRTCRT void _update_transceivers_fec(webrtc_s *webrtc, bool is_offer) { - const ini_item_media_source_s *ini_source; GstWebRTCRTPTransceiver *transceiver; webrtc_gst_slot_s *source; int i, j; @@ -1572,13 +1571,13 @@ void _update_transceivers_fec(webrtc_s *webrtc, bool is_offer) g_object_get(G_OBJECT(transceiver), "direction", &direction, NULL); - ini_source = _ini_get_source_by_type(&webrtc->ini, source->type); - if (ini_source == NULL) - ini_source = &(webrtc->ini.media_source); - if (is_offer) { - if (!ini_source->use_ulpfec_red) + bool use_ulpfec_red; + _get_use_ulpfec_red_from_ini(&webrtc->ini, source->type, &use_ulpfec_red); + + if (!use_ulpfec_red) continue; + __webrtcbin_transceiver_set_ulpfec_red(webrtc, transceiver); } else { if (!webrtc->data_recovery_types[i].red || @@ -1589,7 +1588,7 @@ void _update_transceivers_fec(webrtc_s *webrtc, bool is_offer) if (direction == GST_WEBRTC_RTP_TRANSCEIVER_DIRECTION_SENDONLY || direction == GST_WEBRTC_RTP_TRANSCEIVER_DIRECTION_SENDRECV) - __webrtcbin_transceiver_set_fec_percentage(webrtc, transceiver, ini_source->fec_percentage); + __webrtcbin_transceiver_set_fec_percentage(webrtc, transceiver, _get_fec_percentage_from_ini(&webrtc->ini, source->type)); } } } diff --git a/src/webrtc_source.c b/src/webrtc_source.c index 8c55a094..711108a7 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -38,21 +38,16 @@ static GstPadProbeReturn __camerasrc_probe_cb(GstPad *pad, GstPadProbeInfo *inf static GstCaps *__make_video_raw_caps_with_framerate(webrtc_gst_slot_s *source, webrtc_ini_s *ini, int framerate) { GstCaps *caps = NULL; - const ini_item_media_source_s *ini_source; RET_VAL_IF(source == NULL, NULL, "source is NULL"); RET_VAL_IF(ini == NULL, NULL, "ini is NULL"); - ini_source = _ini_get_source_by_type(ini, source->type); - if (ini_source == NULL) - ini_source = &ini->media_source; - switch (source->type) { case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA: case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST: case WEBRTC_MEDIA_SOURCE_TYPE_SCREEN: { caps = gst_caps_new_simple(MEDIA_TYPE_VIDEO_RAW, - "format", G_TYPE_STRING, ini_source->v_raw_format, + "format", G_TYPE_STRING, _get_raw_format_from_ini(ini, source->type, MEDIA_TYPE_VIDEO), "framerate", GST_TYPE_FRACTION, framerate, 1, "width", G_TYPE_INT, source->video_info.width, "height", G_TYPE_INT, source->video_info.height, @@ -1137,7 +1132,6 @@ static convert_codec_func convert_codec_funcs[] = { int _foreach_supported_transceiver_codec(webrtc_s *webrtc, webrtc_media_source_type_e source_type, webrtc_media_type_e media_type, webrtc_media_source_supported_transceiver_codec_cb callback, void *user_data) { int ret; - const ini_item_media_source_s *ini_source; webrtc_transceiver_codec_e codec; GStrv codecs; guint i; @@ -1150,21 +1144,18 @@ int _foreach_supported_transceiver_codec(webrtc_s *webrtc, webrtc_media_source_t RET_VAL_IF((source_type == WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET), WEBRTC_ERROR_INVALID_PARAMETER, "this API does not support the media packet source"); RET_VAL_IF((source_type > WEBRTC_MEDIA_SOURCE_TYPE_NULL), WEBRTC_ERROR_INVALID_PARAMETER, "invalid source_type"); - ini_source = _ini_get_source_by_type(&webrtc->ini, source_type); - RET_VAL_IF(ini_source == NULL, WEBRTC_ERROR_INVALID_OPERATION, "ini_source is NULL"); - if (media_type == WEBRTC_MEDIA_TYPE_AUDIO && (source_type == WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST || source_type == WEBRTC_MEDIA_SOURCE_TYPE_MIC || source_type == WEBRTC_MEDIA_SOURCE_TYPE_NULL)) { - codecs = ini_source->a_codecs; + codecs = _get_supported_codecs_from_ini(&webrtc->ini, source_type, MEDIA_TYPE_AUDIO); } else if (media_type == WEBRTC_MEDIA_TYPE_VIDEO && (source_type == WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST || source_type == WEBRTC_MEDIA_SOURCE_TYPE_CAMERA || source_type == WEBRTC_MEDIA_SOURCE_TYPE_SCREEN || source_type == WEBRTC_MEDIA_SOURCE_TYPE_NULL)) { - codecs = ini_source->v_codecs; + codecs = _get_supported_codecs_from_ini(&webrtc->ini, source_type, MEDIA_TYPE_VIDEO); } else { LOG_ERROR("invalid media_type[%d] for source_type[%u]", media_type, source_type); @@ -1189,7 +1180,6 @@ int _foreach_supported_transceiver_codec(webrtc_s *webrtc, webrtc_media_source_t static int __validate_codec(webrtc_s *webrtc, webrtc_gst_slot_s *source, webrtc_media_type_e media_type, webrtc_transceiver_codec_e codec) { int ret; - const ini_item_media_source_s *ini_source; GStrv codecs; webrtc_transceiver_codec_e _codec; guint i; @@ -1197,18 +1187,15 @@ static int __validate_codec(webrtc_s *webrtc, webrtc_gst_slot_s *source, webrtc_ RET_VAL_IF(webrtc == NULL, FALSE, "webrtc is NULL"); RET_VAL_IF(source == NULL, FALSE, "source is NULL"); - ini_source = _ini_get_source_by_type(&webrtc->ini, source->type); - RET_VAL_IF(ini_source == NULL, WEBRTC_ERROR_INVALID_OPERATION, "ini_source is NULL"); - if (media_type == WEBRTC_MEDIA_TYPE_AUDIO && source->media_types & MEDIA_TYPE_AUDIO && codec & CODEC_TYPE_AUDIO) { - codecs = ini_source->a_codecs; + codecs = _get_supported_codecs_from_ini(&webrtc->ini, source->type, MEDIA_TYPE_AUDIO); } else if (media_type == WEBRTC_MEDIA_TYPE_VIDEO && source->media_types & MEDIA_TYPE_VIDEO && codec & CODEC_TYPE_VIDEO) { - codecs = ini_source->v_codecs; + codecs = _get_supported_codecs_from_ini(&webrtc->ini, source->type, MEDIA_TYPE_VIDEO); } else { LOG_ERROR("invalid media_type[%d], codec[0x%x] for source[media_types:0x%x, id:%u]", @@ -1373,7 +1360,7 @@ int _set_video_resolution(webrtc_s *webrtc, unsigned int source_id, int width, i { webrtc_gst_slot_s *source; GstElement *capsfilter; - bool drc_support = false; + bool drc_support; RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc 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"); @@ -1389,12 +1376,8 @@ int _set_video_resolution(webrtc_s *webrtc, unsigned int source_id, int width, i return WEBRTC_ERROR_INVALID_OPERATION; } #endif - const ini_item_media_source_s *ini_source = _ini_get_source_by_type(&webrtc->ini, source->type); - if (ini_source == NULL) - ini_source = &webrtc->ini.media_source; - if (ini_source->v_drc_support) - drc_support = true; + _get_drc_support_from_ini(&webrtc->ini, source->type, &drc_support); } if (webrtc->state == WEBRTC_STATE_IDLE || drc_support) { @@ -1403,7 +1386,9 @@ int _set_video_resolution(webrtc_s *webrtc, unsigned int source_id, int width, i source->video_info.origin_width = width; source->video_info.origin_height = height; } else { - if (_is_encoded_format_supported(source->type, &webrtc->ini)) { + bool encoded_support; + _get_video_encoded_support_from_ini(&webrtc->ini, source->type, &encoded_support); + if (encoded_support) { LOG_ERROR("this API does not support source with encoded format"); return WEBRTC_ERROR_INVALID_OPERATION; } diff --git a/src/webrtc_source_file.c b/src/webrtc_source_file.c index 4bc936fa..d6623fa5 100644 --- a/src/webrtc_source_file.c +++ b/src/webrtc_source_file.c @@ -668,11 +668,7 @@ static void __filesrc_pipeline_decodebin_pad_added_cb(GstElement *element, GstPa if (is_audio && g_strrstr(media_type, "raw")) { need_decoding = false; - const ini_item_media_source_s *ini_source = _ini_get_source_by_type(&source->webrtc->ini, source->type); - if (ini_source == NULL) - ini_source = &(source->webrtc->ini.media_source); - - source->av[AV_IDX_AUDIO].codec = ini_source->a_codecs[0]; + source->av[AV_IDX_AUDIO].codec = _get_first_codec_from_ini(&source->webrtc->ini, source->type, MEDIA_TYPE_AUDIO); } #endif g_free(media_type); diff --git a/src/webrtc_source_mediapacket.c b/src/webrtc_source_mediapacket.c index 6ce30bba..875c0d0c 100644 --- a/src/webrtc_source_mediapacket.c +++ b/src/webrtc_source_mediapacket.c @@ -633,14 +633,10 @@ static int __set_mediapacketsrc_codec_info(webrtc_s *webrtc, webrtc_gst_slot_s * 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. */ - const ini_item_media_source_s *ini_source = _ini_get_source_by_type(&webrtc->ini, source->type); - if (ini_source == NULL) - ini_source = &(webrtc->ini.media_source); - if (source->media_types == MEDIA_TYPE_AUDIO) - source->av[AV_IDX_AUDIO].codec = ini_source->a_codecs[0]; + source->av[AV_IDX_AUDIO].codec = _get_first_codec_from_ini(&webrtc->ini, source->type, source->media_types); else - source->av[AV_IDX_VIDEO].codec = ini_source->v_codecs[0]; + source->av[AV_IDX_VIDEO].codec = _get_first_codec_from_ini(&webrtc->ini, source->type, source->media_types); } else { if (source->media_types == MEDIA_TYPE_AUDIO) diff --git a/src/webrtc_source_private.c b/src/webrtc_source_private.c index 10ebe1a9..0b0418a1 100644 --- a/src/webrtc_source_private.c +++ b/src/webrtc_source_private.c @@ -106,15 +106,14 @@ static const char *__get_default_source_element(int type) const char *_get_source_element(webrtc_s *webrtc, int type) { - const ini_item_media_source_s *source; + const char *src_element; RET_VAL_IF(webrtc == NULL, NULL, "webrtc is NULL"); - source = _ini_get_source_by_type(&webrtc->ini, type); - if (source == NULL || source->source_element == NULL) - return __get_default_source_element(type); + if ((src_element = _get_source_element_from_ini(&webrtc->ini, type))) + return src_element; - return source->source_element; + return __get_default_source_element(type); } GstElement *_find_element_in_bin(GstBin *bin, const gchar *name) @@ -147,48 +146,15 @@ GstElement *_find_element_in_bin(GstBin *bin, const gchar *name) bool _is_hw_encoder_used(webrtc_s *webrtc, webrtc_media_source_type_e source_type, media_type_e media_type) { - const ini_item_media_source_s *ini_source; - RET_VAL_IF(webrtc == NULL, NULL, "webrtc is NULL"); - ini_source = _ini_get_source_by_type(&webrtc->ini, source_type); - - switch (media_type) { - case MEDIA_TYPE_AUDIO: - if (ini_source && ini_source->a_hw_encoder_element) - return true; - else if (webrtc->ini.media_source.a_hw_encoder_element) - return true; - break; - case MEDIA_TYPE_VIDEO: - if (ini_source && ini_source->v_hw_encoder_element) - return true; - else if (webrtc->ini.media_source.v_hw_encoder_element) - return true; - break; - default: - LOG_ERROR_IF_REACHED("type(%d)", media_type); - break; - } + if (_get_hw_encoder_from_ini(&webrtc->ini, source_type, media_type)) + return true; LOG_DEBUG("no hw encoder is used, source_type(%d), media_type(%d)", source_type, media_type); return false; } -bool _is_encoded_format_supported(webrtc_media_source_type_e type, webrtc_ini_s *ini) -{ - const ini_item_media_source_s *ini_source; - - RET_VAL_IF(ini == NULL, NULL, "ini is NULL"); - - ini_source = _ini_get_source_by_type(ini, type); - if (ini_source == NULL) - ini_source = &ini->media_source; - - LOG_DEBUG("type[%d], v_encoded_fmt_support[%d]", type, ini_source->v_encoded_fmt_support); - return ini_source->v_encoded_fmt_support; -} - 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"); @@ -755,24 +721,20 @@ exit: static GstCaps *__make_default_raw_caps(webrtc_gst_slot_s *source, webrtc_ini_s *ini) { GstCaps *caps = NULL; - const ini_item_media_source_s *ini_source; GstAudioInfo info; GstAudioFormat format; + int channels, samplerate; RET_VAL_IF(source == NULL, NULL, "source is NULL"); RET_VAL_IF(ini == NULL, NULL, "ini is NULL"); - ini_source = _ini_get_source_by_type(ini, source->type); - if (ini_source == NULL) - ini_source = &ini->media_source; - switch (source->type) { case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST: case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA: case WEBRTC_MEDIA_SOURCE_TYPE_SCREEN: case WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_VIDEO: { caps = gst_caps_new_simple(MEDIA_TYPE_VIDEO_RAW, - "format", G_TYPE_STRING, ini_source->v_raw_format, + "format", G_TYPE_STRING, _get_raw_format_from_ini(ini, source->type, MEDIA_TYPE_VIDEO), "framerate", GST_TYPE_FRACTION, source->video_info.framerate, 1, "width", G_TYPE_INT, source->video_info.width, "height", G_TYPE_INT, source->video_info.height, @@ -785,10 +747,11 @@ static GstCaps *__make_default_raw_caps(webrtc_gst_slot_s *source, webrtc_ini_s #ifdef SUPPORT_FILESRC_AUDIO_FORMAT_CHANGE case WEBRTC_MEDIA_SOURCE_TYPE_FILE: #endif - format = _get_gst_audio_raw_format_from_string(ini_source->a_raw_format); + format = _get_gst_audio_raw_format_from_string(_get_raw_format_from_ini(ini, source->type, MEDIA_TYPE_AUDIO)); 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); + _get_audio_info_from_ini(ini, source->type, &channels, &samplerate); + gst_audio_info_set_format(&info, format, samplerate, channels, NULL); caps = gst_audio_info_to_caps(&info); break; @@ -810,20 +773,16 @@ static GstCaps *__make_default_raw_caps(webrtc_gst_slot_s *source, webrtc_ini_s static GstCaps *__make_default_encoded_caps(webrtc_gst_slot_s *source, webrtc_ini_s *ini, gchar **media_type) { GstCaps *caps; - const ini_item_media_source_s *ini_source; const char *_media_type; + int channels, samplerate; RET_VAL_IF(source == NULL, NULL, "source is NULL"); RET_VAL_IF(ini == NULL, NULL, "ini is NULL"); - ini_source = _ini_get_source_by_type(ini, source->type); - if (ini_source == NULL) - ini_source = &ini->media_source; - - if (source->media_types == MEDIA_TYPE_AUDIO) - RET_VAL_IF(ini_source->a_codecs == NULL, NULL, "a_codecs is NULL"); - else if (source->media_types == MEDIA_TYPE_VIDEO) - RET_VAL_IF(ini_source->v_codecs == NULL, NULL, "v_codecs is NULL"); + if (!_get_supported_codecs_from_ini(ini, source->type, source->media_types)) { + LOG_ERROR("failed to get supported codecs"); + return NULL; + } switch (source->type) { case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST: @@ -844,7 +803,8 @@ static GstCaps *__make_default_encoded_caps(webrtc_gst_slot_s *source, webrtc_in _media_type = _get_audio_media_type(source->av[AV_IDX_AUDIO].codec); RET_VAL_IF(_media_type == NULL, NULL, "_media_type is NULL"); - caps = _get_caps_from_encoded_audio_media_type(_media_type, ini_source->a_channels, ini_source->a_samplerate); + _get_audio_info_from_ini(ini, source->type, &channels, &samplerate); + caps = _get_caps_from_encoded_audio_media_type(_media_type, channels, samplerate); break; case WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET: @@ -852,13 +812,16 @@ static GstCaps *__make_default_encoded_caps(webrtc_gst_slot_s *source, webrtc_in _media_type = _get_audio_media_type(source->av[AV_IDX_AUDIO].codec); RET_VAL_IF(_media_type == NULL, NULL, "_media_type is NULL"); - caps = _get_caps_from_encoded_audio_media_type(_media_type, ini_source->a_channels, ini_source->a_samplerate); + _get_audio_info_from_ini(ini, source->type, &channels, &samplerate); + caps = _get_caps_from_encoded_audio_media_type(_media_type, channels, samplerate); } else if (source->media_types == MEDIA_TYPE_VIDEO) { + int width, height; _media_type = _get_video_media_type(source->av[AV_IDX_VIDEO].codec); RET_VAL_IF(_media_type == NULL, NULL, "_media_type is NULL"); - caps = _get_caps_from_encoded_video_media_type(_media_type, ini_source->v_width, ini_source->v_height); + _get_video_resolution_from_ini(ini, source->type, &width, &height); + caps = _get_caps_from_encoded_video_media_type(_media_type, width, height); } else { LOG_ERROR_IF_REACHED("source->media_types(0x%x)", source->media_types); @@ -880,26 +843,17 @@ static GstCaps *__make_default_encoded_caps(webrtc_gst_slot_s *source, webrtc_in //LCOV_EXCL_START static GstElement *__get_hw_encoder_element(webrtc_s *webrtc, webrtc_gst_slot_s *source) { - const ini_item_media_source_s *ini_source; GstElement *encoder = NULL; RET_VAL_IF(webrtc == NULL, NULL, "webrtc is NULL"); RET_VAL_IF(source == NULL, NULL, "source is NULL"); - ini_source = _ini_get_source_by_type(&webrtc->ini, source->type); - switch (source->media_types) { case MEDIA_TYPE_AUDIO: - if (ini_source && ini_source->a_hw_encoder_element) - return _create_element(ini_source->a_hw_encoder_element, ELEMENT_NAME_AUDIO_ENCODER); - else if (webrtc->ini.media_source.a_hw_encoder_element) - return _create_element(webrtc->ini.media_source.a_hw_encoder_element, ELEMENT_NAME_AUDIO_ENCODER); + return _create_element(_get_hw_encoder_from_ini(&webrtc->ini, source->type, MEDIA_TYPE_AUDIO), ELEMENT_NAME_AUDIO_ENCODER); break; case MEDIA_TYPE_VIDEO: - if (ini_source && ini_source->v_hw_encoder_element) - encoder = _create_element(ini_source->v_hw_encoder_element, ELEMENT_NAME_VIDEO_ENCODER); - else if (webrtc->ini.media_source.v_hw_encoder_element) - encoder = _create_element(webrtc->ini.media_source.v_hw_encoder_element, ELEMENT_NAME_VIDEO_ENCODER); + encoder = _create_element(_get_hw_encoder_from_ini(&webrtc->ini, source->type, MEDIA_TYPE_VIDEO), ELEMENT_NAME_VIDEO_ENCODER); break; default: LOG_ERROR_IF_REACHED("type(0x%x)", source->media_types); @@ -1027,7 +981,8 @@ static GstElement * __prepare_encoder(webrtc_s *webrtc, webrtc_gst_slot_s *sourc static bool __is_videoscale_needed(webrtc_s *webrtc, webrtc_gst_slot_s *source) { - const ini_item_media_source_s *ini_source; + bool drc_support; + bool encoded_support; RET_VAL_IF(webrtc == NULL, false, "webrtc is NULL"); RET_VAL_IF(source == NULL, false, "source is NULL"); @@ -1035,14 +990,13 @@ static bool __is_videoscale_needed(webrtc_s *webrtc, webrtc_gst_slot_s *source) if (!(source->media_types & MEDIA_TYPE_VIDEO)) return false; - if (_is_encoded_format_supported(source->type, &webrtc->ini)) + _get_video_encoded_support_from_ini(&webrtc->ini, source->type, &encoded_support); + if (encoded_support) return false; - ini_source = _ini_get_source_by_type(&webrtc->ini, source->type); - if (ini_source == NULL) - ini_source = &webrtc->ini.media_source; + _get_drc_support_from_ini(&webrtc->ini, source->type, &drc_support); - if (ini_source->v_drc_support) + if (drc_support) return false; if (source->type == WEBRTC_MEDIA_SOURCE_TYPE_FILE || source->type == WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET) @@ -1072,12 +1026,14 @@ int _create_rest_of_elements(webrtc_s *webrtc, webrtc_gst_slot_s *source, bool n idx = GET_AV_IDX(is_audio); if (need_capsfilter) { + bool encoded_support; GstElement *capsfilter = _create_element(DEFAULT_ELEMENT_CAPSFILTER, ELEMENT_NAME_FIRST_CAPSFILTER); if (!capsfilter) return WEBRTC_ERROR_INVALID_OPERATION; APPEND_ELEMENT(*element_list, capsfilter); - if (_is_encoded_format_supported(source->type, &webrtc->ini)) { + _get_video_encoded_support_from_ini(&webrtc->ini, source->type, &encoded_support); + if (encoded_support) { if ((sink_caps = __make_default_encoded_caps(source, &webrtc->ini, NULL))) { PRINT_CAPS(sink_caps, "capsfilter"); g_object_set(G_OBJECT(capsfilter), "caps", sink_caps, NULL); @@ -1230,21 +1186,16 @@ void _set_video_src_resolution(webrtc_gst_slot_s *source, int width, int height) GstCaps *_make_video_raw_caps_with_resolution(webrtc_gst_slot_s *source, webrtc_ini_s *ini, int width, int height) { GstCaps *caps = NULL; - const ini_item_media_source_s *ini_source; RET_VAL_IF(source == NULL, NULL, "source is NULL"); RET_VAL_IF(ini == NULL, NULL, "ini is NULL"); - ini_source = _ini_get_source_by_type(ini, source->type); - if (ini_source == NULL) - ini_source = &ini->media_source; - switch (source->type) { case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST: case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA: case WEBRTC_MEDIA_SOURCE_TYPE_SCREEN: { caps = gst_caps_new_simple(MEDIA_TYPE_VIDEO_RAW, - "format", G_TYPE_STRING, ini_source->v_raw_format, + "format", G_TYPE_STRING, _get_raw_format_from_ini(ini, source->type, MEDIA_TYPE_VIDEO), "framerate", GST_TYPE_FRACTION, source->video_info.framerate, 1, "width", G_TYPE_INT, width, "height", G_TYPE_INT, height,