Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / remoting / protocol / client_video_dispatcher.cc
bloba98bee327ebc384d75cabc5b60f5d19574fa2214
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
3 // found in the LICENSE file.
5 #include "remoting/protocol/client_video_dispatcher.h"
7 #include "base/bind.h"
8 #include "base/callback_helpers.h"
9 #include "net/socket/stream_socket.h"
10 #include "remoting/base/constants.h"
11 #include "remoting/proto/video.pb.h"
12 #include "remoting/protocol/message_serialization.h"
13 #include "remoting/protocol/video_stub.h"
15 namespace remoting {
16 namespace protocol {
18 struct ClientVideoDispatcher::PendingFrame {
19 PendingFrame(int frame_id)
20 : frame_id(frame_id),
21 done(false) {}
22 int frame_id;
23 bool done;
26 ClientVideoDispatcher::ClientVideoDispatcher(VideoStub* video_stub)
27 : ChannelDispatcherBase(kVideoChannelName),
28 video_stub_(video_stub),
29 parser_(base::Bind(&ClientVideoDispatcher::ProcessVideoPacket,
30 base::Unretained(this)),
31 reader()),
32 weak_factory_(this) {
35 ClientVideoDispatcher::~ClientVideoDispatcher() {
38 void ClientVideoDispatcher::ProcessVideoPacket(
39 scoped_ptr<VideoPacket> video_packet,
40 const base::Closure& done) {
41 base::ScopedClosureRunner done_runner(done);
43 int frame_id = video_packet->frame_id();
45 if (!video_packet->has_frame_id()) {
46 video_stub_->ProcessVideoPacket(video_packet.Pass(), done_runner.Release());
47 return;
50 PendingFramesList::iterator pending_frame =
51 pending_frames_.insert(pending_frames_.end(), PendingFrame(frame_id));
53 video_stub_->ProcessVideoPacket(
54 video_packet.Pass(),
55 base::Bind(&ClientVideoDispatcher::OnPacketDone,
56 weak_factory_.GetWeakPtr(), pending_frame));
59 void ClientVideoDispatcher::OnPacketDone(
60 PendingFramesList::iterator pending_frame) {
61 // Mark the frame as done.
62 DCHECK(!pending_frame->done);
63 pending_frame->done = true;
65 // Send VideoAck for all packets in the head of the queue that have finished
66 // rendering.
67 while (!pending_frames_.empty() && pending_frames_.front().done) {
68 VideoAck ack_message;
69 ack_message.set_frame_id(pending_frames_.front().frame_id);
70 writer()->Write(SerializeAndFrameMessage(ack_message), base::Closure());
71 pending_frames_.pop_front();
75 } // namespace protocol
76 } // namespace remoting