OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "net/socket/stream_socket.h" | 8 #include "net/socket/stream_socket.h" |
9 #include "remoting/base/constants.h" | 9 #include "remoting/base/constants.h" |
10 #include "remoting/proto/video.pb.h" | 10 #include "remoting/proto/video.pb.h" |
| 11 #include "remoting/protocol/errors.h" |
| 12 #include "remoting/protocol/message_serialization.h" |
11 #include "remoting/protocol/video_stub.h" | 13 #include "remoting/protocol/video_stub.h" |
12 | 14 |
13 namespace remoting { | 15 namespace remoting { |
14 namespace protocol { | 16 namespace protocol { |
15 | 17 |
16 ClientVideoDispatcher::ClientVideoDispatcher(VideoStub* video_stub) | 18 ClientVideoDispatcher::ClientVideoDispatcher(VideoStub* video_stub) |
17 : ChannelDispatcherBase(kVideoChannelName), | 19 : ChannelDispatcherBase(kVideoChannelName), |
18 parser_(base::Bind(&VideoStub::ProcessVideoPacket, | 20 video_stub_(video_stub), |
19 base::Unretained(video_stub)), | 21 parser_(base::Bind(&ClientVideoDispatcher::ProcessVideoPacket, |
| 22 base::Unretained(this)), |
20 reader()) { | 23 reader()) { |
21 } | 24 } |
22 | 25 |
23 ClientVideoDispatcher::~ClientVideoDispatcher() { | 26 ClientVideoDispatcher::~ClientVideoDispatcher() { |
24 } | 27 } |
25 | 28 |
| 29 void ClientVideoDispatcher::ProcessVideoPacket( |
| 30 scoped_ptr<VideoPacket> video_packet, |
| 31 const base::Closure& done) { |
| 32 base::TimeTicks now = base::TimeTicks::Now(); |
| 33 |
| 34 int frame_id = video_packet->frame_id(); |
| 35 video_stub_->ProcessVideoPacket( |
| 36 video_packet.Pass(), |
| 37 base::Bind(&ClientVideoDispatcher::OnPacketProgress, |
| 38 base::Unretained(this), frame_id, |
| 39 reader()->last_message_read_duration(), now, done)); |
| 40 } |
| 41 |
| 42 void ClientVideoDispatcher::OnPacketProgress( |
| 43 int frame_id, |
| 44 base::TimeDelta time_to_receive, |
| 45 base::TimeTicks received_time, |
| 46 const base::Closure& done, |
| 47 VideoStub::PacketProgress packet_progress) { |
| 48 // Only interested in DONE notification. |
| 49 if (packet_progress != VideoStub::PacketProgress::DONE) |
| 50 return; |
| 51 |
| 52 done.Run(); |
| 53 |
| 54 // Don't send Ack message if the host doesn't support it. |
| 55 if (channel_config().version <= kVideoStreamVersionNoAck) |
| 56 return; |
| 57 |
| 58 // Send VideoAck. |
| 59 VideoAck ack_message; |
| 60 ack_message.set_frame_id(frame_id); |
| 61 ack_message.set_time_to_receive_us(time_to_receive.InMicroseconds()); |
| 62 ack_message.set_rendering_delay_us( |
| 63 (base::TimeTicks::Now() - received_time).InMicroseconds()); |
| 64 writer()->Write(SerializeAndFrameMessage(ack_message), base::Closure()); |
| 65 } |
| 66 |
26 } // namespace protocol | 67 } // namespace protocol |
27 } // namespace remoting | 68 } // namespace remoting |
OLD | NEW |