diff options
Diffstat (limited to 'osdep')
-rw-r--r-- | osdep/io.c | 36 | ||||
-rw-r--r-- | osdep/io.h | 10 | ||||
-rw-r--r-- | osdep/macosx_application.h | 3 | ||||
-rw-r--r-- | osdep/macosx_application.m | 3 | ||||
-rw-r--r-- | osdep/macosx_application_objc.h | 3 | ||||
-rw-r--r-- | osdep/macosx_events.h | 4 | ||||
-rw-r--r-- | osdep/mpv.rc | 11 | ||||
-rw-r--r-- | osdep/path-macosx.m | 3 | ||||
-rw-r--r-- | osdep/terminal-win.c | 59 | ||||
-rw-r--r-- | osdep/terminal.h | 12 | ||||
-rw-r--r-- | osdep/timer-linux.c | 9 | ||||
-rw-r--r-- | osdep/timer-win2.c | 9 | ||||
-rw-r--r-- | osdep/timer.h | 9 | ||||
-rw-r--r-- | osdep/win32-console-wrapper.c | 4 |
14 files changed, 85 insertions, 90 deletions
diff --git a/osdep/io.c b/osdep/io.c index e63509a4f8..fdb625d080 100644 --- a/osdep/io.c +++ b/osdep/io.c @@ -1,22 +1,24 @@ /* * unicode/utf-8 I/O helpers and wrappers for Windows * - * This file is part of mplayer2. * Contains parts based on libav code (http://libav.org). * - * mplayer2 is free software; you can redistribute it and/or modify + * This file is part of mpv. + * + * mpv is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * - * mplayer2 is distributed in the hope that it will be useful, + * mpv is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along - * with mplayer2. If not, see <http://www.gnu.org/licenses/>. + * with mpv. If not, see <http://www.gnu.org/licenses/>. */ + #include <unistd.h> #include <errno.h> #include <assert.h> @@ -121,32 +123,6 @@ char *mp_to_utf8(void *talloc_ctx, const wchar_t *s) #include <fcntl.h> #include <pthread.h> -//http://git.libav.org/?p=libav.git;a=blob;f=cmdutils.c;h=ade3f10ce2fc030e32e375a85fbd06c26d43a433#l161 - -static char** win32_argv_utf8; -static int win32_argc; - -void mp_get_converted_argv(int *argc, char ***argv) -{ - if (!win32_argv_utf8) { - win32_argc = 0; - wchar_t **argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc); - if (win32_argc <= 0 || !argv_w) - return; - - win32_argv_utf8 = talloc_zero_array(NULL, char*, win32_argc + 1); - - for (int i = 0; i < win32_argc; i++) { - win32_argv_utf8[i] = mp_to_utf8(NULL, argv_w[i]); - } - - LocalFree(argv_w); - } - - *argc = win32_argc; - *argv = win32_argv_utf8; -} - static void copy_stat(struct mp_stat *dst, struct _stat64 *src) { dst->st_dev = src->st_dev; diff --git a/osdep/io.h b/osdep/io.h index 0348d3d1a3..8d3e24f551 100644 --- a/osdep/io.h +++ b/osdep/io.h @@ -1,20 +1,20 @@ /* * unicode/utf-8 I/O helpers and wrappers for Windows * - * This file is part of mplayer2. + * This file is part of mpv. * - * mplayer2 is free software; you can redistribute it and/or modify + * mpv is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * - * mplayer2 is distributed in the hope that it will be useful, + * mpv is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along - * with mplayer2. If not, see <http://www.gnu.org/licenses/>. + * with mpv. If not, see <http://www.gnu.org/licenses/>. */ #ifndef MPLAYER_OSDEP_IO @@ -65,8 +65,6 @@ char *mp_to_utf8(void *talloc_ctx, const wchar_t *s); #include <sys/stat.h> #include <fcntl.h> -void mp_get_converted_argv(int *argc, char ***argv); - int mp_printf(const char *format, ...); int mp_fprintf(FILE *stream, const char *format, ...); int mp_open(const char *filename, int oflag, ...); diff --git a/osdep/macosx_application.h b/osdep/macosx_application.h index d6a9425f29..8202093aed 100644 --- a/osdep/macosx_application.h +++ b/osdep/macosx_application.h @@ -12,8 +12,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along - * with mpv; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * with mpv. If not, see <http://www.gnu.org/licenses/>. */ #ifndef MPV_MACOSX_APPLICATION diff --git a/osdep/macosx_application.m b/osdep/macosx_application.m index ac1f4863da..3691e922a5 100644 --- a/osdep/macosx_application.m +++ b/osdep/macosx_application.m @@ -12,8 +12,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along - * with mpv; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * with mpv. If not, see <http://www.gnu.org/licenses/>. */ #include <stdio.h> diff --git a/osdep/macosx_application_objc.h b/osdep/macosx_application_objc.h index 6b0ca15c2e..0f18952c7e 100644 --- a/osdep/macosx_application_objc.h +++ b/osdep/macosx_application_objc.h @@ -12,8 +12,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along - * with mpv; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * with mpv. If not, see <http://www.gnu.org/licenses/>. */ #import <Cocoa/Cocoa.h> diff --git a/osdep/macosx_events.h b/osdep/macosx_events.h index f9008b40ec..a6bfbfef95 100644 --- a/osdep/macosx_events.h +++ b/osdep/macosx_events.h @@ -3,12 +3,12 @@ * * This file is part of mpv. * - * mplayer2 is free software; you can redistribute it and/or modify + * mpv is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * - * mplayer2 is distributed in the hope that it will be useful, + * mpv is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. diff --git a/osdep/mpv.rc b/osdep/mpv.rc index 4a9d611bd7..f2d9042a36 100644 --- a/osdep/mpv.rc +++ b/osdep/mpv.rc @@ -1,21 +1,20 @@ /* - * Windows resource file for MPlayer + * Windows resource file for mpv * - * This file is part of MPlayer. + * This file is part of mpv. * - * MPlayer is free software; you can redistribute it and/or modify + * mpv is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * - * MPlayer is distributed in the hope that it will be useful, + * mpv is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * with mpv. If not, see <http://www.gnu.org/licenses/>. */ #include <winver.h> diff --git a/osdep/path-macosx.m b/osdep/path-macosx.m index 33086c3ea4..ee34f9638b 100644 --- a/osdep/path-macosx.m +++ b/osdep/path-macosx.m @@ -12,8 +12,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along - * with mpv; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * with mpv. If not, see <http://www.gnu.org/licenses/>. */ #import <Foundation/Foundation.h> diff --git a/osdep/terminal-win.c b/osdep/terminal-win.c index 678cedb775..e6b17fd595 100644 --- a/osdep/terminal-win.c +++ b/osdep/terminal-win.c @@ -2,21 +2,20 @@ * * copyright (C) 2003 Sascha Sommer * - * This file is part of MPlayer. + * This file is part of mpv. * - * MPlayer is free software; you can redistribute it and/or modify + * mpv is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * - * MPlayer is distributed in the hope that it will be useful, + * mpv is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * with mpv. If not, see <http://www.gnu.org/licenses/>. */ // See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/UserInput/VirtualKeyCodes.asp @@ -250,24 +249,48 @@ void mp_write_console_ansi(HANDLE wstream, char *buf) } } -int terminal_init(void) +static bool is_a_console(HANDLE h) +{ + return GetConsoleMode(h, &(DWORD){0}); +} + +static void reopen_console_handle(DWORD std, FILE *stream) +{ + HANDLE wstream = GetStdHandle(std); + if (is_a_console(wstream)) { + int fd = _open_osfhandle((intptr_t)wstream, _O_TEXT); + dup2(fd, fileno(stream)); + setvbuf(stream, NULL, _IONBF, 0); + } +} + +bool terminal_try_attach(void) { - if (AttachConsole(ATTACH_PARENT_PROCESS)) { - // We have been started by something with a console window. - // Redirect output streams to that console's low-level handles, - // so we can actually use WriteConsole later on. + // mpv.exe is a flagged as a GUI application, but it acts as a console + // application when started from the console wrapper (see + // osdep/win32-console-wrapper.c). The console wrapper sets + // _started_from_console=yes, so check that variable before trying to + // attach to the console. + wchar_t console_env[4] = { 0 }; + if (!GetEnvironmentVariableW(L"_started_from_console", console_env, 4)) + return false; + if (wcsncmp(console_env, L"yes", 4)) + return false; + SetEnvironmentVariableW(L"_started_from_console", NULL); - int hConHandle; + if (!AttachConsole(ATTACH_PARENT_PROCESS)) + return false; - hConHandle = _open_osfhandle((intptr_t)hSTDOUT, _O_TEXT); - *stdout = *_fdopen(hConHandle, "w"); - setvbuf(stdout, NULL, _IONBF, 0); + // We have a console window. Redirect output streams to that console's + // low-level handles, so we can actually use WriteConsole later on. + reopen_console_handle(STD_OUTPUT_HANDLE, stdout); + reopen_console_handle(STD_ERROR_HANDLE, stderr); - hConHandle = _open_osfhandle((intptr_t)hSTDERR, _O_TEXT); - *stderr = *_fdopen(hConHandle, "w"); - setvbuf(stderr, NULL, _IONBF, 0); - } + return true; +} +int terminal_init(void) +{ CONSOLE_SCREEN_BUFFER_INFO cinfo; DWORD cmode = 0; GetConsoleMode(hSTDOUT, &cmode); diff --git a/osdep/terminal.h b/osdep/terminal.h index fc98f0c469..ebe4cc7ee8 100644 --- a/osdep/terminal.h +++ b/osdep/terminal.h @@ -4,21 +4,20 @@ * * copyright (C) 1999 A'rpi/ESP-team * - * This file is part of MPlayer. + * This file is part of mpv. * - * MPlayer is free software; you can redistribute it and/or modify + * mpv is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * - * MPlayer is distributed in the hope that it will be useful, + * mpv is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * with mpv. If not, see <http://www.gnu.org/licenses/>. */ #ifndef MPLAYER_GETCH2_H @@ -47,4 +46,7 @@ void terminal_get_size(int *w, int *h); // Windows only. void mp_write_console_ansi(void *wstream, char *buf); +/* Windows-only function to attach to the parent process's console */ +bool terminal_try_attach(void); + #endif /* MPLAYER_GETCH2_H */ diff --git a/osdep/timer-linux.c b/osdep/timer-linux.c index 2424cc653d..a3433819be 100644 --- a/osdep/timer-linux.c +++ b/osdep/timer-linux.c @@ -2,21 +2,20 @@ * precise timer routines for Linux/UNIX * copyright (C) LGB & A'rpi/ASTRAL * - * This file is part of MPlayer. + * This file is part of mpv. * - * MPlayer is free software; you can redistribute it and/or modify + * mpv is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * - * MPlayer is distributed in the hope that it will be useful, + * mpv is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * with mpv. If not, see <http://www.gnu.org/licenses/>. */ #include <unistd.h> diff --git a/osdep/timer-win2.c b/osdep/timer-win2.c index fbbdc923f1..b87456f3ce 100644 --- a/osdep/timer-win2.c +++ b/osdep/timer-win2.c @@ -1,21 +1,20 @@ /* * precise timer routines for Windows * - * This file is part of MPlayer. + * This file is part of mpv. * - * MPlayer is free software; you can redistribute it and/or modify + * mpv is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * - * MPlayer is distributed in the hope that it will be useful, + * mpv is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * with mpv. If not, see <http://www.gnu.org/licenses/>. */ #include <windows.h> diff --git a/osdep/timer.h b/osdep/timer.h index 2bef4130df..547323943d 100644 --- a/osdep/timer.h +++ b/osdep/timer.h @@ -1,19 +1,18 @@ /* - * This file is part of MPlayer. + * This file is part of mpv. * - * MPlayer is free software; you can redistribute it and/or modify + * mpv is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * - * MPlayer is distributed in the hope that it will be useful, + * mpv is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * with mpv. If not, see <http://www.gnu.org/licenses/>. */ #ifndef MPLAYER_TIMER_H diff --git a/osdep/win32-console-wrapper.c b/osdep/win32-console-wrapper.c index c8c297b482..8cebcf8c83 100644 --- a/osdep/win32-console-wrapper.c +++ b/osdep/win32-console-wrapper.c @@ -72,5 +72,9 @@ int wmain(int argc, wchar_t **argv, wchar_t **envp) GetModuleFileNameW(NULL, exe, MAX_PATH); wcscpy(wcsrchr(exe, '.') + 1, L"exe"); + // Set an environment variable so the child process can tell whether it + // was started from this wrapper and attach to the console accordingly + SetEnvironmentVariableW(L"_started_from_console", L"yes"); + return cr_runproc(exe, cmd); } |