OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_MANAGER_H_ | 5 #ifndef MEDIA_AUDIO_AUDIO_MANAGER_H_ |
6 #define MEDIA_AUDIO_AUDIO_MANAGER_H_ | 6 #define MEDIA_AUDIO_AUDIO_MANAGER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "media/audio/audio_parameters.h" | 9 #include "media/audio/audio_parameters.h" |
10 | 10 |
11 class AudioInputStream; | 11 class AudioInputStream; |
12 class AudioOutputStream; | 12 class AudioOutputStream; |
13 class MessageLoop; | 13 class MessageLoop; |
14 | 14 |
15 // Manages all audio resources. In particular it owns the AudioOutputStream | 15 // Manages all audio resources. In particular it owns the AudioOutputStream |
16 // objects. Provides some convenience functions that avoid the need to provide | 16 // objects. Provides some convenience functions that avoid the need to provide |
17 // iterators over the existing streams. | 17 // iterators over the existing streams. |
18 class AudioManager { | 18 class AudioManager { |
19 public: | 19 public: |
20 // Returns true if the OS reports existence of audio devices. This does not | 20 // Returns true if the OS reports existence of audio devices. This does not |
21 // guarantee that the existing devices support all formats and sample rates. | 21 // guarantee that the existing devices support all formats and sample rates. |
22 virtual bool HasAudioOutputDevices() = 0; | 22 virtual bool HasAudioOutputDevices() = 0; |
23 | 23 |
24 // Returns true if the OS reports existence of audio recording devices. This | 24 // Returns true if the OS reports existence of audio recording devices. This |
25 // does not guarantee that the existing devices support all formats and | 25 // does not guarantee that the existing devices support all formats and |
26 // sample rates. | 26 // sample rates. |
27 virtual bool HasAudioInputDevices() = 0; | 27 virtual bool HasAudioInputDevices() = 0; |
28 | 28 |
29 // Factory for all the supported stream formats. The |channels| can be 1 to 5. | 29 // Factory for all the supported stream formats. |params| defines parameters |
30 // The |sample_rate| is in hertz and can be any value supported by the | 30 // of the audio stream to be created. |
31 // platform. For some future formats the |sample_rate| and |bits_per_sample| | 31 // |
32 // can take special values. | 32 // |packet_size| is the requested buffer allocation which |
| 33 // the audio source thinks it can usually fill without blocking. Internally |
| 34 // two or three buffers of |packet_size| size are created, one will be |
| 35 // locked for playback and one will be ready to be filled in the call to |
| 36 // AudioSourceCallback::OnMoreData(). |
| 37 // |
33 // Returns NULL if the combination of the parameters is not supported, or if | 38 // Returns NULL if the combination of the parameters is not supported, or if |
34 // we have reached some other platform specific limit. | 39 // we have reached some other platform specific limit. |
35 // | 40 // |
36 // AUDIO_PCM_LOW_LATENCY can be passed to this method and it has two effects: | 41 // |params.format| can be set to AUDIO_PCM_LOW_LATENCY and that has two |
| 42 // effects: |
37 // 1- Instead of triple buffered the audio will be double buffered. | 43 // 1- Instead of triple buffered the audio will be double buffered. |
38 // 2- A low latency driver or alternative audio subsystem will be used when | 44 // 2- A low latency driver or alternative audio subsystem will be used when |
39 // available. | 45 // available. |
40 // | 46 // |
41 // Do not free the returned AudioOutputStream. It is owned by AudioManager. | 47 // Do not free the returned AudioOutputStream. It is owned by AudioManager. |
42 virtual AudioOutputStream* MakeAudioOutputStream(AudioParameters params) = 0; | 48 virtual AudioOutputStream* MakeAudioOutputStream(AudioParameters params) = 0; |
43 | 49 |
44 // Factory to create audio recording streams. | 50 // Factory to create audio recording streams. |
45 // |channels| can be 1 or 2. | 51 // |channels| can be 1 or 2. |
46 // |sample_rate| is in hertz and can be any value supported by the platform. | 52 // |sample_rate| is in hertz and can be any value supported by the platform. |
47 // |bits_per_sample| can be any value supported by the platform. | 53 // |bits_per_sample| can be any value supported by the platform. |
48 // |samples_per_packet| is in hertz as well and can be 0 to |sample_rate|, | 54 // |samples_per_packet| is in hertz as well and can be 0 to |sample_rate|, |
49 // with 0 suggesting that the implementation use a default value for that | 55 // with 0 suggesting that the implementation use a default value for that |
50 // platform. | 56 // platform. |
51 // Returns NULL if the combination of the parameters is not supported, or if | 57 // Returns NULL if the combination of the parameters is not supported, or if |
52 // we have reached some other platform specific limit. | 58 // we have reached some other platform specific limit. |
53 // | 59 // |
54 // Do not free the returned AudioInputStream. It is owned by AudioManager. | 60 // Do not free the returned AudioInputStream. It is owned by AudioManager. |
55 // When you are done with it, call |Stop()| and |Close()| to release it. | 61 // When you are done with it, call |Stop()| and |Close()| to release it. |
56 virtual AudioInputStream* MakeAudioInputStream(AudioParameters params, | 62 virtual AudioInputStream* MakeAudioInputStream(AudioParameters params) = 0; |
57 int samples_per_packet) = 0; | |
58 | 63 |
59 // Muting continues playback but effectively the volume is set to zero. | 64 // Muting continues playback but effectively the volume is set to zero. |
60 // Un-muting returns the volume to the previous level. | 65 // Un-muting returns the volume to the previous level. |
61 virtual void MuteAll() = 0; | 66 virtual void MuteAll() = 0; |
62 virtual void UnMuteAll() = 0; | 67 virtual void UnMuteAll() = 0; |
63 | 68 |
64 // Returns message loop used for audio IO. | 69 // Returns message loop used for audio IO. |
65 virtual MessageLoop* GetMessageLoop() = 0; | 70 virtual MessageLoop* GetMessageLoop() = 0; |
66 | 71 |
67 // Get AudioManager singleton. | 72 // Get AudioManager singleton. |
68 // TODO(cpu): Define threading requirements for interacting with AudioManager. | 73 // TODO(cpu): Define threading requirements for interacting with AudioManager. |
69 static AudioManager* GetAudioManager(); | 74 static AudioManager* GetAudioManager(); |
70 | 75 |
71 protected: | 76 protected: |
72 virtual ~AudioManager() {} | 77 virtual ~AudioManager() {} |
73 | 78 |
74 // Called from GetAudioManager() to initialiaze the instance. | 79 // Called from GetAudioManager() to initialiaze the instance. |
75 virtual void Init() = 0; | 80 virtual void Init() = 0; |
76 | 81 |
77 private: | 82 private: |
78 static void Destroy(void*); | 83 static void Destroy(void*); |
79 | 84 |
80 // Called by GetAudioManager() to create platform-specific audio manager. | 85 // Called by GetAudioManager() to create platform-specific audio manager. |
81 static AudioManager* CreateAudioManager(); | 86 static AudioManager* CreateAudioManager(); |
82 }; | 87 }; |
83 | 88 |
84 #endif // MEDIA_AUDIO_AUDIO_MANAGER_H_ | 89 #endif // MEDIA_AUDIO_AUDIO_MANAGER_H_ |
OLD | NEW |