| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_writer.h" | 5 #include "remoting/protocol/protobuf_audio_writer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "net/socket/stream_socket.h" | 8 #include "net/socket/stream_socket.h" |
| 9 #include "remoting/base/constants.h" | 9 #include "remoting/base/constants.h" |
| 10 #include "remoting/proto/video.pb.h" | 10 #include "remoting/proto/audio.pb.h" |
| 11 #include "remoting/protocol/session.h" | 11 #include "remoting/protocol/session.h" |
| 12 #include "remoting/protocol/util.h" | 12 #include "remoting/protocol/util.h" |
| 13 | 13 |
| 14 namespace remoting { | 14 namespace remoting { |
| 15 namespace protocol { | 15 namespace protocol { |
| 16 | 16 |
| 17 ProtobufVideoWriter::ProtobufVideoWriter() | 17 ProtobufAudioWriter::ProtobufAudioWriter() |
| 18 : session_(NULL) { | 18 : session_(NULL) { |
| 19 } | 19 } |
| 20 | 20 |
| 21 ProtobufVideoWriter::~ProtobufVideoWriter() { | 21 ProtobufAudioWriter::~ProtobufAudioWriter() { |
| 22 Close(); | 22 Close(); |
| 23 } | 23 } |
| 24 | 24 |
| 25 void ProtobufVideoWriter::Init(protocol::Session* session, | 25 void ProtobufAudioWriter::Init(protocol::Session* session, |
| 26 const InitializedCallback& callback) { | 26 const InitializedCallback& callback) { |
| 27 session_ = session; | 27 session_ = session; |
| 28 initialized_callback_ = callback; | 28 initialized_callback_ = callback; |
| 29 | 29 |
| 30 session_->CreateStreamChannel( | 30 session_->CreateStreamChannel( |
| 31 kVideoChannelName, | 31 kAudioChannelName, |
| 32 base::Bind(&ProtobufVideoWriter::OnChannelReady, base::Unretained(this))); | 32 base::Bind(&ProtobufAudioWriter::OnChannelReady, base::Unretained(this))); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void ProtobufVideoWriter::OnChannelReady(scoped_ptr<net::StreamSocket> socket) { | 35 void ProtobufAudioWriter::OnChannelReady(scoped_ptr<net::StreamSocket> socket) { |
| 36 if (!socket.get()) { | 36 if (!socket.get()) { |
| 37 initialized_callback_.Run(false); | 37 initialized_callback_.Run(false); |
| 38 return; | 38 return; |
| 39 } | 39 } |
| 40 | 40 |
| 41 DCHECK(!channel_.get()); | 41 DCHECK(!channel_.get()); |
| 42 channel_ = socket.Pass(); | 42 channel_ = socket.Pass(); |
| 43 // TODO(sergeyu): Provide WriteFailedCallback for the buffered writer. | 43 // TODO(kxing): Provide WriteFailedCallback for the buffered writer. |
| 44 buffered_writer_.Init( | 44 buffered_writer_.Init( |
| 45 channel_.get(), BufferedSocketWriter::WriteFailedCallback()); | 45 channel_.get(), BufferedSocketWriter::WriteFailedCallback()); |
| 46 | 46 |
| 47 initialized_callback_.Run(true); | 47 initialized_callback_.Run(true); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void ProtobufVideoWriter::Close() { | 50 void ProtobufAudioWriter::Close() { |
| 51 buffered_writer_.Close(); | 51 buffered_writer_.Close(); |
| 52 channel_.reset(); | 52 channel_.reset(); |
| 53 if (session_) { | 53 if (session_) { |
| 54 session_->CancelChannelCreation(kVideoChannelName); | 54 session_->CancelChannelCreation(kAudioChannelName); |
| 55 session_ = NULL; | 55 session_ = NULL; |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 bool ProtobufVideoWriter::is_connected() { | 59 bool ProtobufAudioWriter::is_connected() { |
| 60 return channel_.get() != NULL; | 60 return channel_.get() != NULL; |
| 61 } | 61 } |
| 62 | 62 |
| 63 void ProtobufVideoWriter::ProcessVideoPacket(scoped_ptr<VideoPacket> packet, | 63 void ProtobufAudioWriter::ProcessAudioPacket(scoped_ptr<AudioPacket> packet, |
| 64 const base::Closure& done) { | 64 const base::Closure& done) { |
| 65 buffered_writer_.Write(SerializeAndFrameMessage(*packet), done); | 65 buffered_writer_.Write(SerializeAndFrameMessage(*packet), done); |
| 66 } | 66 } |
| 67 | 67 |
| 68 int ProtobufVideoWriter::GetPendingPackets() { | |
| 69 return buffered_writer_.GetBufferChunks(); | |
| 70 } | |
| 71 | |
| 72 } // namespace protocol | 68 } // namespace protocol |
| 73 } // namespace remoting | 69 } // namespace remoting |
| OLD | NEW |