video_filter: ripple: fix YUV10/RGB black pixel
[vlc.git] / bin / winvlc.c
blob8f22946fef633b00cb8df22ee79a15fc5b51d04a
1 /*****************************************************************************
2 * winvlc.c: the Windows VLC media player
3 *****************************************************************************
4 * Copyright (C) 1998-2011 the VideoLAN team
6 * Authors: Vincent Seguin <seguin@via.ecp.fr>
7 * Samuel Hocevar <sam@zoy.org>
8 * Gildas Bazin <gbazin@videolan.org>
9 * Derk-Jan Hartman <hartman at videolan dot org>
10 * Lots of other people, see the libvlc AUTHORS file
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
31 #ifndef UNICODE
32 #define UNICODE
33 #endif
35 #include <vlc/vlc.h>
36 #include <windows.h>
37 #include <shellapi.h>
39 #ifndef _WIN32_IE
40 # define _WIN32_IE 0x501
41 #endif
42 #include <fcntl.h>
43 #include <io.h>
44 #include <shlobj.h>
45 #define HeapEnableTerminationOnCorruption (HEAP_INFORMATION_CLASS)1
47 #ifdef HAVE_BREAKPAD
48 void CheckCrashDump( const wchar_t* crashdump_path );
49 void* InstallCrashHandler( const wchar_t* crashdump_path );
50 void ReleaseCrashHandler( void* handler );
51 #endif
53 static char *FromWide (const wchar_t *wide)
55 size_t len;
56 len = WideCharToMultiByte (CP_UTF8, 0, wide, -1, NULL, 0, NULL, NULL);
58 char *out = (char *)malloc (len);
59 if (out)
60 WideCharToMultiByte (CP_UTF8, 0, wide, -1, out, len, NULL, NULL);
61 return out;
64 #if (_WIN32_WINNT < _WIN32_WINNT_WIN8)
65 static BOOL SetDefaultDllDirectories_(DWORD flags)
67 HMODULE h = GetModuleHandle(TEXT("kernel32.dll"));
68 if (h == NULL)
69 return FALSE;
71 BOOL (WINAPI * SetDefaultDllDirectoriesReal)(DWORD);
73 SetDefaultDllDirectoriesReal = GetProcAddress(h,
74 "SetDefaultDllDirectories");
75 if (SetDefaultDllDirectoriesReal == NULL)
76 return FALSE;
78 return SetDefaultDllDirectoriesReal(flags);
80 # define SetDefaultDllDirectories SetDefaultDllDirectories_
82 #endif
84 static void PrioritizeSystem32(void)
86 #ifndef HAVE_PROCESS_MITIGATION_IMAGE_LOAD_POLICY
87 typedef struct _PROCESS_MITIGATION_IMAGE_LOAD_POLICY {
88 union {
89 DWORD Flags;
90 struct {
91 DWORD NoRemoteImages :1;
92 DWORD NoLowMandatoryLabelImages :1;
93 DWORD PreferSystem32Images :1;
94 DWORD ReservedFlags :29;
97 } PROCESS_MITIGATION_IMAGE_LOAD_POLICY;
98 #endif
99 #if _WIN32_WINNT < _WIN32_WINNT_WIN8
100 BOOL WINAPI (*SetProcessMitigationPolicy)(PROCESS_MITIGATION_POLICY, PVOID, SIZE_T);
101 HINSTANCE h_Kernel32 = GetModuleHandle(TEXT("kernel32.dll"));
102 if ( !h_Kernel32 )
103 return;
104 SetProcessMitigationPolicy = (BOOL (WINAPI *)(PROCESS_MITIGATION_POLICY, PVOID, SIZE_T))
105 GetProcAddress(h_Kernel32, "SetProcessMitigationPolicy");
106 if (SetProcessMitigationPolicy == NULL)
107 return;
108 #endif
109 PROCESS_MITIGATION_IMAGE_LOAD_POLICY m = { .Flags = 0 };
110 m.PreferSystem32Images = 1;
111 SetProcessMitigationPolicy( 10 /* ProcessImageLoadPolicy */, &m, sizeof( m ) );
114 int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
115 LPSTR lpCmdLine,
116 int nCmdShow )
118 int argc;
120 /* VLC does not change the thread locale, so gettext/libintil will use the
121 * user default locale as reference. */
122 /* gettext versions 0.18-0.18.1 will use the Windows Vista locale name
123 * if the GETTEXT_MUI environment variable is set. If not set or if running
124 * on Windows 2000/XP/2003 an hard-coded language ID list is used. This
125 * putenv() call may become redundant with later versions of gettext. */
126 putenv("GETTEXT_MUI=1");
127 #ifdef TOP_BUILDDIR
128 putenv("VLC_PLUGIN_PATH=Z:"TOP_BUILDDIR"/modules");
129 putenv("VLC_DATA_PATH=Z:"TOP_SRCDIR"/share");
130 #endif
132 #ifndef NDEBUG
133 /* Disable stderr buffering. Indeed, stderr can be buffered on Windows (if
134 * connected to a pipe). */
135 setvbuf (stderr, NULL, _IONBF, BUFSIZ);
136 #endif
138 HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0);
140 /* SetProcessDEPPolicy, SetDllDirectory, & Co. */
141 HINSTANCE h_Kernel32 = GetModuleHandle(TEXT("kernel32.dll"));
142 if (h_Kernel32 != NULL)
144 /* Enable DEP */
145 # define PROCESS_DEP_ENABLE 1
146 BOOL (WINAPI * mySetProcessDEPPolicy)( DWORD dwFlags);
147 mySetProcessDEPPolicy = (BOOL (WINAPI *)(DWORD))
148 GetProcAddress(h_Kernel32, "SetProcessDEPPolicy");
149 if(mySetProcessDEPPolicy)
150 mySetProcessDEPPolicy(PROCESS_DEP_ENABLE);
154 /* Do NOT load any library from cwd. */
155 SetDllDirectory(TEXT(""));
157 /***
158 * The LoadLibrary* calls from the modules and the 3rd party code
159 * will search in SYSTEM32 only
160 * */
161 SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32);
162 /***
163 * Load DLLs from system32 before any other folder (when possible)
165 PrioritizeSystem32();
167 /* Args */
168 wchar_t **wargv = CommandLineToArgvW (GetCommandLine (), &argc);
169 if (wargv == NULL)
170 return 1;
172 char *argv[argc + 3];
173 BOOL crash_handling = TRUE;
174 int j = 0;
175 char *lang = NULL;
177 argv[j++] = FromWide( L"--media-library" );
178 argv[j++] = FromWide( L"--no-ignore-config" );
179 for (int i = 1; i < argc; i++)
181 if(!wcscmp(wargv[i], L"--no-crashdump"))
183 crash_handling = FALSE;
184 continue; /* don't give argument to libvlc */
186 if (!wcsncmp(wargv[i], L"--language", 10) )
188 if (i < argc - 1 && wcsncmp( wargv[i + 1], L"--", 2 ))
189 lang = FromWide (wargv[++i]);
190 continue;
193 argv[j++] = FromWide (wargv[i]);
196 argc = j;
197 argv[argc] = NULL;
198 LocalFree (wargv);
200 #ifdef HAVE_BREAKPAD
201 void* eh = NULL;
202 if(crash_handling)
204 static wchar_t path[MAX_PATH];
205 if( S_OK != SHGetFolderPathW( NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE,
206 NULL, SHGFP_TYPE_CURRENT, path ) )
207 fprintf( stderr, "Can't open the vlc conf PATH\n" );
208 _snwprintf( path+wcslen( path ), MAX_PATH, L"%s", L"\\vlc\\crashdump" );
209 CheckCrashDump( &path[0] );
210 eh = InstallCrashHandler( &path[0] );
212 #endif
214 _setmode( _fileno( stdin ), _O_BINARY ); /* Needed for pipes */
216 /* */
217 if (!lang)
219 HKEY h_key;
220 if( RegOpenKeyEx( HKEY_CURRENT_USER, TEXT("Software\\VideoLAN\\VLC\\"), 0, KEY_READ, &h_key )
221 == ERROR_SUCCESS )
223 TCHAR szData[256];
224 DWORD len = 256;
225 if( RegQueryValueEx( h_key, TEXT("Lang"), NULL, NULL, (LPBYTE) &szData, &len ) == ERROR_SUCCESS )
226 lang = FromWide( szData );
230 if (lang && strncmp( lang, "auto", 4 ) )
232 char tmp[11];
233 snprintf(tmp, 11, "LANG=%s", lang);
234 putenv(tmp);
236 free(lang);
238 /* Initialize libvlc */
239 libvlc_instance_t *vlc;
240 vlc = libvlc_new (argc, (const char **)argv);
241 if (vlc != NULL)
243 libvlc_set_app_id (vlc, "org.VideoLAN.VLC", PACKAGE_VERSION,
244 PACKAGE_NAME);
245 libvlc_set_user_agent (vlc, "VLC media player", "VLC/"PACKAGE_VERSION);
246 libvlc_add_intf (vlc, "hotkeys,none");
247 libvlc_add_intf (vlc, "globalhotkeys,none");
248 libvlc_add_intf (vlc, NULL);
249 libvlc_playlist_play (vlc, -1, 0, NULL);
250 libvlc_wait (vlc);
251 libvlc_release (vlc);
253 else
254 MessageBox (NULL, TEXT("VLC media player could not start.\n"
255 "Either the command line options were invalid or no plugins were found.\n"),
256 TEXT("VLC media player"),
257 MB_OK|MB_ICONERROR);
260 #ifdef HAVE_BREAKPAD
261 ReleaseCrashHandler( eh );
262 #endif
263 for (int i = 0; i < argc; i++)
264 free (argv[i]);
266 (void)hInstance; (void)hPrevInstance; (void)lpCmdLine; (void)nCmdShow;
267 return 0;