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"
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"
17 ProtobufVideoReader::ProtobufVideoReader(VideoPacketFormat::Encoding encoding
)
18 : encoding_(encoding
),
19 channel_factory_(NULL
),
23 ProtobufVideoReader::~ProtobufVideoReader() {
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(
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
) {
46 initialized_callback_
.Run(false);
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