<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - WebRTC: Add RTCRtpTransceiver interface and RTCPeerConnection.addTransceiver()"
   href="https://bugs.webkit.org/show_bug.cgi?id=158189#c3">Comment # 3</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - WebRTC: Add RTCRtpTransceiver interface and RTCPeerConnection.addTransceiver()"
   href="https://bugs.webkit.org/show_bug.cgi?id=158189">bug 158189</a>
              from <span class="vcard"><a class="email" href="mailto:darin&#64;apple.com" title="Darin Adler &lt;darin&#64;apple.com&gt;"> <span class="fn">Darin Adler</span></a>
</span></b>
        <pre>Comment on <span class=""><a href="attachment.cgi?id=280093&amp;action=diff" name="attach_280093" title="Proposed patch">attachment 280093</a> <a href="attachment.cgi?id=280093&amp;action=edit" title="Proposed patch">[details]</a></span>
Proposed patch

View in context: <a href="https://bugs.webkit.org/attachment.cgi?id=280093&amp;action=review">https://bugs.webkit.org/attachment.cgi?id=280093&amp;action=review</a>

<span class="quote">&gt; Source/WebCore/Modules/mediastream/MediaEndpointPeerConnection.cpp:265
&gt; +    RefPtr&lt;RealtimeMediaSource&gt; remoteSource = m_mediaEndpoint-&gt;createMutedRemoteSource(transceiverMid, sourceType);
&gt; +    RefPtr&lt;MediaStreamTrackPrivate&gt; remoteTrackPrivate = MediaStreamTrackPrivate::create(WTFMove(remoteSource), trackId);
&gt; +    Ref&lt;MediaStreamTrack&gt; remoteTrack = MediaStreamTrack::create(*m_client-&gt;scriptExecutionContext(), *remoteTrackPrivate);</span >

Types should all be auto.

<span class="quote">&gt; Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp:164
&gt; +    RefPtr&lt;RTCRtpSender&gt; sender = RTCRtpSender::create(WTFMove(track), Vector&lt;String&gt;(), *this);
&gt; +    RefPtr&lt;RTCRtpReceiver&gt; receiver = m_backend-&gt;createReceiver(transceiverMid, trackKind, trackId);
&gt; +    Ref&lt;RTCRtpTransceiver&gt; transceiver = RTCRtpTransceiver::create(WTFMove(sender), WTFMove(receiver));</span >

Types should just be auto.

<span class="quote">&gt; Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp:187
&gt; +    RefPtr&lt;RTCRtpSender&gt; sender = RTCRtpSender::create(kind, Vector&lt;String&gt;(), *this);
&gt; +    RefPtr&lt;RTCRtpReceiver&gt; receiver = m_backend-&gt;createReceiver(transceiverMid, kind, trackId);
&gt; +    Ref&lt;RTCRtpTransceiver&gt; transceiver = RTCRtpTransceiver::create(WTFMove(sender), WTFMove(receiver));</span >

Types should just be auto.

<span class="quote">&gt; Source/WebCore/Modules/mediastream/RTCPeerConnection.idl:69
&gt; +    [StrictTypeChecking, RaisesException] RTCRtpTransceiver addTransceiver(MediaStreamTrack track, optional Dictionary init);
&gt; +    [StrictTypeChecking, RaisesException] RTCRtpTransceiver addTransceiver(DOMString kind, optional Dictionary init);</span >

New code should never use Dictionary. These dictionaries should defined.

dictionary RTCRtpTransceiverInit {
    boolean send = true;
    boolean receive = true;
    sequence&lt;MediaStream&gt; streams;
    sequence&lt;RTCRtpEncodingParameters&gt; sendEncodings;
};

If the bindings generator can’t handle this dictionary, we should fix it so it can handle it. Every single time we instead use the deprecated Dictionary, we add code we will need to later delete!

