Bug 174519 - Difficult to correlate MediaStreamTracks without RTCRtpTransceiver MIDs
Summary: Difficult to correlate MediaStreamTracks without RTCRtpTransceiver MIDs
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebRTC (show other bugs)
Version: Safari Technology Preview
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2017-07-14 11:49 PDT by Mark Roberts
Modified: 2018-09-20 08:55 PDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Roberts 2017-07-14 11:49:59 PDT
Safari 11 Tech Preview has implemented the "new" RTCRtpReceiver behavior, namely when `addTransceiver` is called, an RTCRtpReceiver is constructed with its `track` set to a MediaStreamTrack with a random ID. So the "old" way of correlating MediaStreamTracks by ID using MSID no longer works. The new approach is to use RTCRtpTransceiver MIDs, per

    https://blog.mozilla.org/webrtc/the-evolution-of-webrtc/

However, Safari does not update its RTCRtpTransceivers' MIDs. I guess this is blocked until Safari moves to the Unified Plan SDP format? Another approach is to use MediaStream IDs, but in order to do this unambiguously I think you'd need to ensure you have at most one MediaStreamTrack of a kind in a given MediaStream.

I've included some code below that demonstrates this issue: I add two audio MediaStreamTracks to the same MediaStream and then try to identify them.

    (async () => {
      const pc1 = new RTCPeerConnection()
      const pc2 = new RTCPeerConnection()

      const stream1 = await navigator.mediaDevices.getUserMedia({ audio: true })
      const stream2 = await navigator.mediaDevices.getUserMedia({ audio: true })
      const [track1] = stream1.getAudioTracks()
      const [track2] = stream2.getAudioTracks()

      pc2.addTrack(track1, stream1)
      pc2.addTrack(track2, stream2)

      pc1.addTransceiver('audio')
      pc1.addTransceiver('audio')

      const offer = await pc1.createOffer()
      await Promise.all([
        pc1.setLocalDescription(offer),
        pc2.setRemoteDescription(offer)
      ])

      const trackEvents = []
      pc1.ontrack = trackEvent => trackEvents.push(trackEvent)

      const answer = await pc2.createAnswer()
      await Promise.all([
        pc1.setRemoteDescription(answer),
        pc2.setLocalDescription(answer)
      ])

      const [, trackEvent2] = trackEvents

      if (trackEvent2.track.id === track2.id) {
        console.log('trackEvent2.track.id matches the MSID.')
        return
      }

      console.warn(
        'trackEvent2.track.id does not match the MSID. ' +
        'I need to correlate this MediaStreamTrack based on ' +
        'some other criteria.')

      if (trackEvent2.streams[0].id === stream2.id) {
        console.log(
          'trackEvent2.streams[0].id matches the MSID. ' +
          'I might be able to correlate MediaStreamTracks this way...')
      }

      if (trackEvent2.transceiver && trackEvent2.transceiver.mid) {
        console.log(
          'trackEvent2.transciever.mid is available. This is the ' +
          'recommended way of correlating MediaStreamTracks.')
        return
      }

      console.warn(
        'trackEvent2 may not contain enough information for me ' +
        'to correlate MediaStreamTracks.')   
    })()

Expected Output:

    trackEvent2.track.id does not match the MSID. I need to correlate this MediaStreamTrack based on some other criteria.
    trackEvent2.streams[0].id matches the MSID. I might be able to correlate MediaStreamTracks this way...
    trackEvent2.transciever.mid is available. This is the recommended way of correlating MediaStreamTracks.

Actual Output:

    trackEvent2.track.id does not match the MSID. I need to correlate this MediaStreamTrack based on some other criteria.
    trackEvent2.streams[0].id matches the MSID. I might be able to correlate MediaStreamTracks this way...
    trackEvent2 may not contain enough information for me to correlate MediaStreamTracks.

Is there some workaround here? Any order I can depend on until MIDs are available?
Comment 1 Radar WebKit Bug Importer 2017-07-15 08:10:52 PDT
<rdar://problem/33335021>
Comment 2 youenn fablet 2018-09-20 08:55:46 PDT
This should be fixed now that unified plan is on by default in WebKit Nightlies.