diff options
Diffstat (limited to 'src/encoder/video/nvenc.c')
-rw-r--r-- | src/encoder/video/nvenc.c | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/encoder/video/nvenc.c b/src/encoder/video/nvenc.c index 718560d..5f578c2 100644 --- a/src/encoder/video/nvenc.c +++ b/src/encoder/video/nvenc.c @@ -1,6 +1,7 @@ #include "../../../include/encoder/video/nvenc.h" #include "../../../include/egl.h" #include "../../../include/cuda.h" +#include "../../../include/window/window.h" #include <libavcodec/avcodec.h> #include <libavutil/hwcontext_cuda.h> @@ -64,21 +65,6 @@ static bool gsr_video_encoder_nvenc_setup_context(gsr_video_encoder_nvenc *self, return true; } -static unsigned int gl_create_texture(gsr_egl *egl, int width, int height, int internal_format, unsigned int format) { - unsigned int texture_id = 0; - egl->glGenTextures(1, &texture_id); - egl->glBindTexture(GL_TEXTURE_2D, texture_id); - egl->glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0, format, GL_UNSIGNED_BYTE, NULL); - - egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - - egl->glBindTexture(GL_TEXTURE_2D, 0); - return texture_id; -} - static bool cuda_register_opengl_texture(gsr_cuda *cuda, CUgraphicsResource *cuda_graphics_resource, CUarray *mapped_array, unsigned int texture_id) { CUresult res; res = cuda->cuGraphicsGLRegisterImage(cuda_graphics_resource, texture_id, GL_TEXTURE_2D, CU_GRAPHICS_REGISTER_FLAGS_NONE); @@ -109,7 +95,7 @@ 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]); + 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); if(self->target_textures[i] == 0) { fprintf(stderr, "gsr error: gsr_video_encoder_nvenc_setup_textures: failed to create opengl texture\n"); return false; @@ -128,13 +114,27 @@ static void gsr_video_encoder_nvenc_stop(gsr_video_encoder_nvenc *self, AVCodecC static bool gsr_video_encoder_nvenc_start(gsr_video_encoder *encoder, AVCodecContext *video_codec_context, AVFrame *frame) { gsr_video_encoder_nvenc *self = encoder->priv; - const bool overclock = gsr_egl_get_display_server(self->params.egl) == GSR_DISPLAY_SERVER_X11 ? self->params.overclock : false; - if(!gsr_cuda_load(&self->cuda, self->params.egl->x11.dpy, overclock)) { + const bool is_x11 = gsr_window_get_display_server(self->params.egl->window) == GSR_DISPLAY_SERVER_X11; + const bool overclock = is_x11 ? self->params.overclock : false; + Display *display = is_x11 ? gsr_window_get_display(self->params.egl->window) : NULL; + if(!gsr_cuda_load(&self->cuda, display, overclock)) { fprintf(stderr, "gsr error: gsr_video_encoder_nvenc_start: failed to load cuda\n"); gsr_video_encoder_nvenc_stop(self, video_codec_context); return false; } + video_codec_context->width = FFALIGN(video_codec_context->width, 2); + video_codec_context->height = FFALIGN(video_codec_context->height, 2); + + if(video_codec_context->width < 128) + video_codec_context->width = 128; + + if(video_codec_context->height < 128) + video_codec_context->height = 128; + + frame->width = video_codec_context->width; + frame->height = video_codec_context->height; + if(!gsr_video_encoder_nvenc_setup_context(self, video_codec_context)) { gsr_video_encoder_nvenc_stop(self, video_codec_context); return false; |