Index: media/audio/win/waveout_output_win.h |
=================================================================== |
--- media/audio/win/waveout_output_win.h (revision 110574) |
+++ media/audio/win/waveout_output_win.h (working copy) |
@@ -11,6 +11,8 @@ |
#include <mmreg.h> |
#include "base/basictypes.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/synchronization/lock.h" |
#include "base/win/scoped_handle.h" |
#include "media/audio/audio_io.h" |
#include "media/audio/audio_parameters.h" |
@@ -28,9 +30,9 @@ |
// you are keeping state in it. |
class PCMWaveOutAudioOutputStream : public AudioOutputStream { |
public: |
- // The ctor takes all the usual parameters, plus |manager| which is the |
- // the audio manager who is creating this object and |device_id| which |
- // is provided by the operating system. |
+ // The ctor takes all the usual parameters, plus |manager| which is the the |
+ // audio manager who is creating this object and |device_id| which is provided |
+ // by the operating system. |
PCMWaveOutAudioOutputStream(AudioManagerWin* manager, |
const AudioParameters& params, |
int num_buffers, |
@@ -53,20 +55,27 @@ |
PCMA_BRAND_NEW, // Initial state. |
PCMA_READY, // Device obtained and ready to play. |
PCMA_PLAYING, // Playing audio. |
+ PCMA_STOPPING, // Audio is stopping, do not "feed" data to Windows. |
PCMA_CLOSED // Device has been released. |
}; |
- // Windows calls us back to feed more data to the device here. See msdn |
- // documentation for 'waveOutProc' for details about the parameters. |
- static void CALLBACK WaveCallback(HWAVEOUT hwo, UINT msg, DWORD_PTR instance, |
- DWORD_PTR param1, DWORD_PTR param2); |
+ // Returns pointer to the n-th buffer. |
+ inline WAVEHDR* GetBuffer(int n) const; |
+ // Size of one buffer in bytes, rounded up if necessary. |
+ inline size_t BufferSize() const; |
+ |
+ // Windows calls us back asking for more data when buffer_event_ signalled. |
+ // See MSDN for help on RegisterWaitForSingleObject() and waveOutOpen(). |
+ static void NTAPI BufferCallback(PVOID lpParameter, BOOLEAN); |
+ |
// If windows reports an error this function handles it and passes it to |
// the attached AudioSourceCallback::OnError(). |
void HandleError(MMRESULT error); |
- // Allocates and prepares the memory that will be used for playback. Only |
- // two buffers are created. |
+ |
+ // Allocates and prepares the memory that will be used for playback. |
void SetupBuffers(); |
+ |
// Deallocates the memory allocated in SetupBuffers. |
void FreeBuffers(); |
@@ -107,19 +116,19 @@ |
// Handle to the instance of the wave device. |
HWAVEOUT waveout_; |
- // Pointer to the first allocated audio buffer. This object owns it. |
- WAVEHDR* buffer_; |
+ // Handle to the buffer event. |
+ base::win::ScopedHandle buffer_event_; |
- // Lock used to prevent stopping the hardware callback thread while it is |
- // pending for data or feeding it to audio driver, because doing that causes |
- // the deadlock. Main thread gets that lock before stopping the playback. |
- // Callback tries to acquire that lock before entering critical code. If |
- // acquire fails then main thread is stopping the playback, callback should |
- // immediately return. |
- // Use Windows-specific lock, not Chrome one, because there is limited set of |
- // functions callback can use. |
- CRITICAL_SECTION lock_; |
+ // Handle returned by RegisterWaitForSingleObject(). |
+ base::win::ScopedHandle waiting_handle_; |
+ // Pointer to the allocated audio buffers, we allocate all buffers in one big |
+ // chunk. This object owns them. |
+ scoped_array<char> buffers_; |
+ |
+ // Lock used to avoid the conflict when callbacks are called simultaneously. |
+ base::Lock lock_; |
+ |
DISALLOW_COPY_AND_ASSIGN(PCMWaveOutAudioOutputStream); |
}; |