diff options
author | dec05eba <dec05eba@protonmail.com> | 2023-10-22 04:56:34 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2023-10-22 04:56:34 +0200 |
commit | 51154b71be6be742541f53a21b5c9d39d0033270 (patch) | |
tree | 348cc95ce90744c14884b2821136586b5ea8ed09 /src | |
parent | 44d50065b92284638398b4989490ac66eb34c53e (diff) |
Fix vram leak for reals
Diffstat (limited to 'src')
-rw-r--r-- | src/capture/capture.c | 12 | ||||
-rw-r--r-- | src/capture/kms_cuda.c | 10 | ||||
-rw-r--r-- | src/capture/kms_vaapi.c | 10 | ||||
-rw-r--r-- | src/capture/nvfbc.c | 1 | ||||
-rw-r--r-- | src/capture/xcomposite_cuda.c | 1 | ||||
-rw-r--r-- | src/capture/xcomposite_vaapi.c | 1 | ||||
-rw-r--r-- | src/main.cpp | 2 |
7 files changed, 33 insertions, 4 deletions
diff --git a/src/capture/capture.c b/src/capture/capture.c index 699745a..eea0d1d 100644 --- a/src/capture/capture.c +++ b/src/capture/capture.c @@ -42,6 +42,18 @@ int gsr_capture_capture(gsr_capture *cap, AVFrame *frame) { return cap->capture(cap, frame); } +void gsr_capture_end(gsr_capture *cap, AVFrame *frame) { + if(!cap->started) { + fprintf(stderr, "gsr error: gsr_capture_end failed: the gsr capture has not been started\n"); + return; + } + + if(!cap->capture_end) + return; + + cap->capture_end(cap, frame); +} + void gsr_capture_destroy(gsr_capture *cap, AVCodecContext *video_codec_context) { cap->destroy(cap, video_codec_context); } diff --git a/src/capture/kms_cuda.c b/src/capture/kms_cuda.c index 13636aa..e7f7ea5 100644 --- a/src/capture/kms_cuda.c +++ b/src/capture/kms_cuda.c @@ -424,6 +424,13 @@ static int gsr_capture_kms_cuda_capture(gsr_capture *cap, AVFrame *frame) { gsr_capture_kms_unload_cuda_graphics(cap_kms); + return 0; +} + +static void gsr_capture_kms_cuda_capture_end(gsr_capture *cap, AVFrame *frame) { + (void)frame; + gsr_capture_kms_cuda *cap_kms = cap->priv; + gsr_egl_cleanup_frame(cap_kms->params.egl); for(int i = 0; i < cap_kms->kms_response.num_fds; ++i) { @@ -432,8 +439,6 @@ static int gsr_capture_kms_cuda_capture(gsr_capture *cap, AVFrame *frame) { cap_kms->kms_response.fds[i].fd = 0; } cap_kms->kms_response.num_fds = 0; - - return 0; } static void gsr_capture_kms_cuda_stop(gsr_capture *cap, AVCodecContext *video_codec_context) { @@ -501,6 +506,7 @@ gsr_capture* gsr_capture_kms_cuda_create(const gsr_capture_kms_cuda_params *para .tick = gsr_capture_kms_cuda_tick, .should_stop = gsr_capture_kms_cuda_should_stop, .capture = gsr_capture_kms_cuda_capture, + .capture_end = gsr_capture_kms_cuda_capture_end, .destroy = gsr_capture_kms_cuda_destroy, .priv = cap_kms }; diff --git a/src/capture/kms_vaapi.c b/src/capture/kms_vaapi.c index 5899f9f..681f345 100644 --- a/src/capture/kms_vaapi.c +++ b/src/capture/kms_vaapi.c @@ -547,6 +547,13 @@ static int gsr_capture_kms_vaapi_capture(gsr_capture *cap, AVFrame *frame) { cap_kms->params.egl->eglSwapBuffers(cap_kms->params.egl->egl_display, cap_kms->params.egl->egl_surface); + return 0; +} + +static void gsr_capture_kms_vaapi_capture_end(gsr_capture *cap, AVFrame *frame) { + (void)frame; + gsr_capture_kms_vaapi *cap_kms = cap->priv; + gsr_egl_cleanup_frame(cap_kms->params.egl); for(int i = 0; i < cap_kms->kms_response.num_fds; ++i) { @@ -555,8 +562,6 @@ static int gsr_capture_kms_vaapi_capture(gsr_capture *cap, AVFrame *frame) { cap_kms->kms_response.fds[i].fd = 0; } cap_kms->kms_response.num_fds = 0; - - return 0; } static void gsr_capture_kms_vaapi_stop(gsr_capture *cap, AVCodecContext *video_codec_context) { @@ -647,6 +652,7 @@ gsr_capture* gsr_capture_kms_vaapi_create(const gsr_capture_kms_vaapi_params *pa .tick = gsr_capture_kms_vaapi_tick, .should_stop = gsr_capture_kms_vaapi_should_stop, .capture = gsr_capture_kms_vaapi_capture, + .capture_end = gsr_capture_kms_vaapi_capture_end, .destroy = gsr_capture_kms_vaapi_destroy, .priv = cap_kms }; diff --git a/src/capture/nvfbc.c b/src/capture/nvfbc.c index 32b83fc..5b62310 100644 --- a/src/capture/nvfbc.c +++ b/src/capture/nvfbc.c @@ -492,6 +492,7 @@ gsr_capture* gsr_capture_nvfbc_create(const gsr_capture_nvfbc_params *params) { .tick = gsr_capture_nvfbc_tick, .should_stop = NULL, .capture = gsr_capture_nvfbc_capture, + .capture_end = NULL, .destroy = gsr_capture_nvfbc_destroy, .priv = cap_nvfbc }; diff --git a/src/capture/xcomposite_cuda.c b/src/capture/xcomposite_cuda.c index e58decb..7e65efa 100644 --- a/src/capture/xcomposite_cuda.c +++ b/src/capture/xcomposite_cuda.c @@ -503,6 +503,7 @@ gsr_capture* gsr_capture_xcomposite_cuda_create(const gsr_capture_xcomposite_cud .tick = gsr_capture_xcomposite_cuda_tick, .should_stop = gsr_capture_xcomposite_cuda_should_stop, .capture = gsr_capture_xcomposite_cuda_capture, + .capture_end = NULL, .destroy = gsr_capture_xcomposite_cuda_destroy, .priv = cap_xcomp }; diff --git a/src/capture/xcomposite_vaapi.c b/src/capture/xcomposite_vaapi.c index 18bcf32..2bc21a7 100644 --- a/src/capture/xcomposite_vaapi.c +++ b/src/capture/xcomposite_vaapi.c @@ -508,6 +508,7 @@ gsr_capture* gsr_capture_xcomposite_vaapi_create(const gsr_capture_xcomposite_va .tick = gsr_capture_xcomposite_vaapi_tick, .should_stop = gsr_capture_xcomposite_vaapi_should_stop, .capture = gsr_capture_xcomposite_vaapi_capture, + .capture_end = NULL, .destroy = gsr_capture_xcomposite_vaapi_destroy, .priv = cap_xcomp }; diff --git a/src/main.cpp b/src/main.cpp index 1f436ff..eb5f8c2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2186,6 +2186,8 @@ int main(int argc, char **argv) { fprintf(stderr, "Error: avcodec_send_frame failed, error: %s\n", av_error_to_string(ret)); } } + + gsr_capture_end(capture, frame); video_pts_counter += num_frames; } } |