Screenshare using getUserMedia

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Screenshare using getUserMedia

Postby askelton » Fri May 19, 2017 3:48 am

Hi,

I'm trying to do screen sharing using cefclient by navigating to a page that has the following javascript. I'm using release 3107 on Windows 7.
Code: Select all
    var conf = {
        mandatory: {
            chromeMediaSource: 'desktop',
            chromeMediaSourceId: 'screen:0',
            maxWidth: 1280,
            maxHeight: 720
        },
        optional: []
    };

    navigator.getUserMedia({audio: false, video: conf},function(stream) {
        console.log('success');
        //set the URL of the video element...
    },function(e){
        console.log(e);
        alert(e);
    })


This kind of approach apparently used to work, according to this post: http://arkenthera.github.io/blog/Enabling-CEF-to-Screen-Share-using-getUserMedia-API/

However, CEF (or Chromium?) doesn't seem to like the chromeMediaSourceId that I'm passing in, and the whole app crashes when calling getUserMedia. If I pass in a random numeric value of three or more digits, it gets as far as CefBrowserHostImpl::RequestMediaAccessPermission(..) and then errors because of the invalid ID, but when I use 'screen:0' it doesn't even get that far before dying.

According to the following (NW.js rather than CEF, but a similar concept), Chromium now requires you to register the screen ID with DesktopStreamsRegistry, which will give you an encrypted string to pass into getUserMedia. This is how Chrome's desktopCapture extension works, and NW.js have fixed their issue by exposing this screen ID registering process in their API.

https://github.com/nwjs/nw.js/issues/4459

I can't see any way of doing this in CEF. Am I missing something, or am I just doing something wrong somewhere?

Thanks.
askelton
Newbie
 
Posts: 1
Joined: Fri May 19, 2017 3:21 am

Re: Screenshare using getUserMedia

Postby mbeale » Wed May 24, 2017 2:08 pm

I have the same issue - would appreciate any help on this. Can we actually do this with CEF as of now?
mbeale
Newbie
 
Posts: 6
Joined: Wed May 24, 2017 2:05 pm

Re: Screenshare using getUserMedia

Postby magreenblatt » Fri May 26, 2017 3:57 pm

Support was added recently in https://bitbucket.org/chromiumembedded/ ... sed-screen. What OS and CEF version are you using? What URL are you testing with?
magreenblatt
Site Admin
 
Posts: 12407
Joined: Fri May 29, 2009 6:57 pm

Re: Screenshare using getUserMedia

Postby JasonLP » Tue May 30, 2017 2:25 pm

Try specifying the source id as 'screen:0:0'

I'm not sure what the extra ':0' is for, but I noticed around Chromium version 49 that the format for the source id changed for Windows.
JasonLP
Mentor
 
Posts: 98
Joined: Fri Jul 25, 2014 10:10 am

Re: Screenshare using getUserMedia

Postby mbeale » Wed May 31, 2017 4:47 am

Thanks for both comments. I'm running on Windows 10 (have also tried 7), CEF distribution version (3.3029.1619.geeeb5d7) which is the current master.

I have some javascript on a local page loaded by a modified cefclient/cefsimple calling getUserMedia with {audio: false, video: conf}, where conf is along the lines of var conf = {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: 'screen:0',
maxWidth: 1280,
maxHeight: 720
},
optional: []
};

The html has a video element in it.

Am pretty sure that have tried screen:0:0 to no avail. Without the chromeMediaSourceId parameter, the screen is captured and rendered locally happily. With the parameter, the application crashes.

What I'd really like to do is be able to specify an application 'window' as the sourceId - as suggested by the page http://arkenthera.github.io/blog/Enabli ... Media-API/, am using 'window:HWND id' where HWND id is an intptr_t cast of the required HWND. (Have also tried slightly variant forms).

From what I and Andrew Skelton can see from the CEF code, the desktop share patch which was part of https://bitbucket.org/chromiumembedded/ ... sed-screen is now on the head?? Is this the case? Also, is this the right way to go about sharing an application window (as opposed to a whole screen/desktop?) - or is that not possible currently?

Am at the moment building the CEF source on my slow-ish machine, with the aim of debugging.

Thank you!
Mike Beale
mbeale
Newbie
 
Posts: 6
Joined: Wed May 24, 2017 2:05 pm

Re: Screenshare using getUserMedia

Postby JasonLP » Wed May 31, 2017 9:08 am

mbeale wrote:Am pretty sure that have tried screen:0:0 to no avail. Without the chromeMediaSourceId parameter, the screen is captured and rendered locally happily. With the parameter, the application crashes.

That makes sense--Without the media source id, it uses a default, which is the entire screen ('screen:-1:0' I believe). Are you certain that screen:0:0 doesn't work?

