# Conflicts:
#	test/src/webrtcdemo/CMakeLists.txt
#	test/src/webrtcdemo/webrtcdemo.cpp
master
zcy 2021-10-19 00:43:09 +08:00
commit 770cda1e03
2 changed files with 167 additions and 14 deletions

View File

@ -1,27 +1,46 @@
cmake_minimum_required(VERSION 3.12) cmake_minimum_required(VERSION 3.12)
project(test_algorithm)
project(test)
project(webrtcdemo) project(webrtcdemo)
project(stunserver) project(stunserver)
project(turnserver) project(turnserver)
project(stunprober) project(stunprober)
<<<<<<< HEAD
add_definitions(-std=c++11 "/DWIN32_LEAN_AND_MEAN" "/Mdd" "/DWEBRTC_WIN") add_definitions(-std=c++11 "/DWIN32_LEAN_AND_MEAN" "/Mdd" "/DWEBRTC_WIN")
=======
add_definitions(-std=c++11 "/DWIN32_LEAN_AND_MEAN")
>>>>>>> fc51075a61ea3d0ec07cbba77045e13b1c51b3a5
message("current dir" ${CMAKE_CURRENT_SOURCE_DIR}) message("current dir" ${CMAKE_CURRENT_SOURCE_DIR})
# set(CMAKE_CXX_FLAGS "-fno-elide-constructors") # set(CMAKE_CXX_FLAGS "-fno-elide-constructors")
aux_source_directory(. SOURCE) aux_source_directory(. SOURCE)
message(info ${SOURCE}) message(info ${SOURCE})
link_directories("${CMAKE_CURRENT_SOURCE_DIR}/third/lib") link_directories("${CMAKE_CURRENT_SOURCE_DIR}/third/xlnt/lib/Debug")
link_directories("${CMAKE_CURRENT_SOURCE_DIR}/third/opencv/staticlib") link_directories("${CMAKE_CURRENT_SOURCE_DIR}/third/xlnt/lib/Release")
link_directories("${CMAKE_CURRENT_SOURCE_DIR}/third/webrc/lib")
link_directories("${CMAKE_CURRENT_SOURCE_DIR}/third/libpng/lib")
link_directories("${CMAKE_CURRENT_SOURCE_DIR}/third/zlib/lib")
<<<<<<< HEAD
link_libraries( libwebrtc.lib ws2_32.lib winmm.lib DXGI.lib) link_libraries( libwebrtc.lib ws2_32.lib winmm.lib DXGI.lib)
=======
link_libraries(xlntd libwebrtc.lib ws2_32.lib winmm.lib libpng16_staticd zlibstaticd.lib DXGI.lib)
>>>>>>> fc51075a61ea3d0ec07cbba77045e13b1c51b3a5
message(${CMAKE_CURRENT_SOURCE_DIR}/third/include) include_directories("${CMAKE_CURRENT_SOURCE_DIR}third/xlnt/include")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/third/include") message(${CMAKE_CURRENT_SOURCE_DIR}/third/webrc/include)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/third/opencv/include") include_directories("${CMAKE_CURRENT_SOURCE_DIR}/third/webrc/include")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/third/opencv/staticlib") include_directories("${CMAKE_CURRENT_SOURCE_DIR}/third/libpng/include")
<<<<<<< HEAD
add_executable(webrtcdemo webrtcdemo.cpp) add_executable(webrtcdemo webrtcdemo.cpp)
add_executable(stunserver stunserver/stunserver_main.cc) add_executable(stunserver stunserver/stunserver_main.cc)
add_executable(turnserver turnserver/read_auth_file.cc turnserver/turnserver_main.cc) add_executable(turnserver turnserver/read_auth_file.cc turnserver/turnserver_main.cc)
add_executable(stunprober stunprober/main.cc) add_executable(stunprober stunprober/main.cc)
=======
add_executable(test_algorithm ./JudgeFault.cpp ./main.cpp )
add_executable(test test.cpp JudgeFault.cpp)
add_executable(webrtcdemo webrtcdemo.cpp)
>>>>>>> fc51075a61ea3d0ec07cbba77045e13b1c51b3a5

View File

