webrtc_source: Save video framerate/width/height value if required element does not... 90/275990/2
authorSangchul Lee <sc11.lee@samsung.com>
Wed, 8 Jun 2022 06:10:58 +0000 (15:10 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 9 Jun 2022 07:27:55 +0000 (16:27 +0900)
This is a preparation for setting option values regardless of elements
creation or linking pads.

[Version] 0.3.118
[Issue Type] Improvement

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

index f14be079ef6fb26af15cbdeb2915960b3a6b4ecf..1f4ef8e38a965f1f067a1a62cf6af8371cc1e3af 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.3.117
+Version:    0.3.118
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index b96d38d6e7cb2faa6b1a084c9ce97ad643dd274f..307f008d722cdf4b4e0f367bee9b67986d910d8d 100644 (file)
@@ -289,16 +289,18 @@ static GstCaps *__make_video_raw_caps_with_resolution(webrtc_gst_slot_s *source,
        switch (source->type) {
        case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST:
        case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA:
-       case WEBRTC_MEDIA_SOURCE_TYPE_SCREEN:
+       case WEBRTC_MEDIA_SOURCE_TYPE_SCREEN: {
+               int framerate = source->video_info.framerate > 0 ? source->video_info.framerate : ini_source->v_framerate;
                caps = gst_caps_new_simple(MEDIA_TYPE_VIDEO_RAW,
                                                "format", G_TYPE_STRING, ini_source->v_raw_format,
-                                               "framerate", GST_TYPE_FRACTION, source->video_info.framerate, 1,
+                                               "framerate", GST_TYPE_FRACTION, framerate, 1,
                                                "width", G_TYPE_INT, width,
                                                "height", G_TYPE_INT, height,
                                                NULL);
                source->video_info.width = width;
                source->video_info.height = height;
                break;
+       }
        default:
                LOG_ERROR_IF_REACHED("type(%d)", source->type);
                break;
@@ -322,15 +324,18 @@ static GstCaps *__make_video_raw_caps_with_framerate(webrtc_gst_slot_s *source,
        switch (source->type) {
        case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA:
        case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST:
-       case WEBRTC_MEDIA_SOURCE_TYPE_SCREEN:
+       case WEBRTC_MEDIA_SOURCE_TYPE_SCREEN: {
+               int width = source->video_info.width > 0 ? source->video_info.width : ini_source->v_width;
+               int height = source->video_info.height > 0 ? source->video_info.height : ini_source->v_height;
                caps = gst_caps_new_simple(MEDIA_TYPE_VIDEO_RAW,
                                                "format", G_TYPE_STRING, ini_source->v_raw_format,
                                                "framerate", GST_TYPE_FRACTION, framerate, 1,
-                                               "width", G_TYPE_INT, source->video_info.width,
-                                               "height", G_TYPE_INT, source->video_info.height,
+                                               "width", G_TYPE_INT, width,
+                                               "height", G_TYPE_INT, height,
                                                NULL);
                source->video_info.framerate = framerate;
                break;
+       }
        default:
                LOG_ERROR_IF_REACHED("type(%d)", source->type);
                break;
@@ -405,18 +410,19 @@ static GstCaps *__make_default_raw_caps(webrtc_gst_slot_s *source, webrtc_ini_s
        case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST:
        case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA:
        case WEBRTC_MEDIA_SOURCE_TYPE_SCREEN:
-       case WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_VIDEO:
+       case WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_VIDEO: {
+               source->video_info.framerate = source->video_info.framerate > 0 ? source->video_info.framerate : ini_source->v_framerate;
+               source->video_info.width = source->video_info.width > 0 ? source->video_info.width : ini_source->v_width;
+               source->video_info.height = source->video_info.height > 0 ? source->video_info.height : ini_source->v_height;
+
                caps = gst_caps_new_simple(MEDIA_TYPE_VIDEO_RAW,
                                                "format", G_TYPE_STRING, ini_source->v_raw_format,
-                                               "framerate", GST_TYPE_FRACTION, ini_source->v_framerate, 1,
-                                               "width", G_TYPE_INT, ini_source->v_width,
-                                               "height", G_TYPE_INT, ini_source->v_height,
+                                               "framerate", GST_TYPE_FRACTION, source->video_info.framerate, 1,
+                                               "width", G_TYPE_INT, source->video_info.width,
+                                               "height", G_TYPE_INT, source->video_info.height,
                                                NULL);
-               source->video_info.width = ini_source->v_width;
-               source->video_info.height = ini_source->v_height;
-               source->video_info.framerate = ini_source->v_framerate;
                break;
-
+       }
        case WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST:
        case WEBRTC_MEDIA_SOURCE_TYPE_MIC:
        case WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_AUDIO:
@@ -511,11 +517,12 @@ static GstCaps *__make_default_encoded_caps(webrtc_gst_slot_s *source, webrtc_in
        case WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_VIDEO:
                _media_type = __get_video_media_type(ini_source->v_codec);
                RET_VAL_IF(_media_type == NULL, NULL, "_media_type is NULL");
-               caps = __get_caps_from_encoded_video_media_type(_media_type, ini_source->v_width, ini_source->v_height);
 
-               source->video_info.width = ini_source->v_width;
-               source->video_info.height = ini_source->v_height;
-               source->video_info.framerate = ini_source->v_framerate;
+               source->video_info.width = source->video_info.width > 0 ? source->video_info.width : ini_source->v_width;
+               source->video_info.height = source->video_info.height > 0 ? source->video_info.height : ini_source->v_height;
+               source->video_info.framerate = source->video_info.framerate > 0 ? source->video_info.framerate : ini_source->v_framerate;
+
+               caps = __get_caps_from_encoded_video_media_type(_media_type, source->video_info.width, source->video_info.height);
                break;
 
        case WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST:
@@ -2903,17 +2910,21 @@ int _set_video_resolution(webrtc_s *webrtc, unsigned int source_id, int width, i
                RET_VAL_IF(!ini_source->v_drc_support, WEBRTC_ERROR_INVALID_OPERATION, "not supported dynamic resolution change");
        }
 
-       capsfilter = __find_element_in_bin(source->bin, ELEMENT_NAME_FIRST_CAPSFILTER);
-       RET_VAL_IF(capsfilter == NULL, WEBRTC_ERROR_INVALID_OPERATION, "could not find the first capsfilter");
+       if ((capsfilter = __find_element_in_bin(source->bin, ELEMENT_NAME_FIRST_CAPSFILTER))) {
+               /* FIXME: check if the [width x height] is supported or not */
+               if (!(new_caps = __make_video_raw_caps_with_resolution(source, &webrtc->ini, width, height)))
+                       return WEBRTC_ERROR_INVALID_OPERATION;
+               PRINT_CAPS(new_caps, "capsfilter");
 
-       /* FIXME: check if the [width x height] is supported or not */
-       if (!(new_caps = __make_video_raw_caps_with_resolution(source, &webrtc->ini, width, height)))
-               return WEBRTC_ERROR_INVALID_OPERATION;
+               g_object_set(G_OBJECT(capsfilter), "caps", new_caps, NULL);
+               gst_caps_unref(new_caps);
 
-       PRINT_CAPS(new_caps, "capsfilter");
+       } else {
+               source->video_info.width = width;
+               source->video_info.height = height;
+       }
 
-       g_object_set(G_OBJECT(capsfilter), "caps", new_caps, NULL);
-       gst_caps_unref(new_caps);
+       LOG_INFO("webrtc[%p], source_id[%u], [%dx%d]", webrtc, source_id, width, height);
 
        return WEBRTC_ERROR_NONE;
 }
@@ -2943,7 +2954,6 @@ int _set_video_framerate(webrtc_s *webrtc, unsigned int source_id, int framerate
        webrtc_gst_slot_s *source;
        GstElement *capsfilter;
        GstCaps *new_caps = NULL;
-       gchar *caps_str;
 
        RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
        RET_VAL_IF((source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "could not find source");
@@ -2955,18 +2965,19 @@ int _set_video_framerate(webrtc_s *webrtc, unsigned int source_id, int framerate
        RET_VAL_IF(webrtc->state != WEBRTC_STATE_IDLE, WEBRTC_ERROR_INVALID_OPERATION, "for now, it is only supported in IDLE state");
 
        /* FIXME: check if the framerate is supported or not */
-       capsfilter = __find_element_in_bin(source->bin, ELEMENT_NAME_FIRST_CAPSFILTER);
-       RET_VAL_IF(capsfilter == NULL, WEBRTC_ERROR_INVALID_OPERATION, "could not find the first capsfilter");
+       if ((capsfilter = __find_element_in_bin(source->bin, ELEMENT_NAME_FIRST_CAPSFILTER))) {
+               if (!(new_caps = __make_video_raw_caps_with_framerate(source, &webrtc->ini, framerate)))
+                       return WEBRTC_ERROR_INVALID_OPERATION;
+               PRINT_CAPS(new_caps, "capsfilter");
 
-       if (!(new_caps = __make_video_raw_caps_with_framerate(source, &webrtc->ini, framerate)))
-               return WEBRTC_ERROR_INVALID_OPERATION;
+               g_object_set(G_OBJECT(capsfilter), "caps", new_caps, NULL);
+               gst_caps_unref(new_caps);
 
-       caps_str = gst_caps_to_string(new_caps);
-       LOG_INFO("capsfilter caps[%s]", caps_str);
-       g_free(caps_str);
+       } else {
+               source->video_info.framerate = framerate;
+       }
 
-       g_object_set(G_OBJECT(capsfilter), "caps", new_caps, NULL);
-       gst_caps_unref(new_caps);
+       LOG_INFO("webrtc[%p], source_id[%u], framerate[%d]", webrtc, source_id, framerate);
 
        return WEBRTC_ERROR_NONE;
 }