Skip to content

Commit

Permalink
linux-pipewire: Pass framerate and resolution at construction
Browse files Browse the repository at this point in the history
This allows the stream negotiation to set the camera values right
from the start.
  • Loading branch information
GeorgesStavracas committed Jan 11, 2024
1 parent bc02779 commit 0335896
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
29 changes: 28 additions & 1 deletion plugins/linux-pipewire/camera-portal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/* ------------------------------------------------- */
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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);

Expand Down
12 changes: 10 additions & 2 deletions plugins/linux-pipewire/pipewire.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions plugins/linux-pipewire/pipewire.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down

0 comments on commit 0335896

Please sign in to comment.