Skip to content

refactor: desktop capturer module - #14835

Merged
zcbenz merged 4 commits into
masterfrom
desktop_media_patch
Oct 3, 2018
Merged

zcbenz merged 4 commits into
masterfrom
desktop_media_patch

Conversation

@deepak1556

@deepak1556 deepak1556 commented Sep 27, 2018 •

Copy link
Copy Markdown
Member
Description of Change
  • Reverts 5a28759, which was added during 66 upgrade to fix desktop capturer. The specs were failing because the capturer was being created on a thread that disallows sync primitives
 Check failed: !g_base_sync_primitives_disallowed.Get().Get(). Waiting on a //base sync primitive is not allowed on this thread to prevent jank and deadlock. If waiting on a //base sync primitive is unavoidable, do it within the scope of a ScopedAllowBaseSyncPrimitives. If in a test, use ScopedAllowBaseSyncPrimitivesForTesting.

hence the workaround of creating it on a separate thread which was causing incorrect usage of weak ptr as seen in #14816

Checklist
  • PR description included and stakeholders cc'd
  • npm test passes
  • tests are changed or added
  • relevant documentation is changed or added
  • PR title follows semantic commit guidelines
Release Notes

Notes: no-notes

@deepak1556
deepak1556 requested review from a team, MarshallOfSound and zcbenz September 27, 2018 10:17
@deepak1556

Copy link
Copy Markdown
Member Author

/cc @ilya-edrenkin this PR removes the patch created in electron/libchromiumcontent#418 , would like your review. Thanks!

@deepak1556 deepak1556 changed the title refactor: desktop capturer module [WIP] refactor: desktop capturer module Sep 27, 2018

// Initialize the source list.
if (source_lists_.empty()) {
std::vector<content::DesktopMediaID::Type> media_types = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) could be const

if (source_lists_.empty()) {
std::vector<content::DesktopMediaID::Type> media_types = {
content::DesktopMediaID::TYPE_SCREEN,
content::DesktopMediaID::TYPE_WINDOW};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to add overhead of forever owning and tracking an instance for screen tracking and an instance for window tracking even if the user is only tracking one of them.=

Is this intentional / desirable?

edit: OK after reading further it looks intentional since MediaCaptureDevicesDispatcher::CreateMediaList() can only be successfully called once, so this object must hold onto its pointers forever.

I am still learning context to the capture code so maybe there are reasons for this that I don't see, but this seems like an unintuitive API contact.

int new_index) = 0;
virtual void OnSourceNameChanged(DesktopMediaList* list, int index) = 0;
virtual void OnSourceThumbnailChanged(DesktopMediaList* list, int index) = 0;
+ virtual bool OnRefreshFinished(DesktopMediaList* list) = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could use a one-liner comment explaining what the bool retval signifies

std::vector<std::unique_ptr<DesktopMediaList>>
MediaCaptureDevicesDispatcher::CreateMediaList(
const std::vector<content::DesktopMediaID::Type>& types) {
// Keep same order as the input |sources| and avoid duplicates.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

input |types| ?

std::unique_ptr<DesktopMediaList> screen_list =
std::make_unique<NativeDesktopMediaList>(
content::DesktopMediaID::TYPE_SCREEN,
std::move(screen_capturer_));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that I understand this: MediaCaptureDevicesDispatcher is a singleton that gives up its screen_capturer_ unique ptr here. So CreateMediaList() can only be called successfully once?

If this is what we intend to ship, we should document it in a comment, or have the function throw if (!screen_capturer_) or something to signpost the expectations we have for the API.

MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher()
: is_device_enumeration_disabled_(false) {
: screen_capturer_(content::desktop_capture::CreateScreenCapturer()),
window_capturer_(content::desktop_capture::CreateWindowCapturer()),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

base::Singleton lazy-instantiates the MCDD, is that correct?

So we're not instantiating these capturers in every Electron instance whether the client asks for them or not?

@ckerr

ckerr commented Sep 27, 2018

Copy link
Copy Markdown
Member

FWIW the specs are passing for me locally:

$ uname -om
x86_64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.1 LTS
Release:	18.04
Codename:	bionic
$ eltest debug --ci -g desktopCapturer
starting dbus @ /tmp/electron.dbusmock.wsVvUDKcfl
starting /home/charles/electron/electron-gn/src/out/debug/electron
1..6
ok 1 desktopCapturer should return a non-empty array of sources
ok 2 desktopCapturer throws an error for invalid options
ok 3 desktopCapturer does not throw an error when called more than once (regression)
ok 4 desktopCapturer responds to subsequent calls of different options
ok 5 desktopCapturer returns an empty display_id for window sources on Windows and Mac
ok 6 desktopCapturer returns display_ids matching the Screen API on Windows and Mac
# tests 6
# pass 6
# fail 0

@ckerr ckerr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously CI needs to go green before merging, but the changes so far LGTM

@deepak1556
deepak1556 force-pushed the desktop_media_patch branch 2 times, most recently from 9a6d95c to 93a3d65 Compare October 2, 2018 08:59
}

void DesktopCapturer::OnSourceThumbnailChanged(int index) {}
if (!capture_window_ && !capture_screen_)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a machine does not have any screen or window, no event would be emitted, this leads to the timeout of tests since the results is empty on CI machines.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this check still has a failing "responds to subsequent calls of different options" test in Linux CI, because desktopCapturer.getSources({ types: ['window'] }, callback) is not returning any result.

From the comments of other tests this test should probably just be disabled on Linux?

@deepak1556 deepak1556 Oct 3, 2018 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a machine does not have any screen or window, no event would be emitted

Ah, missed that!

Removing this check still has a failing "responds to subsequent calls of different options" test in Linux CI,

Before this PR, the refresh method was called irrespective of whether sources were captured https://github.com/electron/electron/blob/master/chromium_src/chrome/browser/media/native_desktop_media_list.cc#L209, the upstream implementation only tries to schedule a new refresh when atleast one source is captured https://cs.chromium.org/chromium/src/chrome/browser/media/webrtc/native_desktop_media_list.cc?sq=package:chromium&g=0&l=312, hence this method would never be called. I am thinking of emitting a new observer event when the source list empty from DesktopMediaListbase::UpdateSourceList which would allow us handle this scenario, we can't move the refresh call outside the existing check because it would preemptively block thumbnail captures for aura windows.

* Creates the screen and window capturer for the liftime of the app
* Fixes incorrect usage of weak ptr
@deepak1556
deepak1556 force-pushed the desktop_media_patch branch from 93a3d65 to 00db215 Compare October 3, 2018 06:57
@deepak1556
deepak1556 force-pushed the desktop_media_patch branch from 00db215 to 1711010 Compare October 3, 2018 08:12
@deepak1556 deepak1556 changed the title [WIP] refactor: desktop capturer module refactor: desktop capturer module Oct 3, 2018
@deepak1556

Copy link
Copy Markdown
Member Author

@zcbenz the specs pass now. Thanks!

@zcbenz zcbenz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@zcbenz

zcbenz commented Oct 3, 2018

Copy link
Copy Markdown
Contributor

The failed macOS tests are not related to this PR, I'm merging this with them ignored.

@zcbenz
zcbenz merged commit 596ae2c into master Oct 3, 2018
@release-clerk

release-clerk Bot commented Oct 3, 2018

Copy link
Copy Markdown

No Release Notes

@zcbenz
zcbenz deleted the desktop_media_patch branch October 3, 2018 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants