Disable session invalidations on Android with a flag.
[chromium-blink-merge.git] / remoting / protocol / protobuf_video_reader.cc
blob178a5de0b9b8fc0338757b39d8af7de74b1beaeb
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.
5 #include "remoting/protocol/protobuf_video_reader.h"
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/channel_factory.h"
12 #include "remoting/protocol/session.h"
14 namespace remoting {
15 namespace protocol {
17 ProtobufVideoReader::ProtobufVideoReader(VideoPacketFormat::Encoding encoding)
18 : encoding_(encoding),
19 channel_factory_(NULL),
20 video_stub_(NULL) {
23 ProtobufVideoReader::~ProtobufVideoReader() {
24 if (channel_factory_)
25 channel_factory_->CancelChannelCreation(kVideoChannelName);
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;
35 channel_factory_->CreateStreamChannel(
36 kVideoChannelName,
37 base::Bind(&ProtobufVideoReader::OnChannelReady, base::Unretained(this)));
40 bool ProtobufVideoReader::is_connected() {
41 return channel_.get() != NULL;
44 void ProtobufVideoReader::OnChannelReady(scoped_ptr<net::StreamSocket> socket) {
45 if (!socket.get()) {
46 initialized_callback_.Run(false);
47 return;
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);
57 void ProtobufVideoReader::OnNewData(scoped_ptr<VideoPacket> packet,
58 const base::Closure& done_task) {
59 video_stub_->ProcessVideoPacket(packet.Pass(), done_task);
62 } // namespace protocol
63 } // namespace remoting