Bug 158191 - WebRTC: Update RTCPeerConnection.addTrack() to create (or reuse) an RTCRtpTransceiver
Summary: WebRTC: Update RTCPeerConnection.addTrack() to create (or reuse) an RTCRtpTra...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks: 143211
  Show dependency treegraph
 
Reported: 2016-05-29 01:48 PDT by Adam Bergkvist
Modified: 2016-06-03 02:52 PDT (History)
1 user (show)

See Also:


Attachments
Proposed patch (15.13 KB, patch)
2016-06-01 11:47 PDT, Adam Bergkvist
no flags Details | Formatted Diff | Diff
Updated patch (15.98 KB, patch)
2016-06-01 22:59 PDT, Adam Bergkvist
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Bergkvist 2016-05-29 01:48:55 PDT
When addTrack is called, there might be an existing RTCRtpTransceiver with an RTCRtpSender that can be reused. This procedure is described at [1].

[1] https://w3c.github.io/webrtc-pc/archives/20160513/webrtc.html#dom-rtcpeerconnection-addtrack
Comment 1 Adam Bergkvist 2016-06-01 11:47:23 PDT
Created attachment 280254 [details]
Proposed patch
Comment 2 Eric Carlson 2016-06-01 12:39:51 PDT
Comment on attachment 280254 [details]
Proposed patch

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

> Source/WebCore/Modules/mediastream/RTCPeerConnection.h:67
> +    Vector<RefPtr<RTCRtpSender>> getSenders() const override { return m_transceiverSet->getSenders(); }
> +    Vector<RefPtr<RTCRtpReceiver>> getReceivers() const { return m_transceiverSet->getReceivers(); }

Can these return a reference to a const Vector: "const Vector<RefPtr<...>>&"?

> Source/WebCore/Modules/mediastream/RTCPeerConnection.h:68
> +    const Vector<RefPtr<RTCRtpTransceiver>>& getTransceivers() const override { return m_transceiverSet->list(); }

Can this be final instead of override?
Comment 3 Adam Bergkvist 2016-06-01 13:05:10 PDT
(In reply to comment #2)
> Comment on attachment 280254 [details]
> Proposed patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=280254&action=review
> 
> > Source/WebCore/Modules/mediastream/RTCPeerConnection.h:67
> > +    Vector<RefPtr<RTCRtpSender>> getSenders() const override { return m_transceiverSet->getSenders(); }
> > +    Vector<RefPtr<RTCRtpReceiver>> getReceivers() const { return m_transceiverSet->getReceivers(); }
> 
> Can these return a reference to a const Vector: "const Vector<RefPtr<...>>&"?

Yes they can; and probably should :). createOfferTask uses getSenders() and modifies the resulting vector, but it can create a new vector from the const ref for its special purpose.

> > Source/WebCore/Modules/mediastream/RTCPeerConnection.h:68
> > +    const Vector<RefPtr<RTCRtpTransceiver>>& getTransceivers() const override { return m_transceiverSet->list(); }
> 
> Can this be final instead of override?

Seems to work. I'm a bit unsure what the result is being that the entire class is final.
Comment 4 Adam Bergkvist 2016-06-01 22:59:29 PDT
Created attachment 280309 [details]
Updated patch

Made getSenders/Receivers() return a const Vector ref.

Kept 'override' on getTransceivers() since, to my understanding, final doesn't provide any extra functionality when the class is final already. I may be wrong on this though.
Comment 5 Adam Bergkvist 2016-06-02 10:26:44 PDT
Comment on attachment 280309 [details]
Updated patch

Thanks for reviewing Eric!
Comment 6 WebKit Commit Bot 2016-06-02 10:49:06 PDT
Comment on attachment 280309 [details]
Updated patch

Clearing flags on attachment: 280309

Committed r201601: <http://trac.webkit.org/changeset/201601>
Comment 7 WebKit Commit Bot 2016-06-02 10:49:09 PDT
All reviewed patches have been landed.  Closing bug.
Comment 8 Darin Adler 2016-06-02 11:00:38 PDT
Comment on attachment 280309 [details]
Updated patch

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

> Source/WebCore/Modules/mediastream/MediaEndpointPeerConnection.cpp:135
> +    RtpSenderVector senders = RtpSenderVector(m_client->getSenders());

I don’t think we need to state the class name twice. Default behavior when receiving a const& is to make a copy, in fact, this should work:

    auto senders = m_client->getSenders();

But we need a comment explaining why we need a copy rather than using the reference. The copy is expensive.
Comment 9 Adam Bergkvist 2016-06-03 02:52:31 PDT
Comment on attachment 280309 [details]
Updated patch

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

>> Source/WebCore/Modules/mediastream/MediaEndpointPeerConnection.cpp:135
>> +    RtpSenderVector senders = RtpSenderVector(m_client->getSenders());
> 
> I don’t think we need to state the class name twice. Default behavior when receiving a const& is to make a copy, in fact, this should work:
> 
>     auto senders = m_client->getSenders();
> 
> But we need a comment explaining why we need a copy rather than using the reference. The copy is expensive.

The content of this function is replaced in https://bugs.webkit.org/show_bug.cgi?id=158203.