From 5c35e439d4c36da0fe85508c9efc0bed6f55ea78 Mon Sep 17 00:00:00 2001 From: zcy <290198252@qq.com> Date: Tue, 12 Oct 2021 15:36:03 +0800 Subject: [PATCH] add webrtc capture demo --- test/src/webrtcdemo/webrtcdemo.cpp | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test/src/webrtcdemo/webrtcdemo.cpp diff --git a/test/src/webrtcdemo/webrtcdemo.cpp b/test/src/webrtcdemo/webrtcdemo.cpp new file mode 100644 index 0000000..505c4f9 --- /dev/null +++ b/test/src/webrtcdemo/webrtcdemo.cpp @@ -0,0 +1,46 @@ +/* + * @Author: your name + * @Date: 2021-10-11 10:01:51 + * @LastEditTime: 2021-10-12 15:29:19 + * @LastEditors: Please set LastEditors + * @Description: In User Settings Edit + * @FilePath: \test_algorithm\webrtcdemo.cpp + */ + +#include + +#ifdef _WIN32 +#include +#pragma comment(lib,"d3d11.lib") +#endif + +#define WEBRTC_WIN + +#include "modules/desktop_capture/desktop_capturer.h" +#include "modules/desktop_capture/cropping_window_capturer.h" +#include "modules/desktop_capture/desktop_capture_options.h" +#include "modules/desktop_capture/screen_capturer_helper.h" +#include "modules/desktop_capture/desktop_frame.h" + +#include + +class CaptureCallBack :public webrtc::DesktopCapturer::Callback{ + virtual void OnCaptureResult(webrtc::DesktopCapturer::Result ret, + std::unique_ptr frame){ + if(ret == webrtc::DesktopCapturer::Result::SUCCESS){ + std::cout << "capture frame "<< frame.get()->size().width() << " " + << frame.get()->size().height()<<"\r\n"; + } + } +}; + +int main(int argc,char *argv[]){ + auto screen_capture_ = std::move(webrtc::DesktopCapturer::CreateScreenCapturer(webrtc::DesktopCaptureOptions::CreateDefault())); + screen_capture_->Start(new CaptureCallBack()); + while(true){ + std::cout<<"hello world\r\n"; + screen_capture_->CaptureFrame(); + Sleep(100); + } + return 0; +} \ No newline at end of file