Bug 167289

Summary: [WebRTC] Implement WebRTC PeerConnection backend based on libwebrtc
Product: WebKit Reporter: youenn fablet <youennf>
Component: WebCore Misc.Assignee: youenn fablet <youennf>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, bfulgham, commit-queue, darin, eric.carlson, jer.noble, jonlee
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 167293, 167294, 168010    
Bug Blocks:    
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch for landing none

Description youenn fablet 2017-01-21 23:19:07 PST
Let's implement WebRTC PeerConnection backend based on libwebrtc, behind the flag until we are ready to pass some tests.
Comment 1 youenn fablet 2017-01-21 23:56:03 PST
Created attachment 299459 [details]
Patch
Comment 2 WebKit Commit Bot 2017-01-21 23:57:07 PST
Attachment 299459 [details] did not pass style-queue:


ERROR: Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSource.h:55:  is_screencast is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
ERROR: Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSource.h:56:  needs_denoising is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
ERROR: Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCUtils.cpp:58:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:117:  One line control clauses should not use braces.  [whitespace/braces] [4]
ERROR: Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:144:  One line control clauses should not use braces.  [whitespace/braces] [4]
ERROR: Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:104:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:117:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:130:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
Total errors found: 8 in 26 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 youenn fablet 2017-01-22 00:00:38 PST
This patch is not functional as is as it is missing WK1/WK2 pieces.
Comment 4 youenn fablet 2017-01-22 00:16:53 PST
Created attachment 299464 [details]
Patch
Comment 5 WebKit Commit Bot 2017-01-22 00:18:19 PST
Attachment 299464 [details] did not pass style-queue:


ERROR: Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSource.h:55:  is_screencast is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
ERROR: Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSource.h:56:  needs_denoising is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
ERROR: Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCUtils.cpp:59:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:117:  One line control clauses should not use braces.  [whitespace/braces] [4]
ERROR: Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:144:  One line control clauses should not use braces.  [whitespace/braces] [4]
ERROR: Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:104:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:117:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:130:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
Total errors found: 8 in 28 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 6 youenn fablet 2017-01-22 10:01:15 PST
Created attachment 299469 [details]
Patch
Comment 7 youenn fablet 2017-01-26 14:57:03 PST
Created attachment 299859 [details]
Patch
Comment 8 WebKit Commit Bot 2017-01-26 15:01:15 PST
Attachment 299859 [details] did not pass style-queue:


ERROR: Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:107:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:121:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:135:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
Total errors found: 3 in 6 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 9 Alex Christensen 2017-01-26 15:08:45 PST
Comment on attachment 299859 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=299859&action=review

> Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:284
> +    RefPtr<LibWebRTCMediaEndpoint> protectedThis(this);
> +    callOnMainThread([protectedThis = WTFMove(protectedThis), stream = WTFMove(stream)] {

Here's the cool C++14/WTF way of doing things like this.
protectedThis = makeRef(*this)

> Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:107
> +        explicit CreateSessionDescriptionObserver(LibWebRTCMediaEndpoint &endpoint) : m_endpoint(endpoint) { }

needs to be on more than one line according to stylebot.
Comment 10 Alex Christensen 2017-01-26 16:07:15 PST
Comment on attachment 299859 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=299859&action=review

> Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:13
> + * 3.  Neither the name of Apple Inc. nor the names of

I think we use a 2-clause copyright header by default for new files now.  See Source/WebCore/LICENSE-APPLE

> Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:64
> +    m_backend = client.createPeerConnection(*this);

This can be in the initializers.

> Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:316
> +    // ASSERT_NOT_REACHED();

Commented out?  Maybe this and the previous one should be notImplemented();

> Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:336
> +    default:

Could we not do a default?
Comment 11 youenn fablet 2017-01-26 16:27:12 PST
Comment on attachment 299859 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=299859&action=review

>> Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:13
>> + * 3.  Neither the name of Apple Inc. nor the names of
> 
> I think we use a 2-clause copyright header by default for new files now.  See Source/WebCore/LICENSE-APPLE

I'll check that

>> Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:64
>> +    m_backend = client.createPeerConnection(*this);
> 
> This can be in the initializers.

ok

>> Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:316
>> +    // ASSERT_NOT_REACHED();
> 
> Commented out?  Maybe this and the previous one should be notImplemented();

Sure

>> Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:336
>> +    default:
> 
> Could we not do a default?

There is a kMax value that we could use instead of default.

>> Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:107
>> +        explicit CreateSessionDescriptionObserver(LibWebRTCMediaEndpoint &endpoint) : m_endpoint(endpoint) { }
> 
> needs to be on more than one line according to stylebot.

I prefer this style when there is only one initialiser.
Comment 12 youenn fablet 2017-01-26 17:58:55 PST
Created attachment 299890 [details]
Patch
Comment 13 WebKit Commit Bot 2017-01-26 18:01:32 PST
Attachment 299890 [details] did not pass style-queue:


ERROR: Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:103:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:117:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:131:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
Total errors found: 3 in 6 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 14 youenn fablet 2017-01-26 18:02:06 PST
(In reply to comment #13)
> Attachment 299890 [details] did not pass style-queue:
> 
> 
> ERROR:
> Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:103: 
> Should be indented on a separate line, with the colon or comma first on that
> line.  [whitespace/indent] [4]
> ERROR:
> Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:117: 
> Should be indented on a separate line, with the colon or comma first on that
> line.  [whitespace/indent] [4]
> ERROR:
> Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:131: 
> Should be indented on a separate line, with the colon or comma first on that
> line.  [whitespace/indent] [4]
> Total errors found: 3 in 6 files
> 
> 
> If any of these errors are false positives, please file a bug against
> check-webkit-style.

Fixing style and license comments
Comment 15 Alex Christensen 2017-01-26 19:38:29 PST
Comment on attachment 299890 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=299890&action=review

> Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:56
> +class LibWebRTCMediaEndpoint final : public RefCounted<LibWebRTCMediaEndpoint>, private webrtc::PeerConnectionObserver {

This should probably be ThreadSafeRefCounted<LibWebRTCMediaEndpoint> since we are ref'ing and deref'ing on different threads.  It hurts performance a bit if we ref and deref a lot because it has to clear the instruction pipeline, but it is necessary if we are ref'ing and deref'ing from different threads.

> Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:47
> +static std::unique_ptr<PeerConnectionBackend> createLibWebRTCPeerConnectionBackend(RTCPeerConnection& peerConnection)
> +{
> +    return std::unique_ptr<PeerConnectionBackend>(new LibWebRTCPeerConnectionBackend(peerConnection));
> +}

This whole function shouldn't be necessary.  Just make the constructor public and call std::make_unique

> Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:53
> +    ASSERT(peerConnection.scriptExecutionContext()->isDocument());

It would be nice if we could make every scriptExecutionContext have a LibWebRTCProvider.  We would need to make LibWebRTCProvider ThreadSafeRefCounted and pass Ref's around.  I might do it later.  This is fine for now, though.
Comment 16 youenn fablet 2017-01-26 21:22:35 PST
(In reply to comment #15)
> Comment on attachment 299890 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=299890&action=review
> 
> > Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:56
> > +class LibWebRTCMediaEndpoint final : public RefCounted<LibWebRTCMediaEndpoint>, private webrtc::PeerConnectionObserver {
> 
> This should probably be ThreadSafeRefCounted<LibWebRTCMediaEndpoint> since
> we are ref'ing and deref'ing on different threads.  It hurts performance a
> bit if we ref and deref a lot because it has to clear the instruction
> pipeline, but it is necessary if we are ref'ing and deref'ing from different
> threads.

Good point, it is probably the simplest solution.


> > Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:47
> > +static std::unique_ptr<PeerConnectionBackend> createLibWebRTCPeerConnectionBackend(RTCPeerConnection& peerConnection)
> > +{
> > +    return std::unique_ptr<PeerConnectionBackend>(new LibWebRTCPeerConnectionBackend(peerConnection));
> > +}
> 
> This whole function shouldn't be necessary.  Just make the constructor
> public and call std::make_unique

Will use make_unique.

> > Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:53
> > +    ASSERT(peerConnection.scriptExecutionContext()->isDocument());
> 
> It would be nice if we could make every scriptExecutionContext have a
> LibWebRTCProvider.  We would need to make LibWebRTCProvider
> ThreadSafeRefCounted and pass Ref's around.  I might do it later.  This is
> fine for now, though.

There is no planned support for WebRTC in workers so is it really worth it.
Having a RefCounted LibWebRTCProvider would be useful for the mock implementation too though.
Comment 17 youenn fablet 2017-01-26 21:34:38 PST
Created attachment 299910 [details]
Patch for landing
Comment 18 WebKit Commit Bot 2017-01-26 22:11:01 PST
Comment on attachment 299910 [details]
Patch for landing

Clearing flags on attachment: 299910

Committed r211255: <http://trac.webkit.org/changeset/211255>
Comment 19 WebKit Commit Bot 2017-01-26 22:11:06 PST
All reviewed patches have been landed.  Closing bug.