From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Thu, 18 Oct 2018 17:07:01 -0700 Subject: desktop_media_list.patch * Expose the capturer source list for the desktopCapturer API * Free the one-time use capturer after thumbnails are fetched diff --git a/chrome/browser/media/webrtc/desktop_media_list.h b/chrome/browser/media/webrtc/desktop_media_list.h index cf7deb678217727e7fe0deed1663b5174164f040..d947051b1cdb36e20a3d9ed29b2172b83eaedf9d 100644 --- a/chrome/browser/media/webrtc/desktop_media_list.h +++ b/chrome/browser/media/webrtc/desktop_media_list.h @@ -52,6 +52,9 @@ class DesktopMediaList { virtual ~DesktopMediaList() {} + // Allows listening to notifications generated by the model. + virtual void AddObserver(DesktopMediaListObserver* observer) = 0; + // Sets time interval between updates. By default list of sources and their // thumbnail are updated once per second. If called after StartUpdating() then // it will take effect only after the next update. @@ -83,6 +86,7 @@ class DesktopMediaList { virtual int GetSourceCount() const = 0; virtual const Source& GetSource(int index) const = 0; + virtual const std::vector& GetSources() const = 0; virtual Type GetMediaListType() const = 0; }; diff --git a/chrome/browser/media/webrtc/desktop_media_list_base.cc b/chrome/browser/media/webrtc/desktop_media_list_base.cc index bce801e2538ec1391e067822f7fda1248cd7c516..4efcf50745b27e66c8f544072993c9bd4490782e 100644 --- a/chrome/browser/media/webrtc/desktop_media_list_base.cc +++ b/chrome/browser/media/webrtc/desktop_media_list_base.cc @@ -24,6 +24,11 @@ DesktopMediaListBase::DesktopMediaListBase(base::TimeDelta update_period, DesktopMediaListBase::~DesktopMediaListBase() = default; +void DesktopMediaListBase::AddObserver(DesktopMediaListObserver* observer) { + DCHECK(!observer_); + observer_ = observer; +} + void DesktopMediaListBase::SetUpdatePeriod(base::TimeDelta period) { DCHECK(!observer_); update_period_ = period; @@ -58,7 +63,7 @@ void DesktopMediaListBase::Update(UpdateCallback callback) { DCHECK(sources_.empty()); DCHECK(!refresh_callback_); refresh_callback_ = std::move(callback); - Refresh(false); + Refresh(true); } int DesktopMediaListBase::GetSourceCount() const { @@ -72,6 +77,11 @@ const DesktopMediaList::Source& DesktopMediaListBase::GetSource( return sources_[index]; } +const std::vector& DesktopMediaListBase::GetSources() + const { + return sources_; +} + DesktopMediaList::Type DesktopMediaListBase::GetMediaListType() const { return type_; } @@ -83,6 +93,12 @@ DesktopMediaListBase::SourceDescription::SourceDescription( void DesktopMediaListBase::UpdateSourcesList( const std::vector& new_sources) { + // Notify observer when there was no new source captured. + if (new_sources.empty()) { + observer_->OnSourceUnchanged(this); + return; + } + typedef std::set SourceSet; SourceSet new_source_set; for (size_t i = 0; i < new_sources.size(); ++i) { diff --git a/chrome/browser/media/webrtc/desktop_media_list_base.h b/chrome/browser/media/webrtc/desktop_media_list_base.h index 0c2b98182a8397d2fb0334ea9619f65222c59467..3340c0060ee7475a8c64de3a1cee9dba24d4a732 100644 --- a/chrome/browser/media/webrtc/desktop_media_list_base.h +++ b/chrome/browser/media/webrtc/desktop_media_list_base.h @@ -27,6 +27,7 @@ class DesktopMediaListBase : public DesktopMediaList { ~DesktopMediaListBase() override; // DesktopMediaList interface. + void AddObserver(DesktopMediaListObserver* observer) override; void SetUpdatePeriod(base::TimeDelta period) override; void SetThumbnailSize(const gfx::Size& thumbnail_size) override; void SetViewDialogWindowId(content::DesktopMediaID dialog_id) override; @@ -34,6 +35,7 @@ class DesktopMediaListBase : public DesktopMediaList { void Update(UpdateCallback callback) override; int GetSourceCount() const override; const Source& GetSource(int index) const override; + const std::vector& GetSources() const override; DesktopMediaList::Type GetMediaListType() const override; static uint32_t GetImageHash(const gfx::Image& image); diff --git a/chrome/browser/media/webrtc/desktop_media_list_observer.h b/chrome/browser/media/webrtc/desktop_media_list_observer.h index ad7f766a36b1b6b2a8bc0f96369f1aaadf6681f7..f6c6c14a0937430df62c9b9c1132c5916a9f2009 100644 --- a/chrome/browser/media/webrtc/desktop_media_list_observer.h +++ b/chrome/browser/media/webrtc/desktop_media_list_observer.h @@ -20,6 +20,7 @@ class DesktopMediaListObserver { int new_index) = 0; virtual void OnSourceNameChanged(DesktopMediaList* list, int index) = 0; virtual void OnSourceThumbnailChanged(DesktopMediaList* list, int index) = 0; + virtual void OnSourceUnchanged(DesktopMediaList* list) = 0; protected: virtual ~DesktopMediaListObserver() {} diff --git a/chrome/browser/media/webrtc/native_desktop_media_list.cc b/chrome/browser/media/webrtc/native_desktop_media_list.cc index 8958de11bc10fc50929a552e9a454b6c143d5713..c2d223f527014ecdcccee78194577a31514fc0c9 100644 --- a/chrome/browser/media/webrtc/native_desktop_media_list.cc +++ b/chrome/browser/media/webrtc/native_desktop_media_list.cc @@ -10,14 +10,15 @@ #include "base/hash/hash.h" #include "base/message_loop/message_pump_type.h" #include "base/single_thread_task_runner.h" +#include "base/strings/string_number_conversions.h" #include "base/strings/utf_string_conversions.h" #include "base/threading/thread_restrictions.h" #include "base/threading/thread_task_runner_handle.h" #include "build/build_config.h" #include "chrome/browser/media/webrtc/desktop_media_list.h" -#include "chrome/grit/generated_resources.h" #include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_thread.h" +#include "electron/grit/electron_resources.h" #include "media/base/video_util.h" #include "third_party/libyuv/include/libyuv/scale_argb.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -259,6 +260,8 @@ void NativeDesktopMediaList::Worker::RefreshNextThumbnail() { FROM_HERE, base::BindOnce(&NativeDesktopMediaList::UpdateNativeThumbnailsFinished, media_list_)); + + capturer_.reset(); } void NativeDesktopMediaList::Worker::OnCaptureResult(