Fix x11 screen capture memory leakage

This commit is contained in:
dijunkun
2023-11-08 01:20:02 -08:00
parent 31e5d5025a
commit b347b160e2
3 changed files with 8 additions and 6 deletions

View File

@@ -239,6 +239,7 @@ int main(int argc, char *argv[]) {
if (av_read_frame(pFormatCtx, packet) >= 0) {
if (packet->stream_index == videoindex) {
avcodec_send_packet(pCodecCtx, packet);
av_packet_unref(packet);
got_picture = avcodec_receive_frame(pCodecCtx, pFrame);
// ret = avcodec_decode_video2(pCodecCtx, pFrame, &got_picture,
// packet);

View File

@@ -96,6 +96,7 @@ int ScreenCaptureX11::Start() {
if (av_read_frame(pFormatCtx_, packet_) >= 0) {
if (packet_->stream_index == videoindex_) {
avcodec_send_packet(pCodecCtx_, packet_);
av_packet_unref(packet_);
got_picture_ = avcodec_receive_frame(pCodecCtx_, pFrame_);
if (!got_picture_) {
@@ -110,7 +111,6 @@ int ScreenCaptureX11::Start() {
_on_data((unsigned char *)nv12_buffer_,
pFrame_->width * pFrame_->height * 3 / 2, pFrame_->width,
pFrame_->height);
// av_packet_unref(packet_);
}
}
}

View File

@@ -6,7 +6,7 @@ add_rules("mode.release", "mode.debug")
set_languages("c++17")
add_requires("spdlog 1.11.0", {system = false})
add_requires("imgui 1.89.9", {configs = {sdl2 = true, sdl2_renderer = true, glfw = true}})
add_requires("imgui 1.89.9", {configs = {sdl2 = true, sdl2_renderer = true}})
add_defines("UNICODE")
add_requires("sdl2", {system = false})
@@ -66,15 +66,16 @@ target("remote_desk")
add_ldflags("-lavformat", "-lavdevice", "-lavfilter", "-lavcodec",
"-lswscale", "-lavutil", "-lswresample",
"-lasound", "-lxcb-shape", "-lxcb-xfixes", "-lsndio", "-lxcb",
"-lxcb-shm", "-lXext", "-lX11", "-lXv", "-ldl", "-lpthread", {force = true})
"-lxcb-shm", "-lXext", "-lX11", "-lXv", "-ldl", "-lpthread",
{force = true})
end
target("linux_capture")
set_kind("binary")
add_packages("sdl2", "imgui", "ffmpeg", "glfw", "glad")
add_packages("sdl2", "imgui", "ffmpeg", "openh264")
add_files("remote_desk_gui/linux_capture.cpp")
add_links("SDL2")
add_ldflags("-lavformat", "-lavdevice", "-lavfilter", "-lavcodec",
"-lswscale", "-lavutil", "-lswresample",
"-lasound", "-lxcb-shape", "-lxcb-xfixes", "-lsndio", "-lxcb",
"-lxcb-shm", "-lXext", "-lX11", "-lXv", "-lpthread", "-lx264", "-ldl", "-lSDL2" ,{force = true})
"-lxcb-shm", "-lXext", "-lX11", "-lXv", "-lpthread", "-lSDL2", "-lopenh264",
"-ldl" ,{force = true})