backend-pipewire: support frame rate configuration

Signed-off-by: Elliot Chen <elliot.chen@nxp.com>
This commit is contained in:
Elliot Chen 2025-09-11 12:19:00 +09:00 committed by Marius Vlad
parent 1a68480421
commit b268b3827c
3 changed files with 18 additions and 13 deletions

View file

@ -1831,7 +1831,7 @@ wet_config_head_has_mirror_of_entry(struct wet_compositor *wet, char *head_name)
static void
parse_simple_mode(struct weston_output *output,
struct weston_config_section *section, int *width,
int *height, struct wet_output_config *defaults,
int *height, int *framerate, struct wet_output_config *defaults,
struct wet_output_config *parsed_options)
{
*width = defaults->width;
@ -1841,11 +1841,12 @@ parse_simple_mode(struct weston_output *output,
char *mode;
weston_config_section_get_string(section, "mode", &mode, NULL);
if (!mode || sscanf(mode, "%dx%d", width, height) != 2) {
if (!mode || sscanf(mode, "%dx%d@%d", width, height, framerate) < 2) {
weston_log("Invalid mode for output %s. Using defaults.\n",
output->name);
*width = defaults->width;
*height = defaults->height;
*framerate = -1;
}
free(mode);
}
@ -1871,6 +1872,7 @@ wet_configure_windowed_output_from_config(struct weston_output *output,
struct wet_output_config *parsed_options = compositor->parsed_options;
int width;
int height;
int framerate = -1;
assert(parsed_options);
@ -1881,7 +1883,7 @@ wet_configure_windowed_output_from_config(struct weston_output *output,
section = weston_config_get_section(wc, "output", "name", output->name);
parse_simple_mode(output, section, &width, &height, defaults,
parse_simple_mode(output, section, &width, &height, &framerate, defaults,
parsed_options);
allow_content_protection(output, section);
@ -3612,6 +3614,7 @@ pipewire_backend_output_configure(struct weston_output *output)
char *gbm_format = NULL;
int width;
int height;
int framerate = -1;
assert(parsed_options);
@ -3622,7 +3625,7 @@ pipewire_backend_output_configure(struct weston_output *output)
section = weston_config_get_section(wc, "output", "name", output->name);
parse_simple_mode(output, section, &width, &height, &defaults,
parse_simple_mode(output, section, &width, &height, &framerate, &defaults,
parsed_options);
weston_config_section_get_string(section, "gbm-format", &gbm_format, NULL);
@ -3633,7 +3636,7 @@ pipewire_backend_output_configure(struct weston_output *output)
api->set_gbm_format(output, gbm_format);
free(gbm_format);
if (api->output_set_size(output, width, height) < 0) {
if (api->output_set_size(output, width, height, framerate) < 0) {
weston_log("Cannot configure output \"%s\" using weston_pipewire_output_api.\n",
output->name);
return -1;
@ -3848,6 +3851,7 @@ vnc_backend_output_configure(struct weston_output *output)
struct weston_config_section *section;
int width;
int height;
int framerate = -1;
bool resizeable;
assert(parsed_options);
@ -3859,7 +3863,7 @@ vnc_backend_output_configure(struct weston_output *output)
section = weston_config_get_section(wc, "output", "name", output->name);
parse_simple_mode(output, section, &width, &height, &defaults,
parse_simple_mode(output, section, &width, &height, &framerate, &defaults,
compositor->parsed_options);
weston_config_section_get_bool(section, "resizeable", &resizeable, true);

View file

@ -54,19 +54,20 @@ struct weston_pipewire_output_api {
const char *name,
const struct pipewire_config *config);
/** Set the size of a PipeWire output to the specified width and height.
/** Set the size and frame rate of a PipeWire output to the specified value.
*
* If the width or height are set to -1, the size of the underlying
* PipeWire head will be used.
* If the width or height or framerate are set to -1, the size or frame rate
* of the underlying PipeWire head will be used.
*
* \param output The weston output for which the size shall be set
* \param width Desired width of the output
* \param height Desired height of the output
* \param framerate Desired frame rate of the output
*
* Returns 0 on success, -1 on failure.
*/
int (*output_set_size)(struct weston_output *output,
int width, int height);
int width, int height, int framerate);
/** The pixel format to be used by the output.
*

View file

@ -1174,14 +1174,13 @@ pipewire_switch_mode(struct weston_output *base, struct weston_mode *target_mode
}
static int
pipewire_output_set_size(struct weston_output *base, int width, int height)
pipewire_output_set_size(struct weston_output *base, int width, int height, int framerate)
{
struct pipewire_output *output = to_pipewire_output(base);
struct weston_head *head;
struct pipewire_head *pw_head;
struct weston_mode *current_mode;
struct weston_mode init_mode;
int framerate = -1;
/* We can only be called once. */
assert(!output->base.current_mode);
@ -1193,7 +1192,8 @@ pipewire_output_set_size(struct weston_output *base, int width, int height)
width = pw_head->config.width;
if (height == -1)
height = pw_head->config.height;
framerate = pw_head->config.framerate;
if (framerate == -1)
framerate = pw_head->config.framerate;
}
if (framerate == -1 || width == -1 || height == -1)
return -1;