Author:
kx...@chromium.org
Date: Wed Aug 1 10:41:43 2012
New Revision: 149441
Log:
Piping for audio encoding.
Review URL:
https://chromiumcodereview.appspot.com/10836017
Added:
trunk/src/remoting/codec/
trunk/src/remoting/codec/DEPS (contents, props changed)
trunk/src/remoting/codec/audio_encoder.h (contents, props changed)
trunk/src/remoting/codec/audio_encoder_verbatim.cc (contents, props changed)
trunk/src/remoting/codec/audio_encoder_verbatim.h (contents, props changed)
Modified:
trunk/src/remoting/host/DEPS
trunk/src/remoting/host/audio_capturer_win.cc
trunk/src/remoting/host/audio_scheduler.cc
trunk/src/remoting/host/audio_scheduler.h
trunk/src/remoting/host/chromoting_host.cc
trunk/src/remoting/host/chromoting_host.h
trunk/src/remoting/remoting.gyp
Added: trunk/src/remoting/codec/DEPS
==============================================================================
--- (empty file)
+++ trunk/src/remoting/codec/DEPS Wed Aug 1 10:41:43 2012
@@ -0,0 +1,3 @@
+include_rules = [
+ "+google/protobuf",
+]
Added: trunk/src/remoting/codec/audio_encoder.h
==============================================================================
--- (empty file)
+++ trunk/src/remoting/codec/audio_encoder.h Wed Aug 1 10:41:43 2012
@@ -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_
Added: trunk/src/remoting/codec/audio_encoder_verbatim.cc
==============================================================================
--- (empty file)
+++ trunk/src/remoting/codec/audio_encoder_verbatim.cc Wed Aug 1 10:41:43 2012
@@ -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
Added: trunk/src/remoting/codec/audio_encoder_verbatim.h
==============================================================================
--- (empty file)
+++ trunk/src/remoting/codec/audio_encoder_verbatim.h Wed Aug 1 10:41:43 2012
@@ -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_
Modified: trunk/src/remoting/host/DEPS
==============================================================================
--- trunk/src/remoting/host/DEPS (original)
+++ trunk/src/remoting/host/DEPS Wed Aug 1 10:41:43 2012
@@ -12,6 +12,7 @@
# at process start.
"+net/socket",
+ "+remoting/codec",
"+remoting/protocol",
"+remoting/jingle_glue",
"+third_party/jsoncpp",
Modified: trunk/src/remoting/host/audio_capturer_win.cc
==============================================================================
--- trunk/src/remoting/host/audio_capturer_win.cc (original)
+++ trunk/src/remoting/host/audio_capturer_win.cc Wed Aug 1 10:41:43 2012
@@ -279,6 +279,7 @@
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());
Modified: trunk/src/remoting/host/audio_scheduler.cc
==============================================================================
--- trunk/src/remoting/host/audio_scheduler.cc (original)
+++ trunk/src/remoting/host/audio_scheduler.cc Wed Aug 1 10:41:43 2012
@@ -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 @@
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 @@
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() {
Modified: trunk/src/remoting/host/audio_scheduler.h
==============================================================================
--- trunk/src/remoting/host/audio_scheduler.h (original)
+++ trunk/src/remoting/host/audio_scheduler.h Wed Aug 1 10:41:43 2012
@@ -21,6 +21,7 @@
} // namespace protocol
class AudioCapturer;
+class AudioEncoder;
class AudioPacket;
// A class for controlling AudioCapturer and forwarding audio packets to the
@@ -45,6 +46,7 @@
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 @@
AudioCapturer* audio_capturer_;
+ scoped_ptr<AudioEncoder> audio_encoder_;
+
protocol::AudioStub* audio_stub_;
bool network_stopped_;
Modified: trunk/src/remoting/host/chromoting_host.cc
==============================================================================
--- trunk/src/remoting/host/chromoting_host.cc (original)
+++ trunk/src/remoting/host/chromoting_host.cc Wed Aug 1 10:41:43 2012
@@ -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 @@
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 @@
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());
Modified: trunk/src/remoting/host/chromoting_host.h
==============================================================================
--- trunk/src/remoting/host/chromoting_host.h (original)
+++ trunk/src/remoting/host/chromoting_host.h Wed Aug 1 10:41:43 2012
@@ -31,6 +31,7 @@
class CandidateSessionConfig;
} // namespace protocol
+class AudioEncoder;
class AudioScheduler;
class ChromotingHostContext;
class DesktopEnvironment;
@@ -165,6 +166,10 @@
// 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();
Modified: trunk/src/remoting/remoting.gyp
==============================================================================
--- trunk/src/remoting/remoting.gyp (original)
+++ trunk/src/remoting/remoting.gyp Wed Aug 1 10:41:43 2012
@@ -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'