chroma: chain: favor YUV10 if output is YUV10
[vlc.git] / src / win32 / specific.c
blob4ab588a7b7e500ac5aa3972cf9716ae6ee2442dd
1 /*****************************************************************************
2 * specific.c: Win32 specific initilization
3 *****************************************************************************
4 * Copyright (C) 2001-2004, 2010 VLC authors and VideoLAN
6 * Authors: Samuel Hocevar <sam@zoy.org>
7 * Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
28 #ifndef UNICODE
29 # define UNICODE
30 #endif
31 #include <vlc_common.h>
32 #include "libvlc.h"
33 #include "../lib/libvlc_internal.h"
34 #include "config/vlc_getopt.h"
36 #include <mmsystem.h>
37 #include <winsock.h>
38 #if VLC_WINSTORE_APP && !defined(__MINGW32__)
39 typedef UINT MMRESULT;
40 #endif
42 static int system_InitWSA(int hi, int lo)
44 WSADATA data;
46 if (WSAStartup(MAKEWORD(hi, lo), &data) == 0)
48 if (LOBYTE(data.wVersion) == 2 && HIBYTE(data.wVersion) == 2)
49 return 0;
50 /* Winsock DLL is not usable */
51 WSACleanup( );
53 return -1;
56 /**
57 * Initializes MME timer, Winsock.
59 void system_Init(void)
61 if (system_InitWSA(2, 2) && system_InitWSA(1, 1))
62 fputs("Error: cannot initialize Winsocks\n", stderr);
65 /*****************************************************************************
66 * system_Configure: check for system specific configuration options.
67 *****************************************************************************/
69 /* Must be same as in modules/control/win_msg.c */
70 typedef struct
72 int argc;
73 int enqueue;
74 char data[];
75 } vlc_ipc_data_t;
77 void system_Configure( libvlc_int_t *p_this, int i_argc, const char *const ppsz_argv[] )
79 #if !VLC_WINSTORE_APP
80 if( var_InheritBool( p_this, "one-instance" )
81 || ( var_InheritBool( p_this, "one-instance-when-started-from-file" )
82 && var_InheritBool( p_this, "started-from-file" ) ) )
84 HANDLE hmutex;
86 msg_Info( p_this, "one instance mode ENABLED");
88 /* Use a named mutex to check if another instance is already running */
89 if( !( hmutex = CreateMutex( 0, TRUE, L"VLC ipc " TEXT(VERSION) ) ) )
91 /* Failed for some reason. Just ignore the option and go on as
92 * normal. */
93 msg_Err( p_this, "one instance mode DISABLED "
94 "(mutex couldn't be created)" );
95 return;
98 if( GetLastError() != ERROR_ALREADY_EXISTS )
100 libvlc_InternalAddIntf( p_this, "win_msg,none" );
101 /* Initialization done.
102 * Release the mutex to unblock other instances */
103 ReleaseMutex( hmutex );
105 else
107 /* Another instance is running */
109 HWND ipcwindow;
111 /* Wait until the 1st instance is initialized */
112 WaitForSingleObject( hmutex, INFINITE );
114 /* Locate the window created by the IPC helper thread of the
115 * 1st instance */
116 if( !( ipcwindow = FindWindow( 0, L"VLC ipc " TEXT(VERSION) ) ) )
118 msg_Err( p_this, "one instance mode DISABLED "
119 "(couldn't find 1st instance of program)" );
120 ReleaseMutex( hmutex );
121 return;
124 /* We assume that the remaining parameters are filenames
125 * and their input options */
126 if( i_argc > 0 )
128 COPYDATASTRUCT wm_data;
129 int i_opt;
130 vlc_ipc_data_t *p_data;
131 size_t i_data = sizeof (*p_data);
133 for( i_opt = 0; i_opt < i_argc; i_opt++ )
135 i_data += sizeof (size_t);
136 i_data += strlen( ppsz_argv[ i_opt ] ) + 1;
139 p_data = malloc( i_data );
140 p_data->argc = i_argc;
141 p_data->enqueue = var_InheritBool( p_this, "playlist-enqueue" );
142 i_data = 0;
143 for( i_opt = 0; i_opt < i_argc; i_opt++ )
145 size_t i_len = strlen( ppsz_argv[ i_opt ] ) + 1;
146 /* Windows will never switch to an architecture
147 * with stronger alignment requirements, right. */
148 *((size_t *)(p_data->data + i_data)) = i_len;
149 i_data += sizeof (size_t);
150 memcpy( &p_data->data[i_data], ppsz_argv[ i_opt ], i_len );
151 i_data += i_len;
153 i_data += sizeof (*p_data);
155 /* Send our playlist items to the 1st instance */
156 wm_data.dwData = 0;
157 wm_data.cbData = i_data;
158 wm_data.lpData = p_data;
159 SendMessage( ipcwindow, WM_COPYDATA, 0, (LPARAM)&wm_data );
162 /* Initialization done.
163 * Release the mutex to unblock other instances */
164 ReleaseMutex( hmutex );
166 /* Bye bye */
167 system_End( );
168 exit( 0 );
171 #endif
175 * Cleans up after system_Init() and system_Configure().
177 void system_End(void)
179 /* XXX: In theory, we should not call this if WSAStartup() failed. */
180 WSACleanup();