| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_PLAYER_H_ | 5 #ifndef COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_PLAYER_H_ |
| 6 #define COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_PLAYER_H_ | 6 #define COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_PLAYER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 bool IsPlaying(); | 41 bool IsPlaying(); |
| 42 | 42 |
| 43 // Takes ownership of the stream. | 43 // Takes ownership of the stream. |
| 44 void set_output_stream_for_testing( | 44 void set_output_stream_for_testing( |
| 45 media::AudioOutputStream* output_stream_for_testing) { | 45 media::AudioOutputStream* output_stream_for_testing) { |
| 46 output_stream_for_testing_.reset(output_stream_for_testing); | 46 output_stream_for_testing_.reset(output_stream_for_testing); |
| 47 } | 47 } |
| 48 | 48 |
| 49 protected: | 49 protected: |
| 50 virtual ~AudioPlayer(); | 50 ~AudioPlayer() override; |
| 51 void set_is_playing(bool is_playing) { is_playing_ = is_playing; } | 51 void set_is_playing(bool is_playing) { is_playing_ = is_playing; } |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 friend class AudioPlayerTest; | 54 friend class AudioPlayerTest; |
| 55 FRIEND_TEST_ALL_PREFIXES(AudioPlayerTest, BasicPlayAndStop); | 55 FRIEND_TEST_ALL_PREFIXES(AudioPlayerTest, BasicPlayAndStop); |
| 56 FRIEND_TEST_ALL_PREFIXES(AudioPlayerTest, OutOfOrderPlayAndStopMultiple); | 56 FRIEND_TEST_ALL_PREFIXES(AudioPlayerTest, OutOfOrderPlayAndStopMultiple); |
| 57 | 57 |
| 58 // Methods to do our various operations; all of these need to be run on the | 58 // Methods to do our various operations; all of these need to be run on the |
| 59 // audio thread. | 59 // audio thread. |
| 60 void InitializeOnAudioThread(); | 60 void InitializeOnAudioThread(); |
| 61 void PlayOnAudioThread( | 61 void PlayOnAudioThread( |
| 62 const scoped_refptr<media::AudioBusRefCounted>& samples); | 62 const scoped_refptr<media::AudioBusRefCounted>& samples); |
| 63 void StopOnAudioThread(); | 63 void StopOnAudioThread(); |
| 64 void StopAndCloseOnAudioThread(); | 64 void StopAndCloseOnAudioThread(); |
| 65 void FinalizeOnAudioThread(); | 65 void FinalizeOnAudioThread(); |
| 66 | 66 |
| 67 // AudioOutputStream::AudioSourceCallback overrides: | 67 // AudioOutputStream::AudioSourceCallback overrides: |
| 68 // Following methods could be called from *ANY* thread. | 68 // Following methods could be called from *ANY* thread. |
| 69 virtual int OnMoreData(media::AudioBus* dest, | 69 int OnMoreData(media::AudioBus* dest, uint32 total_bytes_delay) override; |
| 70 uint32 total_bytes_delay) override; | 70 void OnError(media::AudioOutputStream* stream) override; |
| 71 virtual void OnError(media::AudioOutputStream* stream) override; | |
| 72 | 71 |
| 73 // Flushes the audio loop, making sure that any queued operations are | 72 // Flushes the audio loop, making sure that any queued operations are |
| 74 // performed. | 73 // performed. |
| 75 void FlushAudioLoopForTesting(); | 74 void FlushAudioLoopForTesting(); |
| 76 | 75 |
| 77 bool is_playing_; | 76 bool is_playing_; |
| 78 | 77 |
| 79 // Self-deleting object. | 78 // Self-deleting object. |
| 80 media::AudioOutputStream* stream_; | 79 media::AudioOutputStream* stream_; |
| 81 | 80 |
| 82 scoped_ptr<media::AudioOutputStream> output_stream_for_testing_; | 81 scoped_ptr<media::AudioOutputStream> output_stream_for_testing_; |
| 83 | 82 |
| 84 // All fields below here are protected by this lock. | 83 // All fields below here are protected by this lock. |
| 85 base::Lock state_lock_; | 84 base::Lock state_lock_; |
| 86 | 85 |
| 87 scoped_refptr<media::AudioBusRefCounted> samples_; | 86 scoped_refptr<media::AudioBusRefCounted> samples_; |
| 88 | 87 |
| 89 // Index to the frame in the samples that we need to play next. | 88 // Index to the frame in the samples that we need to play next. |
| 90 int frame_index_; | 89 int frame_index_; |
| 91 | 90 |
| 92 DISALLOW_COPY_AND_ASSIGN(AudioPlayer); | 91 DISALLOW_COPY_AND_ASSIGN(AudioPlayer); |
| 93 }; | 92 }; |
| 94 | 93 |
| 95 } // namespace copresence | 94 } // namespace copresence |
| 96 | 95 |
| 97 #endif // COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_PLAYER_H_ | 96 #endif // COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_PLAYER_H_ |
| OLD | NEW |