Fix vram leak for reals
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user