add webrtc capture demo

master
zcy 2021-10-12 15:36:03 +08:00
parent 7f2c81bbb2
commit 5c35e439d4
1 changed files with 46 additions and 0 deletions

View File

@ -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 <iostream>
#ifdef _WIN32
#include <Windows.h>
#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 <iostream>
class CaptureCallBack :public webrtc::DesktopCapturer::Callback{
virtual void OnCaptureResult(webrtc::DesktopCapturer::Result ret,
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";
}
}
};
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;
}