webrtc_source: Use gst_audio_info_* functions of gst-plugins-base 72/250772/4
authorSangchul Lee <sc11.lee@samsung.com>
Mon, 4 Jan 2021 10:31:35 +0000 (19:31 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 6 Jan 2021 02:50:54 +0000 (11:50 +0900)
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 <sc11.lee@samsung.com>
CMakeLists.txt
packaging/capi-media-webrtc.spec
src/webrtc_source.c

index e6a5639b934911ff1a1d74a22a1d60d36b6faad6..70fe5504d7f213337ec291dae9f2e92e5293e301 100644 (file)
@@ -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)
index f02d8718d5b988d9df0bacd0264b64b4dba21e69..1bdc65d7025781916e493a80b6a0cb0c889a4eb7 100644 (file)
@@ -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)
index 51ceeed1a1c098724ac272648eb94414ae5652ce..8a3b17ad2043ada0632dd2872d4dab56cd664a75 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <gst/audio/audio.h>
 #include "webrtc.h"
 #include "webrtc_private.h"
 #include <tbm_surface_internal.h>
@@ -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);