webrtc_source: Fix problems fail to get default video resolution and framerate after... 85/276585/5
authorhj kim <backto.kim@samsung.com>
Tue, 21 Jun 2022 08:46:57 +0000 (17:46 +0900)
committerhj kim <backto.kim@samsung.com>
Mon, 27 Jun 2022 03:37:31 +0000 (12:37 +0900)
[Version] 0.3.134
[Issue Type] Bug fix

Change-Id: I42cc1604ab07c545fe54df848fc24d855a5e511a

packaging/capi-media-webrtc.spec
src/webrtc_source.c

index ca1cdd336576ce0ce9b8f202d6e4637c8cb87816..cfe4408583876d815430fc626e8b451bf86b7a6e 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.3.133
+Version:    0.3.134
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 8b7455364e8b51edf1d930de1fa730a10a898b24..9a7eb58e52ae8d653bb1e7cbef83733b4854dee8 100644 (file)
@@ -305,15 +305,12 @@ static GstCaps *__make_video_raw_caps_with_resolution(webrtc_gst_slot_s *source,
        case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST:
        case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA:
        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, framerate, 1,
+                                               "framerate", GST_TYPE_FRACTION, source->video_info.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:
@@ -340,15 +337,12 @@ static GstCaps *__make_video_raw_caps_with_framerate(webrtc_gst_slot_s *source,
        case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA:
        case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST:
        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, width,
-                                               "height", G_TYPE_INT, height,
+                                               "width", G_TYPE_INT, source->video_info.width,
+                                               "height", G_TYPE_INT, source->video_info.height,
                                                NULL);
-               source->video_info.framerate = framerate;
                break;
        }
        default:
@@ -426,10 +420,6 @@ static GstCaps *__make_default_raw_caps(webrtc_gst_slot_s *source, webrtc_ini_s
        case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA:
        case WEBRTC_MEDIA_SOURCE_TYPE_SCREEN:
        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, source->video_info.framerate, 1,
@@ -537,11 +527,6 @@ 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(source->av[AV_IDX_VIDEO].codec);
                RET_VAL_IF(_media_type == NULL, NULL, "_media_type is NULL");
-
-               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;
 
@@ -1354,6 +1339,18 @@ static GstElement *__find_element_in_bin(GstBin *bin, const gchar *name)
        return NULL;
 }
 
