| 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 | 10 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 namespace media { | 49 namespace media { |
| 50 | 50 |
| 51 class MEDIA_EXPORT AudioOutputStream { | 51 class MEDIA_EXPORT AudioOutputStream { |
| 52 public: | 52 public: |
| 53 // Audio sources must implement AudioSourceCallback. This interface will be | 53 // Audio sources must implement AudioSourceCallback. This interface will be |
| 54 // called in a random thread which very likely is a high priority thread. Do | 54 // 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 | 55 // not rely on using this thread TLS or make calls that alter the thread |
| 56 // itself such as creating Windows or initializing COM. | 56 // itself such as creating Windows or initializing COM. |
| 57 class MEDIA_EXPORT AudioSourceCallback { | 57 class MEDIA_EXPORT AudioSourceCallback { |
| 58 public: | 58 public: |
| 59 virtual ~AudioSourceCallback() {} | |
| 60 | |
| 61 // Provide more data by filling |dest| up to |max_size| bytes. The provided | 59 // Provide more data by filling |dest| up to |max_size| bytes. The provided |
| 62 // buffer size is determined by the |samples_per_packet| specified in | 60 // buffer size is determined by the |samples_per_packet| specified in |
| 63 // AudioParameters when the stream is created. The source will return | 61 // AudioParameters when the stream is created. The source will return |
| 64 // the number of bytes it filled. The expected structure of |dest| is | 62 // the number of bytes it filled. The expected structure of |dest| is |
| 65 // platform and format specific. | 63 // platform and format specific. |
| 66 // |buffers_state| contains current state of the buffers, and can be used | 64 // |buffers_state| contains current state of the buffers, and can be used |
| 67 // by the source to calculate delay. | 65 // by the source to calculate delay. |
| 68 virtual uint32 OnMoreData(uint8* dest, | 66 virtual uint32 OnMoreData(uint8* dest, |
| 69 uint32 max_size, | 67 uint32 max_size, |
| 70 AudioBuffersState buffers_state) = 0; | 68 AudioBuffersState buffers_state) = 0; |
| 71 | 69 |
| 72 // There was an error while playing a buffer. Audio source cannot be | 70 // There was an error while playing a buffer. Audio source cannot be |
| 73 // destroyed yet. No direct action needed by the AudioStream, but it is | 71 // destroyed yet. No direct action needed by the AudioStream, but it is |
| 74 // a good place to stop accumulating sound data since is is likely that | 72 // a good place to stop accumulating sound data since is is likely that |
| 75 // playback will not continue. |code| is an error code that is platform | 73 // playback will not continue. |code| is an error code that is platform |
| 76 // specific. | 74 // specific. |
| 77 virtual void OnError(AudioOutputStream* stream, int code) = 0; | 75 virtual void OnError(AudioOutputStream* stream, int code) = 0; |
| 78 | 76 |
| 79 // Waits till data becomes available. Used when buffering data starting | 77 // Waits till data becomes available. Used when buffering data starting |
| 80 // new audio stream. | 78 // new audio stream. |
| 81 // Polling is not the best approach, but incorporating messaging loop | 79 // Polling is not the best approach, but incorporating messaging loop |
| 82 // with delayed tasks into guts of complex code is even worse, as it is | 80 // with delayed tasks into guts of complex code is even worse, as it is |
| 83 // very error-prone. We cannot easily add synchronization, interface is | 81 // very error-prone. We cannot easily add synchronization, interface is |
| 84 // already cut in stone because of need of backward compatibility with | 82 // already cut in stone because of need of backward compatibility with |
| 85 // plugins. In any case, data is usually immediately available, | 83 // plugins. In any case, data is usually immediately available, |
| 86 // so there would be no delay. | 84 // so there would be no delay. |
| 87 virtual void WaitTillDataReady() {} | 85 virtual void WaitTillDataReady() {} |
| 86 |
| 87 protected: |
| 88 virtual ~AudioSourceCallback() {} |
| 88 }; | 89 }; |
| 89 | 90 |
| 90 virtual ~AudioOutputStream() {} | 91 virtual ~AudioOutputStream() {} |
| 91 | 92 |
| 92 // Open the stream. false is returned if the stream cannot be opened. | 93 // Open the stream. false is returned if the stream cannot be opened. |
| 93 virtual bool Open() = 0; | 94 virtual bool Open() = 0; |
| 94 | 95 |
| 95 // Starts playing audio and generating AudioSourceCallback::OnMoreData(). | 96 // Starts playing audio and generating AudioSourceCallback::OnMoreData(). |
| 96 // Since implementor of AudioOutputStream may have internal buffers, right | 97 // Since implementor of AudioOutputStream may have internal buffers, right |
| 97 // after calling this method initial buffers are fetched. | 98 // after calling this method initial buffers are fetched. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 112 // Close the stream. This also generates AudioSourceCallback::OnClose(). | 113 // Close the stream. This also generates AudioSourceCallback::OnClose(). |
| 113 // After calling this method, the object should not be used anymore. | 114 // After calling this method, the object should not be used anymore. |
| 114 virtual void Close() = 0; | 115 virtual void Close() = 0; |
| 115 }; | 116 }; |
| 116 | 117 |
| 117 // Models an audio sink receiving recorded audio from the audio driver. | 118 // Models an audio sink receiving recorded audio from the audio driver. |
| 118 class MEDIA_EXPORT AudioInputStream { | 119 class MEDIA_EXPORT AudioInputStream { |
| 119 public: | 120 public: |
| 120 class MEDIA_EXPORT AudioInputCallback { | 121 class MEDIA_EXPORT AudioInputCallback { |
| 121 public: | 122 public: |
| 122 virtual ~AudioInputCallback() {} | |
| 123 | |
| 124 // Called by the audio recorder when a full packet of audio data is | 123 // Called by the audio recorder when a full packet of audio data is |
| 125 // available. This is called from a special audio thread and the | 124 // available. This is called from a special audio thread and the |
| 126 // implementation should return as soon as possible. | 125 // implementation should return as soon as possible. |
| 127 virtual void OnData(AudioInputStream* stream, const uint8* src, | 126 virtual void OnData(AudioInputStream* stream, const uint8* src, |
| 128 uint32 size, uint32 hardware_delay_bytes, | 127 uint32 size, uint32 hardware_delay_bytes, |
| 129 double volume) = 0; | 128 double volume) = 0; |
| 130 | 129 |
| 131 // The stream is done with this callback, the last call received by this | 130 // The stream is done with this callback, the last call received by this |
| 132 // audio sink. | 131 // audio sink. |
| 133 virtual void OnClose(AudioInputStream* stream) = 0; | 132 virtual void OnClose(AudioInputStream* stream) = 0; |
| 134 | 133 |
| 135 // There was an error while recording audio. The audio sink cannot be | 134 // There was an error while recording audio. The audio sink cannot be |
| 136 // destroyed yet. No direct action needed by the AudioInputStream, but it | 135 // destroyed yet. No direct action needed by the AudioInputStream, but it |
| 137 // is a good place to stop accumulating sound data since is is likely that | 136 // is a good place to stop accumulating sound data since is is likely that |
| 138 // recording will not continue. |code| is an error code that is platform | 137 // recording will not continue. |code| is an error code that is platform |
| 139 // specific. | 138 // specific. |
| 140 virtual void OnError(AudioInputStream* stream, int code) = 0; | 139 virtual void OnError(AudioInputStream* stream, int code) = 0; |
| 140 |
| 141 protected: |
| 142 virtual ~AudioInputCallback() {} |
| 141 }; | 143 }; |
| 142 | 144 |
| 143 virtual ~AudioInputStream() {} | 145 virtual ~AudioInputStream() {} |
| 144 | 146 |
| 145 // Open the stream and prepares it for recording. Call Start() to actually | 147 // Open the stream and prepares it for recording. Call Start() to actually |
| 146 // begin recording. | 148 // begin recording. |
| 147 virtual bool Open() = 0; | 149 virtual bool Open() = 0; |
| 148 | 150 |
| 149 // Starts recording audio and generating AudioInputCallback::OnData(). | 151 // Starts recording audio and generating AudioInputCallback::OnData(). |
| 150 // The input stream does not take ownership of this callback. | 152 // The input stream does not take ownership of this callback. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 172 // Sets the Automatic Gain Control (AGC) state. | 174 // Sets the Automatic Gain Control (AGC) state. |
| 173 virtual void SetAutomaticGainControl(bool enabled) = 0; | 175 virtual void SetAutomaticGainControl(bool enabled) = 0; |
| 174 | 176 |
| 175 // Returns the Automatic Gain Control (AGC) state. | 177 // Returns the Automatic Gain Control (AGC) state. |
| 176 virtual bool GetAutomaticGainControl() = 0; | 178 virtual bool GetAutomaticGainControl() = 0; |
| 177 }; | 179 }; |
| 178 | 180 |
| 179 } // namespace media | 181 } // namespace media |
| 180 | 182 |
| 181 #endif // MEDIA_AUDIO_AUDIO_IO_H_ | 183 #endif // MEDIA_AUDIO_AUDIO_IO_H_ |
| OLD | NEW |