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

Issue 8591028: Change the way we are sending audio data to driver when using WaveOut API. (Closed)

Created:
9 years, 1 month ago by enal
Modified:
9 years ago
CC:
chromium-reviews, hclam+watch_chromium.org, ddorwin+watch_chromium.org, fischman+watch_chromium.org, acolwell+watch_chromium.org, annacc+watch_chromium.org, ajwong+watch_chromium.org, vrk (LEFT CHROMIUM), scherkus (not reviewing), ihf+watch_chromium.org
Visibility:
Public.

Description

Change the way we are sending audio data to driver when using WaveOut API. Before, we were "feeding" the driver in the callback when OS returned audio buffer to us. MSDN disallows that, but We were avoiding deadlock when stopping the stream by using some clever tricks. Unfortunately, exactly the same deadlock happens when Windows were draining audio stream when switching the device, and our tricks did not help, as we were not controlling exact timing. Fix is to separate receiving freed buffer and "feeding" audio driver. Now we are using CALLBACK_EVENT wave out mode in which Windows signal event when buffer runs out of data, and using RegisterWaitForSingleObject() so our callback is called by one of thread pool threads. Stopping of playback became slower because now it is synchronous. If that ever become a problem we can use singleton that keeps track of the playing audio streams, than stopping can become instaneous, at a cost of more complex checks in the callback. Unfortunately, no automatic test, as there is no documented way to programmatically switch default audio device on Windows. People were able to figure it out (see http://www.daveamenta.com/2011-05/programmatically-or-command-line-change-the-default-sound-playback-device-in-windows-7/), but there is no guarantee it will continue to work in Win8, or even in next Service Pack for Win7. BUG=41036 TEST=Play any HTML5 audio/video on Windows and change default audio device TEST=using "Control Panel | Sound". There should be no hang, you should hear TEST=audio from the newly chosen device. Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=112147 Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=112484

Patch Set 1 #

Total comments: 35

Patch Set 2 : '' #

Total comments: 11

Patch Set 3 : '' #

Patch Set 4 : '' #

Patch Set 5 : '' #

Total comments: 23

Patch Set 6 : '' #

Total comments: 20

Patch Set 7 : '' #

Patch Set 8 : '' #

Total comments: 4

Patch Set 9 : '' #

Unified diffs Side-by-side diffs Delta from patch set Stats (+166 lines, -114 lines) Patch
M media/audio/audio_util.cc View 1 2 3 4 5 6 1 chunk +5 lines, -0 lines 0 comments Download
M media/audio/win/audio_output_win_unittest.cc View 1 2 3 4 5 6 7 2 chunks +7 lines, -4 lines 0 comments Download
M media/audio/win/waveout_output_win.h View 1 2 3 4 5 6 7 8 4 chunks +29 lines, -20 lines 0 comments Download
M media/audio/win/waveout_output_win.cc View 1 2 3 4 5 6 7 8 9 chunks +125 lines, -90 lines 0 comments Download

Messages

Total messages: 52 (0 generated)
enal1
I believe I finally have code ready...
9 years, 1 month ago (2011-11-17 21:24:54 UTC) #1
tommi (sloooow) - chröme
Great work Eugene. After thinking about this while skimming through the code (I left the ...
9 years, 1 month ago (2011-11-18 09:53:21 UTC) #2
henrika (OOO until Aug 14)
Eugene, I have applied the patch and can confirm that it does avoid the current ...
9 years, 1 month ago (2011-11-18 12:24:21 UTC) #3
enal1
On 2011/11/18 12:24:21, henrika1 wrote: > Eugene, > > I have applied the patch and ...
9 years, 1 month ago (2011-11-18 19:04:34 UTC) #4
enal1
Major comment was "do not use singleton that keeps track of playing audio streams, use ...
9 years, 1 month ago (2011-11-19 00:59:18 UTC) #5
tommi (sloooow) - chröme
excellent! I have one more suggestion below and a couple of nits. Almost there. http://codereview.chromium.org/8591028/diff/7001/media/audio/win/waveout_output_win.cc ...
9 years, 1 month ago (2011-11-19 17:23:27 UTC) #6
tommi (sloooow) - chröme
noticed one more thing. http://codereview.chromium.org/8591028/diff/7001/media/audio/win/waveout_output_win.cc File media/audio/win/waveout_output_win.cc (right): http://codereview.chromium.org/8591028/diff/7001/media/audio/win/waveout_output_win.cc#newcode370 media/audio/win/waveout_output_win.cc:370: AddRef(); Actually, I think this ...
9 years, 1 month ago (2011-11-19 21:58:41 UTC) #7
cpu_(ooo_6.6-7.5)
http://codereview.chromium.org/8591028/diff/7001/media/audio/win/waveout_output_win.cc File media/audio/win/waveout_output_win.cc (right): http://codereview.chromium.org/8591028/diff/7001/media/audio/win/waveout_output_win.cc#newcode312 media/audio/win/waveout_output_win.cc:312: // from here, have to schedule it for the ...
9 years, 1 month ago (2011-11-21 01:18:43 UTC) #8
enal1
> The right approach is to use CALLBACK_EVENT mode, and remove this > overhead. I ...
9 years, 1 month ago (2011-11-21 02:55:48 UTC) #9
henrika (OOO until Aug 14)
Carlos, I read your input in the issue tracker about the initial work you did ...
9 years, 1 month ago (2011-11-21 08:31:51 UTC) #10
enal1
On 2011/11/21 08:31:51, henrika1 wrote: > Carlos, > > I read your input in the ...
9 years, 1 month ago (2011-11-21 20:38:19 UTC) #11
tommi (sloooow) - chröme
http://codereview.chromium.org/8591028/diff/7001/media/audio/win/waveout_output_win.cc File media/audio/win/waveout_output_win.cc (right): http://codereview.chromium.org/8591028/diff/7001/media/audio/win/waveout_output_win.cc#newcode312 media/audio/win/waveout_output_win.cc:312: // from here, have to schedule it for the ...
9 years, 1 month ago (2011-11-22 08:21:45 UTC) #12
enal1
On 2011/11/22 08:21:45, tommi wrote: > http://codereview.chromium.org/8591028/diff/7001/media/audio/win/waveout_output_win.cc > File media/audio/win/waveout_output_win.cc (right): > > http://codereview.chromium.org/8591028/diff/7001/media/audio/win/waveout_output_win.cc#newcode312 > ...
9 years, 1 month ago (2011-11-22 17:24:14 UTC) #13
cpu_(ooo_6.6-7.5)
In my accounting we save one thread. That is, before this change there are two ...
9 years, 1 month ago (2011-11-22 17:41:19 UTC) #14
enal1
I already wrote -- thread B is not real time. Its priority is -3, that ...
9 years, 1 month ago (2011-11-22 17:56:17 UTC) #15
cpu_(ooo_6.6-7.5)
(hit send too soon) Yes the point is to keep the number of context switches ...
9 years, 1 month ago (2011-11-22 18:19:48 UTC) #16
enal1
> You can use the same approach of ObjectWatcher> (src/base/win/object_watcher.cc) I believe I already answered ...
9 years, 1 month ago (2011-11-22 18:24:30 UTC) #17
cpu_(ooo_6.6-7.5)
> In case of event some thread still have to wait. Maybe I haven't been ...
9 years, 1 month ago (2011-11-22 18:30:18 UTC) #18
enal1
Rewrote the code to use event, not callback. Stopping is currently synchronous. Added comment how ...
9 years, 1 month ago (2011-11-22 22:07:21 UTC) #19
henrika (OOO until Aug 14)
Mainly questions and comments first round. Will check more details next time. http://codereview.chromium.org/8591028/diff/29001/media/audio/win/waveout_output_win.cc File media/audio/win/waveout_output_win.cc ...
9 years, 1 month ago (2011-11-23 07:12:50 UTC) #20
cpu_(ooo_6.6-7.5)
http://codereview.chromium.org/8591028/diff/29001/media/audio/win/waveout_output_win.cc File media/audio/win/waveout_output_win.cc (left): http://codereview.chromium.org/8591028/diff/29001/media/audio/win/waveout_output_win.cc#oldcode38 media/audio/win/waveout_output_win.cc:38: static const uint32 kMaxOpenBufferSize = 1024 * 1024 * ...
9 years, 1 month ago (2011-11-23 22:39:56 UTC) #21
cpu_(ooo_6.6-7.5)
http://codereview.chromium.org/8591028/diff/29001/media/audio/win/waveout_output_win.cc File media/audio/win/waveout_output_win.cc (right): http://codereview.chromium.org/8591028/diff/29001/media/audio/win/waveout_output_win.cc#newcode117 media/audio/win/waveout_output_win.cc:117: buffer_event_.Set(::CreateEvent(NULL, FALSE, FALSE, NULL)); please add in the comment ...
9 years, 1 month ago (2011-11-23 23:04:17 UTC) #22
henrika_dont_use
Some more general input/questions: Has it been verified that this new implementation does in fact ...
9 years, 1 month ago (2011-11-24 10:31:00 UTC) #23
enal
I believe I addressed all in-line comments. Yes, I verified that change fixes the problem ...
9 years ago (2011-11-28 22:40:20 UTC) #24
henrika (OOO until Aug 14)
+rtoy Thanks for all your comments and changes Eugene. I've added Raymond on the CC ...
9 years ago (2011-11-29 12:20:42 UTC) #25
Raymond Toy (Google)
http://codereview.chromium.org/8591028/diff/34001/media/audio/audio_util.cc File media/audio/audio_util.cc (right): http://codereview.chromium.org/8591028/diff/34001/media/audio/audio_util.cc#newcode296 media/audio/audio_util.cc:296: if (base::win::GetVersion() <= base::win::VERSION_XP) { On 2011/11/29 12:20:42, henrika1 ...
9 years ago (2011-11-29 18:13:56 UTC) #26
Raymond Toy (Google)
http://codereview.chromium.org/8591028/diff/34001/media/audio/win/waveout_output_win.cc File media/audio/win/waveout_output_win.cc (right): http://codereview.chromium.org/8591028/diff/34001/media/audio/win/waveout_output_win.cc#newcode68 media/audio/win/waveout_output_win.cc:68: return (sizeof(WAVEHDR) + buffer_size_ + 15u) & static_cast<size_t>(~15); Instead ...
9 years ago (2011-11-29 18:18:39 UTC) #27
Raymond Toy (Google)
http://codereview.chromium.org/8591028/diff/34001/media/audio/audio_util.cc File media/audio/audio_util.cc (right): http://codereview.chromium.org/8591028/diff/34001/media/audio/audio_util.cc#newcode299 media/audio/audio_util.cc:299: return 480; I tested this on my Windows 7 ...
9 years ago (2011-11-29 18:45:29 UTC) #28
enal
Addressed all the issues. I believe I now know how to make code bullet-proof and ...
9 years ago (2011-11-29 18:57:44 UTC) #29
enal
1) Increased size of web audio buffer on XP to 2048. That does not help, ...
9 years ago (2011-11-29 19:45:58 UTC) #30
Raymond Toy (Google)
http://codereview.chromium.org/8591028/diff/34001/media/audio/audio_util.cc File media/audio/audio_util.cc (right): http://codereview.chromium.org/8591028/diff/34001/media/audio/audio_util.cc#newcode299 media/audio/audio_util.cc:299: return 480; On 2011/11/29 18:57:44, enal wrote: > On ...
9 years ago (2011-11-29 20:01:29 UTC) #31
enal
Answered. http://codereview.chromium.org/8591028/diff/34001/media/audio/audio_util.cc File media/audio/audio_util.cc (right): http://codereview.chromium.org/8591028/diff/34001/media/audio/audio_util.cc#newcode299 media/audio/audio_util.cc:299: return 480; On 2011/11/29 20:01:29, rtoy wrote: > ...
9 years ago (2011-11-29 21:02:45 UTC) #32
cpu_(ooo_6.6-7.5)
> So I hope Windows audio API waits for event to become non-signaled before it ...
9 years ago (2011-11-30 00:32:20 UTC) #33
cpu_(ooo_6.6-7.5)
I am pretty much lgtm with your change. Hopefully things don't regress. The only concern ...
9 years ago (2011-11-30 00:43:34 UTC) #34
enal1
Code I sent today does not depend on that assumption. It can handle "event losses". ...
9 years ago (2011-11-30 00:47:42 UTC) #35
enal1
Again, code I sent today would handle such case. It goes through all buffers, looking ...
9 years ago (2011-11-30 00:49:36 UTC) #36
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/enal@chromium.org/8591028/35005
9 years ago (2011-11-30 02:50:13 UTC) #37
commit-bot: I haz the power
Change committed as 112147
9 years ago (2011-11-30 06:29:19 UTC) #38
henrika (OOO until Aug 14)
Eugene, nice work. Thanks for doing this! However, this patch breaks the media_unittests on Win7. ...
9 years ago (2011-11-30 08:05:03 UTC) #39
henrika_dont_use
Improved filter: media_unittests --gtest_filter=WinAudioTest*PCMWaveStreamPendingBytes* On Wed, Nov 30, 2011 at 9:05 AM, <henrika@chromium.org> wrote: > ...
9 years ago (2011-11-30 08:12:16 UTC) #40
Raymond Toy (Google)
On 2011/11/29 21:02:45, enal wrote: > Answered. > > http://codereview.chromium.org/8591028/diff/34001/media/audio/audio_util.cc > File media/audio/audio_util.cc (right): > ...
9 years ago (2011-11-30 08:31:49 UTC) #41
tommi (sloooow) - chröme
I'm a bit surprised to see that this was submitted. Only 1 of 5 reviewers ...
9 years ago (2011-11-30 10:33:50 UTC) #42
enal1
Sorry, it was my decision, and it looks I was wrong. I would revert it. ...
9 years ago (2011-11-30 15:56:52 UTC) #43
enal1
On 2011/11/30 15:56:52, enal1 wrote: > Sorry, it was my decision, and it looks I ...
9 years ago (2011-11-30 16:25:07 UTC) #44
enal1
Thank you, exact failure varies between runs on my system. Sometimes there is no failure... ...
9 years ago (2011-11-30 17:07:55 UTC) #45
enal
Addressed nit, made unit test less sensitive to exact timing. http://codereview.chromium.org/8591028/diff/34001/media/audio/win/waveout_output_win.cc File media/audio/win/waveout_output_win.cc (right): http://codereview.chromium.org/8591028/diff/34001/media/audio/win/waveout_output_win.cc#newcode186 ...
9 years ago (2011-11-30 19:41:24 UTC) #46
tommi (sloooow) - chröme
lgtm and thanks for waiting. http://codereview.chromium.org/8591028/diff/34001/media/audio/win/waveout_output_win.cc File media/audio/win/waveout_output_win.cc (right): http://codereview.chromium.org/8591028/diff/34001/media/audio/win/waveout_output_win.cc#newcode127 media/audio/win/waveout_output_win.cc:127: )); nit: close parenthesis ...
9 years ago (2011-12-01 15:28:00 UTC) #47
henrika (OOO until Aug 14)
Did not verify that the new unit test works. LGTM w/ nits.
9 years ago (2011-12-01 15:33:05 UTC) #48
henrika (OOO until Aug 14)
http://codereview.chromium.org/8591028/diff/49002/media/audio/win/waveout_output_win.cc File media/audio/win/waveout_output_win.cc (right): http://codereview.chromium.org/8591028/diff/49002/media/audio/win/waveout_output_win.cc#newcode123 media/audio/win/waveout_output_win.cc:123: buffer_event_.Set(::CreateEvent(NULL, // Security attributes nit (add period '.')? http://codereview.chromium.org/8591028/diff/49002/media/audio/win/waveout_output_win.cc#newcode360 ...
9 years ago (2011-12-01 15:33:14 UTC) #49
Raymond Toy (Google)
On 2011/11/30 08:31:49, rtoy wrote: > On 2011/11/29 21:02:45, enal wrote: > > Answered. > ...
9 years ago (2011-12-01 16:51:09 UTC) #50
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/enal@chromium.org/8591028/57002
9 years ago (2011-12-01 17:09:56 UTC) #51
commit-bot: I haz the power
9 years ago (2011-12-01 18:20:33 UTC) #52
Change committed as 112484

Powered by Google App Engine
This is Rietveld 408576698