1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/cast/net/rtcp/receiver_rtcp_event_subscriber.h"
#include <stddef.h>
#include <stdint.h>
#include <utility>
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/test/simple_test_tick_clock.h"
#include "base/time/tick_clock.h"
#include "media/cast/cast_environment.h"
#include "media/cast/logging/logging_defines.h"
#include "media/cast/test/fake_single_thread_task_runner.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace media {
namespace cast {
namespace {
const size_t kMaxEventEntries = 10u;
const int64_t kDelayMs = 20L;
} // namespace
class ReceiverRtcpEventSubscriberTest : public ::testing::Test {
protected:
ReceiverRtcpEventSubscriberTest()
: testing_clock_(new base::SimpleTestTickClock()),
task_runner_(new test::FakeSingleThreadTaskRunner(testing_clock_)),
cast_environment_(
new CastEnvironment(scoped_ptr<base::TickClock>(testing_clock_),
task_runner_,
task_runner_,
task_runner_)) {}
~ReceiverRtcpEventSubscriberTest() override {}
void TearDown() final {
if (event_subscriber_) {
cast_environment_->logger()->Unsubscribe(event_subscriber_.get());
event_subscriber_.reset();
}
}
void Init(EventMediaType type) {
event_subscriber_.reset(
new ReceiverRtcpEventSubscriber(kMaxEventEntries, type));
cast_environment_->logger()->Subscribe(event_subscriber_.get());
}
void InsertEvents() {
// Video events
scoped_ptr<FrameEvent> playout_event(new FrameEvent());
playout_event->timestamp = testing_clock_->NowTicks();
playout_event->type = FRAME_PLAYOUT;
playout_event->media_type = VIDEO_EVENT;
playout_event->rtp_timestamp = RtpTimeTicks().Expand(UINT32_C(100));
playout_event->frame_id = 2u;
playout_event->delay_delta = base::TimeDelta::FromMilliseconds(kDelayMs);
cast_environment_->logger()->DispatchFrameEvent(std::move(playout_event));
scoped_ptr<FrameEvent> decode_event(new FrameEvent());
decode_event->timestamp = testing_clock_->NowTicks();
decode_event->type = FRAME_DECODED;
decode_event->media_type = VIDEO_EVENT;
decode_event->rtp_timestamp = RtpTimeTicks().Expand(UINT32_C(200));
decode_event->frame_id = 1u;
cast_environment_->logger()->DispatchFrameEvent(std::move(decode_event));
scoped_ptr<PacketEvent> receive_event(new PacketEvent());
receive_event->timestamp = testing_clock_->NowTicks();
receive_event->type = PACKET_RECEIVED;
receive_event->media_type = VIDEO_EVENT;
receive_event->rtp_timestamp = RtpTimeTicks().Expand(UINT32_C(200));
receive_event->frame_id = 2u;
receive_event->packet_id = 1u;
receive_event->max_packet_id = 10u;
receive_event->size = 1024u;
cast_environment_->logger()->DispatchPacketEvent(std::move(receive_event));
// Audio events
playout_event.reset(new FrameEvent());
playout_event->timestamp = testing_clock_->NowTicks();
playout_event->type = FRAME_PLAYOUT;
playout_event->media_type = AUDIO_EVENT;
playout_event->rtp_timestamp = RtpTimeTicks().Expand(UINT32_C(300));
playout_event->frame_id = 4u;
playout_event->delay_delta = base::TimeDelta::FromMilliseconds(kDelayMs);
cast_environment_->logger()->DispatchFrameEvent(std::move(playout_event));
decode_event.reset(new FrameEvent());
decode_event->timestamp = testing_clock_->NowTicks();
decode_event->type = FRAME_DECODED;
decode_event->media_type = AUDIO_EVENT;
decode_event->rtp_timestamp = RtpTimeTicks().Expand(UINT32_C(400));
decode_event->frame_id = 3u;
cast_environment_->logger()->DispatchFrameEvent(std::move(decode_event));
receive_event.reset(new PacketEvent());
receive_event->timestamp = testing_clock_->NowTicks();
receive_event->type = PACKET_RECEIVED;
receive_event->media_type = AUDIO_EVENT;
receive_event->rtp_timestamp = RtpTimeTicks().Expand(UINT32_C(400));
receive_event->frame_id = 5u;
receive_event->packet_id = 1u;
receive_event->max_packet_id = 10u;
receive_event->size = 128u;
cast_environment_->logger()->DispatchPacketEvent(std::move(receive_event));
// Unrelated events
scoped_ptr<FrameEvent> encode_event(new FrameEvent());
encode_event->timestamp = testing_clock_->NowTicks();
encode_event->type = FRAME_ENCODED;
encode_event->media_type = VIDEO_EVENT;
encode_event->rtp_timestamp = RtpTimeTicks().Expand(UINT32_C(100));
encode_event->frame_id = 1u;
cast_environment_->logger()->DispatchFrameEvent(std::move(encode_event));
encode_event.reset(new FrameEvent());
encode_event->timestamp = testing_clock_->NowTicks();
encode_event->type = FRAME_ENCODED;
encode_event->media_type = AUDIO_EVENT;
encode_event->rtp_timestamp = RtpTimeTicks().Expand(UINT32_C(100));
encode_event->frame_id = 1u;
cast_environment_->logger()->DispatchFrameEvent(std::move(encode_event));
}
base::SimpleTestTickClock* testing_clock_; // Owned by CastEnvironment.
scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_;
scoped_refptr<CastEnvironment> cast_environment_;
scoped_ptr<ReceiverRtcpEventSubscriber> event_subscriber_;
};
TEST_F(ReceiverRtcpEventSubscriberTest, LogVideoEvents) {
Init(VIDEO_EVENT);
InsertEvents();
ReceiverRtcpEventSubscriber::RtcpEvents rtcp_events;
event_subscriber_->GetRtcpEventsWithRedundancy(&rtcp_events);
EXPECT_EQ(3u, rtcp_events.size());
}
TEST_F(ReceiverRtcpEventSubscriberTest, LogAudioEvents) {
Init(AUDIO_EVENT);
InsertEvents();
ReceiverRtcpEventSubscriber::RtcpEvents rtcp_events;
event_subscriber_->GetRtcpEventsWithRedundancy(&rtcp_events);
EXPECT_EQ(3u, rtcp_events.size());
}
TEST_F(ReceiverRtcpEventSubscriberTest, DropEventsWhenSizeExceeded) {
Init(VIDEO_EVENT);
for (uint32_t i = 1u; i <= 10u; ++i) {
scoped_ptr<FrameEvent> decode_event(new FrameEvent());
decode_event->timestamp = testing_clock_->NowTicks();
decode_event->type = FRAME_DECODED;
decode_event->media_type = VIDEO_EVENT;
decode_event->rtp_timestamp = RtpTimeTicks().Expand(i * 10);
decode_event->frame_id = i;
cast_environment_->logger()->DispatchFrameEvent(std::move(decode_event));
}
ReceiverRtcpEventSubscriber::RtcpEvents rtcp_events;
event_subscriber_->GetRtcpEventsWithRedundancy(&rtcp_events);
EXPECT_EQ(10u, rtcp_events.size());
}
} // namespace cast
} // namespace media
|