Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(545)

Side by Side Diff: remoting/protocol/host_video_dispatcher.cc

Issue 850983002: Implement video frame acknowledgements in the chromoting protocol. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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(
18 int frame_id,
19 const ProgressCallback& progress_callback)
20 : frame_id(frame_id), progress_callback(progress_callback) {
21 }
22
16 HostVideoDispatcher::HostVideoDispatcher() 23 HostVideoDispatcher::HostVideoDispatcher()
17 : ChannelDispatcherBase(kVideoChannelName) { 24 : ChannelDispatcherBase(kVideoChannelName),
25 frame_id_(0),
26 parser_(
27 base::Bind(&HostVideoDispatcher::OnVideoAck, base::Unretained(this)),
28 reader()) {
18 } 29 }
19 30
20 HostVideoDispatcher::~HostVideoDispatcher() { 31 HostVideoDispatcher::~HostVideoDispatcher() {
21 } 32 }
22 33
23 void HostVideoDispatcher::ProcessVideoPacket(scoped_ptr<VideoPacket> packet, 34 void HostVideoDispatcher::ProcessVideoPacket(
24 const base::Closure& done) { 35 scoped_ptr<VideoPacket> packet,
25 writer()->Write(SerializeAndFrameMessage(*packet), done); 36 const ProgressCallback& progress_callback) {
37 if (SupportsAcks()) {
38 packet->set_frame_id(frame_id_);
39 pending_frames_.push_back(PendingFrame(frame_id_, progress_callback));
40 frame_id_++;
41 }
42
43 writer()->Write(
44 SerializeAndFrameMessage(*packet),
45 base::Bind(&HostVideoDispatcher::OnPacketSent, base::Unretained(this),
46 progress_callback));
47 }
48
49 bool HostVideoDispatcher::SupportsAcks() {
50 return channel_config().version > kVideoStreamVersionNoAck;
51 }
52
53 void HostVideoDispatcher::OnPacketSent(
54 const ProgressCallback& progress_callback) {
55 progress_callback.Run(PacketProgress::SENT);
56
57 // For older clients that don't send explicit video Ack message call notify
58 // DONE state as soon as the frame is pushed to the channel.
59 if (!SupportsAcks())
60 progress_callback.Run(PacketProgress::DONE);
61 }
62
63 void HostVideoDispatcher::OnVideoAck(scoped_ptr<VideoAck> ack,
64 const base::Closure& done) {
65 base::ScopedClosureRunner done_runner(done);
66
67 if (!SupportsAcks()) {
68 LOG(ERROR) << "Unexpected VideoAck message received.";
69 return;
70 }
71
72 if (pending_frames_.empty() ||
73 pending_frames_.front().frame_id != ack->frame_id()) {
74 NotifyError(INCOMPATIBLE_PROTOCOL);
75 return;
76 }
77
78 // TODO(sergeyu): Currently the latency information in |ack| is ignored.
79 // Expose it from this class so that CaptureScheduler can utilize it somehow.
80 // See crbug.com/453177 .
81
82 ProgressCallback progress_callback =
83 pending_frames_.front().progress_callback;
84 pending_frames_.pop_front();
85 progress_callback.Run(PacketProgress::DONE);
26 } 86 }
27 87
28 } // namespace protocol 88 } // namespace protocol
29 } // namespace remoting 89 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698