1 /* 2 * Copyright 2019 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 #ifndef PC_JITTER_BUFFER_DELAY_H_ 12 #define PC_JITTER_BUFFER_DELAY_H_ 13 14 #include <stdint.h> 15 16 #include "absl/types/optional.h" 17 #include "media/base/delayable.h" 18 #include "pc/jitter_buffer_delay_interface.h" 19 #include "rtc_base/thread.h" 20 21 namespace webrtc { 22 23 // JitterBufferDelay converts delay from seconds to milliseconds for the 24 // underlying media channel. It also handles cases when user sets delay before 25 // the start of media_channel by caching its request. Note, this class is not 26 // thread safe. Its thread safe version is defined in 27 // pc/jitter_buffer_delay_proxy.h 28 class JitterBufferDelay : public JitterBufferDelayInterface { 29 public: 30 // Must be called on signaling thread. 31 explicit JitterBufferDelay(rtc::Thread* worker_thread); 32 33 void OnStart(cricket::Delayable* media_channel, uint32_t ssrc) override; 34 35 void OnStop() override; 36 37 void Set(absl::optional<double> delay_seconds) override; 38 39 private: 40 // Throughout webrtc source, sometimes it is also called as |main_thread_|. 41 rtc::Thread* const signaling_thread_; 42 rtc::Thread* const worker_thread_; 43 // Media channel and ssrc together uniqely identify audio stream. 44 cricket::Delayable* media_channel_ = nullptr; 45 absl::optional<uint32_t> ssrc_; 46 absl::optional<double> cached_delay_seconds_; 47 }; 48 49 } // namespace webrtc 50 51 #endif // PC_JITTER_BUFFER_DELAY_H_ 52