| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/client/audio_player_android.h" | 5 #include "remoting/client/audio_player_android.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 | 8 |
| 9 namespace remoting { | 9 namespace remoting { |
| 10 | 10 |
| 11 const int kFrameSizeMs = 40; | 11 const int kFrameSizeMs = 40; |
| 12 const int kNumOfBuffers = 1; | 12 const int kNumOfBuffers = 1; |
| 13 | 13 |
| 14 static_assert(AudioPlayer::kChannels == 2, | 14 static_assert(AudioPlayer::kChannels == 2, |
| 15 "AudioPlayer must be feeding 2 channels data."); | 15 "AudioPlayer must be feeding 2 channels data."); |
| 16 const int kChannelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT; | 16 const int kChannelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT; |
| 17 | 17 |
| 18 AudioPlayerAndroid::AudioPlayerAndroid() { | 18 AudioPlayerAndroid::AudioPlayerAndroid() : weak_factory_(this) { |
| 19 if (slCreateEngine(&engine_object_, 0, nullptr, 0, nullptr, nullptr) != | 19 if (slCreateEngine(&engine_object_, 0, nullptr, 0, nullptr, nullptr) != |
| 20 SL_RESULT_SUCCESS || | 20 SL_RESULT_SUCCESS || |
| 21 (*engine_object_)->Realize(engine_object_, SL_BOOLEAN_FALSE) != | 21 (*engine_object_)->Realize(engine_object_, SL_BOOLEAN_FALSE) != |
| 22 SL_RESULT_SUCCESS || | 22 SL_RESULT_SUCCESS || |
| 23 (*engine_object_) | 23 (*engine_object_) |
| 24 ->GetInterface(engine_object_, SL_IID_ENGINE, &engine_) != | 24 ->GetInterface(engine_object_, SL_IID_ENGINE, &engine_) != |
| 25 SL_RESULT_SUCCESS || | 25 SL_RESULT_SUCCESS || |
| 26 (*engine_)->CreateOutputMix(engine_, &output_mix_object_, 0, nullptr, | 26 (*engine_)->CreateOutputMix(engine_, &output_mix_object_, 0, nullptr, |
| 27 nullptr) != SL_RESULT_SUCCESS || | 27 nullptr) != SL_RESULT_SUCCESS || |
| 28 (*output_mix_object_)->Realize(output_mix_object_, SL_BOOLEAN_FALSE) != | 28 (*output_mix_object_)->Realize(output_mix_object_, SL_BOOLEAN_FALSE) != |
| 29 SL_RESULT_SUCCESS) { | 29 SL_RESULT_SUCCESS) { |
| 30 LOG(ERROR) << "Failed to initialize OpenSL ES."; | 30 LOG(ERROR) << "Failed to initialize OpenSL ES."; |
| 31 } | 31 } |
| 32 } | 32 } |
| 33 | 33 |
| 34 AudioPlayerAndroid::~AudioPlayerAndroid() { | 34 AudioPlayerAndroid::~AudioPlayerAndroid() { |
| 35 DestroyPlayer(); | 35 DestroyPlayer(); |
| 36 if (output_mix_object_) { | 36 if (output_mix_object_) { |
| 37 (*output_mix_object_)->Destroy(output_mix_object_); | 37 (*output_mix_object_)->Destroy(output_mix_object_); |
| 38 } | 38 } |
| 39 if (engine_object_) { | 39 if (engine_object_) { |
| 40 (*engine_object_)->Destroy(engine_object_); | 40 (*engine_object_)->Destroy(engine_object_); |
| 41 } | 41 } |
| 42 } | 42 } |
| 43 | 43 |
| 44 base::WeakPtr<AudioPlayerAndroid> AudioPlayerAndroid::GetWeakPtr() { |
| 45 return weak_factory_.GetWeakPtr(); |
| 46 } |
| 47 |
| 44 uint32_t AudioPlayerAndroid::GetSamplesPerFrame() { | 48 uint32_t AudioPlayerAndroid::GetSamplesPerFrame() { |
| 45 return sample_per_frame_; | 49 return sample_per_frame_; |
| 46 } | 50 } |
| 47 | 51 |
| 48 bool AudioPlayerAndroid::ResetAudioPlayer( | 52 bool AudioPlayerAndroid::ResetAudioPlayer( |
| 49 AudioPacket::SamplingRate sampling_rate) { | 53 AudioPacket::SamplingRate sampling_rate) { |
| 50 if (!output_mix_object_) { | 54 if (!output_mix_object_) { |
| 51 // output mixer not successfully created in ctor. | 55 // output mixer not successfully created in ctor. |
| 52 return false; | 56 return false; |
| 53 } | 57 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 (*player_object_)->Destroy(player_object_); | 148 (*player_object_)->Destroy(player_object_); |
| 145 player_object_ = nullptr; | 149 player_object_ = nullptr; |
| 146 } | 150 } |
| 147 frame_buffer_.reset(); | 151 frame_buffer_.reset(); |
| 148 buffer_size_ = 0; | 152 buffer_size_ = 0; |
| 149 player_ = nullptr; | 153 player_ = nullptr; |
| 150 buffer_queue_ = nullptr; | 154 buffer_queue_ = nullptr; |
| 151 } | 155 } |
| 152 | 156 |
| 153 } // namespace remoting | 157 } // namespace remoting |
| OLD | NEW |