| 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_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 22 matching lines...) Expand all Loading... |
| 33 // - Extra features if a specific hardware is installed (EAX, X-fi) | 33 // - Extra features if a specific hardware is installed (EAX, X-fi) |
| 34 // | 34 // |
| 35 // The primary client of this facility is audio coming from several tabs. | 35 // 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 | 36 // Specifically for this case we avoid supporting complex formats such as MP3 |
| 37 // or WMA. Complex format decoding should be done by the renderers. | 37 // or WMA. Complex format decoding should be done by the renderers. |
| 38 | 38 |
| 39 | 39 |
| 40 // Models an audio stream that gets rendered to the audio hardware output. | 40 // Models an audio stream that gets rendered to the audio hardware output. |
| 41 // Because we support more audio streams than physically available channels | 41 // Because we support more audio streams than physically available channels |
| 42 // a given AudioOutputStream might or might not talk directly to hardware. | 42 // a given AudioOutputStream might or might not talk directly to hardware. |
| 43 // An audio stream allocates several buffers for audio data and calls |
| 44 // AudioSourceCallback::OnModeData() periodically to fill these buffers, |
| 45 // 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 // created. |
| 43 class AudioOutputStream { | 48 class AudioOutputStream { |
| 44 public: | 49 public: |
| 45 // Audio sources must implement AudioSourceCallback. This interface will be | 50 // Audio sources must implement AudioSourceCallback. This interface will be |
| 46 // called in a random thread which very likely is a high priority thread. Do | 51 // called in a random thread which very likely is a high priority thread. Do |
| 47 // not rely on using this thread TLS or make calls that alter the thread | 52 // not rely on using this thread TLS or make calls that alter the thread |
| 48 // itself such as creating Windows or initializing COM. | 53 // itself such as creating Windows or initializing COM. |
| 49 class AudioSourceCallback { | 54 class AudioSourceCallback { |
| 50 public: | 55 public: |
| 51 virtual ~AudioSourceCallback() {} | 56 virtual ~AudioSourceCallback() {} |
| 52 | 57 |
| 53 // Provide more data by filling |dest| up to |max_size| bytes. The provided | 58 // Provide more data by filling |dest| up to |max_size| bytes. The provided |
| 54 // buffer size is usually what is specified in Open(). The source | 59 // buffer size is determined by the |samples_per_packet| specified in |
| 55 // will return the number of bytes it filled. The expected structure of | 60 // AudioParameters when the stream is created. The source will return |
| 56 // |dest| is platform and format specific. | 61 // the number of bytes it filled. The expected structure of |dest| is |
| 57 // |pending_bytes| is the number of bytes will be played before the | 62 // platform and format specific. |
| 58 // requested data is played. | 63 // |buffers_state| contains current state of the buffers, and can be used |
| 64 // by the source to calculate delay. |
| 59 virtual uint32 OnMoreData( | 65 virtual uint32 OnMoreData( |
| 60 AudioOutputStream* stream, uint8* dest, uint32 max_size, | 66 AudioOutputStream* stream, uint8* dest, uint32 max_size, |
| 61 AudioBuffersState buffers_state) = 0; | 67 AudioBuffersState buffers_state) = 0; |
| 62 | 68 |
| 63 // The stream is done with this callback. After this call the audio source | |
| 64 // can go away or be destroyed. | |
| 65 virtual void OnClose(AudioOutputStream* stream) = 0; | |
| 66 | |
| 67 // There was an error while playing a buffer. Audio source cannot be | 69 // There was an error while playing a buffer. Audio source cannot be |
| 68 // destroyed yet. No direct action needed by the AudioStream, but it is | 70 // destroyed yet. No direct action needed by the AudioStream, but it is |
| 69 // a good place to stop accumulating sound data since is is likely that | 71 // a good place to stop accumulating sound data since is is likely that |
| 70 // playback will not continue. |code| is an error code that is platform | 72 // playback will not continue. |code| is an error code that is platform |
| 71 // specific. | 73 // specific. |
| 72 virtual void OnError(AudioOutputStream* stream, int code) = 0; | 74 virtual void OnError(AudioOutputStream* stream, int code) = 0; |
| 73 }; | 75 }; |
| 74 | 76 |
| 75 // Open the stream. |packet_size| is the requested buffer allocation which | 77 // Open the stream. false is returned if the stream cannot be opened. |
| 76 // the audio source thinks it can usually fill without blocking. Internally | 78 virtual bool Open() = 0; |
| 77 // two or three buffers of |packet_size| size are created, one will be | |
| 78 // locked for playback and one will be ready to be filled in the call to | |
| 79 // AudioSourceCallback::OnMoreData(). | |
| 80 // The number of buffers is controlled by AUDIO_PCM_LOW_LATENCY. See more | |
| 81 // information below. | |
| 82 // | |
| 83 // TODO(ajwong): Streams are not reusable, so try to move packet_size into the | |
| 84 // constructor. | |
| 85 virtual bool Open(uint32 packet_size) = 0; | |
| 86 | 79 |
| 87 // Starts playing audio and generating AudioSourceCallback::OnMoreData(). | 80 // Starts playing audio and generating AudioSourceCallback::OnMoreData(). |
| 88 // Since implementor of AudioOutputStream may have internal buffers, right | 81 // Since implementor of AudioOutputStream may have internal buffers, right |
| 89 // after calling this method initial buffers are fetched. | 82 // after calling this method initial buffers are fetched. |
| 90 // | 83 // |
| 91 // The output stream does not take ownership of this callback. | 84 // The output stream does not take ownership of this callback. |
| 92 virtual void Start(AudioSourceCallback* callback) = 0; | 85 virtual void Start(AudioSourceCallback* callback) = 0; |
| 93 | 86 |
| 94 // Stops playing audio. Effect might not be instantaneous as the hardware | 87 // Stops playing audio. Effect might not be instantaneous as the hardware |
| 95 // might have locked audio data that is processing. | 88 // might have locked audio data that is processing. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 142 |
| 150 // Close the stream. This also generates AudioInputCallback::OnClose(). This | 143 // Close the stream. This also generates AudioInputCallback::OnClose(). This |
| 151 // should be the last call made on this object. | 144 // should be the last call made on this object. |
| 152 virtual void Close() = 0; | 145 virtual void Close() = 0; |
| 153 | 146 |
| 154 protected: | 147 protected: |
| 155 virtual ~AudioInputStream() {} | 148 virtual ~AudioInputStream() {} |
| 156 }; | 149 }; |
| 157 | 150 |
| 158 #endif // MEDIA_AUDIO_AUDIO_IO_H_ | 151 #endif // MEDIA_AUDIO_AUDIO_IO_H_ |
| OLD | NEW |