OLD | NEW |
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_reader.h" | 5 #include "remoting/protocol/protobuf_video_reader.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/session.h" | 12 #include "remoting/protocol/session.h" |
13 | 13 |
14 namespace remoting { | 14 namespace remoting { |
15 namespace protocol { | 15 namespace protocol { |
16 | 16 |
17 ProtobufVideoReader::ProtobufVideoReader(VideoPacketFormat::Encoding encoding) | 17 ProtobufVideoReader::ProtobufVideoReader(VideoPacketFormat::Encoding encoding) |
18 : encoding_(encoding), | 18 : session_(NULL), |
| 19 encoding_(encoding), |
19 video_stub_(NULL) { | 20 video_stub_(NULL) { |
20 } | 21 } |
21 | 22 |
22 ProtobufVideoReader::~ProtobufVideoReader() { } | 23 ProtobufVideoReader::~ProtobufVideoReader() { |
| 24 if (session_) |
| 25 session_->CancelChannelCreation(kVideoChannelName); |
| 26 } |
23 | 27 |
24 void ProtobufVideoReader::Init(protocol::Session* session, | 28 void ProtobufVideoReader::Init(protocol::Session* session, |
25 VideoStub* video_stub, | 29 VideoStub* video_stub, |
26 const InitializedCallback& callback) { | 30 const InitializedCallback& callback) { |
| 31 session_ = session; |
27 initialized_callback_ = callback; | 32 initialized_callback_ = callback; |
28 video_stub_ = video_stub; | 33 video_stub_ = video_stub; |
29 | 34 |
30 session->CreateStreamChannel( | 35 session_->CreateStreamChannel( |
31 kVideoChannelName, | 36 kVideoChannelName, |
32 base::Bind(&ProtobufVideoReader::OnChannelReady, base::Unretained(this))); | 37 base::Bind(&ProtobufVideoReader::OnChannelReady, base::Unretained(this))); |
33 } | 38 } |
34 | 39 |
35 void ProtobufVideoReader::OnChannelReady(net::StreamSocket* socket) { | 40 void ProtobufVideoReader::OnChannelReady(net::StreamSocket* socket) { |
36 if (!socket) { | 41 if (!socket) { |
37 initialized_callback_.Run(false); | 42 initialized_callback_.Run(false); |
38 return; | 43 return; |
39 } | 44 } |
40 | 45 |
41 DCHECK(!channel_.get()); | 46 DCHECK(!channel_.get()); |
42 channel_.reset(socket); | 47 channel_.reset(socket); |
43 reader_.Init(socket, base::Bind(&ProtobufVideoReader::OnNewData, | 48 reader_.Init(socket, base::Bind(&ProtobufVideoReader::OnNewData, |
44 base::Unretained(this))); | 49 base::Unretained(this))); |
45 initialized_callback_.Run(true); | 50 initialized_callback_.Run(true); |
46 } | 51 } |
47 | 52 |
48 void ProtobufVideoReader::OnNewData(VideoPacket* packet, | 53 void ProtobufVideoReader::OnNewData(VideoPacket* packet, |
49 const base::Closure& done_task) { | 54 const base::Closure& done_task) { |
50 video_stub_->ProcessVideoPacket(packet, done_task); | 55 video_stub_->ProcessVideoPacket(packet, done_task); |
51 } | 56 } |
52 | 57 |
53 } // namespace protocol | 58 } // namespace protocol |
54 } // namespace remoting | 59 } // namespace remoting |
OLD | NEW |