Skip to content

Commit 3cce28a

Browse files
tytan652RytoEX
authored andcommitted
linux-pipewire: Add framerates to video capture format name
1 parent c11253b commit 3cce28a

1 file changed

Lines changed: 55 additions & 1 deletion

File tree

plugins/linux-pipewire/camera-portal.c

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,13 @@ static void camera_format_list(struct camera_device *dev, obs_property_t *prop)
296296
const char *format_name;
297297
struct spa_rectangle resolution;
298298

299+
const struct spa_pod_prop *framerate_prop = NULL;
300+
struct spa_pod *framerate_pod;
301+
uint32_t n_framerates;
302+
enum spa_choice_type framerate_choice;
303+
const struct spa_fraction *framerate_values;
304+
g_autoptr(GArray) framerates = NULL;
305+
299306
if (p->id != SPA_PARAM_EnumFormat || p->param == NULL)
300307
continue;
301308

@@ -333,7 +340,54 @@ static void camera_format_list(struct camera_device *dev, obs_property_t *prop)
333340
obs_data_set_int(data, "width", resolution.width);
334341
obs_data_set_int(data, "height", resolution.height);
335342

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

0 commit comments

Comments
 (0)