From: hj kim Date: Mon, 25 Jul 2022 08:09:32 +0000 (+0900) Subject: webrtc_source_private: move _get_payload_info() and related code to webrtc_source_pri... X-Git-Tag: submit/tizen/20220726.122258~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F09%2F278709%2F3;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_source_private: move _get_payload_info() and related code to webrtc_source_private.c [Version] 0.3.167 [Issue Type] Refactoring Change-Id: I6aba8972a7d42a2bbe10ef6fbf092a3b780da404 --- diff --git a/include/webrtc_source_private.h b/include/webrtc_source_private.h index d2c332aa..7221cc88 100644 --- a/include/webrtc_source_private.h +++ b/include/webrtc_source_private.h @@ -72,6 +72,14 @@ typedef enum { ELEMENT_FAKESINK } gst_element_e; +typedef struct { + webrtc_transceiver_codec_e codec; + const char *gst_media_type; + const char *media_type; + const char *encoding_name; + int clock_rate; +} rtp_payload_info_s; + const char *_get_audio_format_name(media_format_mimetype_e mime_type); const char *_get_video_format_name(media_format_mimetype_e mime_type, bool zerocopy_enabled); const char *_get_source_element(webrtc_s *webrtc, int type); @@ -95,5 +103,7 @@ void _remove_probe_from_pad_for_pause(webrtc_gst_slot_s *source, unsigned int id GstPadProbeReturn _source_data_probe_cb(GstPad *pad, GstPadProbeInfo *info, gpointer user_data); void _add_probe_to_pad_for_render(webrtc_gst_slot_s *source, unsigned int idx, GstPad *pad, void *probe_cb); void _remove_probe_from_pad_for_render(webrtc_gst_slot_s *source, unsigned int idx); +rtp_payload_info_s * _get_payload_info(webrtc_transceiver_codec_e codec); +rtp_payload_info_s * _get_payload_info_by_encoding_name(const char *encoding_name); #endif /* __TIZEN_MEDIA_WEBRTC_SOURCE_COMMON_H__ */ diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index b2df18c8..44645c19 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.166 +Version: 0.3.167 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_source.c b/src/webrtc_source.c index 816b76c0..5d1126c9 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -33,26 +33,6 @@ static direction_info_s __direction_info[] = { [WEBRTC_TRANSCEIVER_DIRECTION_SENDRECV] = { "SENDRECV", GST_WEBRTC_RTP_TRANSCEIVER_DIRECTION_SENDRECV } }; -typedef struct { - webrtc_transceiver_codec_e codec; - const char *gst_media_type; - const char *media_type; - const char *encoding_name; - int clock_rate; -} rtp_payload_info_s; - -static rtp_payload_info_s __payload_info[] = { - { WEBRTC_TRANSCEIVER_CODEC_PCMU, MEDIA_TYPE_AUDIO_MULAW, "audio", "PCMU", 8000 }, - { WEBRTC_TRANSCEIVER_CODEC_PCMA, MEDIA_TYPE_AUDIO_ALAW, "audio", "PCMA", 8000 }, - { WEBRTC_TRANSCEIVER_CODEC_OPUS, MEDIA_TYPE_AUDIO_OPUS, "audio", "OPUS", 48000 }, - { WEBRTC_TRANSCEIVER_CODEC_VP8, MEDIA_TYPE_VIDEO_VP8, "video", "VP8", 90000 }, - { WEBRTC_TRANSCEIVER_CODEC_VP9, MEDIA_TYPE_VIDEO_VP9, "video", "VP9", 90000 }, - { WEBRTC_TRANSCEIVER_CODEC_H264, MEDIA_TYPE_VIDEO_H264, "video", "H264", 90000 }, - { 0 /* TBD */, MEDIA_TYPE_AUDIO_VORBIS, "audio", "VORBIS", 8000 }, - { 0 /* TBD */, MEDIA_TYPE_VIDEO_JPEG, "video", "JPEG", 90000 }, - { 0, NULL, NULL, NULL, 0 } -}; - static int __link_source_with_webrtcbin(webrtc_gst_slot_s *source, GstElement *webrtcbin); static GstPadProbeReturn __camerasrc_probe_cb(GstPad *pad, GstPadProbeInfo *info, gpointer u_data); @@ -902,25 +882,6 @@ static int __add_transceiver(webrtc_gst_slot_s *source, webrtc_media_type_e medi return WEBRTC_ERROR_NONE; } -static rtp_payload_info_s * __get_payload_info(const char *codec) -{ - int i = 0; - size_t n = 0; - - RET_VAL_IF(codec == NULL, NULL, "codec is NULL"); - - n = ARRAY_SIZE(__payload_info); - - for (i = 0; i < (int)n; i++) { - if ((__payload_info[i].encoding_name) && !strcasecmp(__payload_info[i].encoding_name, codec)) - return &__payload_info[i]; - } - - LOG_ERROR("could not find payload_info. codec[%s]", codec); - - return NULL; -} - static void __check_and_add_recvonly_transceiver(webrtc_gst_slot_s *source) { rtp_payload_info_s *payload_info = NULL; @@ -928,13 +889,13 @@ static void __check_and_add_recvonly_transceiver(webrtc_gst_slot_s *source) RET_IF(source == NULL, "source is NULL"); if (source->av[AV_IDX_AUDIO].direction == WEBRTC_TRANSCEIVER_DIRECTION_RECVONLY && source->av[AV_IDX_AUDIO].codec) { - payload_info = __get_payload_info(source->av[AV_IDX_AUDIO].codec); + payload_info = _get_payload_info_by_encoding_name(source->av[AV_IDX_AUDIO].codec); if (payload_info) __add_transceiver(source, WEBRTC_MEDIA_TYPE_AUDIO, payload_info); } if (source->av[AV_IDX_VIDEO].direction == WEBRTC_TRANSCEIVER_DIRECTION_RECVONLY && source->av[AV_IDX_VIDEO].codec) { - payload_info = __get_payload_info(source->av[AV_IDX_VIDEO].codec); + payload_info = _get_payload_info_by_encoding_name(source->av[AV_IDX_VIDEO].codec); if (payload_info) __add_transceiver(source, WEBRTC_MEDIA_TYPE_VIDEO, payload_info); } @@ -2274,7 +2235,6 @@ int _set_transceiver_codec(webrtc_s *webrtc, unsigned int source_id, webrtc_medi int ret; webrtc_gst_slot_s *source; int av_idx = (media_type == WEBRTC_MEDIA_TYPE_AUDIO) ? AV_IDX_AUDIO : AV_IDX_VIDEO; - int i; rtp_payload_info_s *payload_info = NULL; RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); @@ -2284,12 +2244,7 @@ int _set_transceiver_codec(webrtc_s *webrtc, unsigned int source_id, webrtc_medi RET_VAL_IF((source->type == WEBRTC_MEDIA_SOURCE_TYPE_FILE), WEBRTC_ERROR_INVALID_PARAMETER, "this API does not support the file source"); RET_VAL_IF((source->type == WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET), WEBRTC_ERROR_INVALID_PARAMETER, "this API does not support the media packet source"); - for (i = 0; i != (int)__payload_info[i].codec; i++) { - if (__payload_info[i].codec != codec) - continue; - payload_info = &__payload_info[i]; - break; - } + payload_info = _get_payload_info(codec); RET_VAL_IF(payload_info == NULL, WEBRTC_ERROR_INVALID_OPERATION, "could not find payload_info"); /* NOTE: for null source, set media_types here exceptionally. */ diff --git a/src/webrtc_source_private.c b/src/webrtc_source_private.c index 2e9d453e..b1f7a0a4 100644 --- a/src/webrtc_source_private.c +++ b/src/webrtc_source_private.c @@ -23,6 +23,18 @@ typedef struct { webrtc_gst_slot_s *source; } probe_userdata_s; +static rtp_payload_info_s __payload_info[] = { + { WEBRTC_TRANSCEIVER_CODEC_PCMU, MEDIA_TYPE_AUDIO_MULAW, "audio", "PCMU", 8000 }, + { WEBRTC_TRANSCEIVER_CODEC_PCMA, MEDIA_TYPE_AUDIO_ALAW, "audio", "PCMA", 8000 }, + { WEBRTC_TRANSCEIVER_CODEC_OPUS, MEDIA_TYPE_AUDIO_OPUS, "audio", "OPUS", 48000 }, + { WEBRTC_TRANSCEIVER_CODEC_VP8, MEDIA_TYPE_VIDEO_VP8, "video", "VP8", 90000 }, + { WEBRTC_TRANSCEIVER_CODEC_VP9, MEDIA_TYPE_VIDEO_VP9, "video", "VP9", 90000 }, + { WEBRTC_TRANSCEIVER_CODEC_H264, MEDIA_TYPE_VIDEO_H264, "video", "H264", 90000 }, + { 0 /* TBD */, MEDIA_TYPE_AUDIO_VORBIS, "audio", "VORBIS", 8000 }, + { 0 /* TBD */, MEDIA_TYPE_VIDEO_JPEG, "video", "JPEG", 90000 }, + { 0, NULL, NULL, NULL, 0 } +}; + const char *_get_audio_format_name(media_format_mimetype_e mime_type) { switch (mime_type) { @@ -561,3 +573,36 @@ void _remove_probe_from_pad_for_render(webrtc_gst_slot_s *source, unsigned int i source->av[idx].render.appsrc_caps = NULL; } } + +rtp_payload_info_s * _get_payload_info(webrtc_transceiver_codec_e codec) +{ + int i = 0; + + for (i = 0; i != (int)__payload_info[i].codec; i++) { + if (__payload_info[i].codec == codec) + return &__payload_info[i]; + } + + LOG_ERROR("could not find payload_info. codec[%d]", codec); + + return NULL; +} + +rtp_payload_info_s * _get_payload_info_by_encoding_name(const char *encoding_name) +{ + int i = 0; + size_t n = 0; + + RET_VAL_IF(encoding_name == NULL, NULL, "encoding_name is NULL"); + + n = ARRAY_SIZE(__payload_info); + + for (i = 0; i < (int)n; i++) { + if ((__payload_info[i].encoding_name) && !strcasecmp(__payload_info[i].encoding_name, encoding_name)) + return &__payload_info[i]; + } + + LOG_ERROR("could not find payload_info. encoding_name[%s]", encoding_name); + + return NULL; +}