webrtc_source: Support zerocopy format 52/256552/3
authorSangchul Lee <sc11.lee@samsung.com>
Wed, 7 Apr 2021 01:15:10 +0000 (10:15 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 8 Apr 2021 02:38:46 +0000 (11:38 +0900)
It affects to make it possible to use tizen zerocopy format(SN12, S420)
for camera source and media packet source.

[Version] 0.1.141
[Issue Type] Improvement

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

index b47aadc9b46b960d7961a848c10f73e634d4b7df..6f05e67345a3e22966ffe586c2abdb14c83d5da4 100644 (file)
@@ -382,6 +382,7 @@ typedef struct _webrtc_gst_slot_s {
        int media_types;    /* values of media_type_e combined with bitwise 'or' */
        int mlines[2];      /* index 0 for audio, 1 for video */
        media_format_h media_format;
+       bool zerocopy_enabled;
        webrtc_callbacks_s buffer_state_changed_cb;
        webrtc_callbacks_s *encoded_frame_cb;
        webrtc_s *webrtc;
index 3b523d8b7c40cb315bda263c3727fdac79669763..060cfb9fc0aa5f9065d13f3563416b31652180bc 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.1.140
+Version:    0.1.141
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 6815515c40e968fd5a916c3b72f7ecaa2fa1d646..5806a361573f56947fedfaaa2a700731f0ff3744 100644 (file)
@@ -124,7 +124,7 @@ static codec_type_e __get_video_codec_type(const gchar *media_type)
        return CODEC_TYPE_NOT_SUPPORTED;
 }
 
-static const char *__get_format_name(media_format_mimetype_e mime_type)
+static const char *__get_format_name(media_format_mimetype_e mime_type, bool zerocopy_enabled)
 {
        switch (mime_type) {
        /* RAW formats */
@@ -133,9 +133,9 @@ static const char *__get_format_name(media_format_mimetype_e mime_type)
        case MEDIA_FORMAT_PCM_S24LE:
                return "S24LE";
        case MEDIA_FORMAT_I420:
-               return "I420";
+               return zerocopy_enabled ? "S420" : "I420";
        case MEDIA_FORMAT_NV12:
-               return "NV12";
+               return zerocopy_enabled ? "SN12" : "NV12";
        /* ENCODED formats */
        case MEDIA_FORMAT_OPUS:
                return "OPUS";
@@ -182,7 +182,7 @@ static bool __is_supported_mime_type(media_format_mimetype_e mime_type)
        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), mime_type);
+                       __get_format_name(mime_type, false), mime_type);
                return true;
        /* ENCODED formats */
        case MEDIA_FORMAT_OPUS:
@@ -193,7 +193,7 @@ static bool __is_supported_mime_type(media_format_mimetype_e mime_type)
        case MEDIA_FORMAT_H264_MP:
        case MEDIA_FORMAT_H264_HP:
                LOG_INFO("[%s][ENCODED/%s] mime_type[0x%x]", mime_type & MEDIA_FORMAT_AUDIO ? "AUDIO" : "VIDEO",
-                       __get_format_name(mime_type), mime_type);
+                       __get_format_name(mime_type, false), mime_type);
                return true;
        default:
                LOG_ERROR("not supported mime_type(0x%x)", mime_type);
@@ -245,7 +245,7 @@ static GstCaps *__make_default_raw_caps(webrtc_gst_slot_s *source, webrtc_ini_s
                        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),
+                                                       "format", G_TYPE_STRING, __get_format_name(mime_type, source->zerocopy_enabled),
                                                        "channels", G_TYPE_INT, channels,
                                                        "rate", G_TYPE_INT, samplerate,
                                                        NULL);
@@ -260,7 +260,7 @@ static GstCaps *__make_default_raw_caps(webrtc_gst_slot_s *source, webrtc_ini_s
                        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),
+                                                       "format", G_TYPE_STRING, __get_format_name(mime_type, source->zerocopy_enabled),
                                                        "framerate", GST_TYPE_FRACTION, framerate, 1,
                                                        "width", G_TYPE_INT, width,
                                                        "height", G_TYPE_INT, height,
@@ -313,7 +313,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),
+                                               "format", G_TYPE_STRING, __get_format_name(mime_type, source->zerocopy_enabled),
                                                "framerate", GST_TYPE_FRACTION, framerate, 1,
                                                "width", G_TYPE_INT, width,
                                                "height", G_TYPE_INT, height,
