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

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

Issue 10823323: Add support for multiplexed channels in remoting::protocol::Session interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « remoting/protocol/protobuf_video_writer.h ('k') | remoting/protocol/protocol_mock_objects.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/socket/stream_socket.h" 8 #include "net/socket/stream_socket.h"
9 #include "remoting/base/constants.h" 9 #include "remoting/base/constants.h"
10 #include "remoting/proto/video.pb.h" 10 #include "remoting/proto/video.pb.h"
11 #include "remoting/protocol/channel_factory.h"
11 #include "remoting/protocol/session.h" 12 #include "remoting/protocol/session.h"
12 #include "remoting/protocol/util.h" 13 #include "remoting/protocol/util.h"
13 14
14 namespace remoting { 15 namespace remoting {
15 namespace protocol { 16 namespace protocol {
16 17
17 ProtobufVideoWriter::ProtobufVideoWriter() 18 ProtobufVideoWriter::ProtobufVideoWriter()
18 : session_(NULL) { 19 : channel_factory_(NULL) {
19 } 20 }
20 21
21 ProtobufVideoWriter::~ProtobufVideoWriter() { 22 ProtobufVideoWriter::~ProtobufVideoWriter() {
22 Close(); 23 Close();
23 } 24 }
24 25
25 void ProtobufVideoWriter::Init(protocol::Session* session, 26 void ProtobufVideoWriter::Init(protocol::Session* session,
26 const InitializedCallback& callback) { 27 const InitializedCallback& callback) {
27 session_ = session; 28 channel_factory_ = session->GetTransportChannelFactory();
28 initialized_callback_ = callback; 29 initialized_callback_ = callback;
29 30
30 session_->CreateStreamChannel( 31 channel_factory_->CreateStreamChannel(
31 kVideoChannelName, 32 kVideoChannelName,
32 base::Bind(&ProtobufVideoWriter::OnChannelReady, base::Unretained(this))); 33 base::Bind(&ProtobufVideoWriter::OnChannelReady, base::Unretained(this)));
33 } 34 }
34 35
35 void ProtobufVideoWriter::OnChannelReady(scoped_ptr<net::StreamSocket> socket) { 36 void ProtobufVideoWriter::OnChannelReady(scoped_ptr<net::StreamSocket> socket) {
36 if (!socket.get()) { 37 if (!socket.get()) {
37 initialized_callback_.Run(false); 38 initialized_callback_.Run(false);
38 return; 39 return;
39 } 40 }
40 41
41 DCHECK(!channel_.get()); 42 DCHECK(!channel_.get());
42 channel_ = socket.Pass(); 43 channel_ = socket.Pass();
43 // TODO(sergeyu): Provide WriteFailedCallback for the buffered writer. 44 // TODO(sergeyu): Provide WriteFailedCallback for the buffered writer.
44 buffered_writer_.Init( 45 buffered_writer_.Init(
45 channel_.get(), BufferedSocketWriter::WriteFailedCallback()); 46 channel_.get(), BufferedSocketWriter::WriteFailedCallback());
46 47
47 initialized_callback_.Run(true); 48 initialized_callback_.Run(true);
48 } 49 }
49 50
50 void ProtobufVideoWriter::Close() { 51 void ProtobufVideoWriter::Close() {
51 buffered_writer_.Close(); 52 buffered_writer_.Close();
52 channel_.reset(); 53 channel_.reset();
53 if (session_) { 54 if (channel_factory_) {
54 session_->CancelChannelCreation(kVideoChannelName); 55 channel_factory_->CancelChannelCreation(kVideoChannelName);
55 session_ = NULL; 56 channel_factory_ = NULL;
56 } 57 }
57 } 58 }
58 59
59 bool ProtobufVideoWriter::is_connected() { 60 bool ProtobufVideoWriter::is_connected() {
60 return channel_.get() != NULL; 61 return channel_.get() != NULL;
61 } 62 }
62 63
63 void ProtobufVideoWriter::ProcessVideoPacket(scoped_ptr<VideoPacket> packet, 64 void ProtobufVideoWriter::ProcessVideoPacket(scoped_ptr<VideoPacket> packet,
64 const base::Closure& done) { 65 const base::Closure& done) {
65 buffered_writer_.Write(SerializeAndFrameMessage(*packet), done); 66 buffered_writer_.Write(SerializeAndFrameMessage(*packet), done);
66 } 67 }
67 68
68 int ProtobufVideoWriter::GetPendingVideoPackets() { 69 int ProtobufVideoWriter::GetPendingVideoPackets() {
69 return buffered_writer_.GetBufferChunks(); 70 return buffered_writer_.GetBufferChunks();
70 } 71 }
71 72
72 } // namespace protocol 73 } // namespace protocol
73 } // namespace remoting 74 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/protobuf_video_writer.h ('k') | remoting/protocol/protocol_mock_objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698