| 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_reader.h" | 5 #include "remoting/protocol/audio_reader.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" | |
| 11 #include "remoting/protocol/session.h" | 10 #include "remoting/protocol/session.h" |
| 11 #include "remoting/protocol/session_config.h" |
| 12 | 12 |
| 13 namespace remoting { | 13 namespace remoting { |
| 14 namespace protocol { | 14 namespace protocol { |
| 15 | 15 |
| 16 ProtobufVideoReader::ProtobufVideoReader(VideoPacketFormat::Encoding encoding) | 16 AudioReader::AudioReader(AudioPacket::Encoding encoding) |
| 17 : session_(NULL), | 17 : session_(NULL), |
| 18 encoding_(encoding), | 18 encoding_(encoding), |
| 19 video_stub_(NULL) { | 19 audio_stub_(NULL) { |
| 20 } | 20 } |
| 21 | 21 |
| 22 ProtobufVideoReader::~ProtobufVideoReader() { | 22 AudioReader::~AudioReader() { |
| 23 if (session_) | 23 if (session_) |
| 24 session_->CancelChannelCreation(kVideoChannelName); | 24 session_->CancelChannelCreation(kAudioChannelName); |
| 25 } | 25 } |
| 26 | 26 |
| 27 void ProtobufVideoReader::Init(protocol::Session* session, | 27 void AudioReader::Init(protocol::Session* session, |
| 28 VideoStub* video_stub, | 28 AudioStub* audio_stub, |
| 29 const InitializedCallback& callback) { | 29 const InitializedCallback& callback) { |
| 30 session_ = session; | 30 session_ = session; |
| 31 initialized_callback_ = callback; | 31 initialized_callback_ = callback; |
| 32 video_stub_ = video_stub; | 32 audio_stub_ = audio_stub; |
| 33 | 33 |
| 34 session_->CreateStreamChannel( | 34 session_->CreateStreamChannel( |
| 35 kVideoChannelName, | 35 kAudioChannelName, |
| 36 base::Bind(&ProtobufVideoReader::OnChannelReady, base::Unretained(this))); | 36 base::Bind(&AudioReader::OnChannelReady, base::Unretained(this))); |
| 37 } | 37 } |
| 38 | 38 |
| 39 bool ProtobufVideoReader::is_connected() { | 39 bool AudioReader::is_connected() { |
| 40 return channel_.get() != NULL; | 40 return channel_.get() != NULL; |
| 41 } | 41 } |
| 42 | 42 |
| 43 void ProtobufVideoReader::OnChannelReady(scoped_ptr<net::StreamSocket> socket) { | 43 void AudioReader::OnChannelReady(scoped_ptr<net::StreamSocket> socket) { |
| 44 if (!socket.get()) { | 44 if (!socket.get()) { |
| 45 initialized_callback_.Run(false); | 45 initialized_callback_.Run(false); |
| 46 return; | 46 return; |
| 47 } | 47 } |
| 48 | 48 |
| 49 DCHECK(!channel_.get()); | 49 DCHECK(!channel_.get()); |
| 50 channel_ = socket.Pass(); | 50 channel_ = socket.Pass(); |
| 51 reader_.Init(channel_.get(), base::Bind(&ProtobufVideoReader::OnNewData, | 51 reader_.Init(channel_.get(), base::Bind(&AudioReader::OnNewData, |
| 52 base::Unretained(this))); | 52 base::Unretained(this))); |
| 53 initialized_callback_.Run(true); | 53 initialized_callback_.Run(true); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void ProtobufVideoReader::OnNewData(scoped_ptr<VideoPacket> packet, | 56 void AudioReader::OnNewData(scoped_ptr<AudioPacket> packet, |
| 57 const base::Closure& done_task) { | 57 const base::Closure& done_task) { |
| 58 video_stub_->ProcessVideoPacket(packet.Pass(), done_task); | 58 audio_stub_->ProcessAudioPacket(packet.Pass(), done_task); |
| 59 } |
| 60 |
| 61 // static |
| 62 AudioReader* AudioReader::Create(const SessionConfig& config) { |
| 63 // TODO(kxing): Support different session configurations. |
| 64 return new AudioReader(AudioPacket::ENCODING_RAW); |
| 59 } | 65 } |
| 60 | 66 |
| 61 } // namespace protocol | 67 } // namespace protocol |
| 62 } // namespace remoting | 68 } // namespace remoting |
| OLD | NEW |