webrtc_source: Use gst_audio_info_to_caps() 14/261114/2
authorSangchul Lee <sc11.lee@samsung.com>
Mon, 12 Jul 2021 07:14:04 +0000 (16:14 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Mon, 12 Jul 2021 07:52:20 +0000 (16:52 +0900)
It also set the layout to 'interleaved' internally.

[Version] 0.2.38
[Issue Type] Refactoring

Change-Id: If10b12445a8e252a7af8940625ab222a9719c8bc
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
packaging/capi-media-webrtc.spec
src/webrtc_source.c

index 8a114014ae689bf8a72d44f46cb5da61bb6e45e1..16562d5f6b43c2852992852b2d6d642100117bd5 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.2.37
+Version:    0.2.38
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 3f2197c0ade593d84092ef2b2054b99bb4e0b5bb..e2c2ad6b6eddc38285b6ba558a6240b17946a707 100644 (file)
@@ -122,7 +122,7 @@ static const char * __get_video_media_type(const char *codec_name)
        return NULL;
 }
 
-static const char *__get_format_name(media_format_mimetype_e mime_type, bool zerocopy_enabled)
+static const char *__get_audio_format_name(media_format_mimetype_e mime_type)
 {
        switch (mime_type) {
        /* RAW formats */
@@ -130,15 +130,26 @@ static const char *__get_format_name(media_format_mimetype_e mime_type, bool zer
                return "S16LE";
        case MEDIA_FORMAT_PCM_S24LE:
                return "S24LE";
-       case MEDIA_FORMAT_I420:
-               return zerocopy_enabled ? "S420" : "I420";
-       case MEDIA_FORMAT_NV12:
-               return zerocopy_enabled ? "SN12" : "NV12";
        /* ENCODED formats */
        case MEDIA_FORMAT_OPUS:
                return "OPUS";
        case MEDIA_FORMAT_VORBIS:
                return "VORBIS";
+       default:
+               LOG_ERROR("not supported audio mime_type(0x%x)", mime_type);
+               return NULL;
+       }
+}
+
+static const char *__get_video_format_name(media_format_mimetype_e mime_type, bool zerocopy_enabled)
+{
+       switch (mime_type) {
+       /* RAW formats */
+       case MEDIA_FORMAT_I420:
+               return zerocopy_enabled ? "S420" : "I420";
+       case MEDIA_FORMAT_NV12:
+               return zerocopy_enabled ? "SN12" : "NV12";
+       /* ENCODED formats */
        case MEDIA_FORMAT_VP8:
                return "VP8";
        case MEDIA_FORMAT_VP9:
@@ -150,7 +161,7 @@ static const char *__get_format_name(media_format_mimetype_e mime_type, bool zer
        case MEDIA_FORMAT_MJPEG:
                return "JPEG";
        default:
-               LOG_ERROR("not supported mime_type(0x%x)", mime_type);
+               LOG_ERROR("not supported video mime_type(0x%x)", mime_type);
                return NULL;
        }
 }
@@ -173,28 +184,45 @@ static GstAudioFormat __get_gst_audio_format(media_format_mimetype_e mime_type)
        }
 }
 
