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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
| 10 #include "base/time/time.h" |
10 #include "media/base/audio_bus.h" | 11 #include "media/base/audio_bus.h" |
11 | 12 |
12 // Low-level audio output support. To make sound there are 3 objects involved: | 13 // Low-level audio output support. To make sound there are 3 objects involved: |
13 // - AudioSource : produces audio samples on a pull model. Implements | 14 // - AudioSource : produces audio samples on a pull model. Implements |
14 // the AudioSourceCallback interface. | 15 // the AudioSourceCallback interface. |
15 // - AudioOutputStream : uses the AudioSource to render audio on a given | 16 // - AudioOutputStream : uses the AudioSource to render audio on a given |
16 // channel, format and sample frequency configuration. Data from the | 17 // channel, format and sample frequency configuration. Data from the |
17 // AudioSource is delivered in a 'pull' model. | 18 // AudioSource is delivered in a 'pull' model. |
18 // - AudioManager : factory for the AudioOutputStream objects, manager | 19 // - AudioManager : factory for the AudioOutputStream objects, manager |
19 // of the hardware resources and mixer control. | 20 // of the hardware resources and mixer control. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 class MEDIA_EXPORT AudioOutputStream { | 53 class MEDIA_EXPORT AudioOutputStream { |
53 public: | 54 public: |
54 // Audio sources must implement AudioSourceCallback. This interface will be | 55 // Audio sources must implement AudioSourceCallback. This interface will be |
55 // called in a random thread which very likely is a high priority thread. Do | 56 // called in a random thread which very likely is a high priority thread. Do |
56 // not rely on using this thread TLS or make calls that alter the thread | 57 // not rely on using this thread TLS or make calls that alter the thread |
57 // itself such as creating Windows or initializing COM. | 58 // itself such as creating Windows or initializing COM. |
58 class MEDIA_EXPORT AudioSourceCallback { | 59 class MEDIA_EXPORT AudioSourceCallback { |
59 public: | 60 public: |
60 virtual ~AudioSourceCallback() {} | 61 virtual ~AudioSourceCallback() {} |
61 | 62 |
62 // Provide more data by fully filling |dest|. The source will return | 63 // Provide more data by fully filling |dest|. The source will return the |
63 // the number of frames it filled. |total_bytes_delay| contains current | 64 // number of frames it filled. |delay| is the duration of audio written to |
64 // number of bytes of delay buffered by the AudioOutputStream. | 65 // |dest| in prior calls to OnMoreData() that has not yet been played out, |
65 // |frames_skipped| contains the number of frames skipped by the consumer. | 66 // and |delay_timestamp| is the time when |delay| was measured. The time |
66 virtual int OnMoreData(AudioBus* dest, | 67 // when the first sample added to |dest| is expected to be played out can be |
67 uint32_t total_bytes_delay, | 68 // calculated by adding |delay| to |delay_timestamp|. The accuracy of |
68 uint32_t frames_skipped) = 0; | 69 // |delay| and |delay_timestamp| may vary depending on the platform and |
| 70 // implementation. |prior_frames_skipped| is the number of frames skipped by |
| 71 // the consumer. |
| 72 virtual int OnMoreData(base::TimeDelta delay, |
| 73 base::TimeTicks delay_timestamp, |
| 74 int prior_frames_skipped, |
| 75 AudioBus* dest) = 0; |
69 | 76 |
70 // There was an error while playing a buffer. Audio source cannot be | 77 // 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 | 78 // 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 | 79 // a good place to stop accumulating sound data since is is likely that |
73 // playback will not continue. | 80 // playback will not continue. |
74 virtual void OnError(AudioOutputStream* stream) = 0; | 81 virtual void OnError(AudioOutputStream* stream) = 0; |
75 }; | 82 }; |
76 | 83 |
77 virtual ~AudioOutputStream() {} | 84 virtual ~AudioOutputStream() {} |
78 | 85 |
(...skipping 28 matching lines...) Expand all Loading... |
107 public: | 114 public: |
108 class MEDIA_EXPORT AudioInputCallback { | 115 class MEDIA_EXPORT AudioInputCallback { |
109 public: | 116 public: |
110 // Called by the audio recorder when a full packet of audio data is | 117 // Called by the audio recorder when a full packet of audio data is |
111 // available. This is called from a special audio thread and the | 118 // available. This is called from a special audio thread and the |
112 // implementation should return as soon as possible. | 119 // implementation should return as soon as possible. |
113 // TODO(henrika): should be pure virtual when old OnData() is phased out. | 120 // TODO(henrika): should be pure virtual when old OnData() is phased out. |
114 virtual void OnData(AudioInputStream* stream, | 121 virtual void OnData(AudioInputStream* stream, |
115 const AudioBus* source, | 122 const AudioBus* source, |
116 uint32_t hardware_delay_bytes, | 123 uint32_t hardware_delay_bytes, |
117 double volume){}; | 124 double volume) {} |
118 | 125 |
119 // TODO(henrika): don't use; to be removed. | 126 // TODO(henrika): don't use; to be removed. |
120 virtual void OnData(AudioInputStream* stream, | 127 virtual void OnData(AudioInputStream* stream, |
121 const uint8_t* src, | 128 const uint8_t* src, |
122 uint32_t size, | 129 uint32_t size, |
123 uint32_t hardware_delay_bytes, | 130 uint32_t hardware_delay_bytes, |
124 double volume){}; | 131 double volume) {} |
125 | 132 |
126 // There was an error while recording audio. The audio sink cannot be | 133 // There was an error while recording audio. The audio sink cannot be |
127 // destroyed yet. No direct action needed by the AudioInputStream, but it | 134 // destroyed yet. No direct action needed by the AudioInputStream, but it |
128 // is a good place to stop accumulating sound data since is is likely that | 135 // is a good place to stop accumulating sound data since is is likely that |
129 // recording will not continue. | 136 // recording will not continue. |
130 virtual void OnError(AudioInputStream* stream) = 0; | 137 virtual void OnError(AudioInputStream* stream) = 0; |
131 | 138 |
132 protected: | 139 protected: |
133 virtual ~AudioInputCallback() {} | 140 virtual ~AudioInputCallback() {} |
134 }; | 141 }; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 // Returns the Automatic Gain Control (AGC) state. | 175 // Returns the Automatic Gain Control (AGC) state. |
169 virtual bool GetAutomaticGainControl() = 0; | 176 virtual bool GetAutomaticGainControl() = 0; |
170 | 177 |
171 // Returns the current muting state for the microphone. | 178 // Returns the current muting state for the microphone. |
172 virtual bool IsMuted() = 0; | 179 virtual bool IsMuted() = 0; |
173 }; | 180 }; |
174 | 181 |
175 } // namespace media | 182 } // namespace media |
176 | 183 |
177 #endif // MEDIA_AUDIO_AUDIO_IO_H_ | 184 #endif // MEDIA_AUDIO_AUDIO_IO_H_ |
OLD | NEW |