| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 MEDIA_AUDIO_SOUNDS_AUDIO_STREAM_HANDLER_H_ | 5 #ifndef MEDIA_AUDIO_SOUNDS_AUDIO_STREAM_HANDLER_H_ |
| 6 #define MEDIA_AUDIO_SOUNDS_AUDIO_STREAM_HANDLER_H_ | 6 #define MEDIA_AUDIO_SOUNDS_AUDIO_STREAM_HANDLER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
| 11 #include "base/threading/non_thread_safe.h" | 11 #include "base/threading/non_thread_safe.h" |
| 12 #include "media/audio/audio_io.h" | 12 #include "media/audio/audio_io.h" |
| 13 #include "media/audio/audio_parameters.h" | 13 #include "media/audio/audio_parameters.h" |
| 14 #include "media/audio/sounds/wav_audio_handler.h" | 14 #include "media/audio/sounds/wav_parser.h" |
| 15 #include "media/base/media_export.h" | 15 #include "media/base/media_export.h" |
| 16 | 16 |
| 17 namespace media { | 17 namespace media { |
| 18 | 18 |
| 19 class AudioManager; | 19 class AudioManager; |
| 20 class WavReader; |
| 20 | 21 |
| 21 // This class sends a sound to the audio manager. | 22 // This class sends a sound to the audio manager. |
| 22 class MEDIA_EXPORT AudioStreamHandler : public base::NonThreadSafe { | 23 class MEDIA_EXPORT AudioStreamHandler : public base::NonThreadSafe { |
| 23 public: | 24 public: |
| 24 class TestObserver { | 25 class TestObserver { |
| 25 public: | 26 public: |
| 26 virtual ~TestObserver() {} | 27 virtual ~TestObserver() {} |
| 27 | 28 |
| 28 // Following methods will be called only from the audio thread. | 29 // Following methods will be called only from the audio thread. |
| 29 | 30 |
| 30 // Called when AudioOutputStreamProxy::Start() was successfully called. | 31 // Called when AudioOutputStreamProxy::Start() was successfully called. |
| 31 virtual void OnPlay() = 0; | 32 virtual void OnPlay() = 0; |
| 32 | 33 |
| 34 // Called when current sound is replayed. |
| 35 virtual void OnReplay() = 0; |
| 36 |
| 33 // Called when AudioOutputStreamProxy::Stop() was successfully called. | 37 // Called when AudioOutputStreamProxy::Stop() was successfully called. |
| 34 virtual void OnStop(size_t cursor) = 0; | 38 virtual void OnStop(size_t cursor) = 0; |
| 35 }; | 39 }; |
| 36 | 40 |
| 37 // C-tor for AudioStreamHandler. |wav_data| should be a raw | 41 // C-tor for AudioStreamHandler. |wav_data| should be a raw |
| 38 // uncompressed WAVE data which will be sent to the audio manager. | 42 // uncompressed WAVE data which will be sent to the audio manager. |
| 39 explicit AudioStreamHandler(const base::StringPiece& wav_data); | 43 explicit AudioStreamHandler(const base::StringPiece& wav_data); |
| 40 virtual ~AudioStreamHandler(); | 44 virtual ~AudioStreamHandler(); |
| 41 | 45 |
| 42 // Returns true iff AudioStreamHandler is correctly initialized; | 46 // Returns true iff AudioStreamHandler is correctly initialized; |
| 43 bool IsInitialized() const; | 47 bool IsInitialized() const; |
| 44 | 48 |
| 45 // Stops any previous playback if it's still not completed and | 49 // Stops any previous playback if it's still not completed and |
| 46 // starts new playback. Volume level will be set according to | 50 // starts new playback. Volume level will be set according to |
| 47 // current settings and won't be changed during playback. Returns | 51 // current settings and won't be changed during playback. Returns |
| 48 // true iff new playback was successfully started. | 52 // true iff new playback was successfully started. |
| 49 bool Play(); | 53 bool Play(); |
| 50 | 54 |
| 51 // Stops current playback. | 55 // Stops current playback. |
| 52 void Stop(); | 56 void Stop(); |
| 53 | 57 |
| 54 const WavAudioHandler& wav_audio_handler() const { return wav_audio_; } | 58 const WavParser& wav_parser() const { return wav_parser_; } |
| 55 | 59 |
| 56 private: | 60 private: |
| 57 friend class AudioStreamHandlerTest; | 61 friend class AudioStreamHandlerTest; |
| 58 friend class SoundsManagerTest; | 62 friend class SoundsManagerTest; |
| 59 | 63 |
| 60 class AudioStreamContainer; | 64 class AudioStreamContainer; |
| 61 | 65 |
| 62 static void SetObserverForTesting(TestObserver* observer); | 66 static void SetObserverForTesting(TestObserver* observer); |
| 63 static void SetAudioSourceForTesting( | 67 static void SetAudioSourceForTesting( |
| 64 AudioOutputStream::AudioSourceCallback* source); | 68 AudioOutputStream::AudioSourceCallback* source); |
| 69 void SetWavReaderForTesting(WavReader* reader); |
| 70 void AllowReplayOnceForTesting(); |
| 65 | 71 |
| 66 WavAudioHandler wav_audio_; | 72 void StopAfterDelay(); |
| 73 |
| 74 WavParser wav_parser_; |
| 67 scoped_ptr<AudioStreamContainer> stream_; | 75 scoped_ptr<AudioStreamContainer> stream_; |
| 68 | 76 |
| 69 bool initialized_; | 77 bool initialized_; |
| 70 | 78 |
| 71 DISALLOW_COPY_AND_ASSIGN(AudioStreamHandler); | 79 DISALLOW_COPY_AND_ASSIGN(AudioStreamHandler); |
| 72 }; | 80 }; |
| 73 | 81 |
| 74 } // namespace media | 82 } // namespace media |
| 75 | 83 |
| 76 #endif // MEDIA_AUDIO_SOUNDS_AUDIO_STREAM_HANDLER_H_ | 84 #endif // MEDIA_AUDIO_SOUNDS_AUDIO_STREAM_HANDLER_H_ |
| OLD | NEW |