Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2612)

Unified Diff: remoting/client/plugin/pepper_audio_player.cc

Issue 10795066: Support for both 44.1 kHz and 48 kHz on the client. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reupload Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/client/plugin/pepper_audio_player.cc
diff --git a/remoting/client/plugin/pepper_audio_player.cc b/remoting/client/plugin/pepper_audio_player.cc
index bf67436c1f91c369fb8696e2c62a4ec8958e6991..eb4a40061b4d12d50903f0c77404ebc48b05381e 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,60 @@ 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),
+ failed_playback_(false) {
}
-PepperAudioPlayer::PepperAudioPlayer(pp::Instance* instance)
- : samples_per_frame_(kSampleFrameCount),
- bytes_consumed_(0),
- running_(false) {
+PepperAudioPlayer::~PepperAudioPlayer() {}
+
+bool PepperAudioPlayer::StartPlayback() {
+ bool success = audio_.StartPlayback();
+ if (!success)
+ LOG(ERROR) << "Failed to start Pepper audio player";
+ return success;
+}
+
+void PepperAudioPlayer::ResetAudioPlayer(
Sergey Ulanov 2012/07/24 18:10:03 Don't think we need to separate StartPlayback() an
kxing 2012/07/24 18:32:01 Done.
+ 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);
-}
-
-PepperAudioPlayer::~PepperAudioPlayer() { }
-
-bool PepperAudioPlayer::Start() {
- running_ = audio_.StartPlayback();
- return running_;
+ audio_ = pp::Audio(instance_, audio_config, PepperAudioPlayerCallback, this);
}
void PepperAudioPlayer::ProcessAudioPacket(scoped_ptr<AudioPacket> packet) {
@@ -60,6 +81,25 @@ void PepperAudioPlayer::ProcessAudioPacket(scoped_ptr<AudioPacket> packet) {
}
base::AutoLock auto_lock(lock_);
+ // No-op if the Pepper player won't start.
+ if (failed_playback_) {
+ 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_);
+
+ ResetAudioPlayer(packet->sampling_rate());
+ bool success = StartPlayback();
+ if (!success) {
+ failed_playback_ = true;
+ return;
+ }
+ }
+
queued_packets_.push_back(packet.release());
}
« remoting/client/plugin/pepper_audio_player.h ('K') | « remoting/client/plugin/pepper_audio_player.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698