1.ImGUI display success; 2.To do: fix x264 encode green screen

This commit is contained in:
dijunkun
2023-11-02 02:34:14 -07:00
parent 9be5d90a69
commit 6e19e53603
6 changed files with 42 additions and 25 deletions

View File

@@ -7,7 +7,11 @@ vcpkg/buildtrees/versioning_/versions/pcre/69e232f12c4e3eab4115f0672466a6661978b
linux linux
apt-get install nvidia-cuda-toolkit sudo apt-get install nvidia-cuda-toolkit
solve <cuda.h> solve <cuda.h>
sudo apt-get install libxcb-randr0-dev libxcb-xtest0-dev libxcb-xinerama0-dev libxcb-shape0-dev libxcb-xkb-dev sudo apt-get install libxcb-randr0-dev libxcb-xtest0-dev libxcb-xinerama0-dev libxcb-shape0-dev libxcb-xkb-dev libxcb-xfixes0-dev libxv-dev
sudo apt-get install libavcodec-dev libavformat-dev libavutil-dev libavfilter-dev libavdevice-dev
sudo apt remove libssl-dev libglib2.0-dev

View File

@@ -121,7 +121,7 @@ int main(int argc, char *argv[]) {
// grabbing frame rate // grabbing frame rate
av_dict_set(&options, "framerate", "30", 0); av_dict_set(&options, "framerate", "30", 0);
// Make the grabbed area follow the mouse // Make the grabbed area follow the mouse
av_dict_set(&options, "follow_mouse", "centered", 0); // av_dict_set(&options, "follow_mouse", "centered", 0);
// Video frame size. The default is to capture the full screen // Video frame size. The default is to capture the full screen
av_dict_set(&options, "video_size", "1280x720", 0); av_dict_set(&options, "video_size", "1280x720", 0);
AVInputFormat *ifmt = (AVInputFormat *)av_find_input_format("x11grab"); AVInputFormat *ifmt = (AVInputFormat *)av_find_input_format("x11grab");
@@ -156,7 +156,6 @@ int main(int argc, char *argv[]) {
pCodecCtx = avcodec_alloc_context3(NULL); pCodecCtx = avcodec_alloc_context3(NULL);
avcodec_parameters_to_context(pCodecCtx, pCodecParam); avcodec_parameters_to_context(pCodecCtx, pCodecParam);
// pCodec = const_cast<AVCodec *>(avcodec_find_decoder(AV_CODEC_ID_H264));
pCodec = const_cast<AVCodec *>(avcodec_find_decoder(pCodecCtx->codec_id)); pCodec = const_cast<AVCodec *>(avcodec_find_decoder(pCodecCtx->codec_id));
if (pCodec == NULL) { if (pCodec == NULL) {
printf("Codec not found.\n"); printf("Codec not found.\n");

View File

@@ -592,11 +592,10 @@ int main() {
if (tc >= 0) { if (tc >= 0) {
SendData(peer_server, DATA_TYPE::VIDEO, SendData(peer_server, DATA_TYPE::VIDEO,
(const char *)nv12_buffer, NV12_BUFFER_SIZE); (const char *)nv12_buffer, NV12_BUFFER_SIZE);
// std::cout << "Send" << std::endl; std::cout << "Send" << std::endl;
last_frame_time_ = now_time; last_frame_time_ = now_time;
} }
}); });
screen_capture->Start(); screen_capture->Start();
#endif #endif
} else { } else {

View File

@@ -5,9 +5,20 @@
#define NV12_BUFFER_SIZE 1280 * 720 * 3 / 2 #define NV12_BUFFER_SIZE 1280 * 720 * 3 / 2
unsigned char nv12_buffer_[NV12_BUFFER_SIZE]; unsigned char nv12_buffer_[NV12_BUFFER_SIZE];
ScreenCaptureX11::ScreenCaptureX11() {} FILE *file = nullptr;
ScreenCaptureX11::~ScreenCaptureX11() {} ScreenCaptureX11::ScreenCaptureX11() {
file = fopen("nv12.yuv", "w+b");
if (!file) {
printf("Fail to open nv12.yuv\n");
}
}
ScreenCaptureX11::~ScreenCaptureX11() {
if (capture_thread_->joinable()) {
capture_thread_->join();
}
}
int ScreenCaptureX11::Init(const RECORD_DESKTOP_RECT &rect, const int fps, int ScreenCaptureX11::Init(const RECORD_DESKTOP_RECT &rect, const int fps,
cb_desktop_data cb) { cb_desktop_data cb) {
@@ -22,9 +33,9 @@ int ScreenCaptureX11::Init(const RECORD_DESKTOP_RECT &rect, const int fps,
// grabbing frame rate // grabbing frame rate
av_dict_set(&options_, "framerate", "30", 0); av_dict_set(&options_, "framerate", "30", 0);
// Make the grabbed area follow the mouse // Make the grabbed area follow the mouse
av_dict_set(&options_, "follow_mouse", "centered", 0); // av_dict_set(&options_, "follow_mouse", "centered", 0);
// Video frame size. The default is to capture the full screen // Video frame size. The default is to capture the full screen
// av_dict_set(&options_, "video_size", "1280x720", 0); av_dict_set(&options_, "video_size", "1280x720", 0);
ifmt_ = (AVInputFormat *)av_find_input_format("x11grab"); ifmt_ = (AVInputFormat *)av_find_input_format("x11grab");
if (!ifmt_) { if (!ifmt_) {
printf("Couldn't find_input_format\n"); printf("Couldn't find_input_format\n");
@@ -57,7 +68,6 @@ int ScreenCaptureX11::Init(const RECORD_DESKTOP_RECT &rect, const int fps,
pCodecCtx_ = avcodec_alloc_context3(NULL); pCodecCtx_ = avcodec_alloc_context3(NULL);
avcodec_parameters_to_context(pCodecCtx_, pCodecParam_); avcodec_parameters_to_context(pCodecCtx_, pCodecParam_);
// pCodec_ = const_cast<AVCodec *>(avcodec_find_decoder(AV_CODEC_ID_H264));
pCodec_ = const_cast<AVCodec *>(avcodec_find_decoder(pCodecCtx_->codec_id)); pCodec_ = const_cast<AVCodec *>(avcodec_find_decoder(pCodecCtx_->codec_id));
if (pCodec_ == NULL) { if (pCodec_ == NULL) {
printf("Codec not found.\n"); printf("Codec not found.\n");
@@ -90,6 +100,7 @@ int ScreenCaptureX11::Init(const RECORD_DESKTOP_RECT &rect, const int fps,
int ScreenCaptureX11::Start() { int ScreenCaptureX11::Start() {
capture_thread_.reset(new std::thread([this]() { capture_thread_.reset(new std::thread([this]() {
while (1) { while (1) {
printf("00000\n");
if (av_read_frame(pFormatCtx_, packet_) >= 0) { if (av_read_frame(pFormatCtx_, packet_) >= 0) {
printf("111111444444\n"); printf("111111444444\n");
if (packet_->stream_index == videoindex_) { if (packet_->stream_index == videoindex_) {
@@ -108,6 +119,9 @@ int ScreenCaptureX11::Start() {
pFrame_->height, pFrameNV12_->data, pFrame_->height, pFrameNV12_->data,
pFrameNV12_->linesize); pFrameNV12_->linesize);
fwrite(nv12_buffer_, 1, pFrame_->width * pFrame_->height * 3 / 2,
file);
_on_data((unsigned char *)nv12_buffer_, _on_data((unsigned char *)nv12_buffer_,
pFrame_->width * pFrame_->height * 3 / 2, pFrame_->width, pFrame_->width * pFrame_->height * 3 / 2, pFrame_->width,
pFrame_->height); pFrame_->height);

View File

@@ -6,7 +6,7 @@ add_rules("mode.release", "mode.debug")
set_languages("c++17") set_languages("c++17")
add_requires("spdlog 1.11.0", {system = false}) add_requires("spdlog 1.11.0", {system = false})
add_requires("imgui 1.89.9", {system = false}, {configs = {sdl2 = true}}) add_requires("imgui 1.89.9", {configs = {sdl2 = true, sdl2_renderer = true, glfw = true}})
add_defines("UNICODE") add_defines("UNICODE")
add_requires("sdl2", {system = false}) add_requires("sdl2", {system = false})
@@ -52,8 +52,8 @@ target("screen_capture")
target("remote_desk") target("remote_desk")
set_kind("binary") set_kind("binary")
add_deps("projectx", "screen_capture") add_deps("projectx", "screen_capture")
add_packages("log", "imgui", "sdl2", "ffmpeg") add_packages("log", "sdl2", "imgui", "ffmpeg")
add_files("remote_desk_gui/*.cpp") add_files("remote_desk_gui/main.cpp")
add_includedirs("../../src/interface") add_includedirs("../../src/interface")
if is_os("windows") then if is_os("windows") then
add_links("SDL2-static", "SDL2main", "gdi32", "winmm", add_links("SDL2-static", "SDL2main", "gdi32", "winmm",
@@ -67,3 +67,13 @@ target("remote_desk")
"-lasound", "-lxcb-shape", "-lxcb-xfixes", "-lsndio", "-lxcb", "-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 end
target("linux_capture")
set_kind("binary")
add_packages("sdl2", "imgui", "ffmpeg", "glfw", "glad")
add_files("remote_desk_gui/linux_capture.cpp")
add_links("SDL2")
add_ldflags("-lavformat", "-lavdevice", "-lavfilter", "-lavcodec",
"-lswscale", "-lavutil", "-lswresample", "-lpostproc",
"-lasound", "-lxcb-shape", "-lxcb-xfixes", "-lsndio", "-lxcb",
"-lxcb-shm", "-lXext", "-lX11", "-lXv", "-lpthread", "-lx264", "-ldl", "-lSDL2" ,{force = true})

View File

@@ -227,12 +227,3 @@ target("nicetest")
"pcre2-8", "pcre2-16", "pcre2-32", "pcre2-posix", "pcre2-8", "pcre2-16", "pcre2-32", "pcre2-posix",
"zlib", "ffi", "libcrypto", "libssl", "intl", "iconv", "charset", "bz2", "zlib", "ffi", "libcrypto", "libssl", "intl", "iconv", "charset", "bz2",
"Shell32", "Advapi32", "Dnsapi", "Shlwapi", "Iphlpapi") "Shell32", "Advapi32", "Dnsapi", "Shlwapi", "Iphlpapi")
target("linux_capture")
set_kind("binary")
add_packages("ffmpeg", "sdl2")
add_files("tests/peerconnection/linux_capture.cpp")
add_ldflags("-lavformat", "-lavdevice", "-lavfilter", "-lavcodec",
"-lswscale", "-lavutil", "-lswresample", "-lpostproc",
"-lasound", "-lxcb-shape", "-lxcb-xfixes", "-lsndio", "-lxcb",
"-lxcb-shm", "-lXext", "-lX11", "-lXv", "-lpthread", "-lx264", "-ldl", {force = true})