+static bool __set_default_video_info(webrtc_gst_slot_s *source, const ini_item_media_source_s *ini_source)
+{
+       RET_VAL_IF(source == NULL, false, "source is NULL");
+       RET_VAL_IF(ini_source == NULL, false, "ini_source is NULL");
+
+       source->video_info.framerate = ini_source->v_framerate;
+       source->video_info.width = ini_source->v_width;
+       source->video_info.height = ini_source->v_height;
+
+       return true;
+}
+
 static int __build_screensrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
 {
        int ret;
@@ -1380,6 +1377,9 @@ static int __build_screensrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
        source->av[AV_IDX_VIDEO].raw_format = g_strdup(ini_source->v_raw_format);
        source->av[AV_IDX_VIDEO].codec = ini_source->v_codecs[0];
 
+       if (!__set_default_video_info(source, ini_source))
+               return WEBRTC_ERROR_INVALID_OPERATION;
+
        if (!(screensrc = _create_element(__get_source_element(webrtc, WEBRTC_MEDIA_SOURCE_TYPE_SCREEN), ELEMENT_NAME_SCREENSRC)))
                return WEBRTC_ERROR_INVALID_OPERATION;
        APPEND_ELEMENT(switch_src_list, screensrc);
@@ -1609,6 +1609,9 @@ static int __build_camerasrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
        source->av[AV_IDX_VIDEO].raw_format = g_strdup(ini_source->v_raw_format);
        source->av[AV_IDX_VIDEO].codec = ini_source->v_codecs[0];
 
+       if (!__set_default_video_info(source, ini_source))
+               return WEBRTC_ERROR_INVALID_OPERATION;
+
 #ifndef TIZEN_TV
        if (webrtc->ini.resource_acquisition.camera)
                webrtc->resource.need_to_acquire[MM_RESOURCE_MANAGER_RES_TYPE_CAMERA] = true;
@@ -1797,6 +1800,9 @@ static int __build_videotestsrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
        source->av[AV_IDX_VIDEO].raw_format = g_strdup(ini_source->v_raw_format);
        source->av[AV_IDX_VIDEO].codec = ini_source->v_codecs[0];
 
+       if (!__set_default_video_info(source, ini_source))
+               return WEBRTC_ERROR_INVALID_OPERATION;
+
        if (!(videotestsrc = _create_element(__get_source_element(webrtc, WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST), ELEMENT_NAME_VIDEO_SRC)))
                return WEBRTC_ERROR_INVALID_OPERATION;
 
@@ -1834,6 +1840,9 @@ static int __build_custom_videosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
        source->zerocopy_enabled = __is_hw_encoder_used(webrtc, source->type, source->media_types);
        source->av[AV_IDX_VIDEO].codec = ini_source->v_codecs[0];
 
+       if (!__set_default_video_info(source, ini_source))
+               return WEBRTC_ERROR_INVALID_OPERATION;
+
        if (!(custom_videosrc = _create_element(__get_source_element(webrtc, WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_VIDEO), ELEMENT_NAME_VIDEO_SRC)))
                return WEBRTC_ERROR_INVALID_OPERATION;
 
@@ -3395,11 +3404,10 @@ int _set_video_resolution(webrtc_s *webrtc, unsigned int source_id, int width, i
 
        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");
-       RET_VAL_IF(source->type == WEBRTC_MEDIA_SOURCE_TYPE_NULL, WEBRTC_ERROR_INVALID_PARAMETER, "this API does not support the null source");
        RET_VAL_IF((source->media_types & MEDIA_TYPE_VIDEO) == 0x0, WEBRTC_ERROR_INVALID_PARAMETER, "it's not a video source");
        RET_VAL_IF((source->type == WEBRTC_MEDIA_SOURCE_TYPE_FILE), WEBRTC_ERROR_INVALID_PARAMETER, "this API does not support the file source");
        RET_VAL_IF((source->type == WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET), WEBRTC_ERROR_INVALID_PARAMETER, "this API does not support the media packet source");
-       RET_VAL_IF(source->type == WEBRTC_MEDIA_SOURCE_TYPE_NULL, WEBRTC_ERROR_INVALID_PARAMETER, "this API does not support the null source");
+       RET_VAL_IF((source->type == WEBRTC_MEDIA_SOURCE_TYPE_NULL), WEBRTC_ERROR_INVALID_PARAMETER, "this API does not support the null source");
 
        if (webrtc->state != WEBRTC_STATE_IDLE) {
                const ini_item_media_source_s *ini_source = _ini_get_source_by_type(&webrtc->ini, source->type);
@@ -3417,11 +3425,11 @@ int _set_video_resolution(webrtc_s *webrtc, unsigned int source_id, int width, i
                g_object_set(G_OBJECT(capsfilter), "caps", new_caps, NULL);
                gst_caps_unref(new_caps);
 
-       } else {
-               source->video_info.width = width;
-               source->video_info.height = height;
        }
 
+       source->video_info.width = width;
+       source->video_info.height = height;
+
        LOG_INFO("webrtc[%p], source_id[%u], [%dx%d]", webrtc, source_id, width, height);
 
        return WEBRTC_ERROR_NONE;
@@ -3435,11 +3443,10 @@ int _get_video_resolution(webrtc_s *webrtc, unsigned int source_id, int *width,
        RET_VAL_IF(width == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "width is NULL");
        RET_VAL_IF(height == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "height 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");
-       RET_VAL_IF(source->type == WEBRTC_MEDIA_SOURCE_TYPE_NULL, WEBRTC_ERROR_INVALID_PARAMETER, "this API does not support the null source");
        RET_VAL_IF((source->media_types & MEDIA_TYPE_VIDEO) == 0x0, WEBRTC_ERROR_INVALID_PARAMETER, "it's not a video source");
        RET_VAL_IF((source->type == WEBRTC_MEDIA_SOURCE_TYPE_FILE), WEBRTC_ERROR_INVALID_PARAMETER, "this API does not support the file source");
        RET_VAL_IF((source->type == WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET), WEBRTC_ERROR_INVALID_PARAMETER, "this API does not support the media packet source");
-       RET_VAL_IF(source->type == WEBRTC_MEDIA_SOURCE_TYPE_NULL, WEBRTC_ERROR_INVALID_PARAMETER, "this API does not support the null source");
+       RET_VAL_IF((source->type == WEBRTC_MEDIA_SOURCE_TYPE_NULL), WEBRTC_ERROR_INVALID_PARAMETER, "this API does not support the null source");
 
        *width = source->video_info.width;
        *height = source->video_info.height;
@@ -3457,11 +3464,10 @@ int _set_video_framerate(webrtc_s *webrtc, unsigned int source_id, int framerate
 
        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");
-       RET_VAL_IF(source->type == WEBRTC_MEDIA_SOURCE_TYPE_NULL, WEBRTC_ERROR_INVALID_PARAMETER, "this API does not support the null source");
        RET_VAL_IF((source->media_types & MEDIA_TYPE_VIDEO) == 0x0, WEBRTC_ERROR_INVALID_PARAMETER, "it's not a video source");
        RET_VAL_IF((source->type == WEBRTC_MEDIA_SOURCE_TYPE_FILE), WEBRTC_ERROR_INVALID_PARAMETER, "this API does not support the file source");
        RET_VAL_IF((source->type == WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET), WEBRTC_ERROR_INVALID_PARAMETER, "this API does not support the media packet source");
-       RET_VAL_IF(source->type == WEBRTC_MEDIA_SOURCE_TYPE_NULL, WEBRTC_ERROR_INVALID_PARAMETER, "this API does not support the null source");
+       RET_VAL_IF((source->type == WEBRTC_MEDIA_SOURCE_TYPE_NULL), WEBRTC_ERROR_INVALID_PARAMETER, "this API does not support the null source");
 
        /* TODO: framerate reconfiguration implementation, until then it will return error. */
        RET_VAL_IF(webrtc->state != WEBRTC_STATE_IDLE, WEBRTC_ERROR_INVALID_OPERATION, "for now, it is only supported in IDLE state");
@@ -3475,10 +3481,10 @@ int _set_video_framerate(webrtc_s *webrtc, unsigned int source_id, int framerate
                g_object_set(G_OBJECT(capsfilter), "caps", new_caps, NULL);
                gst_caps_unref(new_caps);
 
-       } else {
-               source->video_info.framerate = framerate;
        }
 
+       source->video_info.framerate = framerate;
+
        LOG_INFO("webrtc[%p], source_id[%u], framerate[%d]", webrtc, source_id, framerate);
 
        return WEBRTC_ERROR_NONE;
@@ -3491,11 +3497,10 @@ int _get_video_framerate(webrtc_s *webrtc, unsigned int source_id, int *framerat
        RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
        RET_VAL_IF(framerate == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "framerate 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");
-       RET_VAL_IF(source->type == WEBRTC_MEDIA_SOURCE_TYPE_NULL, WEBRTC_ERROR_INVALID_PARAMETER, "this API does not support the null source");
        RET_VAL_IF((source->media_types & MEDIA_TYPE_VIDEO) == 0x0, WEBRTC_ERROR_INVALID_PARAMETER, "it's not a video source");
        RET_VAL_IF((source->type == WEBRTC_MEDIA_SOURCE_TYPE_FILE), WEBRTC_ERROR_INVALID_PARAMETER, "this API does not support the file source");
        RET_VAL_IF((source->type == WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET), WEBRTC_ERROR_INVALID_PARAMETER, "this API does not support the media packet source");
-       RET_VAL_IF(source->type == WEBRTC_MEDIA_SOURCE_TYPE_NULL, WEBRTC_ERROR_INVALID_PARAMETER, "this API does not support the null source");
+       RET_VAL_IF((source->type == WEBRTC_MEDIA_SOURCE_TYPE_NULL), WEBRTC_ERROR_INVALID_PARAMETER, "this API does not support the null source");
 
        *framerate = source->video_info.framerate;