From: Sangchul Lee Date: Mon, 4 Jan 2021 10:31:35 +0000 (+0900) Subject: webrtc_source: Use gst_audio_info_* functions of gst-plugins-base X-Git-Tag: submit/tizen/20210729.023123~163 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=df3a44b1fb91e8212556c01f868edc0c57ffd77a;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_source: Use gst_audio_info_* functions of gst-plugins-base gst_audio_info_set_format() and gst_audio_info_to_caps() are used to make caps for raw media format. [Version] 0.1.78 [Issue Type] Improvement Change-Id: I1dd2aa407a2d5f6627c1856d83a992154a746954 Signed-off-by: Sangchul Lee --- diff --git a/CMakeLists.txt b/CMakeLists.txt index e6a5639b..70fe5504 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,8 @@ SET(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib") SET(INC_DIR include) INCLUDE_DIRECTORIES(${INC_DIR}) -SET(dependents "dlog glib-2.0 gstreamer-1.0 gstreamer-webrtc-1.0 gstreamer-video-1.0 json-glib-1.0 iniparser mm-common mm-display-interface capi-media-tool libtbm") +SET(dependents "dlog glib-2.0 gstreamer-1.0 gstreamer-webrtc-1.0 gstreamer-video-1.0 gstreamer-audio-1.0 \ + json-glib-1.0 iniparser mm-common mm-display-interface capi-media-tool libtbm") SET(pc_dependents "capi-base-common" ) INCLUDE(FindPkgConfig) diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index f02d8718..1bdc65d7 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.1.77 +Version: 0.1.78 Release: 0 Group: Multimedia/API License: Apache-2.0 @@ -15,6 +15,7 @@ BuildRequires: pkgconfig(capi-media-tool) BuildRequires: pkgconfig(gstreamer-1.0) BuildRequires: pkgconfig(gstreamer-webrtc-1.0) BuildRequires: pkgconfig(gstreamer-video-1.0) +BuildRequires: pkgconfig(gstreamer-audio-1.0) BuildRequires: pkgconfig(appcore-efl) BuildRequires: pkgconfig(elementary) BuildRequires: pkgconfig(json-glib-1.0) diff --git a/src/webrtc_source.c b/src/webrtc_source.c index 51ceeed1..8a3b17ad 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -14,6 +14,7 @@ * limitations under the License. */ +#include #include "webrtc.h" #include "webrtc_private.h" #include @@ -169,6 +170,24 @@ static const char *__get_format_name(media_format_mimetype_e mime_type) } } +static GstAudioFormat __get_gst_audio_format(media_format_mimetype_e mime_type) +{ + switch (mime_type) { + /* RAW formats */ + case MEDIA_FORMAT_PCM_S16LE: + return GST_AUDIO_FORMAT_S16LE; + case MEDIA_FORMAT_PCM_S24LE: + return GST_AUDIO_FORMAT_S24_32LE; + /* ENCODED formats */ + case MEDIA_FORMAT_OPUS: + case MEDIA_FORMAT_VORBIS: + return GST_AUDIO_FORMAT_ENCODED; + default: + LOG_ERROR("not supported mime_type(0x%x)", mime_type); + return GST_AUDIO_FORMAT_UNKNOWN; + } +} + static bool __is_supported_mime_type(media_format_mimetype_e mime_type) { switch (mime_type) { @@ -285,14 +304,17 @@ static GstCaps *__make_raw_caps_from_media_format(webrtc_gst_slot_s *source) 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()"); - caps = gst_caps_new_simple(MEDIA_TYPE_AUDIO_RAW, - "format", G_TYPE_STRING, __get_format_name(mime_type), - "channels", G_TYPE_INT, channels, - "rate", G_TYPE_INT, samplerate, - NULL); + + 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; @@ -856,7 +878,7 @@ static int __build_mediapacketsrc(webrtc_s *webrtc, webrtc_gst_slot_s *source) return WEBRTC_ERROR_INVALID_OPERATION; } - g_object_set(G_OBJECT(appsrc), "emit-signals", TRUE, "is-live", TRUE, "format", 3, NULL); /* format 3 for time format of the segment events and seek */ + g_object_set(G_OBJECT(appsrc), "emit-signals", TRUE, "is-live", TRUE, "format", GST_FORMAT_TIME, NULL); _connect_and_append_signal(&source->signals, G_OBJECT(appsrc), "need-data", G_CALLBACK(_appsrc_need_data_cb), source); _connect_and_append_signal(&source->signals, G_OBJECT(appsrc), "enough-data", G_CALLBACK(_appsrc_enough_data_cb), source);