summaryrefslogtreecommitdiffstats
path: root/remoting/client
diff options
context:
space:
mode:
authorkxing@chromium.org <kxing@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-24 21:22:57 +0000
committerkxing@chromium.org <kxing@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-24 21:22:57 +0000
commit220206bde0de9ded61ea2a0da8cf7ed02c180ca3 (patch)
tree136288405108baeb656b4e08ab6bcb9a31c738a5 /remoting/client
parent77745dbe19040df439c148cc28f9f7268494508d (diff)
downloadchromium_src-220206bde0de9ded61ea2a0da8cf7ed02c180ca3.zip
chromium_src-220206bde0de9ded61ea2a0da8cf7ed02c180ca3.tar.gz
chromium_src-220206bde0de9ded61ea2a0da8cf7ed02c180ca3.tar.bz2
Support for both 44.1 kHz and 48 kHz on the client.
Review URL: https://chromiumcodereview.appspot.com/10795066 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148203 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/client')
-rw-r--r--remoting/client/audio_player.h5
-rw-r--r--remoting/client/chromoting_client.cc2
-rw-r--r--remoting/client/plugin/pepper_audio_player.cc74
-rw-r--r--remoting/client/plugin/pepper_audio_player.h17
4 files changed, 65 insertions, 33 deletions
diff --git a/remoting/client/audio_player.h b/remoting/client/audio_player.h
index eed8786..0397d09 100644
--- a/remoting/client/audio_player.h
+++ b/remoting/client/audio_player.h
@@ -19,13 +19,8 @@ class AudioPlayer {
public:
virtual ~AudioPlayer() {}
- // Returns true if successful, false otherwise.
- virtual bool Start() = 0;
-
virtual void ProcessAudioPacket(scoped_ptr<AudioPacket> packet) = 0;
- virtual bool IsRunning() const = 0;
-
protected:
AudioPlayer() {}
diff --git a/remoting/client/chromoting_client.cc b/remoting/client/chromoting_client.cc
index b66a13c..f0dd8c7 100644
--- a/remoting/client/chromoting_client.cc
+++ b/remoting/client/chromoting_client.cc
@@ -144,8 +144,6 @@ int ChromotingClient::GetPendingVideoPackets() {
void ChromotingClient::ProcessAudioPacket(scoped_ptr<AudioPacket> packet,
const base::Closure& done) {
audio_player_->ProcessAudioPacket(packet.Pass());
- if (!audio_player_->IsRunning() && connection_->config().is_audio_enabled())
- audio_player_->Start();
done.Run();
}
diff --git a/remoting/client/plugin/pepper_audio_player.cc b/remoting/client/plugin/pepper_audio_player.cc
index bf67436..4448770 100644
--- a/remoting/client/plugin/pepper_audio_player.cc
+++ b/remoting/client/plugin/pepper_audio_player.cc
@@ -7,7 +7,6 @@
#include <algorithm>
#include "base/stl_util.h"
-#include "remoting/proto/audio.pb.h"
namespace {
// Constants used to create an audio configuration resource.
@@ -17,38 +16,59 @@ const uint32_t kSampleFrameCount = 4096u;
// for now).
const uint32_t kChannels = 2u;
const int kSampleSizeBytes = 2;
+
+PP_AudioSampleRate ConvertToPepperSampleRate(
+ remoting::AudioPacket::SamplingRate sampling_rate) {
+ switch (sampling_rate) {
+ case remoting::AudioPacket::SAMPLING_RATE_44100:
+ return PP_AUDIOSAMPLERATE_44100;
+ case remoting::AudioPacket::SAMPLING_RATE_48000:
+ return PP_AUDIOSAMPLERATE_48000;
+ default:
+ NOTREACHED();
+ }
+ return PP_AUDIOSAMPLERATE_NONE;
+}
+
} // namespace
namespace remoting {
-bool PepperAudioPlayer::IsRunning() const {
- return running_;
+PepperAudioPlayer::PepperAudioPlayer(pp::Instance* instance)
+ : instance_(instance),
+ sampling_rate_(AudioPacket::SAMPLING_RATE_INVALID),
+ samples_per_frame_(kSampleFrameCount),
+ bytes_consumed_(0),
+ start_failed_(false) {
}
-PepperAudioPlayer::PepperAudioPlayer(pp::Instance* instance)
- : samples_per_frame_(kSampleFrameCount),
- bytes_consumed_(0),
- running_(false) {
+PepperAudioPlayer::~PepperAudioPlayer() {}
+
+bool PepperAudioPlayer::ResetAudioPlayer(
+ AudioPacket::SamplingRate sampling_rate) {
+ sampling_rate_ = sampling_rate;
+ PP_AudioSampleRate sample_rate =
+ ConvertToPepperSampleRate(sampling_rate);
+
// Ask the browser/device for an appropriate sample frame count size.
samples_per_frame_ =
- pp::AudioConfig::RecommendSampleFrameCount(instance,
- PP_AUDIOSAMPLERATE_44100,
+ pp::AudioConfig::RecommendSampleFrameCount(instance_,
+ sample_rate,
kSampleFrameCount);
// Create an audio configuration resource.
- pp::AudioConfig audio_config = pp::AudioConfig(instance,
- PP_AUDIOSAMPLERATE_44100,
+ pp::AudioConfig audio_config = pp::AudioConfig(instance_,
+ sample_rate,
samples_per_frame_);
// Create an audio resource.
- audio_ = pp::Audio(instance, audio_config, PepperAudioPlayerCallback, this);
-}
+ audio_ = pp::Audio(instance_, audio_config, PepperAudioPlayerCallback, this);
-PepperAudioPlayer::~PepperAudioPlayer() { }
-
-bool PepperAudioPlayer::Start() {
- running_ = audio_.StartPlayback();
- return running_;
+ // Immediately start the player.
+ bool success = audio_.StartPlayback();
+ if (!success)
+ LOG(ERROR) << "Failed to start Pepper audio player";
+ return success;
}
void PepperAudioPlayer::ProcessAudioPacket(scoped_ptr<AudioPacket> packet) {
@@ -60,6 +80,24 @@ void PepperAudioPlayer::ProcessAudioPacket(scoped_ptr<AudioPacket> packet) {
}
base::AutoLock auto_lock(lock_);
+ // No-op if the Pepper player won't start.
+ if (start_failed_) {
+ return;
+ }
+
+ // Start the Pepper audio player if this is the first packet.
+ if (sampling_rate_ != packet->sampling_rate()) {
+ // Drop all packets currently in the queue, since they are sampled at the
+ // wrong rate.
+ STLDeleteElements(&queued_packets_);
+
+ bool success = ResetAudioPlayer(packet->sampling_rate());
+ if (!success) {
+ start_failed_ = true;
+ return;
+ }
+ }
+
queued_packets_.push_back(packet.release());
}
diff --git a/remoting/client/plugin/pepper_audio_player.h b/remoting/client/plugin/pepper_audio_player.h
index 925b0dc..ad7c53d 100644
--- a/remoting/client/plugin/pepper_audio_player.h
+++ b/remoting/client/plugin/pepper_audio_player.h
@@ -15,26 +15,24 @@
#include "ppapi/cpp/audio.h"
#include "ppapi/cpp/instance.h"
#include "remoting/client/audio_player.h"
+#include "remoting/proto/audio.pb.h"
namespace remoting {
-class AudioPacket;
-
class PepperAudioPlayer : public AudioPlayer {
public:
explicit PepperAudioPlayer(pp::Instance* instance);
virtual ~PepperAudioPlayer();
- // Returns true if successful, false otherwise.
- virtual bool Start() OVERRIDE;
-
virtual void ProcessAudioPacket(scoped_ptr<AudioPacket> packet) OVERRIDE;
- virtual bool IsRunning() const OVERRIDE;
-
private:
typedef std::list<AudioPacket*> AudioPacketQueue;
+ // Resets the audio player and starts the playback.
+ // Returns true on success.
+ bool ResetAudioPlayer(AudioPacket::SamplingRate sampling_rate);
+
// Function called by the browser when it needs more audio samples.
static void PepperAudioPlayerCallback(void* samples,
uint32_t buffer_size,
@@ -42,8 +40,11 @@ class PepperAudioPlayer : public AudioPlayer {
void FillWithSamples(void* samples, uint32_t buffer_size);
+ pp::Instance* instance_;
pp::Audio audio_;
+ AudioPacket::SamplingRate sampling_rate_;
+
// The count of sample frames per channel in an audio buffer.
uint32_t samples_per_frame_;
@@ -57,7 +58,7 @@ class PepperAudioPlayer : public AudioPlayer {
// The number of bytes from |queued_packets_| that have been consumed.
size_t bytes_consumed_;
- bool running_;
+ bool start_failed_;
DISALLOW_COPY_AND_ASSIGN(PepperAudioPlayer);
};