⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 278410 in webkit


Ignore:
Timestamp:
Jun 3, 2021, 10:25:28 AM (5 years ago)
Author:
youenn@apple.com
Message:

Cherry-pick webrtc fix to correctly handle audio track state in case of renegotiation
​https://bugs.webkit.org/show_bug.cgi?id=226577

Reviewed by Eric Carlson.

LayoutTests/imported/w3c:

  • web-platform-tests/webrtc/receiver-track-live.https-expected.txt:

Source/ThirdParty/libwebrtc:

Cherry-pick ​https://webrtc.googlesource.com/src/+/c335b0e63bff56ca0fbfa617dee6a644c85df164%5E%21/.
We need to do small changes to peer_connection.cc given the upstream fix is based on a newer version
which has some code moved from peer_connection.cc to rtp_transmission_manager.cc.

  • Source/webrtc/pc/audio_rtp_receiver.cc:
  • Source/webrtc/pc/audio_rtp_receiver.h:
  • Source/webrtc/pc/peer_connection.cc:
  • Source/webrtc/pc/peer_connection_rtp_unittest.cc:
  • Source/webrtc/pc/remote_audio_source.cc:
  • Source/webrtc/pc/remote_audio_source.h:
  • Source/webrtc/pc/rtp_sender_receiver_unittest.cc:

LayoutTests:

Update test now that we have the correct behavior.

  • webrtc/receiver-track-should-stay-live-even-if-receiver-is-inactive.html:
Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r278403 r278410  
     12021-06-03  Youenn Fablet  <youenn@apple.com>
     2
     3        Cherry-pick webrtc fix to correctly handle audio track state in case of renegotiation
     4        https://bugs.webkit.org/show_bug.cgi?id=226577
     5
     6        Reviewed by Eric Carlson.
     7
     8        Update test now that we have the correct behavior.
     9
     10        * webrtc/receiver-track-should-stay-live-even-if-receiver-is-inactive.html:
     11
    1122021-06-03  Alan Bujtas  <zalan@apple.com>
    213
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r278391 r278410  
     12021-06-03  Youenn Fablet  <youenn@apple.com>
     2
     3        Cherry-pick webrtc fix to correctly handle audio track state in case of renegotiation
     4        https://bugs.webkit.org/show_bug.cgi?id=226577
     5
     6        Reviewed by Eric Carlson.
     7
     8        * web-platform-tests/webrtc/receiver-track-live.https-expected.txt:
     9
    1102021-06-02  Alex Christensen  <achristensen@webkit.org>
    211
  • trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/receiver-track-live.https-expected.txt

    r267649 r278410  
    22
    33PASS Setup audio call
    4 FAIL Inactivate the audio transceiver assert_equals: expected "live" but got "ended"
    5 FAIL Reactivate the audio transceiver assert_equals: expected "live" but got "ended"
     4PASS Inactivate the audio transceiver
     5PASS Reactivate the audio transceiver
    66PASS Clean-up
    77
  • trunk/LayoutTests/webrtc/receiver-track-should-stay-live-even-if-receiver-is-inactive.html

    r262905 r278410  
    4747        await pc1.setRemoteDescription(answer);
    4848
    49         // FIXME: The track should be live but is ended due to a bug in our backend.
    50         assert_equals(remoteTrack.readyState, "ended");
     49        assert_equals(remoteTrack.readyState, "live");
    5150    }, "Inactivate the audio transceiver");
    5251
    … …  
    6059        await pc1.setRemoteDescription(answer);
    6160
    62         // FIXME: The track should be live but is ended due to a bug in our backend.
    63         assert_equals(remoteTrack.readyState, "ended");
     61        assert_equals(remoteTrack.readyState, "live");
    6462    }, "Reactivate the audio transceiver");
    6563    </script>
  • trunk/Source/ThirdParty/libwebrtc/ChangeLog

    r278352 r278410  
     12021-06-03  Youenn Fablet  <youenn@apple.com>
     2
     3        Cherry-pick webrtc fix to correctly handle audio track state in case of renegotiation
     4        https://bugs.webkit.org/show_bug.cgi?id=226577
     5
     6        Reviewed by Eric Carlson.
     7
     8        Cherry-pick https://webrtc.googlesource.com/src/+/c335b0e63bff56ca0fbfa617dee6a644c85df164%5E%21/.
     9        We need to do small changes to peer_connection.cc given the upstream fix is based on a newer version
     10        which has some code moved from peer_connection.cc to rtp_transmission_manager.cc.
     11
     12        * Source/webrtc/pc/audio_rtp_receiver.cc:
     13        * Source/webrtc/pc/audio_rtp_receiver.h:
     14        * Source/webrtc/pc/peer_connection.cc:
     15        * Source/webrtc/pc/peer_connection_rtp_unittest.cc:
     16        * Source/webrtc/pc/remote_audio_source.cc:
     17        * Source/webrtc/pc/remote_audio_source.h:
     18        * Source/webrtc/pc/rtp_sender_receiver_unittest.cc:
     19
    1202021-06-02  Youenn Fablet  <youenn@apple.com>
    221
  • trunk/Source/ThirdParty/libwebrtc/Source/webrtc/pc/audio_rtp_receiver.cc

    r269642 r278410  
    3131AudioRtpReceiver::AudioRtpReceiver(rtc::Thread* worker_thread,
    3232                                   std::string receiver_id,
    33                                    std::vector<std::string> stream_ids)
     33                                   std::vector<std::string> stream_ids,
     34                                   bool is_unified_plan)
    3435    : AudioRtpReceiver(worker_thread,
    3536                       receiver_id,
    36                        CreateStreamsFromIds(std::move(stream_ids))) {}
     37                       CreateStreamsFromIds(std::move(stream_ids)),
     38                       is_unified_plan) {}
    3739
    3840AudioRtpReceiver::AudioRtpReceiver(
    3941    rtc::Thread* worker_thread,
    4042    const std::string& receiver_id,
    41     const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams)
     43    const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams,
     44    bool is_unified_plan)
    4245    : worker_thread_(worker_thread),
    4346      id_(receiver_id),
    44       source_(new rtc::RefCountedObject<RemoteAudioSource>(worker_thread)),
     47      source_(new rtc::RefCountedObject<RemoteAudioSource>(
     48          worker_thread,
     49          is_unified_plan
     50              ? RemoteAudioSource::OnAudioChannelGoneAction::kSurvive
     51              : RemoteAudioSource::OnAudioChannelGoneAction::kEnd)),
    4552      track_(AudioTrackProxyWithInternal<AudioTrack>::Create(
    4653          rtc::Thread::Current(),
    … …  
    140147    return;
    141148  }
     149  source_->SetState(MediaSourceInterface::kEnded);
    142150  if (media_channel_) {
    143151    // Allow that SetOutputVolume fail. This is the normal case when the
  • trunk/Source/ThirdParty/libwebrtc/Source/webrtc/pc/audio_rtp_receiver.h

    r269642 r278410  
    4040  AudioRtpReceiver(rtc::Thread* worker_thread,
    4141                   std::string receiver_id,
    42                    std::vector<std::string> stream_ids);
     42                   std::vector<std::string> stream_ids,
     43                   bool is_unified_plan);
    4344  // TODO(https://crbug.com/webrtc/9480): Remove this when streams() is removed.
    4445  AudioRtpReceiver(
    4546      rtc::Thread* worker_thread,
    4647      const std::string& receiver_id,
    47       const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams);
     48      const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams,
     49      bool is_unified_plan);
    4850  virtual ~AudioRtpReceiver();
    4951
  • trunk/Source/ThirdParty/libwebrtc/Source/webrtc/pc/peer_connection.cc

    r269642 r278410  
    12111211    receiver = RtpReceiverProxyWithInternal<RtpReceiverInternal>::Create(
    12121212        signaling_thread(), new AudioRtpReceiver(worker_thread(), receiver_id,
    1213                                                  std::vector<std::string>({})));
     1213                                                 std::vector<std::string>({}), IsUnifiedPlan()));
    12141214    NoteUsageEvent(UsageEvent::AUDIO_ADDED);
    12151215  } else {
    … …  
    22542254  // the constructor taking stream IDs instead.
    22552255  auto* audio_receiver = new AudioRtpReceiver(
    2256       worker_thread(), remote_sender_info.sender_id, streams);
     2256      worker_thread(), remote_sender_info.sender_id, streams, IsUnifiedPlan());
    22572257  audio_receiver->SetMediaChannel(voice_media_channel());
    22582258  if (remote_sender_info.sender_id == kDefaultAudioSenderId) {
  • trunk/Source/ThirdParty/libwebrtc/Source/webrtc/pc/peer_connection_rtp_unittest.cc

    r271793 r278410  
    780780  EXPECT_EQ(receivers[0]->streams()[1]->id(), kStreamId2);
    781781}
     782TEST_F(PeerConnectionRtpTestUnifiedPlan, TracksDoNotEndWhenSsrcChanges) {
     783  constexpr uint32_t kFirstMungedSsrc = 1337u;
     784
     785  auto caller = CreatePeerConnection();
     786  auto callee = CreatePeerConnection();
     787
     788  // Caller offers to receive audio and video.
     789  RtpTransceiverInit init;
     790  init.direction = RtpTransceiverDirection::kRecvOnly;
     791  caller->AddTransceiver(cricket::MEDIA_TYPE_AUDIO, init);
     792  caller->AddTransceiver(cricket::MEDIA_TYPE_VIDEO, init);
     793
     794  // Callee wants to send audio and video tracks.
     795  callee->AddTrack(callee->CreateAudioTrack("audio_track"), {});
     796  callee->AddTrack(callee->CreateVideoTrack("video_track"), {});
     797
     798  // Do inittial offer/answer exchange.
     799  ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal()));
     800  ASSERT_TRUE(
     801      caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal()));
     802  ASSERT_EQ(caller->observer()->add_track_events_.size(), 2u);
     803  ASSERT_EQ(caller->pc()->GetReceivers().size(), 2u);
     804
     805  // Do a follow-up offer/answer exchange where the SSRCs are modified.
     806  ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal()));
     807  auto answer = callee->CreateAnswer();
     808  auto& contents = answer->description()->contents();
     809  ASSERT_TRUE(!contents.empty());
     810  for (size_t i = 0; i < contents.size(); ++i) {
     811    auto& mutable_streams = contents[i].media_description()->mutable_streams();
     812    ASSERT_EQ(mutable_streams.size(), 1u);
     813    mutable_streams[0].ssrcs = {kFirstMungedSsrc + static_cast<uint32_t>(i)};
     814  }
     815  ASSERT_TRUE(
     816      callee->SetLocalDescription(CloneSessionDescription(answer.get())));
     817  ASSERT_TRUE(
     818      caller->SetRemoteDescription(CloneSessionDescription(answer.get())));
     819
     820  // No furher track events should fire because we never changed direction, only
     821  // SSRCs.
     822  ASSERT_EQ(caller->observer()->add_track_events_.size(), 2u);
     823  // We should have the same number of receivers as before.
     824  auto receivers = caller->pc()->GetReceivers();
     825  ASSERT_EQ(receivers.size(), 2u);
     826  // The tracks are still alive.
     827  EXPECT_EQ(receivers[0]->track()->state(),
     828            MediaStreamTrackInterface::TrackState::kLive);
     829  EXPECT_EQ(receivers[1]->track()->state(),
     830            MediaStreamTrackInterface::TrackState::kLive);
     831}
    782832
    783833// Tests that with Unified Plan if the the stream id changes for a track when
  • trunk/Source/ThirdParty/libwebrtc/Source/webrtc/pc/remote_audio_source.cc

    r269642 r278410  
    5252};
    5353
    54 RemoteAudioSource::RemoteAudioSource(rtc::Thread* worker_thread)
     54RemoteAudioSource::RemoteAudioSource(
     55    rtc::Thread* worker_thread,
     56    OnAudioChannelGoneAction on_audio_channel_gone_action)
    5557    : main_thread_(rtc::Thread::Current()),
    5658      worker_thread_(worker_thread),
     59      on_audio_channel_gone_action_(on_audio_channel_gone_action),
    5760      state_(MediaSourceInterface::kLive) {
    5861  RTC_DCHECK(main_thread_);
    … …  
    9194         : media_channel->SetDefaultRawAudioSink(nullptr);
    9295  });
     96}
     97
     98void RemoteAudioSource::SetState(SourceState new_state) {
     99  if (state_ != new_state) {
     100    state_ = new_state;
     101    FireOnChanged();
     102  }
    93103}
    94104
    … …  
    159169
    160170void RemoteAudioSource::OnAudioChannelGone() {
     171  if (on_audio_channel_gone_action_ != OnAudioChannelGoneAction::kEnd) {
     172    return;
     173  }
    161174  // Called when the audio channel is deleted.  It may be the worker thread
    162175  // in libjingle or may be a different worker thread.
    … …  
    173186  RTC_DCHECK(main_thread_->IsCurrent());
    174187  sinks_.clear();
    175   state_ = MediaSourceInterface::kEnded;
    176   FireOnChanged();
     188  SetState(MediaSourceInterface::kEnded);
    177189  // Will possibly delete this RemoteAudioSource since it is reference counted
    178190  // in the message.
  • trunk/Source/ThirdParty/libwebrtc/Source/webrtc/pc/remote_audio_source.h

    r269642 r278410  
    3535                          rtc::MessageHandler {
    3636 public:
    37   explicit RemoteAudioSource(rtc::Thread* worker_thread);
     37  // In Unified Plan, receivers map to m= sections and their tracks and sources
     38  // survive SSRCs being reconfigured. The life cycle of the remote audio source
     39  // is associated with the life cycle of the m= section, and thus even if an
     40  // audio channel is destroyed the RemoteAudioSource should kSurvive.
     41  //
     42  // In Plan B however, remote audio sources map 1:1 with an SSRCs and if an
     43  // audio channel is destroyed, the RemoteAudioSource should kEnd.
     44  enum class OnAudioChannelGoneAction {
     45    kSurvive,
     46    kEnd,
     47  };
     48
     49  explicit RemoteAudioSource(
     50      rtc::Thread* worker_thread,
     51      OnAudioChannelGoneAction on_audio_channel_gone_action);
    3852
    3953  // Register and unregister remote audio source with the underlying media
    … …  
    4357  void Stop(cricket::VoiceMediaChannel* media_channel,
    4458            absl::optional<uint32_t> ssrc);
     59  void SetState(SourceState new_state);
    4560
    4661  // MediaSourceInterface implementation.
    … …  
    6984  rtc::Thread* const main_thread_;
    7085  rtc::Thread* const worker_thread_;
     86  const OnAudioChannelGoneAction on_audio_channel_gone_action_;
    7187  std::list<AudioObserver*> audio_observers_;
    7288  Mutex sink_lock_;
  • trunk/Source/ThirdParty/libwebrtc/Source/webrtc/pc/rtp_sender_receiver_unittest.cc

    r269642 r278410  
    290290      std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams = {}) {
    291291    audio_rtp_receiver_ =
    292         new AudioRtpReceiver(rtc::Thread::Current(), kAudioTrackId, streams);
     292        new AudioRtpReceiver(rtc::Thread::Current(), kAudioTrackId, streams,
     293                             /*is_unified_plan=*/true);
    293294    audio_rtp_receiver_->SetMediaChannel(voice_media_channel_);
    294295    audio_rtp_receiver_->SetupMediaChannel(kAudioSsrc);
Note: See TracChangeset for help on using the changeset viewer.