What I'd really like to do is be able to specify an application 'window' as the sourceId - as suggested by the page http://arkenthera.github.io/blog/Enabli ... Media-API/, am using 'window:HWND id' where HWND id is an intptr_t cast of the required HWND. (Have also tried slightly variant forms).

I am doing this exactly. But just as with the screen, I found that it is necessary to add an additional ':0' to the end, so it might look something like 'window:239552:0'. Looking at the source code, it's based on a define for USE_AURA, but I don't know what this is. Check out content/public/browser/desktop_media_id.cc to see what's going on.
JasonLP
Mentor
 
Posts: 98
Joined: Fri Jul 25, 2014 10:10 am

Re: Screenshare using getUserMedia

Postby mbeale » Wed May 31, 2017 9:44 am

Thanks Jason. Yeah, saw that the AURA flag.

So this is what I'm seeing in my debug log with different combinations (unfortunately only FATAL and ERROR at moment):

1)
chromeMediaSource: 'screen',
chromeMediaSourceId: 'irrelevant' //- always shares whole screen!

That works...

2)
chromeMediaSource: 'desktop',
chromeMediaSourceId: 'window:132952:0' //- a valid window id. Tried hex equivalent 20758 also.

App doesn't crash, but nothing shared, and see in log:
[0531/153357.493:ERROR:video_capture_device_client.cc(412)] error@ DoStartDesktopCaptureOnDeviceThread@y:\work\cef3_git\chromium\src\content\browser\renderer_host\media\video_capture_manager.cc:703, Could not create capture device, OS message: The operation completed successfully. (0x0)

3)
chromeMediaSource: 'desktop',
chromeMediaSourceId: 'window:132952 //- a valid window id but without ':0' appended.

App crashes with:
[0531/153503.421:FATAL:desktop_media_id.cc(177)] Check failed: false.

That follows what you said about the extra AURA param...


4)
chromeMediaSource: 'window',
chromeMediaSourceId: 'window:132952:0' //- a valid window id.

App crashes with:
[0531/153642.751:FATAL:media_stream_manager.cc(823)] Check failed: false.

5)
chromeMediaSource: desktop,
chromeMediaSourceId: screen:0:0'

Works, shares screen.

6)
chromeMediaSource: 'desktop',
chromeMediaSourceId: 'window:5474378:0' //- an invalid window id

As with 2), which seems to suggest that the problem is that it can't do anything with the window specified in 2)??

Any ideas?
mbeale
Newbie
 
Posts: 6
Joined: Wed May 24, 2017 2:05 pm

Re: Screenshare using getUserMedia

Postby mbeale » Wed May 31, 2017 9:59 am

mbeale wrote:Thanks Jason. Yeah, saw that the AURA flag.

2)
chromeMediaSource: 'desktop',
chromeMediaSourceId: 'window:132952:0' //- a valid window id. Tried hex equivalent 20758 also.



Correction - for this scenario, I DO get a crash, with error:
[0531/155613.799:FATAL:desktop_capture_device.cc(228)] Check failed: frame.

sometimes followed by multiple:
[0531/155618.976:WARNING:gpu.cc(124)] Channel encountered error while establishing gpu channel.
mbeale
Newbie
 
Posts: 6
Joined: Wed May 24, 2017 2:05 pm

Re: Screenshare using getUserMedia

Postby JasonLP » Wed May 31, 2017 10:14 am

mbeale wrote:2)
chromeMediaSource: 'desktop',
chromeMediaSourceId: 'window:132952:0' //- a valid window id. Tried hex equivalent 20758 also.

App doesn't crash, but nothing shared, and see in log:
[0531/153357.493:ERROR:video_capture_device_client.cc(412)] error@ DoStartDesktopCaptureOnDeviceThread@y:\work\cef3_git\chromium\src\content\browser\renderer_host\media\video_capture_manager.cc:703, Could not create capture device, OS message: The operation completed successfully. (0x0)



This looks right. Just to be sure, the window id in that case is the HWND of the top-level window you are trying to share, cast to an int, correct?
JasonLP
Mentor
 
Posts: 98
Joined: Fri Jul 25, 2014 10:10 am

Re: Screenshare using getUserMedia

Postby mbeale » Wed May 31, 2017 11:37 am

[quote="JasonLP
This looks right. Just to be sure, the window id in that case is the HWND of the top-level window you are trying to share, cast to an int, correct?[/quote]

Correct Jason. What I'm seeing now is odd; for most HWNDs I choose, I get the 'Check failed: frame' crash; if the HWND belongs to a chrome app that is running, it doesn't crash or error, but I get a blank replicated window (at least the title is present, it's just the window contents are a black rectangle).

Very strange.
mbeale
Newbie
 
Posts: 6
Joined: Wed May 24, 2017 2:05 pm

Next

Return to Support Forum

Who is online

Users browsing this forum: No registered users and 43 guests

cron