OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/protocol/client_video_dispatcher.h" | 5 #include "remoting/protocol/client_video_dispatcher.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 void ProcessVideoPacket(scoped_ptr<VideoPacket> video_packet, | 29 void ProcessVideoPacket(scoped_ptr<VideoPacket> video_packet, |
30 const base::Closure& done) override; | 30 const base::Closure& done) override; |
31 | 31 |
32 // ChannelDispatcherBase::EventHandler interface. | 32 // ChannelDispatcherBase::EventHandler interface. |
33 void OnChannelInitialized(ChannelDispatcherBase* channel_dispatcher) override; | 33 void OnChannelInitialized(ChannelDispatcherBase* channel_dispatcher) override; |
34 void OnChannelError(ChannelDispatcherBase* channel_dispatcher, | 34 void OnChannelError(ChannelDispatcherBase* channel_dispatcher, |
35 ErrorCode error) override; | 35 ErrorCode error) override; |
36 | 36 |
37 protected: | 37 protected: |
38 void OnVideoAck(scoped_ptr<VideoAck> ack, const base::Closure& done); | 38 void OnVideoAck(scoped_ptr<VideoAck> ack, const base::Closure& done); |
| 39 void OnReadError(int error); |
39 | 40 |
40 base::MessageLoop message_loop_; | 41 base::MessageLoop message_loop_; |
41 | 42 |
42 // Set to true in OnChannelInitialized(). | 43 // Set to true in OnChannelInitialized(). |
43 bool initialized_; | 44 bool initialized_; |
44 | 45 |
45 // Client side. | 46 // Client side. |
46 ClientVideoDispatcher dispatcher_; | 47 ClientVideoDispatcher dispatcher_; |
47 FakeSession session_; | 48 FakeSession session_; |
48 | 49 |
(...skipping 16 matching lines...) Expand all Loading... |
65 base::Unretained(this)), | 66 base::Unretained(this)), |
66 &reader_) { | 67 &reader_) { |
67 dispatcher_.Init(&session_, ChannelConfig(ChannelConfig::TRANSPORT_MUX_STREAM, | 68 dispatcher_.Init(&session_, ChannelConfig(ChannelConfig::TRANSPORT_MUX_STREAM, |
68 kDefaultStreamVersion, | 69 kDefaultStreamVersion, |
69 ChannelConfig::CODEC_UNDEFINED), | 70 ChannelConfig::CODEC_UNDEFINED), |
70 this); | 71 this); |
71 base::RunLoop().RunUntilIdle(); | 72 base::RunLoop().RunUntilIdle(); |
72 DCHECK(initialized_); | 73 DCHECK(initialized_); |
73 host_socket_.PairWith( | 74 host_socket_.PairWith( |
74 session_.fake_channel_factory().GetFakeChannel(kVideoChannelName)); | 75 session_.fake_channel_factory().GetFakeChannel(kVideoChannelName)); |
75 reader_.StartReading(&host_socket_); | 76 reader_.StartReading(&host_socket_, |
| 77 base::Bind(&ClientVideoDispatcherTest::OnReadError, |
| 78 base::Unretained(this))); |
76 writer_.Init(&host_socket_, BufferedSocketWriter::WriteFailedCallback()); | 79 writer_.Init(&host_socket_, BufferedSocketWriter::WriteFailedCallback()); |
77 } | 80 } |
78 | 81 |
79 void ClientVideoDispatcherTest::ProcessVideoPacket( | 82 void ClientVideoDispatcherTest::ProcessVideoPacket( |
80 scoped_ptr<VideoPacket> video_packet, | 83 scoped_ptr<VideoPacket> video_packet, |
81 const base::Closure& done) { | 84 const base::Closure& done) { |
82 video_packets_.push_back(video_packet.release()); | 85 video_packets_.push_back(video_packet.release()); |
83 packet_done_callbacks_.push_back(done); | 86 packet_done_callbacks_.push_back(done); |
84 } | 87 } |
85 | 88 |
86 void ClientVideoDispatcherTest::OnChannelInitialized( | 89 void ClientVideoDispatcherTest::OnChannelInitialized( |
87 ChannelDispatcherBase* channel_dispatcher) { | 90 ChannelDispatcherBase* channel_dispatcher) { |
88 initialized_ = true; | 91 initialized_ = true; |
89 } | 92 } |
90 | 93 |
91 void ClientVideoDispatcherTest::OnChannelError( | 94 void ClientVideoDispatcherTest::OnChannelError( |
92 ChannelDispatcherBase* channel_dispatcher, | 95 ChannelDispatcherBase* channel_dispatcher, |
93 ErrorCode error) { | 96 ErrorCode error) { |
94 // Don't expect channel creation to fail. | 97 // Don't expect channel creation to fail. |
95 FAIL(); | 98 FAIL(); |
96 } | 99 } |
97 | 100 |
98 void ClientVideoDispatcherTest::OnVideoAck(scoped_ptr<VideoAck> ack, | 101 void ClientVideoDispatcherTest::OnVideoAck(scoped_ptr<VideoAck> ack, |
99 const base::Closure& done) { | 102 const base::Closure& done) { |
100 ack_messages_.push_back(ack.release()); | 103 ack_messages_.push_back(ack.release()); |
101 done.Run(); | 104 done.Run(); |
102 } | 105 } |
103 | 106 |
| 107 void ClientVideoDispatcherTest::OnReadError(int error) { |
| 108 LOG(FATAL) << "Unexpected read error: " << error; |
| 109 } |
| 110 |
104 // Verify that the client can receive video packets and acks are not sent for | 111 // Verify that the client can receive video packets and acks are not sent for |
105 // VideoPackets that don't have frame_id field set. | 112 // VideoPackets that don't have frame_id field set. |
106 TEST_F(ClientVideoDispatcherTest, WithoutAcks) { | 113 TEST_F(ClientVideoDispatcherTest, WithoutAcks) { |
107 VideoPacket packet; | 114 VideoPacket packet; |
108 packet.set_data(std::string()); | 115 packet.set_data(std::string()); |
109 | 116 |
110 // Send a VideoPacket and verify that the client receives it. | 117 // Send a VideoPacket and verify that the client receives it. |
111 writer_.Write(SerializeAndFrameMessage(packet), base::Closure()); | 118 writer_.Write(SerializeAndFrameMessage(packet), base::Closure()); |
112 base::RunLoop().RunUntilIdle(); | 119 base::RunLoop().RunUntilIdle(); |
113 EXPECT_EQ(1U, video_packets_.size()); | 120 EXPECT_EQ(1U, video_packets_.size()); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 base::RunLoop().RunUntilIdle(); | 178 base::RunLoop().RunUntilIdle(); |
172 | 179 |
173 // Verify order of Ack messages. | 180 // Verify order of Ack messages. |
174 ASSERT_EQ(2U, ack_messages_.size()); | 181 ASSERT_EQ(2U, ack_messages_.size()); |
175 EXPECT_EQ(kTestFrameId, ack_messages_[0]->frame_id()); | 182 EXPECT_EQ(kTestFrameId, ack_messages_[0]->frame_id()); |
176 EXPECT_EQ(kTestFrameId + 1, ack_messages_[1]->frame_id()); | 183 EXPECT_EQ(kTestFrameId + 1, ack_messages_[1]->frame_id()); |
177 } | 184 } |
178 | 185 |
179 } // namespace protocol | 186 } // namespace protocol |
180 } // namespace remoting | 187 } // namespace remoting |
OLD | NEW |