Remove video_alignment_padding variable, replace with putting capture content in the center with frame resolution and capture resolution diff

This commit is contained in:
dec05eba
2024-06-10 18:41:05 +02:00
parent adbd5d9766
commit e43934e2d2
4 changed files with 10 additions and 11 deletions

View File

@@ -42,7 +42,6 @@ struct gsr_capture_base {
gsr_color_conversion color_conversion; gsr_color_conversion color_conversion;
AVCodecContext *video_codec_context; AVCodecContext *video_codec_context;
vec2i video_alignment_padding;
}; };
typedef struct { typedef struct {

View File

@@ -39,7 +39,6 @@ struct gsr_capture_kms {
AVContentLightMetadata *light_metadata; AVContentLightMetadata *light_metadata;
gsr_monitor_rotation monitor_rotation; gsr_monitor_rotation monitor_rotation;
vec2i video_alignment_padding;
}; };
/* Returns 0 on success */ /* Returns 0 on success */

View File

@@ -10,6 +10,10 @@
#define HDMI_STATIC_METADATA_TYPE1 0 #define HDMI_STATIC_METADATA_TYPE1 0
#define HDMI_EOTF_SMPTE_ST2084 2 #define HDMI_EOTF_SMPTE_ST2084 2
static int max_int(int a, int b) {
return a > b ? a : b;
}
/* TODO: On monitor reconfiguration, find monitor x, y, width and height again. Do the same for nvfbc. */ /* TODO: On monitor reconfiguration, find monitor x, y, width and height again. Do the same for nvfbc. */
typedef struct { typedef struct {
@@ -82,9 +86,6 @@ int gsr_capture_kms_start(gsr_capture_kms *self, const char *display_to_capture,
self->base.video_codec_context->height = FFALIGN(self->capture_size.y, 2); self->base.video_codec_context->height = FFALIGN(self->capture_size.y, 2);
} }
self->base.video_alignment_padding.x = self->base.video_codec_context->width - self->capture_size.x;
self->base.video_alignment_padding.y = self->base.video_codec_context->height - self->capture_size.y;
frame->width = self->base.video_codec_context->width; frame->width = self->base.video_codec_context->width;
frame->height = self->base.video_codec_context->height; frame->height = self->base.video_codec_context->height;
return 0; return 0;
@@ -300,8 +301,11 @@ bool gsr_capture_kms_capture(gsr_capture_kms *self, AVFrame *frame, bool hdr, bo
const float texture_rotation = monitor_rotation_to_radians(self->monitor_rotation); const float texture_rotation = monitor_rotation_to_radians(self->monitor_rotation);
const int target_x = max_int(0, frame->width / 2 - self->capture_size.x / 2);
const int target_y = max_int(0, frame->height / 2 - self->capture_size.y / 2);
gsr_color_conversion_draw(&self->base.color_conversion, self->base.input_texture, gsr_color_conversion_draw(&self->base.color_conversion, self->base.input_texture,
(vec2i){self->base.video_alignment_padding.x / 2, self->base.video_alignment_padding.y / 2}, self->capture_size, (vec2i){target_x, target_y}, self->capture_size,
capture_pos, self->capture_size, capture_pos, self->capture_size,
texture_rotation, false); texture_rotation, false);
@@ -332,8 +336,8 @@ bool gsr_capture_kms_capture(gsr_capture_kms *self, AVFrame *frame, bool hdr, bo
break; break;
} }
cursor_pos.x += (self->base.video_alignment_padding.x / 2); cursor_pos.x += target_x;
cursor_pos.y += (self->base.video_alignment_padding.y / 2); cursor_pos.y += target_y;
const intptr_t img_attr_cursor[] = { const intptr_t img_attr_cursor[] = {
EGL_LINUX_DRM_FOURCC_EXT, cursor_drm_fd->pixel_format, EGL_LINUX_DRM_FOURCC_EXT, cursor_drm_fd->pixel_format,

View File

@@ -112,9 +112,6 @@ int gsr_capture_xcomposite_start(gsr_capture_xcomposite *self, AVCodecContext *v
video_codec_context->height = FFALIGN(video_size.y, 2); video_codec_context->height = FFALIGN(video_size.y, 2);
} }
self->base.video_alignment_padding.x = self->base.video_codec_context->width - video_size.x;
self->base.video_alignment_padding.y = self->base.video_codec_context->height - video_size.y;
frame->width = video_codec_context->width; frame->width = video_codec_context->width;
frame->height = video_codec_context->height; frame->height = video_codec_context->height;