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 "base/callback_helpers.h" |
8 #include "net/socket/stream_socket.h" | 9 #include "net/socket/stream_socket.h" |
9 #include "remoting/base/constants.h" | 10 #include "remoting/base/constants.h" |
10 #include "remoting/proto/video.pb.h" | 11 #include "remoting/proto/video.pb.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 |
| 18 struct ClientVideoDispatcher::PendingFrame { |
| 19 PendingFrame(int frame_id) |
| 20 : frame_id(frame_id), |
| 21 done(false) {} |
| 22 int frame_id; |
| 23 bool done; |
| 24 }; |
| 25 |
16 ClientVideoDispatcher::ClientVideoDispatcher(VideoStub* video_stub) | 26 ClientVideoDispatcher::ClientVideoDispatcher(VideoStub* video_stub) |
17 : ChannelDispatcherBase(kVideoChannelName), | 27 : ChannelDispatcherBase(kVideoChannelName), |
18 parser_(base::Bind(&VideoStub::ProcessVideoPacket, | 28 video_stub_(video_stub), |
19 base::Unretained(video_stub)), | 29 parser_(base::Bind(&ClientVideoDispatcher::ProcessVideoPacket, |
| 30 base::Unretained(this)), |
20 reader()) { | 31 reader()) { |
21 } | 32 } |
22 | 33 |
23 ClientVideoDispatcher::~ClientVideoDispatcher() { | 34 ClientVideoDispatcher::~ClientVideoDispatcher() { |
24 } | 35 } |
25 | 36 |
| 37 void ClientVideoDispatcher::ProcessVideoPacket( |
| 38 scoped_ptr<VideoPacket> video_packet, |
| 39 const base::Closure& done) { |
| 40 base::ScopedClosureRunner done_runner(done); |
| 41 |
| 42 int frame_id = video_packet->frame_id(); |
| 43 |
| 44 if (!video_packet->has_frame_id()) { |
| 45 video_stub_->ProcessVideoPacket(video_packet.Pass(), done_runner.Release()); |
| 46 return; |
| 47 } |
| 48 |
| 49 PendingFramesList::iterator pending_frame = |
| 50 pending_frames_.insert(pending_frames_.end(), PendingFrame(frame_id)); |
| 51 |
| 52 video_stub_->ProcessVideoPacket( |
| 53 video_packet.Pass(), base::Bind(&ClientVideoDispatcher::OnPacketDone, |
| 54 base::Unretained(this), pending_frame)); |
| 55 |
| 56 } |
| 57 |
| 58 void ClientVideoDispatcher::OnPacketDone( |
| 59 PendingFramesList::iterator pending_frame) { |
| 60 // Mark the frame as done. |
| 61 DCHECK(!pending_frame->done); |
| 62 pending_frame->done = true; |
| 63 |
| 64 // Send VideoAck for all packets in the head of the queue that have finished |
| 65 // rendering. |
| 66 while (!pending_frames_.empty() && pending_frames_.front().done) { |
| 67 VideoAck ack_message; |
| 68 ack_message.set_frame_id(pending_frames_.front().frame_id); |
| 69 writer()->Write(SerializeAndFrameMessage(ack_message), base::Closure()); |
| 70 pending_frames_.pop_front(); |
| 71 } |
| 72 } |
| 73 |
26 } // namespace protocol | 74 } // namespace protocol |
27 } // namespace remoting | 75 } // namespace remoting |
OLD | NEW |