[vlc-commits] wasapi: use one-time init rather than DllMain()

2015-10-21 Thread Rémi Denis-Courmont
vlc/vlc-2.2 | branch: master | Rémi Denis-Courmont  | Sun Jun 
28 19:08:28 2015 +0300| [baa16ca4c818738c7f114d38c15c27c368330f90] | committer: 
Jean-Baptiste Kempf

wasapi: use one-time init rather than DllMain()

(cherry picked from commit 66302e2c16462072153ff85a621d83c0944a03dc)
Signed-off-by: Jean-Baptiste Kempf 

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.2.git/?a=commit;h=baa16ca4c818738c7f114d38c15c27c368330f90
---

 modules/audio_output/wasapi.c |   27 +++
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/modules/audio_output/wasapi.c b/modules/audio_output/wasapi.c
index 7a47161..48f6d95 100644
--- a/modules/audio_output/wasapi.c
+++ b/modules/audio_output/wasapi.c
@@ -18,6 +18,7 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  */
 
+#define _WIN32_WINNT 0x600
 #ifdef HAVE_CONFIG_H
 # include 
 #endif
@@ -35,25 +36,14 @@
 #include 
 #include "audio_output/mmdevice.h"
 
-static LARGE_INTEGER freq; /* performance counters frequency */
-
-BOOL WINAPI DllMain(HINSTANCE, DWORD, LPVOID); /* avoid warning */
-
-BOOL WINAPI DllMain(HINSTANCE dll, DWORD reason, LPVOID reserved)
+static BOOL CALLBACK InitFreq(INIT_ONCE *once, void *param, void **context)
 {
-(void) dll;
-(void) reserved;
-
-switch (reason)
-{
-case DLL_PROCESS_ATTACH:
-if (!QueryPerformanceFrequency(&freq))
-return FALSE;
-break;
-}
-return TRUE;
+(void) once; (void) context;
+return QueryPerformanceFrequency(param);
 }
 
+static LARGE_INTEGER freq; /* performance counters frequency */
+
 static UINT64 GetQPC(void)
 {
 LARGE_INTEGER counter;
@@ -355,6 +345,11 @@ static HRESULT Start(aout_stream_t *s, 
audio_sample_format_t *restrict fmt,
 /* Fallback to other plugin until pass-through is implemented */
 return E_NOTIMPL;
 
+static INIT_ONCE freq_once = INIT_ONCE_STATIC_INIT;
+
+if (!InitOnceExecuteOnce(&freq_once, InitFreq, &freq, NULL))
+return E_FAIL;
+
 aout_stream_sys_t *sys = malloc(sizeof (*sys));
 if (unlikely(sys == NULL))
 return E_OUTOFMEMORY;

___
vlc-commits mailing list
vlc-commits@videolan.org
https://mailman.videolan.org/listinfo/vlc-commits


[vlc-commits] wasapi: use one-time init rather than DllMain()

2015-06-29 Thread Rémi Denis-Courmont
vlc | branch: master | Rémi Denis-Courmont  | Sun Jun 28 
19:08:28 2015 +0300| [66302e2c16462072153ff85a621d83c0944a03dc] | committer: 
Rémi Denis-Courmont

wasapi: use one-time init rather than DllMain()

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=66302e2c16462072153ff85a621d83c0944a03dc
---

 modules/audio_output/wasapi.c |   27 +++
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/modules/audio_output/wasapi.c b/modules/audio_output/wasapi.c
index 7a47161..48f6d95 100644
--- a/modules/audio_output/wasapi.c
+++ b/modules/audio_output/wasapi.c
@@ -18,6 +18,7 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  */
 
+#define _WIN32_WINNT 0x600
 #ifdef HAVE_CONFIG_H
 # include 
 #endif
@@ -35,25 +36,14 @@
 #include 
 #include "audio_output/mmdevice.h"
 
-static LARGE_INTEGER freq; /* performance counters frequency */
-
-BOOL WINAPI DllMain(HINSTANCE, DWORD, LPVOID); /* avoid warning */
-
-BOOL WINAPI DllMain(HINSTANCE dll, DWORD reason, LPVOID reserved)
+static BOOL CALLBACK InitFreq(INIT_ONCE *once, void *param, void **context)
 {
-(void) dll;
-(void) reserved;
-
-switch (reason)
-{
-case DLL_PROCESS_ATTACH:
-if (!QueryPerformanceFrequency(&freq))
-return FALSE;
-break;
-}
-return TRUE;
+(void) once; (void) context;
+return QueryPerformanceFrequency(param);
 }
 
+static LARGE_INTEGER freq; /* performance counters frequency */
+
 static UINT64 GetQPC(void)
 {
 LARGE_INTEGER counter;
@@ -355,6 +345,11 @@ static HRESULT Start(aout_stream_t *s, 
audio_sample_format_t *restrict fmt,
 /* Fallback to other plugin until pass-through is implemented */
 return E_NOTIMPL;
 
+static INIT_ONCE freq_once = INIT_ONCE_STATIC_INIT;
+
+if (!InitOnceExecuteOnce(&freq_once, InitFreq, &freq, NULL))
+return E_FAIL;
+
 aout_stream_sys_t *sys = malloc(sizeof (*sys));
 if (unlikely(sys == NULL))
 return E_OUTOFMEMORY;

___
vlc-commits mailing list
vlc-commits@videolan.org
https://mailman.videolan.org/listinfo/vlc-commits