Chromium Code Reviews| 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_ | |
| 6 #define COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_PLAYER_ | |
| 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 "media/audio/audio_io.h" | |
| 15 | |
| 16 namespace media { | |
| 17 class AudioBus; | |
| 18 class AudioBusRefCounted; | |
| 19 } | |
| 20 | |
| 21 namespace copresence { | |
| 22 | |
| 23 // The AudioPlayer class will play a set of samples till it is told to stop. | |
| 24 class AudioPlayer : public media::AudioOutputStream::AudioSourceCallback { | |
| 25 public: | |
| 26 AudioPlayer(); | |
| 27 | |
| 28 // Initializes the object. Do not use this object before calling this method. | |
| 29 void Initialize(); | |
| 30 | |
| 31 // Play the given samples. These samples will keep on being played in a loop | |
| 32 // till we explicitly tell the player to stop playing. | |
| 33 void Play(const scoped_refptr<media::AudioBusRefCounted>& samples); | |
|
Daniel Erat
2014/08/05 16:38:52
nit: add a blank line after this line
rkc
2014/08/05 18:00:35
Done.
| |
| 34 // Stop playing. | |
| 35 void Stop(); | |
| 36 | |
| 37 // Cleans up and deletes this object. Do not use object after this call. | |
| 38 void Finalize(); | |
| 39 | |
| 40 // Takes ownership of the stream. | |
| 41 void set_output_stream_for_testing( | |
| 42 media::AudioOutputStream* output_stream_for_testing) { | |
| 43 output_stream_for_testing_.reset(output_stream_for_testing); | |
| 44 } | |
| 45 | |
| 46 private: | |
| 47 friend class AudioPlayerTest; | |
| 48 FRIEND_TEST_ALL_PREFIXES(AudioPlayerTest, BasicPlayAndStop); | |
| 49 FRIEND_TEST_ALL_PREFIXES(AudioPlayerTest, OutOfOrderPlayAndStopMultiple); | |
| 50 | |
| 51 virtual ~AudioPlayer(); | |
| 52 | |
| 53 // Methods to do our various operations; all of these need to be run on the | |
| 54 // audio thread. | |
| 55 void InitializeOnAudioThread(); | |
| 56 void PlayOnAudioThread( | |
| 57 const scoped_refptr<media::AudioBusRefCounted>& samples); | |
| 58 void StopOnAudioThread(); | |
| 59 void StopAndCloseOnAudioThread(); | |
| 60 void FinalizeOnAudioThread(); | |
| 61 | |
| 62 // AudioOutputStream::AudioSourceCallback overrides: | |
| 63 // Following methods could be called from *ANY* thread. | |
| 64 virtual int OnMoreData(media::AudioBus* dest, | |
| 65 media::AudioBuffersState /* state */) OVERRIDE; | |
| 66 virtual void OnError(media::AudioOutputStream* /* stream */) OVERRIDE; | |
| 67 | |
| 68 // Flushes the audio loop, making sure that any queued operations are | |
| 69 // performed. | |
| 70 void FlushAudioLoopForTesting(); | |
| 71 | |
| 72 // Self-deleting object. | |
| 73 media::AudioOutputStream* stream_; | |
| 74 | |
| 75 scoped_ptr<media::AudioOutputStream> output_stream_for_testing_; | |
| 76 | |
| 77 bool is_playing_; | |
| 78 | |
| 79 // All fields below here are protected by this lock. | |
| 80 base::Lock state_lock_; | |
| 81 | |
| 82 scoped_refptr<media::AudioBusRefCounted> samples_; | |
| 83 | |
| 84 // Index to the frame in the samples that we need to play next. | |
| 85 int frame_index_; | |
| 86 | |
| 87 DISALLOW_COPY_AND_ASSIGN(AudioPlayer); | |
| 88 }; | |
| 89 | |
| 90 } // namespace copresence | |
| 91 | |
| 92 #endif // COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_PLAYER_ | |
| OLD | NEW |