Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Unified Diff: media/cast/audio_receiver/audio_receiver_unittest.cc

Issue 280993002: [Cast] Repair receiver playout time calculations and frame skip logic. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/cast/audio_receiver/audio_receiver.cc ('k') | media/cast/audio_sender/audio_sender_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/cast/audio_receiver/audio_receiver_unittest.cc
diff --git a/media/cast/audio_receiver/audio_receiver_unittest.cc b/media/cast/audio_receiver/audio_receiver_unittest.cc
index bcb7e3412186d6cbcf1f1a0efc2ed12940c9449e..9e2b1c21d0159e929bd0dd168dd9244334c9792a 100644
--- a/media/cast/audio_receiver/audio_receiver_unittest.cc
+++ b/media/cast/audio_receiver/audio_receiver_unittest.cc
@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <deque>
+#include <utility>
+
#include "base/bind.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
@@ -15,42 +18,44 @@
#include "media/cast/transport/pacing/mock_paced_packet_sender.h"
#include "testing/gmock/include/gmock/gmock.h"
+using ::testing::_;
+
namespace media {
namespace cast {
-using ::testing::_;
-
namespace {
-const int64 kStartMillisecond = INT64_C(12345678900000);
const uint32 kFirstFrameId = 1234;
+const int kPlayoutDelayMillis = 300;
class FakeAudioClient {
public:
FakeAudioClient() : num_called_(0) {}
virtual ~FakeAudioClient() {}
- void SetNextExpectedResult(uint32 expected_frame_id,
- const base::TimeTicks& expected_playout_time) {
- expected_frame_id_ = expected_frame_id;
- expected_playout_time_ = expected_playout_time;
+ void AddExpectedResult(uint32 expected_frame_id,
+ const base::TimeTicks& expected_playout_time) {
+ expected_results_.push_back(
+ std::make_pair(expected_frame_id, expected_playout_time));
}
void DeliverEncodedAudioFrame(
scoped_ptr<transport::EncodedFrame> audio_frame) {
+ SCOPED_TRACE(::testing::Message() << "num_called_ is " << num_called_);
ASSERT_FALSE(!audio_frame)
<< "If at shutdown: There were unsatisfied requests enqueued.";
- EXPECT_EQ(expected_frame_id_, audio_frame->frame_id);
- EXPECT_EQ(expected_playout_time_, audio_frame->reference_time);
+ ASSERT_FALSE(expected_results_.empty());
+ EXPECT_EQ(expected_results_.front().first, audio_frame->frame_id);
+ EXPECT_EQ(expected_results_.front().second, audio_frame->reference_time);
+ expected_results_.pop_front();
num_called_++;
}
int number_times_called() const { return num_called_; }
private:
+ std::deque<std::pair<uint32, base::TimeTicks> > expected_results_;
int num_called_;
- uint32 expected_frame_id_;
- base::TimeTicks expected_playout_time_;
DISALLOW_COPY_AND_ASSIGN(FakeAudioClient);
};
@@ -67,9 +72,11 @@ class AudioReceiverTest : public ::testing::Test {
audio_config_.codec = transport::kPcm16;
audio_config_.use_external_decoder = true;
audio_config_.feedback_ssrc = 1234;
+ audio_config_.incoming_ssrc = 5678;
+ audio_config_.rtp_max_delay_ms = kPlayoutDelayMillis;
testing_clock_ = new base::SimpleTestTickClock();
- testing_clock_->Advance(
- base::TimeDelta::FromMilliseconds(kStartMillisecond));
+ testing_clock_->Advance(base::TimeTicks::Now() - base::TimeTicks());
+ start_time_ = testing_clock_->NowTicks();
task_runner_ = new test::FakeSingleThreadTaskRunner(testing_clock_);
cast_environment_ = new CastEnvironment(
@@ -99,10 +106,26 @@ class AudioReceiverTest : public ::testing::Test {
payload_.data(), payload_.size(), rtp_header_);
}
+ void FeedLipSyncInfoIntoReceiver() {
+ const base::TimeTicks now = testing_clock_->NowTicks();
+ const int64 rtp_timestamp = (now - start_time_) *
+ audio_config_.frequency / base::TimeDelta::FromSeconds(1);
+ CHECK_LE(0, rtp_timestamp);
+ uint32 ntp_seconds;
+ uint32 ntp_fraction;
+ ConvertTimeTicksToNtp(now, &ntp_seconds, &ntp_fraction);
+ TestRtcpPacketBuilder rtcp_packet;
+ rtcp_packet.AddSrWithNtp(audio_config_.incoming_ssrc,
+ ntp_seconds, ntp_fraction,
+ static_cast<uint32>(rtp_timestamp));
+ receiver_->IncomingPacket(rtcp_packet.GetPacket().Pass());
+ }
+
AudioReceiverConfig audio_config_;
std::vector<uint8> payload_;
RtpCastHeader rtp_header_;
base::SimpleTestTickClock* testing_clock_; // Owned by CastEnvironment.
+ base::TimeTicks start_time_;
transport::MockPacedPacketSender mock_transport_;
scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_;
scoped_refptr<CastEnvironment> cast_environment_;
@@ -113,11 +136,15 @@ class AudioReceiverTest : public ::testing::Test {
scoped_ptr<AudioReceiver> receiver_;
};
-TEST_F(AudioReceiverTest, GetOnePacketEncodedFrame) {
+TEST_F(AudioReceiverTest, ReceivesOneFrame) {
SimpleEventSubscriber event_subscriber;
cast_environment_->Logging()->AddRawEventSubscriber(&event_subscriber);
- EXPECT_CALL(mock_transport_, SendRtcpPacket(_, _)).Times(1);
+ EXPECT_CALL(mock_transport_, SendRtcpPacket(_, _))
+ .WillRepeatedly(testing::Return(true));
+
+ FeedLipSyncInfoIntoReceiver();
+ task_runner_->RunTasks();
// Enqueue a request for an audio frame.
receiver_->GetEncodedAudioFrame(
@@ -129,8 +156,10 @@ TEST_F(AudioReceiverTest, GetOnePacketEncodedFrame) {
EXPECT_EQ(0, fake_audio_client_.number_times_called());
// Deliver one audio frame to the receiver and expect to get one frame back.
- fake_audio_client_.SetNextExpectedResult(kFirstFrameId,
- testing_clock_->NowTicks());
+ const base::TimeDelta target_playout_delay =
+ base::TimeDelta::FromMilliseconds(kPlayoutDelayMillis);
+ fake_audio_client_.AddExpectedResult(
+ kFirstFrameId, testing_clock_->NowTicks() + target_playout_delay);
FeedOneFrameIntoReceiver();
task_runner_->RunTasks();
EXPECT_EQ(1, fake_audio_client_.number_times_called());
@@ -147,10 +176,18 @@ TEST_F(AudioReceiverTest, GetOnePacketEncodedFrame) {
cast_environment_->Logging()->RemoveRawEventSubscriber(&event_subscriber);
}
-TEST_F(AudioReceiverTest, MultiplePendingGetCalls) {
+TEST_F(AudioReceiverTest, ReceivesFramesSkippingWhenAppropriate) {
EXPECT_CALL(mock_transport_, SendRtcpPacket(_, _))
.WillRepeatedly(testing::Return(true));
+ const uint32 rtp_advance_per_frame = audio_config_.frequency / 100;
+ const base::TimeDelta time_advance_per_frame =
+ base::TimeDelta::FromMilliseconds(10);
+
+ FeedLipSyncInfoIntoReceiver();
+ task_runner_->RunTasks();
+ const base::TimeTicks first_frame_capture_time = testing_clock_->NowTicks();
+
// Enqueue a request for an audio frame.
const FrameEncodedCallback frame_encoded_callback =
base::Bind(&FakeAudioClient::DeliverEncodedAudioFrame,
@@ -160,24 +197,15 @@ TEST_F(AudioReceiverTest, MultiplePendingGetCalls) {
EXPECT_EQ(0, fake_audio_client_.number_times_called());
// Receive one audio frame and expect to see the first request satisfied.
- fake_audio_client_.SetNextExpectedResult(kFirstFrameId,
- testing_clock_->NowTicks());
+ const base::TimeDelta target_playout_delay =
+ base::TimeDelta::FromMilliseconds(kPlayoutDelayMillis);
+ fake_audio_client_.AddExpectedResult(
+ kFirstFrameId, first_frame_capture_time + target_playout_delay);
+ rtp_header_.rtp_timestamp = 0;
FeedOneFrameIntoReceiver();
task_runner_->RunTasks();
EXPECT_EQ(1, fake_audio_client_.number_times_called());
- TestRtcpPacketBuilder rtcp_packet;
-
- uint32 ntp_high;
- uint32 ntp_low;
- ConvertTimeTicksToNtp(testing_clock_->NowTicks(), &ntp_high, &ntp_low);
- rtcp_packet.AddSrWithNtp(audio_config_.feedback_ssrc, ntp_high, ntp_low,
- rtp_header_.rtp_timestamp);
-
- testing_clock_->Advance(base::TimeDelta::FromMilliseconds(20));
-
- receiver_->IncomingPacket(rtcp_packet.GetPacket().Pass());
-
// Enqueue a second request for an audio frame, but it should not be
// fulfilled yet.
receiver_->GetEncodedAudioFrame(frame_encoded_callback);
@@ -189,10 +217,11 @@ TEST_F(AudioReceiverTest, MultiplePendingGetCalls) {
rtp_header_.is_key_frame = false;
rtp_header_.frame_id = kFirstFrameId + 2;
rtp_header_.reference_frame_id = 0;
- rtp_header_.rtp_timestamp = 960;
- fake_audio_client_.SetNextExpectedResult(
+ rtp_header_.rtp_timestamp += 2 * rtp_advance_per_frame;
+ fake_audio_client_.AddExpectedResult(
kFirstFrameId + 2,
- testing_clock_->NowTicks() + base::TimeDelta::FromMilliseconds(100));
+ first_frame_capture_time + 2 * time_advance_per_frame +
+ target_playout_delay);
FeedOneFrameIntoReceiver();
// Frame 2 should not come out at this point in time.
@@ -204,25 +233,27 @@ TEST_F(AudioReceiverTest, MultiplePendingGetCalls) {
task_runner_->RunTasks();
EXPECT_EQ(1, fake_audio_client_.number_times_called());
- // After 100 ms has elapsed, Frame 2 is emitted (to satisfy the second
- // request) because a decision was made to skip over the no-show Frame 1.
- testing_clock_->Advance(base::TimeDelta::FromMilliseconds(100));
+ // Now, advance time forward such that the receiver is convinced it should
+ // skip Frame 2. Frame 3 is emitted (to satisfy the second request) because a
+ // decision was made to skip over the no-show Frame 2.
+ testing_clock_->Advance(2 * time_advance_per_frame + target_playout_delay);
task_runner_->RunTasks();
EXPECT_EQ(2, fake_audio_client_.number_times_called());
- // Receive Frame 3 and expect it to fulfill the third request immediately.
+ // Receive Frame 4 and expect it to fulfill the third request immediately.
rtp_header_.frame_id = kFirstFrameId + 3;
rtp_header_.reference_frame_id = rtp_header_.frame_id - 1;
- rtp_header_.rtp_timestamp = 1280;
- fake_audio_client_.SetNextExpectedResult(kFirstFrameId + 3,
- testing_clock_->NowTicks());
+ rtp_header_.rtp_timestamp += rtp_advance_per_frame;
+ fake_audio_client_.AddExpectedResult(
+ kFirstFrameId + 3, first_frame_capture_time + 3 * time_advance_per_frame +
+ target_playout_delay);
FeedOneFrameIntoReceiver();
task_runner_->RunTasks();
EXPECT_EQ(3, fake_audio_client_.number_times_called());
- // Move forward another 100 ms and run any pending tasks (there should be
- // none). Expect no additional frames where emitted.
- testing_clock_->Advance(base::TimeDelta::FromMilliseconds(100));
+ // Move forward to the playout time of an unreceived Frame 5. Expect no
+ // additional frames were emitted.
+ testing_clock_->Advance(3 * time_advance_per_frame);
task_runner_->RunTasks();
EXPECT_EQ(3, fake_audio_client_.number_times_called());
}
« no previous file with comments | « media/cast/audio_receiver/audio_receiver.cc ('k') | media/cast/audio_sender/audio_sender_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698