OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_STREAM_PROXY_H_ | 5 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_PROXY_H_ |
6 #define MEDIA_AUDIO_AUDIO_OUTPUT_STREAM_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/task.h" | 9 #include "base/task.h" |
10 #include "media/audio/audio_io.h" | 10 #include "media/audio/audio_io.h" |
11 #include "media/audio/audio_parameters.h" | 11 #include "media/audio/audio_parameters.h" |
12 | 12 |
13 class AudioOutputDispatcher; | 13 class AudioOutputDispatcher; |
14 | 14 |
15 // AudioOutputProxy is an audio otput stream that uses resources more | 15 // AudioOutputProxy is an audio otput stream that uses resources more |
16 // efficiently than a regular audio output stream: it opens audio | 16 // efficiently than a regular audio output stream: it opens audio |
17 // device only when sound is playing, i.e. between Start() and Stop() | 17 // device only when sound is playing, i.e. between Start() and Stop() |
18 // (there is still one physical stream per each audio output proxy in | 18 // (there is still one physical stream per each audio output proxy in |
19 // playing state). | 19 // playing state). |
20 // | 20 // |
21 // AudioOutputProxy uses AudioOutputDispatcher to open and close | 21 // AudioOutputProxy uses AudioOutputDispatcher to open and close |
22 // physical output streams. | 22 // physical output streams. |
23 class MEDIA_EXPORT AudioOutputProxy : public AudioOutputStream { | 23 class MEDIA_EXPORT AudioOutputProxy : public AudioOutputStream { |
24 public: | 24 public: |
25 // Caller keeps ownership of |dispatcher|. | 25 // Caller keeps ownership of |dispatcher|. |
26 AudioOutputProxy(AudioOutputDispatcher* dispatcher); | 26 explicit AudioOutputProxy(AudioOutputDispatcher* dispatcher); |
27 | 27 |
28 // AudioOutputStream interface. | 28 // AudioOutputStream interface. |
29 virtual bool Open() OVERRIDE; | 29 virtual bool Open() OVERRIDE; |
30 virtual void Start(AudioSourceCallback* callback) OVERRIDE; | 30 virtual void Start(AudioSourceCallback* callback) OVERRIDE; |
31 virtual void Stop() OVERRIDE; | 31 virtual void Stop() OVERRIDE; |
32 virtual void SetVolume(double volume) OVERRIDE; | 32 virtual void SetVolume(double volume) OVERRIDE; |
33 virtual void GetVolume(double* volume) OVERRIDE; | 33 virtual void GetVolume(double* volume) OVERRIDE; |
34 virtual void Close() OVERRIDE; | 34 virtual void Close() OVERRIDE; |
35 | 35 |
36 private: | 36 private: |
37 // Needs to access destructor. | |
38 friend class DeleteTask<AudioOutputProxy>; | |
39 | |
40 enum State { | 37 enum State { |
41 kCreated, | 38 kCreated, |
42 kOpened, | 39 kOpened, |
43 kPlaying, | 40 kPlaying, |
44 kClosed, | 41 kClosed, |
45 kError, | 42 kError, |
46 }; | 43 }; |
47 | 44 |
48 virtual ~AudioOutputProxy(); | 45 virtual ~AudioOutputProxy(); |
49 | 46 |
50 scoped_refptr<AudioOutputDispatcher> dispatcher_; | 47 scoped_refptr<AudioOutputDispatcher> dispatcher_; |
51 State state_; | 48 State state_; |
52 | 49 |
53 // The actual audio stream. Must be set to NULL in any state other | 50 // The actual audio stream. Must be set to NULL in any state other |
54 // than kPlaying. | 51 // than kPlaying. |
55 AudioOutputStream* physical_stream_; | 52 AudioOutputStream* physical_stream_; |
56 | 53 |
57 // Need to save volume here, so that we can restore it in case the stream | 54 // Need to save volume here, so that we can restore it in case the stream |
58 // is stopped, and then started again. | 55 // is stopped, and then started again. |
59 double volume_; | 56 double volume_; |
60 | 57 |
61 DISALLOW_COPY_AND_ASSIGN(AudioOutputProxy); | 58 DISALLOW_COPY_AND_ASSIGN(AudioOutputProxy); |
62 }; | 59 }; |
63 | 60 |
64 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_STREAM_PROXY_H_ | 61 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_PROXY_H_ |
OLD | NEW |