@@ -418,7 +418,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));
+                       _media_type = __get_audio_media_type(__get_format_name(mime_type, source->zerocopy_enabled));
                        RET_VAL_IF(_media_type == NULL, NULL, "media_type is NULL");
 
                        caps = gst_caps_new_simple(_media_type,
@@ -436,7 +436,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));
+                       _media_type = __get_video_media_type(__get_format_name(mime_type, source->zerocopy_enabled));
                        RET_VAL_IF(_media_type == NULL, NULL, "media_type is NULL");
 
                        caps = gst_caps_new_simple(_media_type,
@@ -522,6 +522,7 @@ static GstElement *__get_hw_encoder_element(webrtc_s *webrtc, webrtc_gst_slot_s
 #ifdef TIZEN_FEATURE_RES_MGR
                webrtc->resource.need_to_acquire[MM_RESOURCE_MANAGER_RES_TYPE_VIDEO_ENCODER] = true;
 #endif
+               source->zerocopy_enabled = true;
                return encoder;
        }
 
@@ -951,6 +952,9 @@ static int __complete_mediapacketsrc_from_raw_format(webrtc_s *webrtc, webrtc_gs
        appsrc = __find_element_in_bin(source->bin, "appsrc");
        RET_VAL_IF(appsrc == NULL, WEBRTC_ERROR_INVALID_OPERATION, "appsrc is NULL");
 
+       if ((ret = __create_rest_of_elements(webrtc, source, NULL, &encoder, &payloader, &queue, &capsfilter)) != WEBRTC_ERROR_NONE)
+               return ret;
+
        if (!(sink_caps = __make_raw_caps_from_media_format(source))) {
                LOG_ERROR("failed to __make_raw_caps_from_media_format()");
                return WEBRTC_ERROR_INVALID_OPERATION;
@@ -962,9 +966,6 @@ static int __complete_mediapacketsrc_from_raw_format(webrtc_s *webrtc, webrtc_gs
        g_object_set(G_OBJECT(appsrc), "caps", sink_caps, NULL);
        gst_caps_unref(sink_caps);
 
-       if ((ret = __create_rest_of_elements(webrtc, source, NULL, &encoder, &payloader, &queue, &capsfilter)) != WEBRTC_ERROR_NONE)
-               return ret;
-
        gst_bin_add_many(GST_BIN(source->bin), encoder, payloader, queue, capsfilter, NULL);
        if (!gst_element_link_many(appsrc, encoder, payloader, queue, capsfilter, NULL)) {
                LOG_ERROR("failed to gst_element_link_many()");
@@ -986,7 +987,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));
+       _media_type = __get_video_media_type(__get_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);
        /* FIXME: prepare other types */
 
@@ -1016,6 +1017,9 @@ static int __complete_mediapacketsrc_from_encoded_format(webrtc_s *webrtc, webrt
        appsrc = __find_element_in_bin(source->bin, "appsrc");
        RET_VAL_IF(appsrc == NULL, WEBRTC_ERROR_INVALID_OPERATION, "appsrc is NULL");
 
+       if ((ret = __create_rest_of_elements_for_encoded_format(webrtc, source, &payloader, &queue, &capsfilter)) != WEBRTC_ERROR_NONE)
+               return ret;
+
        if (!(sink_caps = __make_encoded_caps_for_appsrc(source))) {
                LOG_ERROR("failed to __make_encoded_caps_for_appsrc()");
                return WEBRTC_ERROR_INVALID_OPERATION;
@@ -1027,9 +1031,6 @@ static int __complete_mediapacketsrc_from_encoded_format(webrtc_s *webrtc, webrt
        g_object_set(G_OBJECT(appsrc), "caps", sink_caps, NULL);
        gst_caps_unref(sink_caps);
 
-       if ((ret = __create_rest_of_elements_for_encoded_format(webrtc, source, &payloader, &queue, &capsfilter)) != WEBRTC_ERROR_NONE)
-               return ret;
-
        gst_bin_add_many(GST_BIN(source->bin), payloader, queue, capsfilter, NULL);
        if (!gst_element_link_many(appsrc, payloader, queue, capsfilter, NULL)) {
                LOG_ERROR("failed to gst_element_link_many()");