Skip to content

Commit 0335896

Browse files
linux-pipewire: Pass framerate and resolution at construction
This allows the stream negotiation to set the camera values right from the start.
1 parent bc02779 commit 0335896

3 files changed

Lines changed: 42 additions & 3 deletions

File tree

plugins/linux-pipewire/camera-portal.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ struct camera_portal_source {
4343

4444
obs_pipewire_stream *obs_pw_stream;
4545
char *device_id;
46+
47+
struct {
48+
struct spa_rectangle rect;
49+
bool set;
50+
} resolution;
51+
52+
struct {
53+
struct spa_fraction fraction;
54+
bool set;
55+
} framerate;
4656
};
4757

4858
/* ------------------------------------------------- */
@@ -259,6 +269,8 @@ static bool update_device_id(struct camera_portal_source *camera_source,
259269
static void stream_camera(struct camera_portal_source *camera_source)
260270
{
261271
struct obs_pipwire_connect_stream_info connect_info;
272+
const struct spa_rectangle *resolution = NULL;
273+
const struct spa_fraction *framerate = NULL;
262274
struct camera_device *device;
263275

264276
g_clear_pointer(&camera_source->obs_pw_stream,
@@ -273,12 +285,20 @@ static void stream_camera(struct camera_portal_source *camera_source)
273285
blog(LOG_INFO, "[camera-portal] streaming camera '%s'",
274286
camera_source->device_id);
275287

288+
if (camera_source->resolution.set)
289+
resolution = &camera_source->resolution.rect;
290+
if (camera_source->framerate.set)
291+
framerate = &camera_source->framerate.fraction;
292+
276293
connect_info = (struct obs_pipwire_connect_stream_info){
277294
.stream_name = "OBS PipeWire Camera",
278295
.stream_properties = pw_properties_new(
279296
PW_KEY_MEDIA_TYPE, "Video", PW_KEY_MEDIA_CATEGORY,
280297
"Capture", PW_KEY_MEDIA_ROLE, "Camera", NULL),
281-
};
298+
.video = {
299+
.resolution = resolution,
300+
.framerate = framerate,
301+
}};
282302

283303
camera_source->obs_pw_stream = obs_pipewire_connect_stream(
284304
connection->obs_pw, camera_source->source, device->id,
@@ -1239,11 +1259,18 @@ static const char *pipewire_camera_get_name(void *data)
12391259
static void *pipewire_camera_create(obs_data_t *settings, obs_source_t *source)
12401260
{
12411261
struct camera_portal_source *camera_source;
1262+
bool set;
12421263

12431264
camera_source = bzalloc(sizeof(struct camera_portal_source));
12441265
camera_source->source = source;
12451266
camera_source->device_id =
12461267
bstrdup(obs_data_get_string(settings, "device_id"));
1268+
camera_source->framerate.set =
1269+
parse_framerate(&camera_source->framerate.fraction,
1270+
obs_data_get_string(settings, "framerate"));
1271+
camera_source->resolution.set =
1272+
parse_resolution(&camera_source->resolution.rect,
1273+
obs_data_get_string(settings, "resolution"));
12471274

12481275
access_camera(camera_source);
12491276

plugins/linux-pipewire/pipewire.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,8 +1215,16 @@ obs_pipewire_stream *obs_pipewire_connect_stream(
12151215
obs_pw_stream->obs_pw = obs_pw;
12161216
obs_pw_stream->source = source;
12171217
obs_pw_stream->cursor.visible = connect_info->screencast.cursor_visible;
1218-
obs_pw_stream->framerate.set = false;
1219-
obs_pw_stream->resolution.set = false;
1218+
obs_pw_stream->framerate.set = connect_info->video.framerate != NULL;
1219+
obs_pw_stream->resolution.set = connect_info->video.resolution != NULL;
1220+
1221+
if (obs_pw_stream->framerate.set)
1222+
obs_pw_stream->framerate.fraction =
1223+
*connect_info->video.framerate;
1224+
1225+
if (obs_pw_stream->resolution.set)
1226+
obs_pw_stream->resolution.rect =
1227+
*connect_info->video.resolution;
12201228

12211229
init_format_info(obs_pw_stream);
12221230

plugins/linux-pipewire/pipewire.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ struct obs_pipwire_connect_stream_info {
3333
struct {
3434
bool cursor_visible;
3535
} screencast;
36+
struct {
37+
const struct spa_rectangle *resolution;
38+
const struct spa_fraction *framerate;
39+
} video;
3640
};
3741

3842
obs_pipewire *

0 commit comments

Comments
 (0)