Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
9c803bc0
Commit
9c803bc0
authored
May 16, 2012
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wasapi: factorize/check COM initialization
parent
39ee3d11
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
18 deletions
+33
-18
modules/audio_output/wasapi.c
modules/audio_output/wasapi.c
+33
-18
No files found.
modules/audio_output/wasapi.c
View file @
9c803bc0
...
...
@@ -46,6 +46,24 @@ vlc_module_begin()
set_callbacks
(
Open
,
Close
)
vlc_module_end
()
static
int
TryEnter
(
void
)
{
HRESULT
hr
=
CoInitializeEx
(
NULL
,
COINIT_MULTITHREADED
);
return
-!!
FAILED
(
hr
);
}
static
void
Enter
(
void
)
{
HRESULT
hr
=
CoInitializeEx
(
NULL
,
COINIT_MULTITHREADED
);
if
(
unlikely
(
FAILED
(
hr
)))
abort
();
}
static
void
Leave
(
void
)
{
CoUninitialize
();
}
struct
aout_sys_t
{
IAudioClient
*
client
;
...
...
@@ -65,7 +83,7 @@ static void Play(audio_output_t *aout, block_t *block)
aout_sys_t
*
sys
=
aout
->
sys
;
HRESULT
hr
;
CoInitializeEx
(
NULL
,
COINIT_MULTITHREADED
);
Enter
(
);
if
(
likely
(
sys
->
clock
!=
NULL
))
{
UINT64
pos
,
qpcpos
;
...
...
@@ -121,7 +139,7 @@ static void Play(audio_output_t *aout, block_t *block)
+
block
->
i_nb_samples
*
CLOCK_FREQ
/
aout
->
format
.
i_rate
);
}
CoUninitializ
e
();
Leav
e
();
block_Release
(
block
);
}
...
...
@@ -130,7 +148,7 @@ static void Pause(audio_output_t *aout, bool paused, mtime_t date)
aout_sys_t
*
sys
=
aout
->
sys
;
HRESULT
hr
;
CoInitializeEx
(
NULL
,
COINIT_MULTITHREADED
);
Enter
(
);
if
(
paused
)
hr
=
IAudioClient_Stop
(
sys
->
client
);
else
...
...
@@ -138,7 +156,7 @@ static void Pause(audio_output_t *aout, bool paused, mtime_t date)
if
(
FAILED
(
hr
))
msg_Warn
(
aout
,
"cannot %s stream (error 0x%lx)"
,
paused
?
"stop"
:
"start"
,
hr
);
CoUninitializ
e
();
Leav
e
();
(
void
)
date
;
}
...
...
@@ -150,12 +168,12 @@ static void Flush(audio_output_t *aout, bool wait)
if
(
wait
)
return
;
/* Not drain implemented */
CoInitializeEx
(
NULL
,
COINIT_MULTITHREADED
);
Enter
(
);
IAudioClient_Stop
(
sys
->
client
);
hr
=
IAudioClient_Reset
(
sys
->
client
);
if
(
FAILED
(
hr
))
msg_Warn
(
aout
,
"cannot reset stream (error 0x%lx)"
,
hr
);
CoUninitializ
e
();
Leav
e
();
}
static
int
SimpleVolumeSet
(
audio_output_t
*
aout
,
float
vol
,
bool
mute
)
...
...
@@ -166,8 +184,8 @@ static int SimpleVolumeSet(audio_output_t *aout, float vol, bool mute)
if
(
vol
>
1
.)
vol
=
1
.;
Enter
();
/* NOTE: better change volume while muted (if mute is toggled) */
CoInitializeEx
(
NULL
,
COINIT_MULTITHREADED
);
if
(
mute
)
{
hr
=
ISimpleAudioVolume_SetMute
(
sys
->
volume
.
simple
,
true
,
NULL
);
...
...
@@ -185,7 +203,7 @@ static int SimpleVolumeSet(audio_output_t *aout, float vol, bool mute)
if
(
FAILED
(
hr
))
msg_Warn
(
aout
,
"cannot unmute session (error 0x%lx)"
,
hr
);
}
CoUninitializ
e
();
Leav
e
();
return
0
;
}
...
...
@@ -268,9 +286,7 @@ static void MTAThread(void *data)
aout_sys_t
*
sys
=
aout
->
sys
;
HRESULT
hr
;
hr
=
CoInitializeEx
(
NULL
,
COINIT_MULTITHREADED
);
if
(
unlikely
(
FAILED
(
hr
)))
abort
();
Enter
();
hr
=
IAudioClient_GetService
(
sys
->
client
,
&
IID_IAudioRenderClient
,
(
void
**
)
&
sys
->
render
);
...
...
@@ -299,7 +315,7 @@ static void MTAThread(void *data)
IAudioClock_Release
(
sys
->
clock
);
IAudioRenderClient_Release
(
sys
->
render
);
fail:
CoUninitializ
e
();
Leav
e
();
ReleaseSemaphore
(
sys
->
ready
,
1
,
NULL
);
}
...
...
@@ -323,8 +339,7 @@ static int Open(vlc_object_t *obj)
sys
->
done
=
NULL
;
aout
->
sys
=
sys
;
hr
=
CoInitializeEx
(
NULL
,
COINIT_MULTITHREADED
);
if
(
FAILED
(
hr
))
if
(
TryEnter
())
{
free
(
sys
);
return
VLC_EGENERIC
;
...
...
@@ -430,7 +445,7 @@ static int Open(vlc_object_t *obj)
aout
->
pf_flush
=
Flush
;
/*if (AOUT_FMT_LINEAR(&format) && !exclusive)*/
aout_VolumeHardInit
(
aout
,
SimpleVolumeSet
,
false
);
CoUninitializ
e
();
Leav
e
();
return
VLC_SUCCESS
;
error:
if
(
sys
->
done
!=
NULL
)
...
...
@@ -439,7 +454,7 @@ error:
CloseHandle
(
sys
->
done
);
if
(
sys
->
client
!=
NULL
)
IAudioClient_Release
(
sys
->
client
);
CoUninitializ
e
();
Leav
e
();
free
(
sys
);
return
VLC_EGENERIC
;
}
...
...
@@ -449,12 +464,12 @@ static void Close (vlc_object_t *obj)
audio_output_t
*
aout
=
(
audio_output_t
*
)
obj
;
aout_sys_t
*
sys
=
aout
->
sys
;
CoInitializeEx
(
NULL
,
COINIT_MULTITHREADED
);
Enter
(
);
ReleaseSemaphore
(
sys
->
done
,
1
,
NULL
);
/* tell MTA thread to finish */
WaitForSingleObject
(
sys
->
ready
,
INFINITE
);
/* wait for that ^ */
IAudioClient_Stop
(
sys
->
client
);
/* should not be needed */
IAudioClient_Release
(
sys
->
client
);
CoUninitializ
e
();
Leav
e
();
CloseHandle
(
sys
->
done
);
CloseHandle
(
sys
->
ready
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment