forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 2
/
bug495794_closeAudio.patch
105 lines (98 loc) · 3.72 KB
/
bug495794_closeAudio.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
diff --git a/media/libsydneyaudio/src/sydney_audio_waveapi.c b/media/libsydneyaudio/src/sydney_audio_waveapi.c
--- a/media/libsydneyaudio/src/sydney_audio_waveapi.c
+++ b/media/libsydneyaudio/src/sydney_audio_waveapi.c
@@ -416,29 +416,34 @@ int openAudio(sa_stream_t *s) {
wfx.nBlockAlign = (wfx.wBitsPerSample * wfx.nChannels) >> 3;
wfx.nAvgBytesPerSec = wfx.nBlockAlign * wfx.nSamplesPerSec;
supported = waveOutOpen(NULL, WAVE_MAPPER, &wfx, (DWORD_PTR)0, (DWORD_PTR)0,
WAVE_FORMAT_QUERY);
if (supported == MMSYSERR_NOERROR) { // audio device opened sucessfully
status = waveOutOpen((LPHWAVEOUT)&(s->hWaveOut), WAVE_MAPPER, &wfx,
(DWORD_PTR)waveOutProc, (DWORD_PTR)s, CALLBACK_FUNCTION);
- HANDLE_WAVE_ERROR(status, "opening audio device for playback");
- printf("Audio device sucessfully opened\n");
+ if (status != MMSYSERR_NOERROR) {
+ freeBlocks(s->waveBlocks);
+ s->waveBlocks = NULL;
+ HANDLE_WAVE_ERROR(status, "opening audio device for playback");
+ }
}
else if (supported == WAVERR_BADFORMAT) {
- printf("Requested format not supported...\n");
- // clean up the memory
- freeBlocks(s->waveBlocks);
+ printf("Requested format not supported.\n");
+ // clean up the memory
+ freeBlocks(s->waveBlocks);
+ s->waveBlocks = NULL;
return SA_ERROR_NOT_SUPPORTED;
}
else {
- printf("Error opening default audio device. Exiting...\n");
- // clean up the memory
- freeBlocks(s->waveBlocks);
+ printf("Error opening default audio device.\n");
+ // clean up the memory
+ freeBlocks(s->waveBlocks);
+ s->waveBlocks = NULL;
return SA_ERROR_SYSTEM;
}
// create notification for data written to a device
s->callbackEvent = CreateEvent(0, FALSE, FALSE, 0);
// initialise critical section for operations on waveFreeBlockCound variable
InitializeCriticalSection(&(s->waveCriticalSection));
return SA_SUCCESS;
@@ -454,40 +459,43 @@ int closeAudio(sa_stream_t * s) {
result = SA_SUCCESS;
// reseting audio device and flushing buffers
status = waveOutReset(s->hWaveOut);
if (status != MMSYSERR_NOERROR) {
result = getSAErrorCode(status);
}
- /* wait for all blocks to complete */
- while(s->waveFreeBlockCount < BLOCK_COUNT) {
- Sleep(10);
+ if (s->waveBlocks) {
+ /* wait for all blocks to complete */
+ while(s->waveFreeBlockCount < BLOCK_COUNT) {
+ Sleep(10);
+ }
+
+ /* unprepare any blocks that are still prepared */
+ for(i = 0; i < s->waveFreeBlockCount; i++) {
+ if(s->waveBlocks[i].dwFlags & WHDR_PREPARED) {
+ status = waveOutUnprepareHeader(s->hWaveOut, &(s->waveBlocks[i]), sizeof(WAVEHDR));
+ if (status != MMSYSERR_NOERROR) {
+ result = getSAErrorCode(status);
+ }
+ }
+ }
+
+ freeBlocks(s->waveBlocks);
+ s->waveBlocks = NULL;
}
- /* unprepare any blocks that are still prepared */
- for(i = 0; i < s->waveFreeBlockCount; i++) {
- if(s->waveBlocks[i].dwFlags & WHDR_PREPARED) {
- status = waveOutUnprepareHeader(s->hWaveOut, &(s->waveBlocks[i]), sizeof(WAVEHDR));
- if (status != MMSYSERR_NOERROR) {
- result = getSAErrorCode(status);
- }
- }
- }
-
- freeBlocks(s->waveBlocks);
status = waveOutClose(s->hWaveOut);
if (status != MMSYSERR_NOERROR) {
result = getSAErrorCode(status);
}
DeleteCriticalSection(&(s->waveCriticalSection));
CloseHandle(s->callbackEvent);
- printf("[audio] audio resources cleanup completed\n");
return result;
}
/**
* \brief - writes PCM audio samples to audio device
* \param s - valid handle to opened sydney stream
* \param data - pointer to memory storing audio samples to be played
* \param nsamples - number of samples in the memory pointed by previous parameter