That should get you started.
#include "modules/video_capture/video_capture.h"
#include "media/base/adapted_video_track_source.h"
#include "rtc_base/logging.h"
//Abstract class
class my_VideoSource : public rtc::AdaptedVideoTrackSource, public rtc::VideoSinkInterface<webrtc::VideoFrame>
{
public:
my_VideoSource();
virtual ~my_VideoSource();
virtual webrtc::MediaSourceInterface::SourceState Start(const webrtc::VideoCaptureCapability& requested_cap) = 0;
virtual void Stop() = 0;
virtual bool IsRunning() = 0;
virtual bool IsScreencast() const = 0;
bool is_screencast() const override { return IsScreencast(); }
absl::optional<bool> needs_denoising() const override { return false; }
bool remote() const override { return false; }
webrtc::MediaSourceInterface::SourceState state() const override;
// If true, run video adaptation. By default, video adaptation is enabled
// and users must call video_adapter()->OnOutputFormatRequest()
// to receive frames.
bool enable_video_adapter() const { return enable_video_adapter_; }
void set_enable_video_adapter(bool enable_video_adapter) {
enable_video_adapter_ = enable_video_adapter;
}
virtual bool adaptVideoFormat(const VideoFormat& format) = 0;
protected:
RTC_DISALLOW_COPY_AND_ASSIGN(VideoSource);
webrtc::MediaSourceInterface::SourceState state_;
bool enable_video_adapter_;
};
#include <mutex>
#include <thread>
#include "rtc_base/ref_counted_object.h"
#include "rtc_base/thread.h"
#include "modules/desktop_capture/desktop_capturer.h"
#include "VideoSource.h"
namespace webrtc { class DesktopFrame;
} // namespace webrtc
const int kDefaultDpi = 96;
// This class controls the capture of video frames from the desktop and is used
// to construct a my_VideoSource as part of the webrtc PeerConnection API.
// DesktopCapturerAdapter acts as an adapter between webrtc::DesktopCapturer
// and the cricket::VideoCapturer interface, which it implements. It is used
// to construct a cricket::VideoSource for a PeerConnection, to capture frames
// of the desktop. As indicated in the base implementation, Start() and Stop()
// should be called on the same thread.
class my_DesktopSourceAdapter : public my_VideoSource, public webrtc::DesktopCapturer::Callback
{public:
my_DesktopSourceAdapter(bool isScreenCapture);
virtual ~my_DesktopSourceAdapter();
webrtc::MediaSourceInterface::SourceState Start(const webrtc::VideoCaptureCapability& not_used) override;
void Stop() override;
bool IsRunning() override;
bool IsScreencast() const override { return true; }; void setSource(uint32_t id);
bool adaptVideoFormat(const VideoFormat& format) override { RTC_LOG(INFO) << "DesktopSourceAdapter::adaptVideoFormat Not implemented yet.";
return false;
}
private:
// webrtc::DesktopCapturer::Callback implementation.
void OnCaptureResult(webrtc::DesktopCapturer::Result result, std::unique_ptr<webrtc::DesktopFrame> frame) override;
// Kicks off the next frame capture using |desktop_capturer_|. The captured frame will be passed to OnCaptureCompleted().
void CaptureNextFrame();
void OnFrame(const webrtc::VideoFrame& frame) override;
// This is where the capture is actually happening
// the timing of the capture (to achieve 30fps) is
// also handled there.
bool enable_video_adapter() const { return enable_video_adapter_; } void set_enable_video_adapter(bool enable_video_adapter) { enable_video_adapter_ = enable_video_adapter;
}
bool enable_video_adapter_;
std::unique_ptr<webrtc::DesktopCapturer> desktop_capturer_;
volatile bool capture_pending_ = false;
volatile bool running = false;
std::mutex mutex;
std::thread timer;
std::condition_variable condition;
rtc::Thread* desktopCapturerThread;
void SignalFrameCapturedOnStartThread(const webrtc::VideoFrame& frame);
};