| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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. | |
| 4 | |
| 5 #ifndef COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_PLAYER_IMPL_H_ | |
| 6 #define COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_PLAYER_IMPL_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/gtest_prod_util.h" | |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/synchronization/lock.h" | |
| 14 #include "components/copresence/mediums/audio/audio_player.h" | |
| 15 #include "media/audio/audio_io.h" | |
| 16 | |
| 17 namespace media { | |
| 18 class AudioBus; | |
| 19 class AudioBusRefCounted; | |
| 20 } | |
| 21 | |
| 22 namespace copresence { | |
| 23 | |
| 24 // The AudioPlayerImpl class will play a set of samples till it is told to stop. | |
| 25 class AudioPlayerImpl final | |
| 26 : public AudioPlayer, | |
| 27 public media::AudioOutputStream::AudioSourceCallback { | |
| 28 public: | |
| 29 AudioPlayerImpl(); | |
| 30 | |
| 31 // AudioPlayer overrides: | |
| 32 void Initialize() override; | |
| 33 void Play(const scoped_refptr<media::AudioBusRefCounted>& samples) override; | |
| 34 void Stop() override; | |
| 35 void Finalize() override; | |
| 36 | |
| 37 // Takes ownership of the stream. | |
| 38 void set_output_stream_for_testing( | |
| 39 media::AudioOutputStream* output_stream_for_testing) { | |
| 40 output_stream_for_testing_.reset(output_stream_for_testing); | |
| 41 } | |
| 42 | |
| 43 private: | |
| 44 friend class AudioPlayerTest; | |
| 45 FRIEND_TEST_ALL_PREFIXES(AudioPlayerTest, BasicPlayAndStop); | |
| 46 FRIEND_TEST_ALL_PREFIXES(AudioPlayerTest, OutOfOrderPlayAndStopMultiple); | |
| 47 | |
| 48 ~AudioPlayerImpl() override; | |
| 49 | |
| 50 // Methods to do our various operations; all of these need to be run on the | |
| 51 // audio thread. | |
| 52 void InitializeOnAudioThread(); | |
| 53 void PlayOnAudioThread( | |
| 54 const scoped_refptr<media::AudioBusRefCounted>& samples); | |
| 55 void StopOnAudioThread(); | |
| 56 void StopAndCloseOnAudioThread(); | |
| 57 void FinalizeOnAudioThread(); | |
| 58 | |
| 59 // AudioOutputStream::AudioSourceCallback overrides: | |
| 60 // Following methods could be called from *ANY* thread. | |
| 61 int OnMoreData(media::AudioBus* dest, uint32 total_bytes_delay) override; | |
| 62 void OnError(media::AudioOutputStream* stream) override; | |
| 63 | |
| 64 // Flushes the audio loop, making sure that any queued operations are | |
| 65 // performed. | |
| 66 void FlushAudioLoopForTesting(); | |
| 67 | |
| 68 bool is_playing_; | |
| 69 | |
| 70 // Self-deleting object. | |
| 71 media::AudioOutputStream* stream_; | |
| 72 | |
| 73 scoped_ptr<media::AudioOutputStream> output_stream_for_testing_; | |
| 74 | |
| 75 // All fields below here are protected by this lock. | |
| 76 base::Lock state_lock_; | |
| 77 | |
| 78 scoped_refptr<media::AudioBusRefCounted> samples_; | |
| 79 | |
| 80 // Index to the frame in the samples that we need to play next. | |
| 81 int frame_index_; | |
| 82 | |
| 83 DISALLOW_COPY_AND_ASSIGN(AudioPlayerImpl); | |
| 84 }; | |
| 85 | |
| 86 } // namespace copresence | |
| 87 | |
| 88 #endif // COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_PLAYER_IMPL_H_ | |
| OLD | NEW |