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