mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-19 08:37:54 +01:00

This reverts commit3ed36c0521
. Reason for revert: Breaks downstream project. Original change's description: > Reland "Remove `stopped_` from AudioRtpReceiver and VideoRtpReceiver." > > This is a reland ofbb57e2d7aa
> > 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}
183 lines
6.5 KiB
C++
183 lines
6.5 KiB
C++
/*
|
|
* Copyright 2019 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/video_rtp_receiver.h"
|
|
|
|
#include <memory>
|
|
|
|
#include "api/video/test/mock_recordable_encoded_frame.h"
|
|
#include "media/base/fake_media_engine.h"
|
|
#include "test/gmock.h"
|
|
|
|
using ::testing::_;
|
|
using ::testing::AnyNumber;
|
|
using ::testing::InSequence;
|
|
using ::testing::Mock;
|
|
using ::testing::NiceMock;
|
|
using ::testing::SaveArg;
|
|
using ::testing::StrictMock;
|
|
|
|
namespace webrtc {
|
|
namespace {
|
|
|
|
class VideoRtpReceiverTest : public testing::Test {
|
|
protected:
|
|
class MockVideoMediaChannel : public cricket::FakeVideoMediaChannel {
|
|
public:
|
|
MockVideoMediaChannel(
|
|
cricket::FakeVideoEngine* engine,
|
|
const cricket::VideoOptions& options,
|
|
TaskQueueBase* network_thread = rtc::Thread::Current())
|
|
: FakeVideoMediaChannel(engine, options, network_thread) {}
|
|
MOCK_METHOD(void,
|
|
SetRecordableEncodedFrameCallback,
|
|
(uint32_t, std::function<void(const RecordableEncodedFrame&)>),
|
|
(override));
|
|
MOCK_METHOD(void,
|
|
ClearRecordableEncodedFrameCallback,
|
|
(uint32_t),
|
|
(override));
|
|
MOCK_METHOD(void, GenerateKeyFrame, (uint32_t), (override));
|
|
};
|
|
|
|
class MockVideoSink : public rtc::VideoSinkInterface<RecordableEncodedFrame> {
|
|
public:
|
|
MOCK_METHOD(void, OnFrame, (const RecordableEncodedFrame&), (override));
|
|
};
|
|
|
|
VideoRtpReceiverTest()
|
|
: worker_thread_(rtc::Thread::Create()),
|
|
channel_(nullptr, cricket::VideoOptions()),
|
|
receiver_(rtc::make_ref_counted<VideoRtpReceiver>(
|
|
worker_thread_.get(),
|
|
std::string("receiver"),
|
|
std::vector<std::string>({"stream"}))) {
|
|
worker_thread_->Start();
|
|
receiver_->SetMediaChannel(&channel_);
|
|
}
|
|
|
|
~VideoRtpReceiverTest() override {
|
|
// Clear expectations that tests may have set up before calling Stop().
|
|
Mock::VerifyAndClearExpectations(&channel_);
|
|
receiver_->Stop();
|
|
}
|
|
|
|
webrtc::VideoTrackSourceInterface* Source() {
|
|
return receiver_->streams()[0]->FindVideoTrack("receiver")->GetSource();
|
|
}
|
|
|
|
std::unique_ptr<rtc::Thread> worker_thread_;
|
|
NiceMock<MockVideoMediaChannel> channel_;
|
|
rtc::scoped_refptr<VideoRtpReceiver> receiver_;
|
|
};
|
|
|
|
TEST_F(VideoRtpReceiverTest, SupportsEncodedOutput) {
|
|
EXPECT_TRUE(Source()->SupportsEncodedOutput());
|
|
}
|
|
|
|
TEST_F(VideoRtpReceiverTest, GeneratesKeyFrame) {
|
|
EXPECT_CALL(channel_, GenerateKeyFrame(0));
|
|
Source()->GenerateKeyFrame();
|
|
}
|
|
|
|
TEST_F(VideoRtpReceiverTest,
|
|
GenerateKeyFrameOnChannelSwitchUnlessGenerateKeyframeCalled) {
|
|
// A channel switch without previous call to GenerateKeyFrame shouldn't
|
|
// cause a call to happen on the new channel.
|
|
MockVideoMediaChannel channel2(nullptr, cricket::VideoOptions());
|
|
EXPECT_CALL(channel_, GenerateKeyFrame).Times(0);
|
|
EXPECT_CALL(channel2, GenerateKeyFrame).Times(0);
|
|
receiver_->SetMediaChannel(&channel2);
|
|
Mock::VerifyAndClearExpectations(&channel2);
|
|
|
|
// Generate a key frame. When we switch channel next time, we will have to
|
|
// re-generate it as we don't know if it was eventually received
|
|
Source()->GenerateKeyFrame();
|
|
MockVideoMediaChannel channel3(nullptr, cricket::VideoOptions());
|
|
EXPECT_CALL(channel3, GenerateKeyFrame);
|
|
receiver_->SetMediaChannel(&channel3);
|
|
|
|
// Switching to a new channel should now not cause calls to GenerateKeyFrame.
|
|
StrictMock<MockVideoMediaChannel> channel4(nullptr, cricket::VideoOptions());
|
|
receiver_->SetMediaChannel(&channel4);
|
|
|
|
// We must call Stop() here since the mock media channels live on the stack
|
|
// and `receiver_` still has a pointer to those objects.
|
|
receiver_->Stop();
|
|
}
|
|
|
|
TEST_F(VideoRtpReceiverTest, EnablesEncodedOutput) {
|
|
EXPECT_CALL(channel_, SetRecordableEncodedFrameCallback(/*ssrc=*/0, _));
|
|
EXPECT_CALL(channel_, ClearRecordableEncodedFrameCallback).Times(0);
|
|
MockVideoSink sink;
|
|
Source()->AddEncodedSink(&sink);
|
|
}
|
|
|
|
TEST_F(VideoRtpReceiverTest, DisablesEncodedOutput) {
|
|
EXPECT_CALL(channel_, ClearRecordableEncodedFrameCallback(/*ssrc=*/0));
|
|
MockVideoSink sink;
|
|
Source()->AddEncodedSink(&sink);
|
|
Source()->RemoveEncodedSink(&sink);
|
|
}
|
|
|
|
TEST_F(VideoRtpReceiverTest, DisablesEnablesEncodedOutputOnChannelSwitch) {
|
|
InSequence s;
|
|
EXPECT_CALL(channel_, SetRecordableEncodedFrameCallback);
|
|
EXPECT_CALL(channel_, ClearRecordableEncodedFrameCallback);
|
|
MockVideoSink sink;
|
|
Source()->AddEncodedSink(&sink);
|
|
MockVideoMediaChannel channel2(nullptr, cricket::VideoOptions());
|
|
EXPECT_CALL(channel2, SetRecordableEncodedFrameCallback);
|
|
receiver_->SetMediaChannel(&channel2);
|
|
Mock::VerifyAndClearExpectations(&channel2);
|
|
|
|
// When clearing encoded frame buffer function, we need channel switches
|
|
// to NOT set the callback again.
|
|
EXPECT_CALL(channel2, ClearRecordableEncodedFrameCallback);
|
|
Source()->RemoveEncodedSink(&sink);
|
|
StrictMock<MockVideoMediaChannel> channel3(nullptr, cricket::VideoOptions());
|
|
receiver_->SetMediaChannel(&channel3);
|
|
|
|
// We must call Stop() here since the mock media channels live on the stack
|
|
// and `receiver_` still has a pointer to those objects.
|
|
receiver_->Stop();
|
|
}
|
|
|
|
TEST_F(VideoRtpReceiverTest, BroadcastsEncodedFramesWhenEnabled) {
|
|
std::function<void(const RecordableEncodedFrame&)> broadcast;
|
|
EXPECT_CALL(channel_, SetRecordableEncodedFrameCallback(_, _))
|
|
.WillRepeatedly(SaveArg<1>(&broadcast));
|
|
MockVideoSink sink;
|
|
Source()->AddEncodedSink(&sink);
|
|
|
|
// Make sure SetEncodedFrameBufferFunction completes.
|
|
Mock::VerifyAndClearExpectations(&channel_);
|
|
|
|
// Pass two frames on different contexts.
|
|
EXPECT_CALL(sink, OnFrame).Times(2);
|
|
MockRecordableEncodedFrame frame;
|
|
broadcast(frame);
|
|
worker_thread_->Invoke<void>(RTC_FROM_HERE, [&] { broadcast(frame); });
|
|
}
|
|
|
|
TEST_F(VideoRtpReceiverTest, EnablesEncodedOutputOnChannelRestart) {
|
|
InSequence s;
|
|
EXPECT_CALL(channel_, ClearRecordableEncodedFrameCallback(0));
|
|
MockVideoSink sink;
|
|
Source()->AddEncodedSink(&sink);
|
|
EXPECT_CALL(channel_, SetRecordableEncodedFrameCallback(4711, _));
|
|
receiver_->SetupMediaChannel(4711);
|
|
EXPECT_CALL(channel_, ClearRecordableEncodedFrameCallback(4711));
|
|
EXPECT_CALL(channel_, SetRecordableEncodedFrameCallback(0, _));
|
|
receiver_->SetupUnsignaledMediaChannel();
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace webrtc
|