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/message_serialization.h" | |
11 #include "remoting/protocol/video_stub.h" | 12 #include "remoting/protocol/video_stub.h" |
12 | 13 |
13 namespace remoting { | 14 namespace remoting { |
14 namespace protocol { | 15 namespace protocol { |
15 | 16 |
17 struct ClientVideoDispatcher::PendingFrame { | |
18 PendingFrame(int frame_id) | |
19 : frame_id(frame_id), | |
20 done(false) {} | |
21 int frame_id; | |
22 bool done; | |
23 }; | |
24 | |
16 ClientVideoDispatcher::ClientVideoDispatcher(VideoStub* video_stub) | 25 ClientVideoDispatcher::ClientVideoDispatcher(VideoStub* video_stub) |
17 : ChannelDispatcherBase(kVideoChannelName), | 26 : ChannelDispatcherBase(kVideoChannelName), |
18 parser_(base::Bind(&VideoStub::ProcessVideoPacket, | 27 video_stub_(video_stub), |
19 base::Unretained(video_stub)), | 28 parser_(base::Bind(&ClientVideoDispatcher::ProcessVideoPacket, |
29 base::Unretained(this)), | |
20 reader()) { | 30 reader()) { |
21 } | 31 } |
22 | 32 |
23 ClientVideoDispatcher::~ClientVideoDispatcher() { | 33 ClientVideoDispatcher::~ClientVideoDispatcher() { |
24 } | 34 } |
25 | 35 |
36 void ClientVideoDispatcher::ProcessVideoPacket( | |
37 scoped_ptr<VideoPacket> video_packet, | |
38 const base::Closure& done) { | |
39 int frame_id = video_packet->frame_id(); | |
40 | |
41 if (!video_packet->has_frame_id()) { | |
42 video_stub_->ProcessVideoPacket(video_packet.Pass(), done); | |
43 return; | |
44 } | |
45 | |
46 PendingFramesList::iterator pending_frame = | |
47 pending_frames_.insert(pending_frames_.end(), PendingFrame(frame_id)); | |
48 | |
49 video_stub_->ProcessVideoPacket( | |
50 video_packet.Pass(), base::Bind(&ClientVideoDispatcher::OnPacketDone, | |
51 base::Unretained(this), pending_frame)); | |
Wez
2015/02/11 02:22:56
Why do we only want to ACK after the frame has bee
Sergey Ulanov
2015/02/17 19:37:07
If the renderer is slow/blocked we want the host t
Wez
2015/02/21 03:12:02
Acknowledged.
| |
52 | |
53 done.Run(); | |
Wez
2015/02/11 02:22:56
ScopedTaskRunner for this?
Sergey Ulanov
2015/02/17 19:37:07
Done.
| |
54 } | |
55 | |
56 void ClientVideoDispatcher::OnPacketDone( | |
57 PendingFramesList::iterator pending_frame) { | |
Wez
2015/02/11 02:22:56
You're passing in an iterator into the list, but t
Sergey Ulanov
2015/02/17 19:37:07
std::list<> iterators remain valid even when the l
| |
58 // Mark the frame as done. | |
59 pending_frame->done = true; | |
60 | |
61 // Send VideoAck for all packets in the head of the queue that have finished | |
62 // rendering. | |
63 while (!pending_frames_.empty() && pending_frames_.front().done) { | |
Wez
2015/02/11 02:22:56
Why do you need this loop? Surely you'll already h
Sergey Ulanov
2015/02/17 19:37:07
VideoAck messages should be sent in the order Vide
Wez
2015/02/21 03:12:02
Ahhhh, OK, yes I see what you mean. SGTM
| |
64 VideoAck ack_message; | |
65 ack_message.set_frame_id(pending_frames_.front().frame_id); | |
66 writer()->Write(SerializeAndFrameMessage(ack_message), base::Closure()); | |
67 pending_frames_.pop_front(); | |
68 } | |
69 } | |
70 | |
26 } // namespace protocol | 71 } // namespace protocol |
27 } // namespace remoting | 72 } // namespace remoting |
OLD | NEW |