summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorkxing@chromium.org <kxing@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-01 17:41:43 +0000
committerkxing@chromium.org <kxing@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-01 17:41:43 +0000
commitabad505506cdee422daaeb6f3de37b15393058f8 (patch)
treee6312b9f1137989bdce6833df2f3cc19943a2e05 /remoting
parentca254112419d316f0e89c92d6dc9487fc80bebf1 (diff)
downloadchromium_src-abad505506cdee422daaeb6f3de37b15393058f8.zip
chromium_src-abad505506cdee422daaeb6f3de37b15393058f8.tar.gz
chromium_src-abad505506cdee422daaeb6f3de37b15393058f8.tar.bz2
Piping for audio encoding.
Review URL: https://chromiumcodereview.appspot.com/10836017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149441 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/codec/DEPS3
-rw-r--r--remoting/codec/audio_encoder.h23
-rw-r--r--remoting/codec/audio_encoder_verbatim.cc22
-rw-r--r--remoting/codec/audio_encoder_verbatim.h29
-rw-r--r--remoting/host/DEPS1
-rw-r--r--remoting/host/audio_capturer_win.cc1
-rw-r--r--remoting/host/audio_scheduler.cc10
-rw-r--r--remoting/host/audio_scheduler.h4
-rw-r--r--remoting/host/chromoting_host.cc18
-rw-r--r--remoting/host/chromoting_host.h5
-rw-r--r--remoting/remoting.gyp5
11 files changed, 119 insertions, 2 deletions
diff --git a/remoting/codec/DEPS b/remoting/codec/DEPS
new file mode 100644
index 0000000..9e5dc3c
--- /dev/null
+++ b/remoting/codec/DEPS
@@ -0,0 +1,3 @@
+include_rules = [
+ "+google/protobuf",
+]
diff --git a/remoting/codec/audio_encoder.h b/remoting/codec/audio_encoder.h
new file mode 100644
index 0000000..30147d6
--- /dev/null
+++ b/remoting/codec/audio_encoder.h
@@ -0,0 +1,23 @@
+// 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_CODEC_AUDIO_ENCODER_H_
+#define REMOTING_CODEC_AUDIO_ENCODER_H_
+
+#include "base/memory/scoped_ptr.h"
+
+namespace remoting {
+
+class AudioPacket;
+
+class AudioEncoder {
+ public:
+ virtual ~AudioEncoder() {}
+
+ virtual scoped_ptr<AudioPacket> Encode(scoped_ptr<AudioPacket> packet) = 0;
+};
+
+} // namespace remoting
+
+#endif // REMOTING_CODEC_AUDIO_ENCODER_H_
diff --git a/remoting/codec/audio_encoder_verbatim.cc b/remoting/codec/audio_encoder_verbatim.cc
new file mode 100644
index 0000000..b81486b
--- /dev/null
+++ b/remoting/codec/audio_encoder_verbatim.cc
@@ -0,0 +1,22 @@
+// 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/codec/audio_encoder_verbatim.h"
+
+#include "base/logging.h"
+#include "remoting/proto/audio.pb.h"
+
+namespace remoting {
+
+AudioEncoderVerbatim::AudioEncoderVerbatim() {}
+
+AudioEncoderVerbatim::~AudioEncoderVerbatim() {}
+
+scoped_ptr<AudioPacket> AudioEncoderVerbatim::Encode(
+ scoped_ptr<AudioPacket> packet) {
+ DCHECK_EQ(AudioPacket::ENCODING_RAW, packet->encoding());
+ return packet.Pass();
+}
+
+} // namespace remoting
diff --git a/remoting/codec/audio_encoder_verbatim.h b/remoting/codec/audio_encoder_verbatim.h
new file mode 100644
index 0000000..d3bc9ca
--- /dev/null
+++ b/remoting/codec/audio_encoder_verbatim.h
@@ -0,0 +1,29 @@
+// 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_CODEC_AUDIO_ENCODER_VERBATIM_H_
+#define REMOTING_CODEC_AUDIO_ENCODER_VERBATIM_H_
+
+#include "remoting/codec/audio_encoder.h"
+
+namespace remoting {
+
+class AudioPacket;
+
+class AudioEncoderVerbatim : public AudioEncoder {
+ public:
+ AudioEncoderVerbatim();
+ virtual ~AudioEncoderVerbatim();
+
+ // AudioEncoder implementation.
+ virtual scoped_ptr<AudioPacket> Encode(
+ scoped_ptr<AudioPacket> packet) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AudioEncoderVerbatim);
+};
+
+} // namespace remoting
+
+#endif // REMOTING_CODEC_AUDIO_ENCODER_VERBATIM_H_
diff --git a/remoting/host/DEPS b/remoting/host/DEPS
index 4e1fca2..18c82e2 100644
--- a/remoting/host/DEPS
+++ b/remoting/host/DEPS
@@ -12,6 +12,7 @@ include_rules = [
# at process start.
"+net/socket",
+ "+remoting/codec",
"+remoting/protocol",
"+remoting/jingle_glue",
"+third_party/jsoncpp",
diff --git a/remoting/host/audio_capturer_win.cc b/remoting/host/audio_capturer_win.cc
index 5ea6bc3..b450a9a 100644
--- a/remoting/host/audio_capturer_win.cc
+++ b/remoting/host/audio_capturer_win.cc
@@ -279,6 +279,7 @@ void AudioCapturerWin::DoCapture() {
packet->set_sampling_rate(sampling_rate_);
packet->set_bytes_per_sample(
static_cast<AudioPacket::BytesPerSample>(sizeof(int16)));
+ packet->set_encoding(AudioPacket::ENCODING_RAW);
if (!IsPacketOfSilence(packet.get()))
callback_.Run(packet.Pass());
diff --git a/remoting/host/audio_scheduler.cc b/remoting/host/audio_scheduler.cc
index bb4aeb6..e104885 100644
--- a/remoting/host/audio_scheduler.cc
+++ b/remoting/host/audio_scheduler.cc
@@ -9,6 +9,7 @@
#include "base/location.h"
#include "base/logging.h"
#include "base/single_thread_task_runner.h"
+#include "remoting/codec/audio_encoder.h"
#include "remoting/host/audio_capturer.h"
#include "remoting/proto/audio.pb.h"
#include "remoting/protocol/audio_stub.h"
@@ -19,10 +20,12 @@ AudioScheduler::AudioScheduler(
scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
AudioCapturer* audio_capturer,
+ scoped_ptr<AudioEncoder> audio_encoder,
protocol::AudioStub* audio_stub)
: capture_task_runner_(capture_task_runner),
network_task_runner_(network_task_runner),
audio_capturer_(audio_capturer),
+ audio_encoder_(audio_encoder.Pass()),
audio_stub_(audio_stub),
network_stopped_(false) {
DCHECK(capture_task_runner_);
@@ -57,10 +60,13 @@ void AudioScheduler::OnClientDisconnected() {
AudioScheduler::~AudioScheduler() {
}
-void AudioScheduler::NotifyAudioPacketCaptured(scoped_ptr<AudioPacket> packet) {
+void AudioScheduler::NotifyAudioPacketCaptured(
+ scoped_ptr<AudioPacket> packet) {
+ scoped_ptr<AudioPacket> encoded_packet =
+ audio_encoder_->Encode(packet.Pass());
network_task_runner_->PostTask(
FROM_HERE, base::Bind(&AudioScheduler::DoSendAudioPacket,
- this, base::Passed(packet.Pass())));
+ this, base::Passed(encoded_packet.Pass())));
}
void AudioScheduler::DoStart() {
diff --git a/remoting/host/audio_scheduler.h b/remoting/host/audio_scheduler.h
index 05a06c6..d82de21 100644
--- a/remoting/host/audio_scheduler.h
+++ b/remoting/host/audio_scheduler.h
@@ -21,6 +21,7 @@ class AudioStub;
} // namespace protocol
class AudioCapturer;
+class AudioEncoder;
class AudioPacket;
// A class for controlling AudioCapturer and forwarding audio packets to the
@@ -45,6 +46,7 @@ class AudioScheduler : public base::RefCountedThreadSafe<AudioScheduler> {
scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
AudioCapturer* audio_capturer,
+ scoped_ptr<AudioEncoder> audio_encoder,
protocol::AudioStub* audio_stub);
// Stop the recording session.
@@ -75,6 +77,8 @@ class AudioScheduler : public base::RefCountedThreadSafe<AudioScheduler> {
AudioCapturer* audio_capturer_;
+ scoped_ptr<AudioEncoder> audio_encoder_;
+
protocol::AudioStub* audio_stub_;
bool network_stopped_;
diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc
index 7a55169..4e84aaa 100644
--- a/remoting/host/chromoting_host.cc
+++ b/remoting/host/chromoting_host.cc
@@ -13,6 +13,8 @@
#include "remoting/base/encoder.h"
#include "remoting/base/encoder_row_based.h"
#include "remoting/base/encoder_vp8.h"
+#include "remoting/codec/audio_encoder.h"
+#include "remoting/codec/audio_encoder_verbatim.h"
#include "remoting/host/audio_scheduler.h"
#include "remoting/host/chromoting_host_context.h"
#include "remoting/host/desktop_environment.h"
@@ -220,10 +222,13 @@ void ChromotingHost::OnSessionChannelsConnected(ClientSession* client) {
desktop_environment_->capturer(),
encoder);
if (client->connection()->session()->config().is_audio_enabled()) {
+ scoped_ptr<AudioEncoder> audio_encoder =
+ CreateAudioEncoder(client->connection()->session()->config());
audio_scheduler_ = new AudioScheduler(
context_->capture_task_runner(),
context_->network_task_runner(),
desktop_environment_->audio_capturer(),
+ audio_encoder.Pass(),
client->connection()->audio_stub());
}
@@ -417,6 +422,19 @@ Encoder* ChromotingHost::CreateEncoder(const protocol::SessionConfig& config) {
return NULL;
}
+// static
+scoped_ptr<AudioEncoder> ChromotingHost::CreateAudioEncoder(
+ const protocol::SessionConfig& config) {
+ const protocol::ChannelConfig& audio_config = config.audio_config();
+
+ if (audio_config.codec == protocol::ChannelConfig::CODEC_VERBATIM) {
+ return scoped_ptr<AudioEncoder>(new AudioEncoderVerbatim());
+ }
+
+ NOTIMPLEMENTED();
+ return scoped_ptr<AudioEncoder>(NULL);
+}
+
void ChromotingHost::StopScreenRecorder() {
DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
DCHECK(recorder_.get());
diff --git a/remoting/host/chromoting_host.h b/remoting/host/chromoting_host.h
index 713f969..ee745c8 100644
--- a/remoting/host/chromoting_host.h
+++ b/remoting/host/chromoting_host.h
@@ -31,6 +31,7 @@ class SessionConfig;
class CandidateSessionConfig;
} // namespace protocol
+class AudioEncoder;
class AudioScheduler;
class ChromotingHostContext;
class DesktopEnvironment;
@@ -165,6 +166,10 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>,
// Creates encoder for the specified configuration.
static Encoder* CreateEncoder(const protocol::SessionConfig& config);
+ // Creates an audio encoder for the specified configuration.
+ static scoped_ptr<AudioEncoder> CreateAudioEncoder(
+ const protocol::SessionConfig& config);
+
virtual ~ChromotingHost();
void StopScreenRecorder();
diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp
index 808a38b..df6ab09 100644
--- a/remoting/remoting.gyp
+++ b/remoting/remoting.gyp
@@ -1181,6 +1181,11 @@
'base/stoppable.h',
'base/util.cc',
'base/util.h',
+ # TODO(kxing): Seperate the audio and video codec files into a separate
+ # target.
+ 'codec/audio_encoder.h',
+ 'codec/audio_encoder_verbatim.cc',
+ 'codec/audio_encoder_verbatim.h',
],
}, # end of target 'remoting_base'