summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkxing@chromium.org <kxing@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-15 00:58:37 +0000
committerkxing@chromium.org <kxing@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-15 00:58:37 +0000
commitb55a55f0eaef95f064d0773f7e1708b8e457bc45 (patch)
treed17a434471a8f0fa7b163a7b301aa714c98a5d0e
parent9d890d7411db7f7d0c993d0e94e9f3daf80c7392 (diff)
downloadchromium_src-b55a55f0eaef95f064d0773f7e1708b8e457bc45.zip
chromium_src-b55a55f0eaef95f064d0773f7e1708b8e457bc45.tar.gz
chromium_src-b55a55f0eaef95f064d0773f7e1708b8e457bc45.tar.bz2
Added files for audio writers.
The structure of AudioWriter and ProtobufAudioWriter are similar to their video counterparts. Review URL: https://chromiumcodereview.appspot.com/10535153 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142297 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--remoting/base/constants.cc1
-rw-r--r--remoting/base/constants.h1
-rw-r--r--remoting/protocol/audio_writer.cc76
-rw-r--r--remoting/protocol/audio_writer.h71
-rw-r--r--remoting/remoting.gyp2
5 files changed, 151 insertions, 0 deletions
diff --git a/remoting/base/constants.cc b/remoting/base/constants.cc
index 54ca8b8..a93f0f4 100644
--- a/remoting/base/constants.cc
+++ b/remoting/base/constants.cc
@@ -12,6 +12,7 @@ const char kChromotingTokenDefaultServiceName[] = "chromiumsync";
const char kChromotingXmlNamespace[] = "google:remoting";
+const char kAudioChannelName[] = "audio";
const char kControlChannelName[] = "control";
const char kEventChannelName[] = "event";
const char kVideoChannelName[] = "video";
diff --git a/remoting/base/constants.h b/remoting/base/constants.h
index 538564d..f5ea537 100644
--- a/remoting/base/constants.h
+++ b/remoting/base/constants.h
@@ -18,6 +18,7 @@ extern const char kChromotingTokenDefaultServiceName[];
extern const char kChromotingXmlNamespace[];
// Channel names.
+extern const char kAudioChannelName[];
extern const char kControlChannelName[];
extern const char kEventChannelName[];
extern const char kVideoChannelName[];
diff --git a/remoting/protocol/audio_writer.cc b/remoting/protocol/audio_writer.cc
new file mode 100644
index 0000000..dc8a939
--- /dev/null
+++ b/remoting/protocol/audio_writer.cc
@@ -0,0 +1,76 @@
+// 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_writer.h"
+
+#include "base/bind.h"
+#include "net/socket/stream_socket.h"
+#include "remoting/base/constants.h"
+#include "remoting/proto/audio.pb.h"
+#include "remoting/protocol/session.h"
+#include "remoting/protocol/session_config.h"
+#include "remoting/protocol/util.h"
+
+namespace remoting {
+namespace protocol {
+
+AudioWriter::AudioWriter()
+ : session_(NULL) {
+}
+
+AudioWriter::~AudioWriter() {
+ Close();
+}
+
+void AudioWriter::Init(protocol::Session* session,
+ const InitializedCallback& callback) {
+ session_ = session;
+ initialized_callback_ = callback;
+
+ session_->CreateStreamChannel(
+ kAudioChannelName,
+ base::Bind(&AudioWriter::OnChannelReady, base::Unretained(this)));
+}
+
+void AudioWriter::OnChannelReady(scoped_ptr<net::StreamSocket> socket) {
+ if (!socket.get()) {
+ initialized_callback_.Run(false);
+ return;
+ }
+
+ DCHECK(!channel_.get());
+ channel_ = socket.Pass();
+ // TODO(sergeyu): Provide WriteFailedCallback for the buffered writer.
+ buffered_writer_.Init(
+ channel_.get(), BufferedSocketWriter::WriteFailedCallback());
+
+ initialized_callback_.Run(true);
+}
+
+void AudioWriter::Close() {
+ buffered_writer_.Close();
+ channel_.reset();
+ if (session_) {
+ session_->CancelChannelCreation(kAudioChannelName);
+ session_ = NULL;
+ }
+}
+
+bool AudioWriter::is_connected() {
+ return channel_.get() != NULL;
+}
+
+void AudioWriter::ProcessAudioPacket(scoped_ptr<AudioPacket> packet,
+ const base::Closure& done) {
+ buffered_writer_.Write(SerializeAndFrameMessage(*packet), done);
+}
+
+// static
+AudioWriter* AudioWriter::Create(const SessionConfig& config) {
+ // TODO(kxing): Support different session configurations.
+ return new AudioWriter();
+}
+
+} // namespace protocol
+} // namespace remoting
diff --git a/remoting/protocol/audio_writer.h b/remoting/protocol/audio_writer.h
new file mode 100644
index 0000000..517c0a6
--- /dev/null
+++ b/remoting/protocol/audio_writer.h
@@ -0,0 +1,71 @@
+// 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.
+
+#ifndef REMOTING_PROTOCOL_AUDIO_WRITER_H_
+#define REMOTING_PROTOCOL_AUDIO_WRITER_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/callback.h"
+#include "base/compiler_specific.h"
+#include "base/memory/scoped_ptr.h"
+#include "remoting/protocol/audio_stub.h"
+#include "remoting/protocol/buffered_socket_writer.h"
+
+namespace net {
+class StreamSocket;
+} // namespace net
+
+namespace remoting {
+namespace protocol {
+
+class Session;
+class SessionConfig;
+
+class AudioWriter : public AudioStub {
+ public:
+ virtual ~AudioWriter();
+
+ // The callback is called when initialization is finished. The
+ // parameter is set to true on success.
+ typedef base::Callback<void(bool)> InitializedCallback;
+
+ static AudioWriter* Create(const SessionConfig& config);
+
+ // Initializes the writer.
+ void Init(Session* session, const InitializedCallback& callback);
+
+ // Stops writing. Must be called on the network thread before this
+ // object is destroyed.
+ void Close();
+
+ // Returns true if the channel is connected.
+ bool is_connected();
+
+ // AudioStub interface.
+ virtual void ProcessAudioPacket(scoped_ptr<AudioPacket> packet,
+ const base::Closure& done) OVERRIDE;
+
+ private:
+ AudioWriter();
+
+ void OnChannelReady(scoped_ptr<net::StreamSocket> socket);
+
+ Session* session_;
+
+ InitializedCallback initialized_callback_;
+
+ // TODO(sergeyu): Remove |channel_| and let |buffered_writer_| own it.
+ scoped_ptr<net::StreamSocket> channel_;
+
+ BufferedSocketWriter buffered_writer_;
+
+ DISALLOW_COPY_AND_ASSIGN(AudioWriter);
+};
+
+} // namespace protocol
+} // namespace remoting
+
+#endif // REMOTING_PROTOCOL_AUDIO_WRITER_H_
diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp
index c636c86..3711e7d 100644
--- a/remoting/remoting.gyp
+++ b/remoting/remoting.gyp
@@ -1505,6 +1505,8 @@
],
'sources': [
'protocol/audio_stub.h',
+ 'protocol/audio_writer.cc',
+ 'protocol/audio_writer.h',
'protocol/auth_util.cc',
'protocol/auth_util.h',
'protocol/authentication_method.cc',