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::OnVideoPacket, |
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::OnVideoPacket(scoped_ptr<VideoPacket> video_packet, | |
30 const base::Closure& done) { | |
31 base::TimeTicks now = base::TimeTicks::Now(); | |
32 | |
33 VideoAck ack_message; | |
Wez
2015/01/21 01:35:38
Is creating and copying a protobuf super cheap? Co
Sergey Ulanov
2015/01/29 01:33:28
Done.
| |
34 ack_message.set_frame_id(video_packet->frame_id()); | |
35 | |
36 ack_message.set_time_to_receive_us( | |
37 reader()->last_message_read_delay().InMicroseconds()); | |
Wez
2015/01/21 01:35:39
nit: This line is logically part of initializing a
Sergey Ulanov
2015/01/29 01:33:28
Done.
| |
38 | |
39 video_stub_->ProcessVideoPacket( | |
40 video_packet.Pass(), | |
41 base::Bind(&ClientVideoDispatcher::OnPacketProcessed, | |
42 base::Unretained(this), ack_message, now, done)); | |
43 } | |
44 | |
45 void ClientVideoDispatcher::OnPacketProcessed(VideoAck ack_message, | |
46 base::TimeTicks received_time, | |
47 const base::Closure& done) { | |
48 done.Run(); | |
49 | |
50 // Send Ack message for newer version of the protocol. | |
51 if (channel_config().version >= kVideoWithAckStreamVersion) { | |
Wez
2015/01/21 01:35:39
The stream version never changes mid-session, so I
Sergey Ulanov
2015/01/29 01:33:28
Done.
| |
52 base::TimeDelta rendering_delay = base::TimeTicks::Now() - received_time; | |
53 ack_message.set_rendering_delay_us(rendering_delay.InMicroseconds()); | |
54 writer()->Write(SerializeAndFrameMessage(ack_message), base::Closure()); | |
55 } | |
56 } | |
57 | |
26 } // namespace protocol | 58 } // namespace protocol |
27 } // namespace remoting | 59 } // namespace remoting |
OLD | NEW |