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

Side by Side Diff: remoting/protocol/client_video_dispatcher_unittest.cc

Issue 850983002: Implement video frame acknowledgements in the chromoting protocol. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 unified diff | Download patch
« no previous file with comments | « remoting/protocol/client_video_dispatcher.cc ('k') | remoting/protocol/connection_to_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "remoting/protocol/client_video_dispatcher.h"
6
7 #include "base/bind.h"
8 #include "base/memory/scoped_vector.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h"
11 #include "remoting/base/constants.h"
12 #include "remoting/proto/video.pb.h"
13 #include "remoting/protocol/fake_session.h"
14 #include "remoting/protocol/fake_stream_socket.h"
15 #include "remoting/protocol/message_serialization.h"
16 #include "remoting/protocol/video_stub.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18
19 namespace remoting {
20 namespace protocol {
21
22 class ClientVideoDispatcherTest : public testing::Test,
23 public VideoStub,
24 public ChannelDispatcherBase::EventHandler {
25 public:
26 ClientVideoDispatcherTest();
27
28 // VideoStub interface.
29 void ProcessVideoPacket(scoped_ptr<VideoPacket> video_packet,
30 const base::Closure& done) override;
31
32 // ChannelDispatcherBase::EventHandler interface.
33 void OnChannelInitialized(ChannelDispatcherBase* channel_dispatcher) override;
34 void OnChannelError(ChannelDispatcherBase* channel_dispatcher,
35 ErrorCode error) override;
36
37 protected:
38 void OnVideoAck(scoped_ptr<VideoAck> ack, const base::Closure& done);
39
40 base::MessageLoop message_loop_;
41
42 // Set to true in OnChannelInitialized().
43 bool initialized_;
44
45 // Client side.
46 ClientVideoDispatcher dispatcher_;
47 FakeSession session_;
48
49 // Host side.
50 FakeStreamSocket host_socket_;
51 MessageReader reader_;
52 ProtobufMessageParser<VideoAck> parser_;
53 BufferedSocketWriter writer_;
54
55 ScopedVector<VideoPacket> video_packets_;
56 std::vector<base::Closure> packet_done_callbacks_;
57
58 ScopedVector<VideoAck> ack_messages_;
59 };
60
61 ClientVideoDispatcherTest::ClientVideoDispatcherTest()
62 : initialized_(false),
63 dispatcher_(this),
64 parser_(base::Bind(&ClientVideoDispatcherTest::OnVideoAck,
65 base::Unretained(this)),
66 &reader_) {
67 dispatcher_.Init(&session_, ChannelConfig(ChannelConfig::TRANSPORT_MUX_STREAM,
68 kDefaultStreamVersion,
69 ChannelConfig::CODEC_UNDEFINED),
70 this);
71 base::RunLoop().RunUntilIdle();
72 DCHECK(initialized_);
73 host_socket_.PairWith(
74 session_.fake_channel_factory().GetFakeChannel(kVideoChannelName));
75 reader_.StartReading(&host_socket_);
76 writer_.Init(&host_socket_, BufferedSocketWriter::WriteFailedCallback());
77 }
78
79 void ClientVideoDispatcherTest::ProcessVideoPacket(
80 scoped_ptr<VideoPacket> video_packet,
81 const base::Closure& done) {
82 video_packets_.push_back(video_packet.release());
83 packet_done_callbacks_.push_back(done);
84 }
85
86 void ClientVideoDispatcherTest::OnChannelInitialized(
87 ChannelDispatcherBase* channel_dispatcher) {
88 initialized_ = true;
89 }
90
91 void ClientVideoDispatcherTest::OnChannelError(
92 ChannelDispatcherBase* channel_dispatcher,
93 ErrorCode error) {
94 // Don't expect channel creation to fail.
95 FAIL();
96 }
97
98 void ClientVideoDispatcherTest::OnVideoAck(scoped_ptr<VideoAck> ack,
99 const base::Closure& done) {
100 ack_messages_.push_back(ack.release());
101 done.Run();
102 }
103
104 // Verify that the client can receive video packets and acks are not sent for
105 // VideoPackets that don't have frame_id field set.
106 TEST_F(ClientVideoDispatcherTest, WithoutAcks) {
107 VideoPacket packet;
108 packet.set_data(std::string());
109
110 // Send a VideoPacket and verify that the client receives it.
111 writer_.Write(SerializeAndFrameMessage(packet), base::Closure());
112 base::RunLoop().RunUntilIdle();
113 EXPECT_EQ(1U, video_packets_.size());
114
115 packet_done_callbacks_.front().Run();
116 base::RunLoop().RunUntilIdle();
117
118 // Ack should never be sent for the packet without frame_id.
119 EXPECT_TRUE(ack_messages_.empty());
120 }
121
122 // Verifies that the dispatcher sends Ack message with correct rendering delay.
123 TEST_F(ClientVideoDispatcherTest, WithAcks) {
124 int kTestFrameId = 3;
125
126 VideoPacket packet;
127 packet.set_data(std::string());
128 packet.set_frame_id(kTestFrameId);
129
130 // Send a VideoPacket and verify that the client receives it.
131 writer_.Write(SerializeAndFrameMessage(packet), base::Closure());
132 base::RunLoop().RunUntilIdle();
133 EXPECT_EQ(1U, video_packets_.size());
134
135 // Ack should only be sent after the packet is processed.
136 EXPECT_TRUE(ack_messages_.empty());
137 base::RunLoop().RunUntilIdle();
138
139 // Fake completion of video packet decoding, to trigger the Ack.
140 packet_done_callbacks_.front().Run();
141 base::RunLoop().RunUntilIdle();
142
143 // Verify that the Ack message has been received.
144 ASSERT_EQ(1U, ack_messages_.size());
145 EXPECT_EQ(kTestFrameId, ack_messages_[0]->frame_id());
146 }
147
148 // Verify that Ack messages are sent in correct order.
149 TEST_F(ClientVideoDispatcherTest, AcksOrder) {
150 int kTestFrameId = 3;
151
152 VideoPacket packet;
153 packet.set_data(std::string());
154 packet.set_frame_id(kTestFrameId);
155
156 // Send two VideoPackets.
157 writer_.Write(SerializeAndFrameMessage(packet), base::Closure());
158 base::RunLoop().RunUntilIdle();
159
160 packet.set_frame_id(kTestFrameId + 1);
161 writer_.Write(SerializeAndFrameMessage(packet), base::Closure());
162 base::RunLoop().RunUntilIdle();
163
164 EXPECT_EQ(2U, video_packets_.size());
165 EXPECT_TRUE(ack_messages_.empty());
166
167 // Call completion callbacks in revers order.
168 packet_done_callbacks_[1].Run();
169 packet_done_callbacks_[0].Run();
170
171 base::RunLoop().RunUntilIdle();
172
173 // Verify order of Ack messages.
174 ASSERT_EQ(2U, ack_messages_.size());
175 EXPECT_EQ(kTestFrameId, ack_messages_[0]->frame_id());
176 EXPECT_EQ(kTestFrameId + 1, ack_messages_[1]->frame_id());
177 }
178
179 } // namespace protocol
180 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/client_video_dispatcher.cc ('k') | remoting/protocol/connection_to_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698