diff --git a/remote_desk_gui/main.cpp b/remote_desk_gui/main.cpp index 90cbf03..649fb60 100644 --- a/remote_desk_gui/main.cpp +++ b/remote_desk_gui/main.cpp @@ -591,8 +591,7 @@ int main() { if (tc >= 0) { SendData(peer_server, DATA_TYPE::VIDEO, - (const char *)nv12_buffer, NV12_BUFFER_SIZE); - std::cout << "Send" << std::endl; + (const char *)data, NV12_BUFFER_SIZE); last_frame_time_ = now_time; } }); diff --git a/screen_capture/linux/screen_capture_x11.cpp b/screen_capture/linux/screen_capture_x11.cpp index def4c75..0ab6619 100644 --- a/screen_capture/linux/screen_capture_x11.cpp +++ b/screen_capture/linux/screen_capture_x11.cpp @@ -5,14 +5,7 @@ #define NV12_BUFFER_SIZE 1280 * 720 * 3 / 2 unsigned char nv12_buffer_[NV12_BUFFER_SIZE]; -FILE *file = nullptr; - -ScreenCaptureX11::ScreenCaptureX11() { - file = fopen("nv12.yuv", "w+b"); - if (!file) { - printf("Fail to open nv12.yuv\n"); - } -} +ScreenCaptureX11::ScreenCaptureX11() {} ScreenCaptureX11::~ScreenCaptureX11() { if (capture_thread_->joinable()) { @@ -79,7 +72,7 @@ int ScreenCaptureX11::Init(const RECORD_DESKTOP_RECT &rect, const int fps, } pFrame_ = av_frame_alloc(); - pFrameNV12_ = av_frame_alloc(); + pFrameNv12_ = av_frame_alloc(); const int pixel_w = 1280, pixel_h = 720; int screen_w = 1280, screen_h = 720; @@ -100,31 +93,24 @@ int ScreenCaptureX11::Init(const RECORD_DESKTOP_RECT &rect, const int fps, int ScreenCaptureX11::Start() { capture_thread_.reset(new std::thread([this]() { while (1) { - printf("00000\n"); if (av_read_frame(pFormatCtx_, packet_) >= 0) { - printf("111111444444\n"); if (packet_->stream_index == videoindex_) { - printf("11111155555\n"); avcodec_send_packet(pCodecCtx_, packet_); got_picture_ = avcodec_receive_frame(pCodecCtx_, pFrame_); - printf("33333333\n"); - if (!got_picture_) { - printf("44444444444\n"); - av_image_fill_arrays(pFrameNV12_->data, pFrameNV12_->linesize, + if (!got_picture_) { + av_image_fill_arrays(pFrameNv12_->data, pFrameNv12_->linesize, nv12_buffer_, AV_PIX_FMT_NV12, pFrame_->width, pFrame_->height, 1); sws_scale(img_convert_ctx_, pFrame_->data, pFrame_->linesize, 0, - pFrame_->height, pFrameNV12_->data, - pFrameNV12_->linesize); - - fwrite(nv12_buffer_, 1, pFrame_->width * pFrame_->height * 3 / 2, - file); + pFrame_->height, pFrameNv12_->data, + pFrameNv12_->linesize); _on_data((unsigned char *)nv12_buffer_, pFrame_->width * pFrame_->height * 3 / 2, pFrame_->width, pFrame_->height); + // av_packet_unref(packet_); } } } diff --git a/screen_capture/linux/screen_capture_x11.h b/screen_capture/linux/screen_capture_x11.h index a3fc710..93b3719 100644 --- a/screen_capture/linux/screen_capture_x11.h +++ b/screen_capture/linux/screen_capture_x11.h @@ -74,7 +74,7 @@ class ScreenCaptureX11 { AVDictionary *options_ = nullptr; AVInputFormat *ifmt_ = nullptr; AVFrame *pFrame_ = nullptr; - AVFrame *pFrameNV12_ = nullptr; + AVFrame *pFrameNv12_ = nullptr; AVPacket *packet_ = nullptr; struct SwsContext *img_convert_ctx_ = nullptr; diff --git a/xmake.lua b/xmake.lua index 91ed743..669ce93 100644 --- a/xmake.lua +++ b/xmake.lua @@ -1,6 +1,6 @@ set_project("remote_desk") set_version("0.0.1") -set_license("GPL-3.0") +set_license("LGPL-3.0") add_rules("mode.release", "mode.debug") set_languages("c++17") @@ -15,6 +15,7 @@ if is_os("windows") then add_links("Shell32", "windowsapp", "dwmapi", "User32", "kernel32") add_requires("vcpkg::ffmpeg 5.1.2", {configs = {shared = false}}) elseif is_os("linux") then + add_requireconfs("ffmpeg.x264", {configs = {pic = true}}) add_requires("ffmpeg 5.1.2", {system = false}) add_syslinks("pthread", "dl") elseif is_os("macosx") then @@ -63,7 +64,7 @@ target("remote_desk") elseif is_os("linux") then add_links("SDL2") add_ldflags("-lavformat", "-lavdevice", "-lavfilter", "-lavcodec", - "-lswscale", "-lavutil", "-lswresample", "-lpostproc", + "-lswscale", "-lavutil", "-lswresample", "-lasound", "-lxcb-shape", "-lxcb-xfixes", "-lsndio", "-lxcb", "-lxcb-shm", "-lXext", "-lX11", "-lXv", "-ldl", "-lpthread", {force = true}) end @@ -74,6 +75,6 @@ target("linux_capture") add_files("remote_desk_gui/linux_capture.cpp") add_links("SDL2") add_ldflags("-lavformat", "-lavdevice", "-lavfilter", "-lavcodec", - "-lswscale", "-lavutil", "-lswresample", "-lpostproc", + "-lswscale", "-lavutil", "-lswresample", "-lasound", "-lxcb-shape", "-lxcb-xfixes", "-lsndio", "-lxcb", "-lxcb-shm", "-lXext", "-lX11", "-lXv", "-lpthread", "-lx264", "-ldl", "-lSDL2" ,{force = true}) \ No newline at end of file