Re-land: C++ readability review
[chromium-blink-merge.git] / remoting / client / plugin / pepper_audio_player.cc
blob4b1f02a067ca699f6689e63e450ec73784cf0e0f
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"
7 #include <algorithm>
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;
15 namespace remoting {
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;
35 break;
36 case AudioPacket::SAMPLING_RATE_48000:
37 pp_sampling_rate = PP_AUDIOSAMPLERATE_48000;
38 break;
39 default:
40 LOG(ERROR) << "Unsupported audio sampling rate: " << sampling_rate;
41 return false;
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();
58 if (!success)
59 LOG(ERROR) << "Failed to start Pepper audio player";
60 return success;
63 } // namespace remoting