1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "remoting/client/plugin/pepper_audio_player.h"
9 #include "base/logging.h"
10 #include "base/stl_util.h"
12 // The frame size we will request from the browser.
13 const int kFrameSizeMs
= 40;
17 PepperAudioPlayer::PepperAudioPlayer(pp::Instance
* instance
)
18 : instance_(instance
),
19 samples_per_frame_(0) {
22 PepperAudioPlayer::~PepperAudioPlayer() {
25 uint32
PepperAudioPlayer::GetSamplesPerFrame() {
26 return samples_per_frame_
;
29 bool PepperAudioPlayer::ResetAudioPlayer(
30 AudioPacket::SamplingRate sampling_rate
) {
31 PP_AudioSampleRate pp_sampling_rate
= PP_AUDIOSAMPLERATE_NONE
;
32 switch (sampling_rate
) {
33 case AudioPacket::SAMPLING_RATE_44100
:
34 pp_sampling_rate
= PP_AUDIOSAMPLERATE_44100
;
36 case AudioPacket::SAMPLING_RATE_48000
:
37 pp_sampling_rate
= PP_AUDIOSAMPLERATE_48000
;
40 LOG(ERROR
) << "Unsupported audio sampling rate: " << sampling_rate
;
44 // Ask the browser/device for an appropriate frame size.
45 samples_per_frame_
= pp::AudioConfig::RecommendSampleFrameCount(
46 instance_
, pp_sampling_rate
,
47 kFrameSizeMs
* sampling_rate
/ base::Time::kMillisecondsPerSecond
);
49 // Create an audio configuration resource.
50 pp::AudioConfig audio_config
= pp::AudioConfig(
51 instance_
, pp_sampling_rate
, samples_per_frame_
);
53 // Create an audio resource.
54 audio_
= pp::Audio(instance_
, audio_config
, AudioPlayerCallback
, this);
56 // Immediately start the player.
57 bool success
= audio_
.StartPlayback();
59 LOG(ERROR
) << "Failed to start Pepper audio player";
63 } // namespace remoting