+static GstAudioFormat __get_gst_audio_format_from_string(const char *format)
+{
+       RET_VAL_IF(format == NULL, GST_AUDIO_FORMAT_UNKNOWN, "format is NULL");
+
+       if (!strcmp(format, "S16LE"))
+               return GST_AUDIO_FORMAT_S16LE;
+       if (!strcmp(format, "S24LE"))
+               return GST_AUDIO_FORMAT_S24_32LE;
+
+       LOG_ERROR("not supported raw format(%s)", format);
+       return GST_AUDIO_FORMAT_UNKNOWN;
+}
+
 static bool __is_supported_mime_type(media_format_mimetype_e mime_type)
 {
        switch (mime_type) {
-       /* RAW formats */
+       /* AUDIO/RAW formats */
        case MEDIA_FORMAT_PCM_S16LE:
        case MEDIA_FORMAT_PCM_S24LE:
+               LOG_INFO("[AUDIO][RAW/%s] mime_type[0x%x]", __get_audio_format_name(mime_type), mime_type);
+               return true;
+       /* VIDEO/RAW formats */
        case MEDIA_FORMAT_I420:
        case MEDIA_FORMAT_NV12:
-               LOG_INFO("[%s][RAW/%s] mime_type[0x%x]", mime_type & MEDIA_FORMAT_AUDIO ? "AUDIO" : "VIDEO",
-                       __get_format_name(mime_type, false), mime_type);
+               LOG_INFO("[VIDEO][RAW/%s] mime_type[0x%x]", __get_video_format_name(mime_type, false), mime_type);
                return true;
-       /* ENCODED formats */
+       /* AUDIO/ENCODED formats */
        case MEDIA_FORMAT_OPUS:
        case MEDIA_FORMAT_VORBIS:
+               LOG_INFO("[AUDIO][ENCODED/%s] mime_type[0x%x]", __get_audio_format_name(mime_type), mime_type);
+               return true;
+       /* VIDEO/ENCODED formats */
        case MEDIA_FORMAT_VP8:
        case MEDIA_FORMAT_VP9:
        case MEDIA_FORMAT_H264_SP:
        case MEDIA_FORMAT_H264_MP:
        case MEDIA_FORMAT_H264_HP:
        case MEDIA_FORMAT_MJPEG:
-               LOG_INFO("[%s][ENCODED/%s] mime_type[0x%x]", mime_type & MEDIA_FORMAT_AUDIO ? "AUDIO" : "VIDEO",
-                       __get_format_name(mime_type, false), mime_type);
+               LOG_INFO("[VIDEO][ENCODED/%s] mime_type[0x%x]", __get_video_format_name(mime_type, false), mime_type);
                return true;
        default:
                LOG_ERROR("not supported mime_type(0x%x)", mime_type);
@@ -239,6 +267,8 @@ static GstCaps *__make_default_raw_caps(webrtc_gst_slot_s *source, webrtc_ini_s
 {
        GstCaps *caps = NULL;
        ini_item_media_source_s *ini_source;
+       GstAudioInfo info;
+       GstAudioFormat format;
 
        RET_VAL_IF(source == NULL, NULL, "source is NULL");
        RET_VAL_IF(ini == NULL, NULL, "ini is NULL");
@@ -265,11 +295,11 @@ static GstCaps *__make_default_raw_caps(webrtc_gst_slot_s *source, webrtc_ini_s
        case WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST:
        case WEBRTC_MEDIA_SOURCE_TYPE_MIC:
        case WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_AUDIO:
-               caps = gst_caps_new_simple(MEDIA_TYPE_AUDIO_RAW,
-                                               "format", G_TYPE_STRING, ini_source->a_raw_format,
-                                               "channels", G_TYPE_INT, ini_source->a_channels,
-                                               "rate", G_TYPE_INT, ini_source->a_samplerate,
-                                               NULL);
+               format = __get_gst_audio_format_from_string(ini_source->a_raw_format);
+               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);
+               caps = gst_audio_info_to_caps(&info);
                break;
 
        case WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET: {
@@ -280,14 +310,19 @@ static GstCaps *__make_default_raw_caps(webrtc_gst_slot_s *source, webrtc_ini_s
                if (source->media_types == MEDIA_TYPE_AUDIO) {
                        int channels;
                        int samplerate;
+                       const char *format_name;
 
                        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, source->zerocopy_enabled),
-                                                       "channels", G_TYPE_INT, channels,
-                                                       "rate", G_TYPE_INT, samplerate,
-                                                       NULL);
+
+                       format_name = __get_audio_format_name(mime_type);
+                       RET_VAL_IF(format_name == NULL, NULL, "not supported mime_type");
+
+                       format = __get_gst_audio_format_from_string(format_name);
+                       RET_VAL_IF(format == GST_AUDIO_FORMAT_UNKNOWN, NULL, "not supported raw format");
+
+                       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;
@@ -298,8 +333,9 @@ static GstCaps *__make_default_raw_caps(webrtc_gst_slot_s *source, webrtc_ini_s
                                NULL, "failed to media_format_get_video_info()");
                        RET_VAL_IF(media_format_get_video_frame_rate(source->media_format, &framerate) != MEDIA_FORMAT_ERROR_NONE,
                                NULL, "failed to media_format_get_video_frame_rate()");
+
                        caps = gst_caps_new_simple(MEDIA_TYPE_VIDEO_RAW,
-                                                       "format", G_TYPE_STRING, __get_format_name(mime_type, source->zerocopy_enabled),
+                                                       "format", G_TYPE_STRING, __get_video_format_name(mime_type, source->zerocopy_enabled),
                                                        "framerate", GST_TYPE_FRACTION, framerate, 1,
                                                        "width", G_TYPE_INT, width,
                                                        "height", G_TYPE_INT, height,
@@ -353,7 +389,7 @@ static GstCaps *__make_raw_caps_from_media_format(webrtc_gst_slot_s *source)
                RET_VAL_IF(media_format_get_video_frame_rate(source->media_format, &framerate) != MEDIA_FORMAT_ERROR_NONE,
                        NULL, "failed to media_format_get_video_frame_rate()");
                caps = gst_caps_new_simple(MEDIA_TYPE_VIDEO_RAW,
-                                               "format", G_TYPE_STRING, __get_format_name(mime_type, source->zerocopy_enabled),
+                                               "format", G_TYPE_STRING, __get_video_format_name(mime_type, source->zerocopy_enabled),
                                                "framerate", GST_TYPE_FRACTION, framerate, 1,
                                                "width", G_TYPE_INT, width,
                                                "height", G_TYPE_INT, height,
@@ -489,7 +525,7 @@ static GstCaps *__make_encoded_caps_from_media_format(webrtc_gst_slot_s *source,
                        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()");
 
-                       _media_type = __get_audio_media_type(__get_format_name(mime_type, source->zerocopy_enabled));
+                       _media_type = __get_audio_media_type(__get_audio_format_name(mime_type));
                        RET_VAL_IF(_media_type == NULL, NULL, "media_type is NULL");
 
                        caps = __get_caps_from_encoded_audio_media_type(_media_type, channels, samplerate);
@@ -504,7 +540,7 @@ static GstCaps *__make_encoded_caps_from_media_format(webrtc_gst_slot_s *source,
                        RET_VAL_IF(media_format_get_video_frame_rate(source->media_format, &framerate) != MEDIA_FORMAT_ERROR_NONE,
                                NULL, "failed to media_format_get_video_frame_rate()");
 
-                       _media_type = __get_video_media_type(__get_format_name(mime_type, source->zerocopy_enabled));
+                       _media_type = __get_video_media_type(__get_video_format_name(mime_type, source->zerocopy_enabled));
                        RET_VAL_IF(_media_type == NULL, NULL, "media_type is NULL");
 
                        caps = __get_caps_from_encoded_video_media_type(_media_type, width, height);
@@ -1602,7 +1638,7 @@ static GstCaps *__make_encoded_caps_for_appsrc(webrtc_gst_slot_s *source)
        RET_VAL_IF(media_format_get_video_info(source->media_format, &mime_type, NULL, NULL, NULL, NULL) != MEDIA_FORMAT_ERROR_NONE,
                                NULL, "failed to media_format_get_video_info()");
 
-       _media_type = __get_video_media_type(__get_format_name(mime_type, source->zerocopy_enabled));
+       _media_type = __get_video_media_type(__get_video_format_name(mime_type, source->zerocopy_enabled));
        RET_VAL_IF(g_strcmp0(_media_type, MEDIA_TYPE_VIDEO_H264), NULL, "not supported type(%s)", _media_type);
 
        return __make_encoded_caps_from_media_format(source, NULL);