aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/encoder
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2025-09-21 03:19:56 +0200
committerdec05eba <dec05eba@protonmail.com>2025-09-21 03:19:56 +0200
commit2c22782ca0af78070089938feb873beaa1d78722 (patch)
tree2e609414f93980fc8934cb78418a565706c3852b /src/encoder
parenta4c227c43ea57aa65e10a186935930a6033fa429 (diff)
Dont use glGetTexLevelParameteriv, it's only available in opengl es 3.1
Diffstat (limited to 'src/encoder')
-rw-r--r--src/encoder/video/nvenc.c8
-rw-r--r--src/encoder/video/software.c8
-rw-r--r--src/encoder/video/vaapi.c6
-rw-r--r--src/encoder/video/video.c4
-rw-r--r--src/encoder/video/vulkan.c8
5 files changed, 26 insertions, 8 deletions
diff --git a/src/encoder/video/nvenc.c b/src/encoder/video/nvenc.c
index 5f578c2..0318a17 100644
--- a/src/encoder/video/nvenc.c
+++ b/src/encoder/video/nvenc.c
@@ -12,6 +12,7 @@ typedef struct {
gsr_video_encoder_nvenc_params params;
unsigned int target_textures[2];
+ vec2i target_texture_size[2];
AVBufferRef *device_ctx;
@@ -95,7 +96,8 @@ static bool gsr_video_encoder_nvenc_setup_textures(gsr_video_encoder_nvenc *self
const int div[2] = {1, 2}; // divide UV texture size by 2 because chroma is half size
for(int i = 0; i < 2; ++i) {
- self->target_textures[i] = gl_create_texture(self->params.egl, video_codec_context->width / div[i], video_codec_context->height / div[i], self->params.color_depth == GSR_COLOR_DEPTH_8_BITS ? internal_formats_nv12[i] : internal_formats_p010[i], formats[i], GL_NEAREST);
+ self->target_texture_size[i] = (vec2i){ video_codec_context->width / div[i], video_codec_context->height / div[i] };
+ self->target_textures[i] = gl_create_texture(self->params.egl, self->target_texture_size[i].x, self->target_texture_size[i].y, self->params.color_depth == GSR_COLOR_DEPTH_8_BITS ? internal_formats_nv12[i] : internal_formats_p010[i], formats[i], GL_NEAREST);
if(self->target_textures[i] == 0) {
fprintf(stderr, "gsr error: gsr_video_encoder_nvenc_setup_textures: failed to create opengl texture\n");
return false;
@@ -198,10 +200,12 @@ static void gsr_video_encoder_nvenc_copy_textures_to_frame(gsr_video_encoder *en
self->cuda.cuStreamSynchronize(self->cuda_stream);
}
-static void gsr_video_encoder_nvenc_get_textures(gsr_video_encoder *encoder, unsigned int *textures, int *num_textures, gsr_destination_color *destination_color) {
+static void gsr_video_encoder_nvenc_get_textures(gsr_video_encoder *encoder, unsigned int *textures, vec2i *texture_sizes, int *num_textures, gsr_destination_color *destination_color) {
gsr_video_encoder_nvenc *self = encoder->priv;
textures[0] = self->target_textures[0];
textures[1] = self->target_textures[1];
+ texture_sizes[0] = self->target_texture_size[0];
+ texture_sizes[1] = self->target_texture_size[1];
*num_textures = 2;
*destination_color = self->params.color_depth == GSR_COLOR_DEPTH_10_BITS ? GSR_DESTINATION_COLOR_P010 : GSR_DESTINATION_COLOR_NV12;
}
diff --git a/src/encoder/video/software.c b/src/encoder/video/software.c
index d8d9828..b473bb9 100644
--- a/src/encoder/video/software.c
+++ b/src/encoder/video/software.c
@@ -13,6 +13,7 @@ typedef struct {
gsr_video_encoder_software_params params;
unsigned int target_textures[2];
+ vec2i texture_sizes[2];
} gsr_video_encoder_software;
static bool gsr_video_encoder_software_setup_textures(gsr_video_encoder_software *self, AVCodecContext *video_codec_context, AVFrame *frame) {
@@ -34,7 +35,8 @@ static bool gsr_video_encoder_software_setup_textures(gsr_video_encoder_software
const int div[2] = {1, 2}; // divide UV texture size by 2 because chroma is half size
for(int i = 0; i < 2; ++i) {
- self->target_textures[i] = gl_create_texture(self->params.egl, video_codec_context->width / div[i], video_codec_context->height / div[i], self->params.color_depth == GSR_COLOR_DEPTH_8_BITS ? internal_formats_nv12[i] : internal_formats_p010[i], formats[i], GL_NEAREST);
+ self->texture_sizes[i] = (vec2i){ video_codec_context->width / div[i], video_codec_context->height / div[i] };
+ self->target_textures[i] = gl_create_texture(self->params.egl, self->texture_sizes[i].x, self->texture_sizes[i].y, self->params.color_depth == GSR_COLOR_DEPTH_8_BITS ? internal_formats_nv12[i] : internal_formats_p010[i], formats[i], GL_NEAREST);
if(self->target_textures[i] == 0) {
fprintf(stderr, "gsr error: gsr_capture_kms_setup_cuda_textures: failed to create opengl texture\n");
return false;
@@ -86,10 +88,12 @@ static void gsr_video_encoder_software_copy_textures_to_frame(gsr_video_encoder
//self->params.egl->glFinish();
}
-static void gsr_video_encoder_software_get_textures(gsr_video_encoder *encoder, unsigned int *textures, int *num_textures, gsr_destination_color *destination_color) {
+static void gsr_video_encoder_software_get_textures(gsr_video_encoder *encoder, unsigned int *textures, vec2i *texture_sizes, int *num_textures, gsr_destination_color *destination_color) {
gsr_video_encoder_software *self = encoder->priv;
textures[0] = self->target_textures[0];
textures[1] = self->target_textures[1];
+ texture_sizes[0] = self->texture_sizes[0];
+ texture_sizes[1] = self->texture_sizes[1];
*num_textures = 2;
*destination_color = self->params.color_depth == GSR_COLOR_DEPTH_10_BITS ? GSR_DESTINATION_COLOR_P010 : GSR_DESTINATION_COLOR_NV12;
}
diff --git a/src/encoder/video/vaapi.c b/src/encoder/video/vaapi.c
index 0daf4d8..9cf4def 100644
--- a/src/encoder/video/vaapi.c
+++ b/src/encoder/video/vaapi.c
@@ -16,6 +16,7 @@ typedef struct {
gsr_video_encoder_vaapi_params params;
unsigned int target_textures[2];
+ vec2i texture_sizes[2];
AVBufferRef *device_ctx;
VADisplay va_dpy;
@@ -112,6 +113,7 @@ static bool gsr_video_encoder_vaapi_setup_textures(gsr_video_encoder_vaapi *self
intptr_t img_attr[44];
setup_dma_buf_attrs(img_attr, formats[i], self->prime.width / div[i], self->prime.height / div[i],
fds, offsets, pitches, modifiers, self->prime.layers[layer].num_planes, true);
+ self->texture_sizes[i] = (vec2i){ self->prime.width / div[i], self->prime.height / div[i] };
while(self->params.egl->eglGetError() != EGL_SUCCESS){}
EGLImage image = self->params.egl->eglCreateImage(self->params.egl->egl_display, 0, EGL_LINUX_DMA_BUF_EXT, NULL, img_attr);
@@ -214,10 +216,12 @@ void gsr_video_encoder_vaapi_stop(gsr_video_encoder_vaapi *self, AVCodecContext
}
}
-static void gsr_video_encoder_vaapi_get_textures(gsr_video_encoder *encoder, unsigned int *textures, int *num_textures, gsr_destination_color *destination_color) {
+static void gsr_video_encoder_vaapi_get_textures(gsr_video_encoder *encoder, unsigned int *textures, vec2i *texture_sizes, int *num_textures, gsr_destination_color *destination_color) {
gsr_video_encoder_vaapi *self = encoder->priv;
textures[0] = self->target_textures[0];
textures[1] = self->target_textures[1];
+ texture_sizes[0] = self->texture_sizes[0];
+ texture_sizes[1] = self->texture_sizes[1];
*num_textures = 2;
*destination_color = self->params.color_depth == GSR_COLOR_DEPTH_10_BITS ? GSR_DESTINATION_COLOR_P010 : GSR_DESTINATION_COLOR_NV12;
}
diff --git a/src/encoder/video/video.c b/src/encoder/video/video.c
index ce3b61b..80f2cf0 100644
--- a/src/encoder/video/video.c
+++ b/src/encoder/video/video.c
@@ -22,7 +22,7 @@ void gsr_video_encoder_copy_textures_to_frame(gsr_video_encoder *encoder, AVFram
encoder->copy_textures_to_frame(encoder, frame, color_conversion);
}
-void gsr_video_encoder_get_textures(gsr_video_encoder *encoder, unsigned int *textures, int *num_textures, gsr_destination_color *destination_color) {
+void gsr_video_encoder_get_textures(gsr_video_encoder *encoder, unsigned int *textures, vec2i *texture_sizes, int *num_textures, gsr_destination_color *destination_color) {
assert(encoder->started);
- encoder->get_textures(encoder, textures, num_textures, destination_color);
+ encoder->get_textures(encoder, textures, texture_sizes, num_textures, destination_color);
}
diff --git a/src/encoder/video/vulkan.c b/src/encoder/video/vulkan.c
index 802934d..16b21a1 100644
--- a/src/encoder/video/vulkan.c
+++ b/src/encoder/video/vulkan.c
@@ -16,6 +16,7 @@
typedef struct {
gsr_video_encoder_vulkan_params params;
unsigned int target_textures[2];
+ vec2i texture_sizes[2];
AVBufferRef *device_ctx;
} gsr_video_encoder_vulkan;
@@ -224,6 +225,9 @@ static bool gsr_video_encoder_vulkan_setup_textures(gsr_video_encoder_vulkan *se
fprintf(stderr, "3 gl error: %d\n", self->params.egl->glGetError());
self->params.egl->glBindTexture(GL_TEXTURE_2D, 0);
+
+ self->texture_sizes[0] = (vec2i){ frame->width, frame->height };
+ self->texture_sizes[1] = (vec2i){ frame->width/2, frame->height/2 };
}
#endif
return true;
@@ -270,10 +274,12 @@ void gsr_video_encoder_vulkan_stop(gsr_video_encoder_vulkan *self, AVCodecContex
av_buffer_unref(&self->device_ctx);
}
-static void gsr_video_encoder_vulkan_get_textures(gsr_video_encoder *encoder, unsigned int *textures, int *num_textures, gsr_destination_color *destination_color) {
+static void gsr_video_encoder_vulkan_get_textures(gsr_video_encoder *encoder, unsigned int *textures, vec2i *texture_sizes, int *num_textures, gsr_destination_color *destination_color) {
gsr_video_encoder_vulkan *self = encoder->priv;
textures[0] = self->target_textures[0];
textures[1] = self->target_textures[1];
+ texture_sizes[0] = self->texture_sizes[0];
+ texture_sizes[1] = self->texture_sizes[1];
*num_textures = 2;
*destination_color = self->params.color_depth == GSR_COLOR_DEPTH_10_BITS ? GSR_DESTINATION_COLOR_P010 : GSR_DESTINATION_COLOR_NV12;
}