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_IO_H_ | 5 #ifndef MEDIA_AUDIO_AUDIO_IO_H_ |
6 #define MEDIA_AUDIO_AUDIO_IO_H_ | 6 #define MEDIA_AUDIO_AUDIO_IO_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "media/audio/audio_buffers_state.h" | 9 #include "media/audio/audio_buffers_state.h" |
| 10 #include "media/base/audio_bus.h" |
10 | 11 |
11 // Low-level audio output support. To make sound there are 3 objects involved: | 12 // Low-level audio output support. To make sound there are 3 objects involved: |
12 // - AudioSource : produces audio samples on a pull model. Implements | 13 // - AudioSource : produces audio samples on a pull model. Implements |
13 // the AudioSourceCallback interface. | 14 // the AudioSourceCallback interface. |
14 // - AudioOutputStream : uses the AudioSource to render audio on a given | 15 // - AudioOutputStream : uses the AudioSource to render audio on a given |
15 // channel, format and sample frequency configuration. Data from the | 16 // channel, format and sample frequency configuration. Data from the |
16 // AudioSource is delivered in a 'pull' model. | 17 // AudioSource is delivered in a 'pull' model. |
17 // - AudioManager : factory for the AudioOutputStream objects, manager | 18 // - AudioManager : factory for the AudioOutputStream objects, manager |
18 // of the hardware resources and mixer control. | 19 // of the hardware resources and mixer control. |
19 // | 20 // |
(...skipping 14 matching lines...) Expand all Loading... |
34 // | 35 // |
35 // The primary client of this facility is audio coming from several tabs. | 36 // The primary client of this facility is audio coming from several tabs. |
36 // Specifically for this case we avoid supporting complex formats such as MP3 | 37 // Specifically for this case we avoid supporting complex formats such as MP3 |
37 // or WMA. Complex format decoding should be done by the renderers. | 38 // or WMA. Complex format decoding should be done by the renderers. |
38 | 39 |
39 | 40 |
40 // Models an audio stream that gets rendered to the audio hardware output. | 41 // Models an audio stream that gets rendered to the audio hardware output. |
41 // Because we support more audio streams than physically available channels | 42 // Because we support more audio streams than physically available channels |
42 // a given AudioOutputStream might or might not talk directly to hardware. | 43 // a given AudioOutputStream might or might not talk directly to hardware. |
43 // An audio stream allocates several buffers for audio data and calls | 44 // An audio stream allocates several buffers for audio data and calls |
44 // AudioSourceCallback::OnModeData() periodically to fill these buffers, | 45 // AudioSourceCallback::OnMoreData() periodically to fill these buffers, |
45 // as the data is written to the audio device. Size of each packet is determined | 46 // as the data is written to the audio device. Size of each packet is determined |
46 // by |samples_per_packet| specified in AudioParameters when the stream is | 47 // by |samples_per_packet| specified in AudioParameters when the stream is |
47 // created. | 48 // created. |
48 | 49 |
49 namespace media { | 50 namespace media { |
50 | 51 |
51 class MEDIA_EXPORT AudioOutputStream { | 52 class MEDIA_EXPORT AudioOutputStream { |
52 public: | 53 public: |
53 // Audio sources must implement AudioSourceCallback. This interface will be | 54 // Audio sources must implement AudioSourceCallback. This interface will be |
54 // called in a random thread which very likely is a high priority thread. Do | 55 // called in a random thread which very likely is a high priority thread. Do |
55 // not rely on using this thread TLS or make calls that alter the thread | 56 // not rely on using this thread TLS or make calls that alter the thread |
56 // itself such as creating Windows or initializing COM. | 57 // itself such as creating Windows or initializing COM. |
57 class MEDIA_EXPORT AudioSourceCallback { | 58 class MEDIA_EXPORT AudioSourceCallback { |
58 public: | 59 public: |
59 // Provide more data by filling |dest| up to |max_size| bytes. The provided | 60 // Provide more data by fully filling |audio_bus|. The source will return |
60 // buffer size is determined by the |samples_per_packet| specified in | 61 // the number of frames it filled. |buffers_state| contains current state |
61 // AudioParameters when the stream is created. The source will return | 62 // of the buffers, and can be used by the source to calculate delay. |
62 // the number of bytes it filled. The expected structure of |dest| is | 63 virtual int OnMoreData(AudioBus* audio_bus, |
63 // platform and format specific. | 64 AudioBuffersState buffers_state) = 0; |
64 // |buffers_state| contains current state of the buffers, and can be used | |
65 // by the source to calculate delay. | |
66 virtual uint32 OnMoreData(uint8* dest, | |
67 uint32 max_size, | |
68 AudioBuffersState buffers_state) = 0; | |
69 | 65 |
70 // There was an error while playing a buffer. Audio source cannot be | 66 // There was an error while playing a buffer. Audio source cannot be |
71 // destroyed yet. No direct action needed by the AudioStream, but it is | 67 // destroyed yet. No direct action needed by the AudioStream, but it is |
72 // a good place to stop accumulating sound data since is is likely that | 68 // a good place to stop accumulating sound data since is is likely that |
73 // playback will not continue. |code| is an error code that is platform | 69 // playback will not continue. |code| is an error code that is platform |
74 // specific. | 70 // specific. |
75 virtual void OnError(AudioOutputStream* stream, int code) = 0; | 71 virtual void OnError(AudioOutputStream* stream, int code) = 0; |
76 | 72 |
77 // Waits till data becomes available. Used when buffering data starting | 73 // Waits till data becomes available. Used when buffering data starting |
78 // new audio stream. | 74 // new audio stream. |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 // Sets the Automatic Gain Control (AGC) state. | 170 // Sets the Automatic Gain Control (AGC) state. |
175 virtual void SetAutomaticGainControl(bool enabled) = 0; | 171 virtual void SetAutomaticGainControl(bool enabled) = 0; |
176 | 172 |
177 // Returns the Automatic Gain Control (AGC) state. | 173 // Returns the Automatic Gain Control (AGC) state. |
178 virtual bool GetAutomaticGainControl() = 0; | 174 virtual bool GetAutomaticGainControl() = 0; |
179 }; | 175 }; |
180 | 176 |
181 } // namespace media | 177 } // namespace media |
182 | 178 |
183 #endif // MEDIA_AUDIO_AUDIO_IO_H_ | 179 #endif // MEDIA_AUDIO_AUDIO_IO_H_ |
OLD | NEW |