Bug 1456101 - ensure X11 DesktopCapture module is created on main thread
MozReview-Commit-ID: 8lP03135ttK
--- a/dom/media/systemservices/VideoEngine.cpp
+++ b/dom/media/systemservices/VideoEngine.cpp
@@ -63,19 +63,35 @@ VideoEngine::CreateVideoCapture(int32_t&
CaptureEntry entry = {-1, nullptr};
if (mCaptureDevInfo.type == webrtc::CaptureDeviceType::Camera) {
entry = CaptureEntry(id,
webrtc::VideoCaptureFactory::Create(deviceUniqueIdUTF8));
} else {
#ifndef WEBRTC_ANDROID
+#ifdef MOZ_X11
+ webrtc::VideoCaptureModule* captureModule;
+ auto type = mCaptureDevInfo.type;
+ nsresult result = NS_DispatchToMainThread(media::NewRunnableFrom(
+ [&captureModule, id, deviceUniqueIdUTF8, type]() -> nsresult {
+ captureModule = webrtc::DesktopCaptureImpl::Create(id, deviceUniqueIdUTF8, type);
+ return NS_OK;
+ }), nsIEventTarget::DISPATCH_SYNC);
+
+ if (result == NS_OK) {
+ entry = CaptureEntry(id, captureModule);
+ } else {
+ return;
+ }
+#else
entry = CaptureEntry(
id,
webrtc::DesktopCaptureImpl::Create(id, deviceUniqueIdUTF8, mCaptureDevInfo.type));
+#endif
#else
MOZ_ASSERT("CreateVideoCapture NO DESKTOP CAPTURE IMPL ON ANDROID" == nullptr);
#endif
}
mCaps.emplace(id, std::move(entry));
mIdMap.emplace(id, id);
}
--- a/media/webrtc/trunk/webrtc/video_engine/desktop_capture_impl.cc
+++ b/media/webrtc/trunk/webrtc/video_engine/desktop_capture_impl.cc
@@ -443,33 +443,38 @@ DesktopCaptureImpl::DesktopCaptureImpl(c
// XXX Note that this won't capture drift!
delta_ntp_internal_ms_(Clock::GetRealTimeClock()->CurrentNtpInMilliseconds() -
last_capture_time_),
time_event_(EventWrapper::Create()),
mRefCount(0),
#if defined(_WIN32)
capturer_thread_(new rtc::PlatformUIThread(Run, this, "ScreenCaptureThread")),
#else
+#if defined(WEBRTC_LINUX)
+ capturer_thread_(nullptr),
+#else
capturer_thread_(new rtc::PlatformThread(Run, this, "ScreenCaptureThread")),
#endif
+#endif
started_(false) {
//-> TODO @@NG why is this crashing (seen on Linux)
//-> capturer_thread_->SetPriority(rtc::kHighPriority);
_requestedCapability.width = kDefaultWidth;
_requestedCapability.height = kDefaultHeight;
_requestedCapability.maxFPS = 30;
_requestedCapability.rawType = kVideoI420;
_requestedCapability.codecType = kVideoCodecUnknown;
memset(_incomingFrameTimesNanos, 0, sizeof(_incomingFrameTimesNanos));
}
DesktopCaptureImpl::~DesktopCaptureImpl() {
time_event_->Set();
- capturer_thread_->Stop();
-
+ if (capturer_thread_) {
+ capturer_thread_->Stop();
+ }
delete &_callBackCs;
delete &_apiCs;
}
void DesktopCaptureImpl::RegisterCaptureDataCallback(rtc::VideoSinkInterface<VideoFrame> *dataCallback)
{
CriticalSectionScoped cs(&_apiCs);
CriticalSectionScoped cs2(&_callBackCs);
@@ -659,17 +664,23 @@ int32_t DesktopCaptureImpl::StartCapture
#if defined(_WIN32)
uint32_t maxFPSNeeded = 1000/_requestedCapability.maxFPS;
capturer_thread_->RequestCallbackTimer(maxFPSNeeded);
#endif
if (started_) {
return 0;
}
-
+#if defined(WEBRTC_LINUX)
+ // Lazily init capturer_thread_
+ if (!capturer_thread_) {
+ capturer_thread_ = std::unique_ptr<rtc::PlatformThread>(
+ new rtc::PlatformThread(Run, this, "ScreenCaptureThread"));
+ }
+#endif
desktop_capturer_cursor_composer_->Start(this);
capturer_thread_->Start();
started_ = true;
return 0;
}
bool DesktopCaptureImpl::FocusOnSelectedSource()