jitter_buffer_delay.h 1.7 KB

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