Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 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 | |
| 15 | PeerConnectionInterface::RTCOfferAnswerOptions IceRestartOfferAnswerOptions() { |
| 16 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 17 | options.ice_restart = true; |
| 18 | return options; |
| 19 | } |
| 20 | |
| 21 | void 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 | |
| 29 | void 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 | |
| 47 | int FindFirstMediaStatsIndexByKind( |
| 48 | const std::string& kind, |
| 49 | const std::vector<const webrtc::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 | |
Evan Shrubsole | 7619b7c | 2022-03-01 10:42:44 +0100 | [diff] [blame] | 59 | TaskQueueMetronome::TaskQueueMetronome(TaskQueueFactory* factory, |
| 60 | TimeDelta tick_period) |
| 61 | : tick_period_(tick_period), |
| 62 | queue_(factory->CreateTaskQueue("MetronomeQueue", |
| 63 | TaskQueueFactory::Priority::HIGH)) { |
| 64 | tick_task_ = RepeatingTaskHandle::Start(queue_.Get(), [this] { |
| 65 | MutexLock lock(&mutex_); |
| 66 | for (auto* listener : listeners_) { |
| 67 | listener->OnTickTaskQueue()->PostTask( |
| 68 | ToQueuedTask([listener] { listener->OnTick(); })); |
| 69 | } |
| 70 | return tick_period_; |
| 71 | }); |
| 72 | } |
| 73 | |
| 74 | TaskQueueMetronome::~TaskQueueMetronome() { |
| 75 | RTC_DCHECK(listeners_.empty()); |
| 76 | rtc::Event stop_event; |
| 77 | queue_.PostTask([this, &stop_event] { |
| 78 | tick_task_.Stop(); |
| 79 | stop_event.Set(); |
| 80 | }); |
| 81 | stop_event.Wait(1000); |
| 82 | } |
| 83 | |
| 84 | void TaskQueueMetronome::AddListener(TickListener* listener) { |
| 85 | MutexLock lock(&mutex_); |
| 86 | auto [it, inserted] = listeners_.insert(listener); |
| 87 | RTC_DCHECK(inserted); |
| 88 | } |
| 89 | |
| 90 | void TaskQueueMetronome::RemoveListener(TickListener* listener) { |
| 91 | MutexLock lock(&mutex_); |
| 92 | auto it = listeners_.find(listener); |
| 93 | RTC_DCHECK(it != listeners_.end()); |
| 94 | listeners_.erase(it); |
| 95 | } |
| 96 | |
| 97 | TimeDelta TaskQueueMetronome::TickPeriod() const { |
| 98 | return tick_period_; |
| 99 | } |
| 100 | |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 101 | } // namespace webrtc |