Adds "tts" permission for Input Tools & XKB extension.
[chromium-blink-merge.git] / media / audio / sounds / audio_stream_handler.h
blobf814aaef5993b793052fd54bf80105f8c634d57e
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
3 // found in the LICENSE file.
5 #ifndef MEDIA_AUDIO_SOUNDS_AUDIO_STREAM_HANDLER_H_
6 #define MEDIA_AUDIO_SOUNDS_AUDIO_STREAM_HANDLER_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/strings/string_piece.h"
11 #include "base/threading/non_thread_safe.h"
12 #include "media/audio/audio_io.h"
13 #include "media/audio/audio_parameters.h"
14 #include "media/audio/sounds/wav_audio_handler.h"
15 #include "media/base/media_export.h"
17 namespace media {
19 class AudioManager;
21 // This class sends a sound to the audio manager.
22 class MEDIA_EXPORT AudioStreamHandler : public base::NonThreadSafe {
23 public:
24 class TestObserver {
25 public:
26 virtual ~TestObserver() {}
28 // Following methods will be called only from the audio thread.
30 // Called when AudioOutputStreamProxy::Start() was successfully called.
31 virtual void OnPlay() = 0;
33 // Called when AudioOutputStreamProxy::Stop() was successfully called.
34 virtual void OnStop(size_t cursor) = 0;
37 // C-tor for AudioStreamHandler. |wav_data| should be a raw
38 // uncompressed WAVE data which will be sent to the audio manager.
39 explicit AudioStreamHandler(const base::StringPiece& wav_data);
40 virtual ~AudioStreamHandler();
42 // Returns true iff AudioStreamHandler is correctly initialized;
43 bool IsInitialized() const;
45 // Plays sound. Volume level will be set according to current settings
46 // and won't be changed during playback. Returns true iff new playback
47 // was successfully started.
49 // NOTE: if current playback isn't at end of stream, playback request
50 // is dropped, but true is returned.
51 bool Play();
53 // Stops current playback.
54 void Stop();
56 const WavAudioHandler& wav_audio_handler() const { return wav_audio_; }
58 private:
59 friend class AudioStreamHandlerTest;
60 friend class SoundsManagerTest;
62 class AudioStreamContainer;
64 static void SetObserverForTesting(TestObserver* observer);
65 static void SetAudioSourceForTesting(
66 AudioOutputStream::AudioSourceCallback* source);
68 WavAudioHandler wav_audio_;
69 scoped_ptr<AudioStreamContainer> stream_;
71 bool initialized_;
73 DISALLOW_COPY_AND_ASSIGN(AudioStreamHandler);
76 } // namespace media
78 #endif // MEDIA_AUDIO_SOUNDS_AUDIO_STREAM_HANDLER_H_