OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "remoting/protocol/protobuf_video_reader.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "net/socket/stream_socket.h" | |
9 #include "remoting/base/constants.h" | |
10 #include "remoting/proto/video.pb.h" | |
11 #include "remoting/protocol/session.h" | |
12 #include "remoting/protocol/stream_channel_factory.h" | |
13 | |
14 namespace remoting { | |
15 namespace protocol { | |
16 | |
17 ProtobufVideoReader::ProtobufVideoReader(VideoPacketFormat::Encoding encoding) | |
18 : encoding_(encoding), | |
19 channel_factory_(NULL), | |
20 video_stub_(NULL) { | |
21 } | |
22 | |
23 ProtobufVideoReader::~ProtobufVideoReader() { | |
24 if (channel_factory_) | |
25 channel_factory_->CancelChannelCreation(kVideoChannelName); | |
26 } | |
27 | |
28 void ProtobufVideoReader::Init(protocol::Session* session, | |
29 VideoStub* video_stub, | |
30 const InitializedCallback& callback) { | |
31 channel_factory_ = session->GetTransportChannelFactory(); | |
32 initialized_callback_ = callback; | |
33 video_stub_ = video_stub; | |
34 | |
35 channel_factory_->CreateChannel( | |
36 kVideoChannelName, | |
37 base::Bind(&ProtobufVideoReader::OnChannelReady, base::Unretained(this))); | |
38 } | |
39 | |
40 bool ProtobufVideoReader::is_connected() { | |
41 return channel_.get() != NULL; | |
42 } | |
43 | |
44 void ProtobufVideoReader::OnChannelReady(scoped_ptr<net::StreamSocket> socket) { | |
45 if (!socket.get()) { | |
46 initialized_callback_.Run(false); | |
47 return; | |
48 } | |
49 | |
50 DCHECK(!channel_.get()); | |
51 channel_ = socket.Pass(); | |
52 reader_.Init(channel_.get(), base::Bind(&ProtobufVideoReader::OnNewData, | |
53 base::Unretained(this))); | |
54 initialized_callback_.Run(true); | |
55 } | |
56 | |
57 void ProtobufVideoReader::OnNewData(scoped_ptr<VideoPacket> packet, | |
58 const base::Closure& done_task) { | |
59 video_stub_->ProcessVideoPacket(packet.Pass(), done_task); | |
60 } | |
61 | |
62 } // namespace protocol | |
63 } // namespace remoting | |
OLD | NEW |