playwright/browser_patches/firefox/juggler/screencast/HeadlessWindowCapturer.h
Yury Semikhatsky 02aa31048c
browser(firefox): cross thread sync in screencast (#16320)
* nsIScreencastServiceClient is not thread safe refcounted so we make nsScreencastService::Session a thread safe refcounted object and keep it alive while there are inflight frames. Once such frames get handled on the main thread we check if the session has been stopped.
* Removed mCaptureCallbackCs in favor of atomic counter (mClient is not accessed only on the main thread).
* HeadlessWindowCapturer now holds RefPtr to the headless window object to avoid use after free when clearing it as a listener on the widget.
* ScreencastEncoder is not ref counted anymore.

Pretty-diff: 5f5042ff1e
2022-08-05 15:25:26 -07:00

65 lines
2.2 KiB
C++

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#pragma once
#include <memory>
#include <set>
#include "api/video/video_frame.h"
#include "api/video/video_sink_interface.h"
#include "modules/video_capture/video_capture.h"
#include "rtc_base/deprecated/recursive_critical_section.h"
#include "video_engine/desktop_capture_impl.h"
class nsIWidget;
namespace mozilla {
namespace widget {
class HeadlessWidget;
}
class HeadlessWindowCapturer : public webrtc::VideoCaptureModuleEx {
public:
static rtc::scoped_refptr<webrtc::VideoCaptureModuleEx> Create(mozilla::widget::HeadlessWidget*);
void RegisterCaptureDataCallback(
rtc::VideoSinkInterface<webrtc::VideoFrame>* dataCallback) override;
void DeRegisterCaptureDataCallback(
rtc::VideoSinkInterface<webrtc::VideoFrame>* dataCallback) override;
int32_t StopCaptureIfAllClientsClose() override;
void RegisterRawFrameCallback(webrtc::RawFrameCallback* rawFrameCallback) override;
void DeRegisterRawFrameCallback(webrtc::RawFrameCallback* rawFrameCallback) override;
int32_t SetCaptureRotation(webrtc::VideoRotation) override { return -1; }
bool SetApplyRotation(bool) override { return false; }
bool GetApplyRotation() override { return true; }
const char* CurrentDeviceName() const override { return "Headless window"; }
// Platform dependent
int32_t StartCapture(const webrtc::VideoCaptureCapability& capability) override;
bool FocusOnSelectedSource() override { return false; }
int32_t StopCapture() override;
bool CaptureStarted() override;
int32_t CaptureSettings(webrtc::VideoCaptureCapability& settings) override {
return -1;
}
protected:
HeadlessWindowCapturer(mozilla::widget::HeadlessWidget*);
~HeadlessWindowCapturer() override;
private:
void NotifyFrameCaptured(const webrtc::VideoFrame& frame);
RefPtr<mozilla::widget::HeadlessWidget> mWindow;
rtc::RecursiveCriticalSection _callBackCs;
std::set<rtc::VideoSinkInterface<webrtc::VideoFrame>*> _dataCallBacks;
std::set<webrtc::RawFrameCallback*> _rawFrameCallbacks;
};
} // namespace mozilla