#define DEFAULT_ELEMENT_VIDEOTESTSRC "videotestsrc"
#define DEFAULT_ELEMENT_AUDIOTESTSRC "audiotestsrc"
#define DEFAULT_ELEMENT_APPSRC "appsrc"
+#define DEFAULT_ELEMENT_SCREENSRC "waylandsrc"
+#define DEFAULT_ELEMENT_VIDEOCONVERT "videoconvert"
#define DEFAULT_ELEMENT_CAPSFILTER "capsfilter"
#define DEFAULT_ELEMENT_QUEUE "queue"
switch (source->type) {
case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA:
case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST:
+ case WEBRTC_MEDIA_SOURCE_TYPE_SCREEN:
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,
switch (source->type) {
case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA:
case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST:
+ case WEBRTC_MEDIA_SOURCE_TYPE_SCREEN:
_media_type = __get_video_media_type(ini_source->v_codec);
RET_VAL_IF(_media_type == NULL, NULL, "_media_type is NULL");
element = DEFAULT_ELEMENT_VIDEOTESTSRC;
else if (type == WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET)
element = DEFAULT_ELEMENT_APPSRC;
+ else if (type == WEBRTC_MEDIA_SOURCE_TYPE_SCREEN)
+ element = DEFAULT_ELEMENT_SCREENSRC;
else
LOG_ERROR_IF_REACHED("type(%d)", type);
return source->source_element;
}
+static int __create_elements_for_screensrc(webrtc_s *webrtc, webrtc_gst_slot_s *source,
+ GstElement **screensrc, GstElement **capsfilter, GstElement **videoconvert)
+{
+ GstCaps *caps = NULL;
+ gchar *caps_str = NULL;
+ ini_item_media_source_s *ini_source = NULL;
+
+ RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
+ RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
+ RET_VAL_IF(screensrc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "screensrc is NULL");
+ RET_VAL_IF(capsfilter == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "capsfilter is NULL");
+ RET_VAL_IF(videoconvert == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "videoconvert is NULL");
+
+ if (!(*screensrc = _create_element(__get_source_element(webrtc, WEBRTC_MEDIA_SOURCE_TYPE_SCREEN), NULL))) {
+ LOG_ERROR("failed to create screensrc");
+ return WEBRTC_ERROR_INVALID_OPERATION;
+ }
+
+ if (!(*videoconvert = _create_element(DEFAULT_ELEMENT_VIDEOCONVERT, NULL))) {
+ LOG_ERROR("failed to create videoconvert");
+ return WEBRTC_ERROR_INVALID_OPERATION;
+ }
+
+ if (!(*capsfilter = _create_element(DEFAULT_ELEMENT_CAPSFILTER, NULL))) {
+ LOG_ERROR("failed to create capsfilter");
+ return WEBRTC_ERROR_INVALID_OPERATION;
+ }
+
+ ini_source = _ini_get_source_by_type(&webrtc->ini, source->type);
+ if (ini_source == NULL)
+ ini_source = &webrtc->ini.media_source;
+
+ caps = gst_caps_new_simple(MEDIA_TYPE_VIDEO_RAW,
+ "format", G_TYPE_STRING, "BGRA",
+ "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,
+ NULL);
+ caps_str = gst_caps_to_string(caps);
+ LOG_INFO("capsfilter caps[%s] for screensrc", caps_str);
+ g_free(caps_str);
+
+ g_object_set(G_OBJECT(*capsfilter), "caps", caps, NULL);
+ gst_caps_unref(caps);
+
+ return WEBRTC_ERROR_NONE;
+}
+
+static int __build_screensrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
+{
+ int ret = WEBRTC_ERROR_NONE;
+ GstElement *screensrc = NULL;
+ GstElement *capsfilter1 = NULL;
+ GstElement *videoconvert = NULL;
+ GstElement *capsfilter2 = NULL;
+ GstElement *videoenc = NULL;
+ GstElement *videopay = NULL;
+ GstElement *queue = NULL;
+ GstElement *capsfilter3 = NULL;
+
+ RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
+ RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
+ RET_VAL_IF(source->src_pad == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "src_pad is NULL");
+ RET_VAL_IF(source->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL");
+
+ source->media_types = MEDIA_TYPE_VIDEO;
+
+ if ((ret = __create_elements_for_screensrc(webrtc, source, &screensrc, &capsfilter1, &videoconvert)) != WEBRTC_ERROR_NONE)
+ goto exit;
+
+ if ((ret = __create_rest_of_elements(webrtc, source, &capsfilter2, &videoenc, &videopay, &queue, &capsfilter3)) != WEBRTC_ERROR_NONE)
+ goto exit;
+
+ gst_bin_add_many(source->bin, screensrc, capsfilter1, videoconvert, capsfilter2, videoenc, videopay, queue, capsfilter3, NULL);
+ if (!gst_element_link_many(screensrc, capsfilter1, videoconvert, capsfilter2, videoenc, videopay, queue, capsfilter3, NULL)) {
+ LOG_ERROR("failed to gst_element_link_many()");
+ goto exit_with_remove_from_bin;
+ }
+
+ ret = _set_ghost_pad_target(source->src_pad, capsfilter3, true);
+ if (ret != WEBRTC_ERROR_NONE)
+ goto exit_with_remove_from_bin;
+
+ return WEBRTC_ERROR_NONE;
+
+exit_with_remove_from_bin:
+ gst_bin_remove_many(source->bin, screensrc, capsfilter1, videoconvert, capsfilter2, videoenc, videopay, queue, capsfilter3, NULL);
+
+ return WEBRTC_ERROR_INVALID_OPERATION;
+
+exit:
+ SAFE_GST_OBJECT_UNREF(screensrc);
+ SAFE_GST_OBJECT_UNREF(capsfilter1);
+ SAFE_GST_OBJECT_UNREF(videoconvert);
+ SAFE_GST_OBJECT_UNREF(capsfilter2);
+ SAFE_GST_OBJECT_UNREF(videoenc);
+ SAFE_GST_OBJECT_UNREF(videopay);
+ SAFE_GST_OBJECT_UNREF(queue);
+ SAFE_GST_OBJECT_UNREF(capsfilter3);
+
+ return ret;
+}
+
static int __build_camerasrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
{
int ret = WEBRTC_ERROR_NONE;
case WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET:
return __build_mediapacketsrc(webrtc, source);
+ case WEBRTC_MEDIA_SOURCE_TYPE_SCREEN:
+ return __build_screensrc(webrtc, source);
+
default:
LOG_ERROR_IF_REACHED("type(%d)", source->type);
return WEBRTC_ERROR_INVALID_PARAMETER;
RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
RET_VAL_IF(webrtc->gst.source_slots == NULL, WEBRTC_ERROR_INVALID_OPERATION, "source_slots is NULL");
RET_VAL_IF(source_id == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is NULL");
- RET_VAL_IF(type > WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET, WEBRTC_ERROR_INVALID_PARAMETER, "invalid source type(%d)", type);
+ RET_VAL_IF(type > WEBRTC_MEDIA_SOURCE_TYPE_SCREEN, WEBRTC_ERROR_INVALID_PARAMETER, "invalid source type(%d)", type);
/* bin_name/source will be freed by function which is set to g_hash_table_new_full() */
id = __get_unoccupied_id(webrtc->gst.source_slots);