@ -1,7 +1,11 @@
/* /*
* @Author: your name * @Author: your name
* @Date: 2021-10-11 10:01:51 * @Date: 2021-10-11 10:01:51
<<<<<<< HEAD
* @LastEditTime: 2021-10-17 11:23:29 * @LastEditTime: 2021-10-17 11:23:29
=======
* @LastEditTime: 2021-10-13 11:46:58
>>>>>>> fc51075a61ea3d0ec07cbba77045e13b1c51b3a5
* @LastEditors: Please set LastEditors * @LastEditors: Please set LastEditors
* @Description: In User Settings Edit * @Description: In User Settings Edit
* @FilePath: \test_algorithm\webrtcdemo.cpp * @FilePath: \test_algorithm\webrtcdemo.cpp
@ -11,7 +15,7 @@
#ifdef _WIN32 #ifdef _WIN32
#include <Windows.h> #include <Windows.h>
#pragma comment(lib,"d3d11.lib") #pragma comment(lib, "d3d11.lib")
#endif #endif
#define WEBRTC_WIN #define WEBRTC_WIN
@ -23,24 +27,154 @@
#include "modules/desktop_capture/desktop_frame.h" #include "modules/desktop_capture/desktop_frame.h"
#include <iostream> #include <iostream>
#include "png.h"
/******************************图片数据*********************************/
typedef struct _pic_data pic_data;
struct _pic_data
{
int width, height; /* 尺寸 */
int bit_depth; /* 位深 */
int flag; /* 一个标志表示是否有alpha通道 */
class CaptureCallBack :public webrtc::DesktopCapturer::Callback{ unsigned char **rgba; /* 图片数组 */
};
/**********************************************************************/
#define PNG_BYTES_TO_CHECK 4
#define HAVE_ALPHA 1
#define NO_ALPHA 0
int write_png_file(char *file_name, pic_data *graph)
/* 功能将LCUI_Graph结构中的数据写入至png文件 */
{
int j, i, temp, pos;
png_byte color_type;
png_structp png_ptr;
png_infop info_ptr;
png_bytep *row_pointers;
/* create file */
FILE *fp = fopen(file_name, "wb");
if (!fp)
{
printf("[write_png_file] File %s could not be opened for writing", file_name);
return -1;
}
/* initialize stuff */
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr)
{
printf("[write_png_file] png_create_write_struct failed");
return -1;
}
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
printf("[write_png_file] png_create_info_struct failed");
return -1;
}
if (setjmp(png_jmpbuf(png_ptr)))
{
printf("[write_png_file] Error during init_io");
return -1;
}
png_init_io(png_ptr, fp);
/* write header */
if (setjmp(png_jmpbuf(png_ptr)))
{
printf("[write_png_file] Error during writing header");
return -1;
}
/* 判断要写入至文件的图片数据是否有透明度,来选择色彩类型 */
if (graph->flag == HAVE_ALPHA)
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
else
color_type = PNG_COLOR_TYPE_RGB;
png_set_IHDR(png_ptr, info_ptr, graph->width, graph->height,
graph->bit_depth, color_type, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_write_info(png_ptr, info_ptr);
/* write bytes */
if (setjmp(png_jmpbuf(png_ptr)))
{
printf("[write_png_file] Error during writing bytes");
return -1;
}
if (graph->flag == HAVE_ALPHA)
temp = (4 * graph->width);
else
temp = (3 * graph->width);
pos = 0;
row_pointers = (png_bytep *)malloc(graph->height * sizeof(png_bytep));
for (i = 0; i < graph->height; i++)
{
row_pointers[i] = ((png_bytep )malloc(temp));
memcpy(row_pointers[i],*graph->rgba + i*temp,temp);
}
png_write_image(png_ptr, row_pointers);
/* end write */
if (setjmp(png_jmpbuf(png_ptr)))
{
printf("[write_png_file] Error during end of write");
return -1;
}
png_write_end(png_ptr, NULL);
/* cleanup heap allocation */
for (j = 0; j < graph->height; j++)
free(row_pointers[j]);
free(row_pointers);
fclose(fp);
return 0;
}
class CaptureCallBack : public webrtc::DesktopCapturer::Callback
{
virtual void OnCaptureResult(webrtc::DesktopCapturer::Result ret, virtual void OnCaptureResult(webrtc::DesktopCapturer::Result ret,
<<<<<<< HEAD
std::unique_ptr<webrtc::DesktopFrame> frame){ std::unique_ptr<webrtc::DesktopFrame> frame){
if(ret == webrtc::DesktopCapturer::Result::SUCCESS){ if(ret == webrtc::DesktopCapturer::Result::SUCCESS){
std::cout std::cout
<< "capture frame " << "capture frame "
<< frame.get()->size().width() << " " << frame.get()->size().width() << " "
<< frame.get()->size().height() << "\r\n"; << frame.get()->size().height() << "\r\n";
=======
std::unique_ptr<webrtc::DesktopFrame> frame)
{
if (ret == webrtc::DesktopCapturer::Result::SUCCESS)
{
std::cout << "capture frame " << frame.get()->size().width() << " "
<< frame.get()->size().height() << "\r\n " << frame.get()->capture_time_ms() << " " << frame.get()->stride() << "\r\n";
pic_data pic;
pic.width = frame.get()->size().width();
pic.height = frame.get()->size().height();
auto data = frame.get()->data();
pic.rgba = (uint8_t**)(&(data));
pic.bit_depth = 8;
pic.flag = 1;
write_png_file("test.png",&pic);
exit(0);
>>>>>>> fc51075a61ea3d0ec07cbba77045e13b1c51b3a5
} }
} }
}; };
int main(int argc,char *argv[]){ int main(int argc, char *argv[])
auto screen_capture_ = std::move(webrtc::DesktopCapturer::CreateScreenCapturer(webrtc::DesktopCaptureOptions::CreateDefault())); {
auto screen_capture_ =
std::move(webrtc::DesktopCapturer::CreateScreenCapturer(webrtc::DesktopCaptureOptions::CreateDefault()));
screen_capture_->Start(new CaptureCallBack()); screen_capture_->Start(new CaptureCallBack());
while(true){ while (true)
std::cout<<"hello world\r\n"; {
screen_capture_->CaptureFrame(); screen_capture_->CaptureFrame();
Sleep(100); Sleep(100);
} }