<span class="quote">&gt; Source/WebCore/Modules/mediastream/RTCRtpTransceiver.cpp:98
&gt; +const String&amp; RTCRtpTransceiver::directionString() const
&gt; +{
&gt; +    switch (m_direction) {
&gt; +    case Direction::Sendrecv: return sendrecvString();
&gt; +    case Direction::Sendonly: return sendonlyString();
&gt; +    case Direction::Recvonly: return recvonlyString();
&gt; +    case Direction::Inactive: return inactiveString();
&gt; +    }
&gt; +
&gt; +    ASSERT_NOT_REACHED();
&gt; +    return emptyString();
&gt; +}
&gt; +
&gt; +static bool parseDirectionString(const String&amp; string, RTCRtpTransceiver::Direction&amp; outDirection)
&gt; +{
&gt; +    if (string == sendrecvString())
&gt; +        outDirection = RTCRtpTransceiver::Direction::Sendrecv;
&gt; +    else if (string == sendonlyString())
&gt; +        outDirection = RTCRtpTransceiver::Direction::Sendonly;
&gt; +    else if (string == recvonlyString())
&gt; +        outDirection = RTCRtpTransceiver::Direction::Recvonly;
&gt; +    else if (string == inactiveString())
&gt; +        outDirection = RTCRtpTransceiver::Direction::Inactive;
&gt; +    else
&gt; +        return false;
&gt; +
&gt; +    return true;
&gt; +}</span >

Since bindings create functions like this for all enumerations, we should avoid writing this code ourselves if possible. What makes this necessary?

<span class="quote">&gt; Source/WebCore/Modules/mediastream/RTCRtpTransceiver.cpp:110
&gt; +bool RTCRtpTransceiver::configureWithDictionary(const Dictionary&amp; dictionary)
&gt; +{
&gt; +    String direction;
&gt; +    if (dictionary.get(&quot;direction&quot;, direction)) {
&gt; +        if (!parseDirectionString(direction, m_direction))
&gt; +            return false;
&gt; +    }
&gt; +
&gt; +    // FIMXE: fix streams
&gt; +    return true;
&gt; +}</span >

Since bindings create functions like this for dictionaries, we should avoid writing this code ourselves if possible. What makes this necessary? The bindings should convert dictionaries into structs and we should pass those around.

<span class="quote">&gt; Source/WebCore/platform/mediastream/MediaEndpoint.h:82
&gt; +    virtual RefPtr&lt;RealtimeMediaSource&gt; createMutedRemoteSource(const String&amp; mid, RealtimeMediaSource::Type) = 0;</span >

Should return Ref, not RefPtr. Caller can’t handle nullptr without crashing.

<span class="quote">&gt; Source/WebCore/platform/mediastream/RealtimeMediaSource.cpp:52
&gt;  RealtimeMediaSource::RealtimeMediaSource(const String&amp; id, Type type, const String&amp; name)
&gt; -    : m_id(id)
&gt; +    : m_muted(false)
&gt; +    , m_id(id)
&gt;      , m_type(type)
&gt;      , m_name(name)
&gt;      , m_stopped(false)
&gt; -    , m_muted(false)
&gt;      , m_readonly(false)
&gt;      , m_remote(false)
&gt;      , m_fitnessScore(0)</span >

Most data members should be initialized in the header, not in the constructor, except for the ones where we are initializing from passed in values.

<span class="quote">&gt; Source/WebCore/platform/mock/MockRealtimeAudioSource.cpp:43
&gt;  RefPtr&lt;MockRealtimeAudioSource&gt; MockRealtimeAudioSource::create()</span >

Return type should be Ref, not RefPtr.

<span class="quote">&gt; Source/WebCore/platform/mock/MockRealtimeAudioSource.cpp:48
&gt; +RefPtr&lt;MockRealtimeAudioSource&gt; MockRealtimeAudioSource::createMuted(const String&amp; name)</span >

Return type should be Ref, not RefPtr.

<span class="quote">&gt; Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp:52
&gt;  RefPtr&lt;MockRealtimeVideoSource&gt; MockRealtimeVideoSource::create()</span >

Return type should be Ref, not RefPtr.

<span class="quote">&gt; Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp:57
&gt; +RefPtr&lt;MockRealtimeVideoSource&gt; MockRealtimeVideoSource::createMuted(const String&amp; name)</span >

Return type should be Ref, not RefPtr.

<span class="quote">&gt; Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp:59
&gt; +    RefPtr&lt;MockRealtimeVideoSource&gt; source = adoptRef(new MockRealtimeVideoSource(name));</span >

Should be Ref, not RefPtr.

<span class="quote">&gt; Source/WebCore/platform/mock/MockRealtimeVideoSource.h:50
&gt;      static RefPtr&lt;MockRealtimeVideoSource&gt; create();
&gt; +    static RefPtr&lt;MockRealtimeVideoSource&gt; createMuted(const String&amp; name);</span >

Return type should be Ref, not RefPtr.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>