1 /* 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include "pc/test/integration_test_helpers.h" 12 13 namespace webrtc { 14 IceRestartOfferAnswerOptions()15PeerConnectionInterface::RTCOfferAnswerOptions IceRestartOfferAnswerOptions() { 16 PeerConnectionInterface::RTCOfferAnswerOptions options; 17 options.ice_restart = true; 18 return options; 19 } 20 RemoveSsrcsAndMsids(cricket::SessionDescription * desc)21void RemoveSsrcsAndMsids(cricket::SessionDescription* desc) { 22 for (ContentInfo& content : desc->contents()) { 23 content.media_description()->mutable_streams().clear(); 24 } 25 desc->set_msid_supported(false); 26 desc->set_msid_signaling(0); 27 } 28 RemoveSsrcsAndKeepMsids(cricket::SessionDescription * desc)29void RemoveSsrcsAndKeepMsids(cricket::SessionDescription* desc) { 30 for (ContentInfo& content : desc->contents()) { 31 std::string track_id; 32 std::vector<std::string> stream_ids; 33 if (!content.media_description()->streams().empty()) { 34 const StreamParams& first_stream = 35 content.media_description()->streams()[0]; 36 track_id = first_stream.id; 37 stream_ids = first_stream.stream_ids(); 38 } 39 content.media_description()->mutable_streams().clear(); 40 StreamParams new_stream; 41 new_stream.id = track_id; 42 new_stream.set_stream_ids(stream_ids); 43 content.media_description()->AddStream(new_stream); 44 } 45 } 46 FindFirstMediaStatsIndexByKind(const std::string & kind,const std::vector<const webrtc::DEPRECATED_RTCMediaStreamTrackStats * > & media_stats_vec)47int FindFirstMediaStatsIndexByKind( 48 const std::string& kind, 49 const std::vector<const webrtc::DEPRECATED_RTCMediaStreamTrackStats*>& 50 media_stats_vec) { 51 for (size_t i = 0; i < media_stats_vec.size(); i++) { 52 if (media_stats_vec[i]->kind.ValueToString() == kind) { 53 return i; 54 } 55 } 56 return -1; 57 } 58 TaskQueueMetronome(TimeDelta tick_period)59TaskQueueMetronome::TaskQueueMetronome(TimeDelta tick_period) 60 : tick_period_(tick_period) { 61 sequence_checker_.Detach(); 62 } 63 ~TaskQueueMetronome()64TaskQueueMetronome::~TaskQueueMetronome() { 65 RTC_DCHECK_RUN_ON(&sequence_checker_); 66 } RequestCallOnNextTick(absl::AnyInvocable<void ()&&> callback)67void TaskQueueMetronome::RequestCallOnNextTick( 68 absl::AnyInvocable<void() &&> callback) { 69 RTC_DCHECK_RUN_ON(&sequence_checker_); 70 callbacks_.push_back(std::move(callback)); 71 // Only schedule a tick callback for the first `callback` addition. 72 // Schedule on the current task queue to comply with RequestCallOnNextTick 73 // requirements. 74 if (callbacks_.size() == 1) { 75 TaskQueueBase::Current()->PostDelayedTask( 76 SafeTask(safety_.flag(), 77 [this] { 78 RTC_DCHECK_RUN_ON(&sequence_checker_); 79 std::vector<absl::AnyInvocable<void() &&>> callbacks; 80 callbacks_.swap(callbacks); 81 for (auto& callback : callbacks) 82 std::move(callback)(); 83 }), 84 tick_period_); 85 } 86 } 87 TickPeriod() const88TimeDelta TaskQueueMetronome::TickPeriod() const { 89 RTC_DCHECK_RUN_ON(&sequence_checker_); 90 return tick_period_; 91 } 92 93 } // namespace webrtc 94