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/host_video_dispatcher.h" | 5 #include "remoting/protocol/host_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/protocol/errors.h" |
11 #include "remoting/protocol/message_serialization.h" | 12 #include "remoting/protocol/message_serialization.h" |
12 | 13 |
13 namespace remoting { | 14 namespace remoting { |
14 namespace protocol { | 15 namespace protocol { |
15 | 16 |
17 HostVideoDispatcher::PendingFrame::PendingFrame(int frame_id, | |
18 const base::Closure& done) | |
19 : frame_id(frame_id), done(done) { | |
20 } | |
21 | |
16 HostVideoDispatcher::HostVideoDispatcher() | 22 HostVideoDispatcher::HostVideoDispatcher() |
17 : ChannelDispatcherBase(kVideoChannelName) { | 23 : ChannelDispatcherBase(kVideoChannelName), |
24 frame_id_(0), | |
25 parser_( | |
26 base::Bind(&HostVideoDispatcher::OnVideoAck, base::Unretained(this)), | |
27 reader()) { | |
18 } | 28 } |
19 | 29 |
20 HostVideoDispatcher::~HostVideoDispatcher() { | 30 HostVideoDispatcher::~HostVideoDispatcher() { |
21 } | 31 } |
22 | 32 |
23 void HostVideoDispatcher::ProcessVideoPacket(scoped_ptr<VideoPacket> packet, | 33 void HostVideoDispatcher::ProcessVideoPacket(scoped_ptr<VideoPacket> packet, |
24 const base::Closure& done) { | 34 const base::Closure& done) { |
25 writer()->Write(SerializeAndFrameMessage(*packet), done); | 35 // For older clients that don't send explicit video Ack message call |done| as |
36 // soon as the frame is pushed to the channel. | |
37 if (channel_config().version < kVideoWithAckStreamVersion) { | |
38 writer()->Write(SerializeAndFrameMessage(*packet), done); | |
39 return; | |
40 } | |
41 | |
42 pending_frames_.push_back(PendingFrame(frame_id_, done)); | |
43 packet->set_frame_id(frame_id_); | |
44 frame_id_++; | |
45 writer()->Write(SerializeAndFrameMessage(*packet), base::Closure()); | |
46 } | |
47 | |
48 bool HostVideoDispatcher::SupportsAcks() { | |
49 return channel_config().version >= kVideoWithAckStreamVersion; | |
50 } | |
51 | |
52 void HostVideoDispatcher::OnVideoAck(scoped_ptr<VideoAck> ack, | |
53 const base::Closure& done) { | |
Wez
2015/01/21 01:35:40
Need some kind of comment and bug # reference in h
Sergey Ulanov
2015/01/29 01:33:29
Done.
| |
54 base::ScopedClosureRunner done_runner(done); | |
55 | |
56 if (pending_frames_.empty() || | |
57 pending_frames_.front().frame_id != ack->frame_id()) { | |
58 NotifyError(INCOMPATIBLE_PROTOCOL); | |
59 return; | |
60 } | |
61 | |
62 pending_frames_.front().done.Run(); | |
Wez
2015/01/21 01:35:40
Are you guaranteed that the callback won't delete
Sergey Ulanov
2015/01/29 01:33:29
Done.
| |
63 pending_frames_.pop_front(); | |
26 } | 64 } |
27 | 65 |
28 } // namespace protocol | 66 } // namespace protocol |
29 } // namespace remoting | 67 } // namespace remoting |
OLD | NEW |