Index: remoting/protocol/audio_reader.cc |
diff --git a/remoting/protocol/audio_reader.cc b/remoting/protocol/audio_reader.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6a607bd11eaf05db32752874008972705a230e8f |
--- /dev/null |
+++ b/remoting/protocol/audio_reader.cc |
@@ -0,0 +1,68 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "remoting/protocol/audio_reader.h" |
+ |
+#include "base/bind.h" |
+#include "net/socket/stream_socket.h" |
+#include "remoting/base/constants.h" |
+#include "remoting/protocol/session.h" |
+#include "remoting/protocol/session_config.h" |
+ |
+namespace remoting { |
+namespace protocol { |
+ |
+AudioReader::AudioReader(AudioPacket::Encoding encoding) |
+ : session_(NULL), |
+ encoding_(encoding), |
+ audio_stub_(NULL) { |
+} |
+ |
+AudioReader::~AudioReader() { |
+ if (session_) |
+ session_->CancelChannelCreation(kAudioChannelName); |
+} |
+ |
+// static |
+scoped_ptr<AudioReader> AudioReader::Create(const SessionConfig& config) { |
+ // TODO(kxing): Support different session configurations. |
+ return scoped_ptr<AudioReader>(new AudioReader(AudioPacket::ENCODING_RAW)); |
Wez
2012/06/15 20:40:54
This limits you to using a single audio encoding p
|
+} |
+ |
+void AudioReader::Init(protocol::Session* session, |
+ AudioStub* audio_stub, |
+ const InitializedCallback& callback) { |
+ session_ = session; |
+ initialized_callback_ = callback; |
+ audio_stub_ = audio_stub; |
+ |
+ session_->CreateStreamChannel( |
+ kAudioChannelName, |
+ base::Bind(&AudioReader::OnChannelReady, base::Unretained(this))); |
+} |
+ |
+bool AudioReader::is_connected() { |
+ return channel_.get() != NULL; |
+} |
+ |
+void AudioReader::OnChannelReady(scoped_ptr<net::StreamSocket> socket) { |
+ if (!socket.get()) { |
+ initialized_callback_.Run(false); |
+ return; |
+ } |
+ |
+ DCHECK(!channel_.get()); |
Wez
2012/06/15 20:40:54
DCHECK() this in Init() as well, to trap mistaken
|
+ channel_ = socket.Pass(); |
+ reader_.Init(channel_.get(), base::Bind(&AudioReader::OnNewData, |
+ base::Unretained(this))); |
+ initialized_callback_.Run(true); |
+} |
+ |
+void AudioReader::OnNewData(scoped_ptr<AudioPacket> packet, |
+ const base::Closure& done_task) { |
+ audio_stub_->ProcessAudioPacket(packet.Pass(), done_task); |
+} |
+ |
+} // namespace protocol |
+} // namespace remoting |