Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(774)

Side by Side Diff: media/audio/win/waveout_output_win.h

Issue 4661001: Simplified AudioOutputStream interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_WIN_WAVEOUT_OUTPUT_WIN_H_ 5 #ifndef MEDIA_AUDIO_WIN_WAVEOUT_OUTPUT_WIN_H_
6 #define MEDIA_AUDIO_WIN_WAVEOUT_OUTPUT_WIN_H_ 6 #define MEDIA_AUDIO_WIN_WAVEOUT_OUTPUT_WIN_H_
7 7
8 #include <windows.h> 8 #include <windows.h>
9 #include <mmsystem.h> 9 #include <mmsystem.h>
10 #include <mmreg.h> 10 #include <mmreg.h>
(...skipping 17 matching lines...) Expand all
28 class PCMWaveOutAudioOutputStream : public AudioOutputStream { 28 class PCMWaveOutAudioOutputStream : public AudioOutputStream {
29 public: 29 public:
30 // The ctor takes all the usual parameters, plus |manager| which is the 30 // The ctor takes all the usual parameters, plus |manager| which is the
31 // the audio manager who is creating this object and |device_id| which 31 // the audio manager who is creating this object and |device_id| which
32 // is provided by the operating system. 32 // is provided by the operating system.
33 PCMWaveOutAudioOutputStream(AudioManagerWin* manager, AudioParameters params, 33 PCMWaveOutAudioOutputStream(AudioManagerWin* manager, AudioParameters params,
34 int num_buffers, UINT device_id); 34 int num_buffers, UINT device_id);
35 virtual ~PCMWaveOutAudioOutputStream(); 35 virtual ~PCMWaveOutAudioOutputStream();
36 36
37 // Implementation of AudioOutputStream. 37 // Implementation of AudioOutputStream.
38 virtual bool Open(uint32 packet_size); 38 virtual bool Open();
39 virtual void Close(); 39 virtual void Close();
40 virtual void Start(AudioSourceCallback* callback); 40 virtual void Start(AudioSourceCallback* callback);
41 virtual void Stop(); 41 virtual void Stop();
42 virtual void SetVolume(double volume); 42 virtual void SetVolume(double volume);
43 virtual void GetVolume(double* volume); 43 virtual void GetVolume(double* volume);
44 44
45 // Sends a buffer to the audio driver for playback. 45 // Sends a buffer to the audio driver for playback.
46 void QueueNextPacket(WAVEHDR* buffer); 46 void QueueNextPacket(WAVEHDR* buffer);
47 47
48 private: 48 private:
49 enum State { 49 enum State {
50 PCMA_BRAND_NEW, // Initial state. 50 PCMA_BRAND_NEW, // Initial state.
51 PCMA_READY, // Device obtained and ready to play. 51 PCMA_READY, // Device obtained and ready to play.
52 PCMA_PLAYING, // Playing audio. 52 PCMA_PLAYING, // Playing audio.
53 PCMA_STOPPING, // Trying to stop, waiting for callback to finish. 53 PCMA_STOPPING, // Trying to stop, waiting for callback to finish.
54 PCMA_STOPPED, // Stopped. Device was reset. 54 PCMA_STOPPED, // Stopped. Device was reset.
55 PCMA_CLOSED // Device has been released. 55 PCMA_CLOSED // Device has been released.
56 }; 56 };
57 57
58 // Windows calls us back to feed more data to the device here. See msdn 58 // Windows calls us back to feed more data to the device here. See msdn
59 // documentation for 'waveOutProc' for details about the parameters. 59 // documentation for 'waveOutProc' for details about the parameters.
60 static void CALLBACK WaveCallback(HWAVEOUT hwo, UINT msg, DWORD_PTR instance, 60 static void CALLBACK WaveCallback(HWAVEOUT hwo, UINT msg, DWORD_PTR instance,
61 DWORD_PTR param1, DWORD_PTR param2); 61 DWORD_PTR param1, DWORD_PTR param2);
62 62
63 // If windows reports an error this function handles it and passes it to 63 // If windows reports an error this function handles it and passes it to
64 // the attached AudioSourceCallback::OnError(). 64 // the attached AudioSourceCallback::OnError().
65 void HandleError(MMRESULT error); 65 void HandleError(MMRESULT error);
66 // Allocates and prepares the memory that will be used for playback. Only 66 // Allocates and prepares the memory that will be used for playback. Only
67 // two buffers are created. 67 // two buffers are created.
68 void SetupBuffers(uint32 rq_size); 68 void SetupBuffers();
69 // Deallocates the memory allocated in SetupBuffers. 69 // Deallocates the memory allocated in SetupBuffers.
70 void FreeBuffers(); 70 void FreeBuffers();
71 71
72 // Reader beware. Visual C has stronger guarantees on volatile vars than 72 // Reader beware. Visual C has stronger guarantees on volatile vars than
73 // most people expect. In fact, it has release semantics on write and 73 // most people expect. In fact, it has release semantics on write and
74 // acquire semantics on reads. See the msdn documentation. 74 // acquire semantics on reads. See the msdn documentation.
75 volatile State state_; 75 volatile State state_;
76 76
77 // The audio manager that created this output stream. We notify it when 77 // The audio manager that created this output stream. We notify it when
78 // we close so it can release its own resources. 78 // we close so it can release its own resources.
(...skipping 30 matching lines...) Expand all
109 // Pointer to the first allocated audio buffer. This object owns it. 109 // Pointer to the first allocated audio buffer. This object owns it.
110 WAVEHDR* buffer_; 110 WAVEHDR* buffer_;
111 111
112 // An event that is signaled when the callback thread is ready to stop. 112 // An event that is signaled when the callback thread is ready to stop.
113 ScopedHandle stopped_event_; 113 ScopedHandle stopped_event_;
114 114
115 DISALLOW_COPY_AND_ASSIGN(PCMWaveOutAudioOutputStream); 115 DISALLOW_COPY_AND_ASSIGN(PCMWaveOutAudioOutputStream);
116 }; 116 };
117 117
118 #endif // MEDIA_AUDIO_WIN_WAVEOUT_OUTPUT_WIN_H_ 118 #endif // MEDIA_AUDIO_WIN_WAVEOUT_OUTPUT_WIN_H_
119
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698