Getting rid of GetDefaultProfile(), clean up of ProfileManager (which was in a seriou...
[chromium-blink-merge.git] / remoting / protocol / protobuf_video_writer.cc
blob7fd57c7bca42ca27564f930110749dfbfe12c763
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_writer.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"
13 #include "remoting/protocol/util.h"
15 namespace remoting {
16 namespace protocol {
18 ProtobufVideoWriter::ProtobufVideoWriter()
19 : channel_factory_(NULL) {
22 ProtobufVideoWriter::~ProtobufVideoWriter() {
23 Close();
26 void ProtobufVideoWriter::Init(protocol::Session* session,
27 const InitializedCallback& callback) {
28 channel_factory_ = session->GetTransportChannelFactory();
29 initialized_callback_ = callback;
31 channel_factory_->CreateStreamChannel(
32 kVideoChannelName,
33 base::Bind(&ProtobufVideoWriter::OnChannelReady, base::Unretained(this)));
36 void ProtobufVideoWriter::OnChannelReady(scoped_ptr<net::StreamSocket> socket) {
37 if (!socket.get()) {
38 initialized_callback_.Run(false);
39 return;
42 DCHECK(!channel_.get());
43 channel_ = socket.Pass();
44 // TODO(sergeyu): Provide WriteFailedCallback for the buffered writer.
45 buffered_writer_.Init(
46 channel_.get(), BufferedSocketWriter::WriteFailedCallback());
48 initialized_callback_.Run(true);
51 void ProtobufVideoWriter::Close() {
52 buffered_writer_.Close();
53 channel_.reset();
54 if (channel_factory_) {
55 channel_factory_->CancelChannelCreation(kVideoChannelName);
56 channel_factory_ = NULL;
60 bool ProtobufVideoWriter::is_connected() {
61 return channel_.get() != NULL;
64 void ProtobufVideoWriter::ProcessVideoPacket(scoped_ptr<VideoPacket> packet,
65 const base::Closure& done) {
66 // Older clients may expect deprecated flags field. Always set it to 7.
68 // TODO(sergeyu): Remove this field after M31 is released.
69 packet->set_deprecated_flags(7);
71 buffered_writer_.Write(SerializeAndFrameMessage(*packet), done);
74 } // namespace protocol
75 } // namespace remoting