Skip to content

Commit 9ae7734

Browse files
committed
linux-pipewire: Add framerates to video capture format name
1 parent d8961dc commit 9ae7734

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

plugins/linux-pipewire/camera-portal.c

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ static void camera_format_list(struct camera_device *dev, obs_property_t *prop)
295295
uint32_t format = 0;
296296
const char *format_name;
297297
struct spa_rectangle resolution;
298+
const struct spa_pod_prop *framerate_prop = NULL;
299+
struct spa_pod *framerate_pod;
300+
uint32_t n_framerates;
301+
enum spa_choice_type framerate_choice;
302+
const struct spa_fraction *framerate_values;
303+
g_autoptr(GArray) framerates = NULL;
298304

299305
if (p->id != SPA_PARAM_EnumFormat || p->param == NULL)
300306
continue;
@@ -333,7 +339,54 @@ static void camera_format_list(struct camera_device *dev, obs_property_t *prop)
333339
obs_data_set_int(data, "width", resolution.width);
334340
obs_data_set_int(data, "height", resolution.height);
335341

336-
dstr_printf(&str, "%ux%u - %s", resolution.width, resolution.height, format_name);
342+
framerate_prop = spa_pod_find_prop(p->param, NULL, SPA_FORMAT_VIDEO_framerate);
343+
if (!framerate_prop)
344+
continue;
345+
346+
framerate_pod = spa_pod_get_values(&framerate_prop->value, &n_framerates, &framerate_choice);
347+
if (framerate_pod->type != SPA_TYPE_Fraction) {
348+
blog(LOG_WARNING, "Framerate is not a fraction - something is wrong");
349+
continue;
350+
}
351+
352+
framerate_values = SPA_POD_BODY(framerate_pod);
353+
framerates = g_array_new(FALSE, FALSE, sizeof(struct spa_fraction));
354+
355+
switch (framerate_choice) {
356+
case SPA_CHOICE_None:
357+
g_array_append_val(framerates, framerate_values[0]);
358+
break;
359+
case SPA_CHOICE_Range:
360+
blog(LOG_WARNING, "Ranged framerates not supported");
361+
continue;
362+
case SPA_CHOICE_Step:
363+
blog(LOG_WARNING, "Stepped framerates not supported");
364+
continue;
365+
case SPA_CHOICE_Enum:
366+
/* i=0 is the default framerate, skip it */
367+
for (uint32_t i = 1; i < n_framerates; i++)
368+
g_array_append_val(framerates, framerate_values[i]);
369+
break;
370+
default:
371+
continue;
372+
}
373+
374+
dstr_printf(&str, "%ux%u - ", resolution.width, resolution.height);
375+
376+
for (size_t i = 0; i < framerates->len; i++) {
377+
const struct spa_fraction *framerate = &g_array_index(framerates, struct spa_fraction, i);
378+
379+
if (i != 0)
380+
dstr_cat(&str, ", ");
381+
382+
if (framerate->denom == 1)
383+
dstr_catf(&str, "%u", framerate->num);
384+
else
385+
dstr_catf(&str, "%.2f", framerate->num / (double)framerate->denom);
386+
}
387+
388+
dstr_catf(&str, " fps - %s", format_name);
389+
337390
obs_property_list_add_string(prop, str.array, obs_data_get_json(data));
338391
dstr_free(&str);
339392
}

0 commit comments

Comments
 (0)