aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-07-05 11:34:34 +0200
committerdec05eba <dec05eba@protonmail.com>2024-07-05 11:34:34 +0200
commit56e9d15e0f9fb5c6ccaa9525dd7ec7a93659f6f7 (patch)
tree08bbb78f6964eb82f812f85e32af97fd22fc63ae
parent3400f4d5446357945fe5ce87eeb4dba472370a19 (diff)
Fix capture incorrect alignment with cpu encoding for some window sizes
-rw-r--r--src/capture/kms.c21
-rw-r--r--src/capture/nvfbc.c8
-rw-r--r--src/capture/xcomposite.c20
-rw-r--r--src/encoder/video/software.c10
-rw-r--r--src/encoder/video/vaapi.c16
5 files changed, 33 insertions, 42 deletions
diff --git a/src/capture/kms.c b/src/capture/kms.c
index 5b39805..2601c5b 100644
--- a/src/capture/kms.c
+++ b/src/capture/kms.c
@@ -152,25 +152,8 @@ static int gsr_capture_kms_start(gsr_capture *cap, AVCodecContext *video_codec_c
/* Disable vsync */
self->params.egl->eglSwapInterval(self->params.egl->egl_display, 0);
- // TODO: Move this and xcomposite equivalent to a common section unrelated to capture method
- if(self->params.egl->gpu_info.vendor == GSR_GPU_VENDOR_AMD && video_codec_context->codec_id == AV_CODEC_ID_HEVC) {
- // TODO: dont do this if using ffmpeg reports that this is not needed (AMD driver bug that was fixed recently)
- video_codec_context->width = FFALIGN(self->capture_size.x, 64);
- video_codec_context->height = FFALIGN(self->capture_size.y, 16);
- } else if(self->params.egl->gpu_info.vendor == GSR_GPU_VENDOR_AMD && video_codec_context->codec_id == AV_CODEC_ID_AV1) {
- // TODO: Dont do this for VCN 5 and forward which should fix this hardware bug
- video_codec_context->width = FFALIGN(self->capture_size.x, 64);
- // AMD driver has special case handling for 1080 height to set it to 1082 instead of 1088 (1080 aligned to 16).
- // TODO: Set height to 1082 in this case, but it wont work because it will be aligned to 1088.
- if(self->capture_size.y == 1080) {
- video_codec_context->height = 1080;
- } else {
- video_codec_context->height = FFALIGN(self->capture_size.y, 16);
- }
- } else {
- video_codec_context->width = FFALIGN(self->capture_size.x, 2);
- video_codec_context->height = FFALIGN(self->capture_size.y, 2);
- }
+ video_codec_context->width = FFALIGN(self->capture_size.x, 2);
+ video_codec_context->height = FFALIGN(self->capture_size.y, 2);
frame->width = video_codec_context->width;
frame->height = video_codec_context->height;
diff --git a/src/capture/nvfbc.c b/src/capture/nvfbc.c
index b619250..9c7a041 100644
--- a/src/capture/nvfbc.c
+++ b/src/capture/nvfbc.c
@@ -359,11 +359,11 @@ static int gsr_capture_nvfbc_start(gsr_capture *cap, AVCodecContext *video_codec
}
if(cap_nvfbc->capture_region) {
- video_codec_context->width = cap_nvfbc->width & ~1;
- video_codec_context->height = cap_nvfbc->height & ~1;
+ video_codec_context->width = FFALIGN(cap_nvfbc->width, 2);
+ video_codec_context->height = FFALIGN(cap_nvfbc->height, 2);
} else {
- video_codec_context->width = cap_nvfbc->tracking_width & ~1;
- video_codec_context->height = cap_nvfbc->tracking_height & ~1;
+ video_codec_context->width = FFALIGN(cap_nvfbc->tracking_width, 2);
+ video_codec_context->height = FFALIGN(cap_nvfbc->tracking_height, 2);
}
frame->width = video_codec_context->width;
diff --git a/src/capture/xcomposite.c b/src/capture/xcomposite.c
index eb49d15..4f89e11 100644
--- a/src/capture/xcomposite.c
+++ b/src/capture/xcomposite.c
@@ -168,24 +168,8 @@ static int gsr_capture_xcomposite_start(gsr_capture *cap, AVCodecContext *video_
if(self->params.region_size.x > 0 && self->params.region_size.y > 0)
video_size = self->params.region_size;
- if(self->params.egl->gpu_info.vendor == GSR_GPU_VENDOR_AMD && video_codec_context->codec_id == AV_CODEC_ID_HEVC) {
- // TODO: dont do this if using ffmpeg reports that this is not needed (AMD driver bug that was fixed recently)
- video_codec_context->width = FFALIGN(video_size.x, 64);
- video_codec_context->height = FFALIGN(video_size.y, 16);
- } else if(self->params.egl->gpu_info.vendor == GSR_GPU_VENDOR_AMD && video_codec_context->codec_id == AV_CODEC_ID_AV1) {
- // TODO: Dont do this for VCN 5 and forward which should fix this hardware bug
- video_codec_context->width = FFALIGN(video_size.x, 64);
- // AMD driver has special case handling for 1080 height to set it to 1082 instead of 1088 (1080 aligned to 16).
- // TODO: Set height to 1082 in this case, but it wont work because it will be aligned to 1088.
- if(video_size.y == 1080) {
- video_codec_context->height = 1080;
- } else {
- video_codec_context->height = FFALIGN(video_size.y, 16);
- }
- } else {
- video_codec_context->width = FFALIGN(video_size.x, 2);
- video_codec_context->height = FFALIGN(video_size.y, 2);
- }
+ video_codec_context->width = FFALIGN(video_size.x, 2);
+ video_codec_context->height = FFALIGN(video_size.y, 2);
frame->width = video_codec_context->width;
frame->height = video_codec_context->height;
diff --git a/src/encoder/video/software.c b/src/encoder/video/software.c
index c5fde4d..4666ffd 100644
--- a/src/encoder/video/software.c
+++ b/src/encoder/video/software.c
@@ -6,6 +6,8 @@
#include <stdlib.h>
+#define LINESIZE_ALIGNMENT 4
+
typedef struct {
gsr_video_encoder_software_params params;
@@ -28,7 +30,7 @@ static unsigned int gl_create_texture(gsr_egl *egl, int width, int height, int i
}
static bool gsr_video_encoder_software_setup_textures(gsr_video_encoder_software *self, AVCodecContext *video_codec_context, AVFrame *frame) {
- int res = av_frame_get_buffer(frame, 1); // TODO: Align?
+ int res = av_frame_get_buffer(frame, LINESIZE_ALIGNMENT);
if(res < 0) {
fprintf(stderr, "gsr error: gsr_video_encoder_software_setup_textures: av_frame_get_buffer failed: %d\n", res);
return false;
@@ -61,6 +63,12 @@ static void gsr_video_encoder_software_stop(gsr_video_encoder_software *self, AV
static bool gsr_video_encoder_software_start(gsr_video_encoder *encoder, AVCodecContext *video_codec_context, AVFrame *frame) {
gsr_video_encoder_software *encoder_software = encoder->priv;
+ video_codec_context->width = FFALIGN(video_codec_context->width, LINESIZE_ALIGNMENT);
+ video_codec_context->height = FFALIGN(video_codec_context->height, 2);
+
+ frame->width = video_codec_context->width;
+ frame->height = video_codec_context->height;
+
if(!gsr_video_encoder_software_setup_textures(encoder_software, video_codec_context, frame)) {
gsr_video_encoder_software_stop(encoder_software, video_codec_context);
return false;
diff --git a/src/encoder/video/vaapi.c b/src/encoder/video/vaapi.c
index 318ab1a..2df140d 100644
--- a/src/encoder/video/vaapi.c
+++ b/src/encoder/video/vaapi.c
@@ -151,6 +151,22 @@ static void gsr_video_encoder_vaapi_stop(gsr_video_encoder_vaapi *self, AVCodecC
static bool gsr_video_encoder_vaapi_start(gsr_video_encoder *encoder, AVCodecContext *video_codec_context, AVFrame *frame) {
gsr_video_encoder_vaapi *encoder_vaapi = encoder->priv;
+ if(encoder_vaapi->params.egl->gpu_info.vendor == GSR_GPU_VENDOR_AMD && video_codec_context->codec_id == AV_CODEC_ID_HEVC) {
+ // TODO: dont do this if using ffmpeg reports that this is not needed (AMD driver bug that was fixed recently)
+ video_codec_context->width = FFALIGN(video_codec_context->width, 64);
+ video_codec_context->height = FFALIGN(video_codec_context->height, 16);
+ } else if(encoder_vaapi->params.egl->gpu_info.vendor == GSR_GPU_VENDOR_AMD && video_codec_context->codec_id == AV_CODEC_ID_AV1) {
+ // TODO: Dont do this for VCN 5 and forward which should fix this hardware bug
+ video_codec_context->width = FFALIGN(video_codec_context->width, 64);
+ // AMD driver has special case handling for 1080 height to set it to 1082 instead of 1088 (1080 aligned to 16).
+ // TODO: Set height to 1082 in this case, but it wont work because it will be aligned to 1088.
+ if(video_codec_context->height == 1080) {
+ video_codec_context->height = 1080;
+ } else {
+ video_codec_context->height = FFALIGN(video_codec_context->height, 16);
+ }
+ }
+
if(!gsr_video_encoder_vaapi_setup_context(encoder_vaapi, video_codec_context)) {
gsr_video_encoder_vaapi_stop(encoder_vaapi, video_codec_context);
return false;