You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.5 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #include "pc/jitter_buffer_delay.h"
  11. #include <stdint.h>
  12. #include "absl/types/optional.h"
  13. #include "api/scoped_refptr.h"
  14. #include "pc/test/mock_delayable.h"
  15. #include "rtc_base/ref_counted_object.h"
  16. #include "rtc_base/thread.h"
  17. #include "test/gmock.h"
  18. #include "test/gtest.h"
  19. using ::testing::Return;
  20. namespace {
  21. constexpr int kSsrc = 1234;
  22. } // namespace
  23. namespace webrtc {
  24. class JitterBufferDelayTest : public ::testing::Test {
  25. public:
  26. JitterBufferDelayTest()
  27. : delay_(new rtc::RefCountedObject<JitterBufferDelay>(
  28. rtc::Thread::Current())) {}
  29. protected:
  30. rtc::scoped_refptr<JitterBufferDelayInterface> delay_;
  31. MockDelayable delayable_;
  32. };
  33. TEST_F(JitterBufferDelayTest, Set) {
  34. delay_->OnStart(&delayable_, kSsrc);
  35. EXPECT_CALL(delayable_, SetBaseMinimumPlayoutDelayMs(kSsrc, 3000))
  36. .WillOnce(Return(true));
  37. // Delay in seconds.
  38. delay_->Set(3.0);
  39. }
  40. TEST_F(JitterBufferDelayTest, Caching) {
  41. // Check that value is cached before start.
  42. delay_->Set(4.0);
  43. // Check that cached value applied on the start.
  44. EXPECT_CALL(delayable_, SetBaseMinimumPlayoutDelayMs(kSsrc, 4000))
  45. .WillOnce(Return(true));
  46. delay_->OnStart(&delayable_, kSsrc);
  47. }
  48. TEST_F(JitterBufferDelayTest, Clamping) {
  49. delay_->OnStart(&delayable_, kSsrc);
  50. // In current Jitter Buffer implementation (Audio or Video) maximum supported
  51. // value is 10000 milliseconds.
  52. EXPECT_CALL(delayable_, SetBaseMinimumPlayoutDelayMs(kSsrc, 10000))
  53. .WillOnce(Return(true));
  54. delay_->Set(10.5);
  55. // Test int overflow.
  56. EXPECT_CALL(delayable_, SetBaseMinimumPlayoutDelayMs(kSsrc, 10000))
  57. .WillOnce(Return(true));
  58. delay_->Set(21474836470.0);
  59. EXPECT_CALL(delayable_, SetBaseMinimumPlayoutDelayMs(kSsrc, 0))
  60. .WillOnce(Return(true));
  61. delay_->Set(-21474836470.0);
  62. // Boundary value in seconds to milliseconds conversion.
  63. EXPECT_CALL(delayable_, SetBaseMinimumPlayoutDelayMs(kSsrc, 0))
  64. .WillOnce(Return(true));
  65. delay_->Set(0.0009);
  66. EXPECT_CALL(delayable_, SetBaseMinimumPlayoutDelayMs(kSsrc, 0))
  67. .WillOnce(Return(true));
  68. delay_->Set(-2.0);
  69. }
  70. } // namespace webrtc