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

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

Issue 8573013: Add CancelChannelCreation() in protocol::Session interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/protobuf_video_writer.h" 5 #include "remoting/protocol/protobuf_video_writer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/task.h" 8 #include "base/task.h"
9 #include "net/socket/stream_socket.h" 9 #include "net/socket/stream_socket.h"
10 #include "remoting/base/constants.h" 10 #include "remoting/base/constants.h"
11 #include "remoting/proto/video.pb.h" 11 #include "remoting/proto/video.pb.h"
12 #include "remoting/protocol/rtp_writer.h" 12 #include "remoting/protocol/rtp_writer.h"
13 #include "remoting/protocol/session.h" 13 #include "remoting/protocol/session.h"
14 #include "remoting/protocol/util.h" 14 #include "remoting/protocol/util.h"
15 15
16 namespace remoting { 16 namespace remoting {
17 namespace protocol { 17 namespace protocol {
18 18
19 ProtobufVideoWriter::ProtobufVideoWriter(base::MessageLoopProxy* message_loop) 19 ProtobufVideoWriter::ProtobufVideoWriter(base::MessageLoopProxy* message_loop)
20 : buffered_writer_(new BufferedSocketWriter(message_loop)) { 20 : session_(NULL),
21 buffered_writer_(new BufferedSocketWriter(message_loop)) {
21 } 22 }
22 23
23 ProtobufVideoWriter::~ProtobufVideoWriter() { } 24 ProtobufVideoWriter::~ProtobufVideoWriter() {
25 Close();
26 }
24 27
25 void ProtobufVideoWriter::Init(protocol::Session* session, 28 void ProtobufVideoWriter::Init(protocol::Session* session,
26 const InitializedCallback& callback) { 29 const InitializedCallback& callback) {
30 session_ = session;
27 initialized_callback_ = callback; 31 initialized_callback_ = callback;
28 32
29 session->CreateStreamChannel( 33 session_->CreateStreamChannel(
30 kVideoChannelName, 34 kVideoChannelName,
31 base::Bind(&ProtobufVideoWriter::OnChannelReady, base::Unretained(this))); 35 base::Bind(&ProtobufVideoWriter::OnChannelReady, base::Unretained(this)));
32 } 36 }
33 37
34 void ProtobufVideoWriter::OnChannelReady(net::StreamSocket* socket) { 38 void ProtobufVideoWriter::OnChannelReady(net::StreamSocket* socket) {
35 if (!socket) { 39 if (!socket) {
36 initialized_callback_.Run(false); 40 initialized_callback_.Run(false);
37 return; 41 return;
38 } 42 }
39 43
40 DCHECK(!channel_.get()); 44 DCHECK(!channel_.get());
41 channel_.reset(socket); 45 channel_.reset(socket);
42 // TODO(sergeyu): Provide WriteFailedCallback for the buffered writer. 46 // TODO(sergeyu): Provide WriteFailedCallback for the buffered writer.
43 buffered_writer_->Init(socket, BufferedSocketWriter::WriteFailedCallback()); 47 buffered_writer_->Init(socket, BufferedSocketWriter::WriteFailedCallback());
44 48
45 initialized_callback_.Run(true); 49 initialized_callback_.Run(true);
46 } 50 }
47 51
48 void ProtobufVideoWriter::Close() { 52 void ProtobufVideoWriter::Close() {
49 buffered_writer_->Close(); 53 buffered_writer_->Close();
50 channel_.reset(); 54 channel_.reset();
55 if (session_)
56 session_->CancelChannelCreation(kVideoChannelName);
Wez 2011/11/15 22:29:13 Clear |session_| here, or move this code into the
Sergey Ulanov 2011/11/16 00:01:33 Done.
51 } 57 }
52 58
53 void ProtobufVideoWriter::ProcessVideoPacket(const VideoPacket* packet, 59 void ProtobufVideoWriter::ProcessVideoPacket(const VideoPacket* packet,
54 const base::Closure& done) { 60 const base::Closure& done) {
55 buffered_writer_->Write(SerializeAndFrameMessage(*packet), done); 61 buffered_writer_->Write(SerializeAndFrameMessage(*packet), done);
56 } 62 }
57 63
58 int ProtobufVideoWriter::GetPendingPackets() { 64 int ProtobufVideoWriter::GetPendingPackets() {
59 return buffered_writer_->GetBufferChunks(); 65 return buffered_writer_->GetBufferChunks();
60 } 66 }
61 67
62 } // namespace protocol 68 } // namespace protocol
63 } // namespace remoting 69 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698