webrtc/pc/audio_rtp_receiver_unittest.cc
Mirko Bonadei 2da85916ab Revert "Reland "Remove stopped_ from AudioRtpReceiver and VideoRtpReceiver.""
This reverts commit 3ed36c0521.

Reason for revert: Breaks downstream project.

Original change's description:
> Reland "Remove `stopped_` from AudioRtpReceiver and VideoRtpReceiver."
>
> This is a reland of bb57e2d7aa
>
> The difference from the original CL is that a check for
> `state_ == kLive` inside of RemoteAudioSource::AddSink has been removed.
> This caused a side effect that registering the sink while the source
> was in an "initializing" state, failed. The last remaining state
> however, is `kEnded` - but since there's no logic in the class around
> the expected value of the states, the check inside of AddSink()
> doesn't provide an additional value - it's rather a surprise for
> developers if it doesn't succeed. So, now removed.
>
> Original change's description:
> > Remove `stopped_` from AudioRtpReceiver and VideoRtpReceiver.
> >
> > This simplifies the logic in these classes a bit, which makes upcoming
> > change easier. The `stopped_` flag in these classes was essentially
> > the same thing as `media_channel_ == nullptr`, which is what's
> > consistently used now for the same checks.
> >
> > Bug: webrtc:13540
> > Change-Id: Ib60bfad9f28d5ddee8a8d5170c3f2a7ef017a5ca
> > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/250163
> > Reviewed-by: Harald Alvestrand <hta@webrtc.org>
> > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
> > Cr-Commit-Position: refs/heads/main@{#35907}
>
> Bug: webrtc:13540
> Change-Id: I3e5b3046fae11cb56b50c38c5f08972a6f283dd5
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/251326
> Auto-Submit: Tomas Gunnarsson <tommi@webrtc.org>
> Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
> Reviewed-by: Harald Alvestrand <hta@webrtc.org>
> Commit-Queue: Harald Alvestrand <hta@webrtc.org>
> Cr-Commit-Position: refs/heads/main@{#35958}

TBR=ilnik@webrtc.org,tommi@webrtc.org,hta@webrtc.org,webrtc-scoped@luci-project-accounts.iam.gserviceaccount.com

Change-Id: Ieb7235d88c808c78ad0847403be991d4dce1ace6
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:13540
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/251383
Owners-Override: Mirko Bonadei <mbonadei@webrtc.org>
Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35963}
2022-02-09 10:55:25 +00:00

92 lines
2.9 KiB
C++

/*
* Copyright 2021 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "pc/audio_rtp_receiver.h"
#include "media/base/media_channel.h"
#include "pc/test/mock_voice_media_channel.h"
#include "rtc_base/gunit.h"
#include "rtc_base/thread.h"
#include "test/gmock.h"
#include "test/gtest.h"
using ::testing::_;
using ::testing::InvokeWithoutArgs;
using ::testing::Mock;
static const int kTimeOut = 100;
static const double kDefaultVolume = 1;
static const double kVolume = 3.7;
static const uint32_t kSsrc = 3;
namespace webrtc {
class AudioRtpReceiverTest : public ::testing::Test {
protected:
AudioRtpReceiverTest()
: worker_(rtc::Thread::Current()),
receiver_(
rtc::make_ref_counted<AudioRtpReceiver>(worker_,
std::string(),
std::vector<std::string>(),
false)),
media_channel_(rtc::Thread::Current()) {
EXPECT_CALL(media_channel_, SetRawAudioSink(kSsrc, _));
EXPECT_CALL(media_channel_, SetBaseMinimumPlayoutDelayMs(kSsrc, _));
}
~AudioRtpReceiverTest() {
receiver_->SetMediaChannel(nullptr);
receiver_->Stop();
}
rtc::Thread* worker_;
rtc::scoped_refptr<AudioRtpReceiver> receiver_;
cricket::MockVoiceMediaChannel media_channel_;
};
TEST_F(AudioRtpReceiverTest, SetOutputVolumeIsCalled) {
std::atomic_int set_volume_calls(0);
EXPECT_CALL(media_channel_, SetOutputVolume(kSsrc, kDefaultVolume))
.WillOnce(InvokeWithoutArgs([&] {
set_volume_calls++;
return true;
}));
receiver_->track();
receiver_->track()->set_enabled(true);
receiver_->SetMediaChannel(&media_channel_);
receiver_->SetupMediaChannel(kSsrc);
EXPECT_CALL(media_channel_, SetOutputVolume(kSsrc, kVolume))
.WillOnce(InvokeWithoutArgs([&] {
set_volume_calls++;
return true;
}));
receiver_->OnSetVolume(kVolume);
EXPECT_TRUE_WAIT(set_volume_calls == 2, kTimeOut);
}
TEST_F(AudioRtpReceiverTest, VolumesSetBeforeStartingAreRespected) {
// Set the volume before setting the media channel. It should still be used
// as the initial volume.
receiver_->OnSetVolume(kVolume);
receiver_->track()->set_enabled(true);
receiver_->SetMediaChannel(&media_channel_);
// The previosly set initial volume should be propagated to the provided
// media_channel_ as soon as SetupMediaChannel is called.
EXPECT_CALL(media_channel_, SetOutputVolume(kSsrc, kVolume));
receiver_->SetupMediaChannel(kSsrc);
}
} // namespace webrtc