فهرست منبع

linux-pipewire: Pass framerate and resolution at construction

This allows the stream negotiation to set the camera values right
from the start.
Georges Basile Stavracas Neto 1 سال پیش
والد
کامیت
03358961aa
3فایلهای تغییر یافته به همراه42 افزوده شده و 3 حذف شده
  1. 28 1
      plugins/linux-pipewire/camera-portal.c
  2. 10 2
      plugins/linux-pipewire/pipewire.c
  3. 4 0
      plugins/linux-pipewire/pipewire.h

+ 28 - 1
plugins/linux-pipewire/camera-portal.c

@@ -43,6 +43,16 @@ struct camera_portal_source {
 
 	obs_pipewire_stream *obs_pw_stream;
 	char *device_id;
+
+	struct {
+		struct spa_rectangle rect;
+		bool set;
+	} resolution;
+
+	struct {
+		struct spa_fraction fraction;
+		bool set;
+	} framerate;
 };
 
 /* ------------------------------------------------- */
@@ -259,6 +269,8 @@ static bool update_device_id(struct camera_portal_source *camera_source,
 static void stream_camera(struct camera_portal_source *camera_source)
 {
 	struct obs_pipwire_connect_stream_info connect_info;
+	const struct spa_rectangle *resolution = NULL;
+	const struct spa_fraction *framerate = NULL;
 	struct camera_device *device;
 
 	g_clear_pointer(&camera_source->obs_pw_stream,
@@ -273,12 +285,20 @@ static void stream_camera(struct camera_portal_source *camera_source)
 	blog(LOG_INFO, "[camera-portal] streaming camera '%s'",
 	     camera_source->device_id);
 
+	if (camera_source->resolution.set)
+		resolution = &camera_source->resolution.rect;
+	if (camera_source->framerate.set)
+		framerate = &camera_source->framerate.fraction;
+
 	connect_info = (struct obs_pipwire_connect_stream_info){
 		.stream_name = "OBS PipeWire Camera",
 		.stream_properties = pw_properties_new(
 			PW_KEY_MEDIA_TYPE, "Video", PW_KEY_MEDIA_CATEGORY,
 			"Capture", PW_KEY_MEDIA_ROLE, "Camera", NULL),
-	};
+		.video = {
+			.resolution = resolution,
+			.framerate = framerate,
+		}};
 
 	camera_source->obs_pw_stream = obs_pipewire_connect_stream(
 		connection->obs_pw, camera_source->source, device->id,
@@ -1239,11 +1259,18 @@ static const char *pipewire_camera_get_name(void *data)
 static void *pipewire_camera_create(obs_data_t *settings, obs_source_t *source)
 {
 	struct camera_portal_source *camera_source;
+	bool set;
 
 	camera_source = bzalloc(sizeof(struct camera_portal_source));
 	camera_source->source = source;
 	camera_source->device_id =
 		bstrdup(obs_data_get_string(settings, "device_id"));
+	camera_source->framerate.set =
+		parse_framerate(&camera_source->framerate.fraction,
+				obs_data_get_string(settings, "framerate"));
+	camera_source->resolution.set =
+		parse_resolution(&camera_source->resolution.rect,
+				 obs_data_get_string(settings, "resolution"));
 
 	access_camera(camera_source);
 

+ 10 - 2
plugins/linux-pipewire/pipewire.c

@@ -1215,8 +1215,16 @@ obs_pipewire_stream *obs_pipewire_connect_stream(
 	obs_pw_stream->obs_pw = obs_pw;
 	obs_pw_stream->source = source;
 	obs_pw_stream->cursor.visible = connect_info->screencast.cursor_visible;
-	obs_pw_stream->framerate.set = false;
-	obs_pw_stream->resolution.set = false;
+	obs_pw_stream->framerate.set = connect_info->video.framerate != NULL;
+	obs_pw_stream->resolution.set = connect_info->video.resolution != NULL;
+
+	if (obs_pw_stream->framerate.set)
+		obs_pw_stream->framerate.fraction =
+			*connect_info->video.framerate;
+
+	if (obs_pw_stream->resolution.set)
+		obs_pw_stream->resolution.rect =
+			*connect_info->video.resolution;
 
 	init_format_info(obs_pw_stream);
 

+ 4 - 0
plugins/linux-pipewire/pipewire.h

@@ -33,6 +33,10 @@ struct obs_pipwire_connect_stream_info {
 	struct {
 		bool cursor_visible;
 	} screencast;
+	struct {
+		const struct spa_rectangle *resolution;
+		const struct spa_fraction *framerate;
+	} video;
 };
 
 obs_pipewire *