OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_AUDIO_OUTPUT_PROXY_H_ | 5 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_PROXY_H_ |
6 #define MEDIA_AUDIO_AUDIO_OUTPUT_PROXY_H_ | 6 #define MEDIA_AUDIO_AUDIO_OUTPUT_PROXY_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/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/synchronization/lock.h" |
11 #include "base/threading/non_thread_safe.h" | 12 #include "base/threading/non_thread_safe.h" |
12 #include "media/audio/audio_io.h" | 13 #include "media/audio/audio_io.h" |
13 #include "media/audio/audio_parameters.h" | 14 #include "media/audio/audio_parameters.h" |
14 | 15 |
15 class AudioOutputDispatcher; | 16 class AudioOutputDispatcher; |
16 | 17 |
17 // AudioOutputProxy is an audio otput stream that uses resources more | 18 // AudioOutputProxy is an audio otput stream that uses resources more |
18 // efficiently than a regular audio output stream: it opens audio | 19 // efficiently than a regular audio output stream: it opens audio |
19 // device only when sound is playing, i.e. between Start() and Stop() | 20 // device only when sound is playing, i.e. between Start() and Stop() |
20 // (there is still one physical stream per each audio output proxy in | 21 // (there is still one physical stream per each audio output proxy in |
21 // playing state). | 22 // playing state). |
22 // | 23 // |
23 // AudioOutputProxy uses AudioOutputDispatcher to open and close | 24 // AudioOutputProxy uses AudioOutputDispatcher to open and close |
24 // physical output streams. | 25 // physical output streams. |
25 class MEDIA_EXPORT AudioOutputProxy | 26 class MEDIA_EXPORT AudioOutputProxy |
26 : public AudioOutputStream, | 27 : public AudioOutputStream, |
| 28 public AudioOutputStream::AudioSourceCallback, |
27 public NON_EXPORTED_BASE(base::NonThreadSafe) { | 29 public NON_EXPORTED_BASE(base::NonThreadSafe) { |
28 public: | 30 public: |
29 // Caller keeps ownership of |dispatcher|. | 31 // Caller keeps ownership of |dispatcher|. |
30 explicit AudioOutputProxy(AudioOutputDispatcher* dispatcher); | 32 explicit AudioOutputProxy(AudioOutputDispatcher* dispatcher); |
31 | 33 |
32 // AudioOutputStream interface. | 34 // AudioOutputStream interface. |
33 virtual bool Open() OVERRIDE; | 35 virtual bool Open() OVERRIDE; |
34 virtual void Start(AudioSourceCallback* callback) OVERRIDE; | 36 virtual void Start(AudioSourceCallback* callback) OVERRIDE; |
35 virtual void Stop() OVERRIDE; | 37 virtual void Stop() OVERRIDE; |
36 virtual void SetVolume(double volume) OVERRIDE; | 38 virtual void SetVolume(double volume) OVERRIDE; |
37 virtual void GetVolume(double* volume) OVERRIDE; | 39 virtual void GetVolume(double* volume) OVERRIDE; |
38 virtual void Close() OVERRIDE; | 40 virtual void Close() OVERRIDE; |
39 | 41 |
| 42 // AudioSourceCallback interface. |
| 43 virtual uint32 OnMoreData( |
| 44 AudioOutputStream* stream, uint8* dest, uint32 max_size, |
| 45 AudioBuffersState buffers_state) OVERRIDE; |
| 46 virtual void OnError(AudioOutputStream* stream, int code) OVERRIDE; |
| 47 virtual void WaitTillDataReady() OVERRIDE; |
| 48 |
40 private: | 49 private: |
41 enum State { | 50 enum State { |
42 kCreated, | 51 kCreated, |
43 kOpened, | 52 kOpened, |
44 kPlaying, | 53 kPlaying, |
45 kClosed, | 54 kClosed, |
46 kError, | 55 kError, |
47 }; | 56 }; |
48 | 57 |
49 virtual ~AudioOutputProxy(); | 58 virtual ~AudioOutputProxy(); |
50 | 59 |
51 scoped_refptr<AudioOutputDispatcher> dispatcher_; | 60 scoped_refptr<AudioOutputDispatcher> dispatcher_; |
52 State state_; | 61 State state_; |
53 | 62 |
54 // The actual audio stream. Must be set to NULL in any state other | |
55 // than kPlaying. | |
56 AudioOutputStream* physical_stream_; | |
57 | |
58 // Need to save volume here, so that we can restore it in case the stream | 63 // Need to save volume here, so that we can restore it in case the stream |
59 // is stopped, and then started again. | 64 // is stopped, and then started again. |
60 double volume_; | 65 double volume_; |
61 | 66 |
| 67 // Callback. |
| 68 AudioSourceCallback* audio_source_callback_; |
| 69 |
| 70 // Lock protecting |volume_| -- we can read it in the hardware audio thread. |
| 71 base::Lock lock_; |
| 72 |
62 DISALLOW_COPY_AND_ASSIGN(AudioOutputProxy); | 73 DISALLOW_COPY_AND_ASSIGN(AudioOutputProxy); |
63 }; | 74 }; |
64 | 75 |
65 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_PROXY_H_ | 76 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_PROXY_H_ |
OLD | NEW |