This source file includes following definitions.
- samples_per_frame_
- GetSamplesPerFrame
- ResetAudioPlayer
#include "remoting/client/plugin/pepper_audio_player.h"
#include <algorithm>
#include "base/logging.h"
#include "base/stl_util.h"
const int kFrameSizeMs = 40;
namespace remoting {
PepperAudioPlayer::PepperAudioPlayer(pp::Instance* instance)
: instance_(instance),
samples_per_frame_(0) {
}
PepperAudioPlayer::~PepperAudioPlayer() {
}
uint32 PepperAudioPlayer::GetSamplesPerFrame() {
return samples_per_frame_;
}
bool PepperAudioPlayer::ResetAudioPlayer(
AudioPacket::SamplingRate sampling_rate) {
PP_AudioSampleRate pp_sampling_rate = PP_AUDIOSAMPLERATE_NONE;
switch (sampling_rate) {
case AudioPacket::SAMPLING_RATE_44100:
pp_sampling_rate = PP_AUDIOSAMPLERATE_44100;
break;
case AudioPacket::SAMPLING_RATE_48000:
pp_sampling_rate = PP_AUDIOSAMPLERATE_48000;
break;
default:
LOG(ERROR) << "Unsupported audio sampling rate: " << sampling_rate;
return false;
}
samples_per_frame_ = pp::AudioConfig::RecommendSampleFrameCount(
instance_, pp_sampling_rate,
kFrameSizeMs * sampling_rate / base::Time::kMillisecondsPerSecond);
pp::AudioConfig audio_config = pp::AudioConfig(
instance_, pp_sampling_rate, samples_per_frame_);
audio_ = pp::Audio(instance_, audio_config, AudioPlayerCallback, this);
bool success = audio_.StartPlayback();
if (!success)
LOG(ERROR) << "Failed to start Pepper audio player";
return success;
}
}