summaryrefslogtreecommitdiffstats
path: root/osdep
Commit message (Collapse)AuthorAgeFilesLines
* subprocess: minor cosmetic cleanupwm42014-11-223-5/+9
| | | | | Don't recursively include the whole stream.h header; only include what's minimally needed, and handle the rest with forward declarations.
* lua: subprocess: move to osdep/subprocess-{win,posix}.cJames Ross-Gowan2014-11-223-0/+547
| | | | | | The subprocess code was already split into fairly general functions, separate from the Lua code. It's getting pretty big though, especially the Windows-specific parts, so move it into its own files.
* Catch SIGPIPEwm42014-11-201-0/+3
| | | | | | | | | | | | | | Avoids a crash if OpenSSL tries to write to a broken connection with write(). Obviously OpenSSL really should use send() with MSG_NOSIGNAL, but for some reason it doesn't. This should probably be considered an OpenSSL bug, but since in this case we "own" the process, there is no harm in ignoring the signal. This is not done with libmpv, because as a library we don't want to mess with global state. It's also not done if terminal handling is disabled - this is a bit arbitrary, but I don't care much.
* terminal-unix: Add some comments about FD use.Rudolf Polzer2014-11-131-0/+8
|
* terminal-unix: Fix initial terminal state.Rudolf Polzer2014-11-131-1/+1
| | | | | | When mpv is backgrounded initially (via & in the shell), do no longer change terminal settings on startup. This fixes broken local echo after launching a backgrounded mpv.
* atomics: add atomic_compare_exchange_strong()wm42014-11-091-0/+11
| | | | | | | | | | | | | | | | As usual, we use C11 semantics, and emulate it if <stdatomic.h> is not available. It's a bit messy with __sync_val_compare_and_swap(). We assume it has "strong" semantics (it can't fail sporadically), but I'm not sure if this is really the case. On the other hand, weak semantics don't seem to be possible, since the builtin can't distinguish between the two failure cases that could occur. Also, to match the C11 interface, use of gcc builtins is unavoidable. Add a check to the build system to make sure the compiler supports them (although I don't think there's any compiler which supports __sync_*, but not these extensions). Needed for the following commit.
* win32: silence some warningsJames Ross-Gowan2014-11-081-1/+1
| | | | Signed-off-by: wm4 <wm4@nowhere>
* osdep: potentially fix compilation on OpenBSDwm42014-10-311-0/+1
| | | | | The <pthread_np.h> header expects that <pthread.h> was already included. We were including <pthread.h> only later via our threads.h.
* osdep: add helper for creating a sane pipe()wm42014-10-262-4/+21
| | | | | Or in other words, a pipe that has the CLOEXEC flag set. Needed since Linux' pipe2() is not in POSIX yet.
* terminal: drop ncurses/terminfo/termcap supportwm42014-10-231-386/+3
| | | | | | It was disabled since the last release, and nobody complained loudly. Further details see commit 4b5c3ea7.
* terminal: strictly don't read terminal input if stdout is not a terminalwm42014-10-231-5/+8
| | | | | | | | | | | | | Doing that doesn't make sense anyway: it's meant for interactive input, and if the output of the player is not on the terminal, how will you interact with it? It was also quite in the way when trying to read verbose output with e.g. less while the player was running, because the player would grab half of all input meant for less (simply because stdin is still connected to the terminal). Remove the now redundant special-casing of pipe input.
* win32: change config path prioritieswm42014-10-231-2/+2
| | | | | | | | | | | | | | | | | Assume mpv.exe is located in $mpv_exe_dir, then config files were preferably loaded from "$mpv_exe_dir/mpv". This was mostly traditional, and inherited from MPlayer times. Reverse the config path priority order, and prefer $CSIDL_APPDATA/mpv as main config path. This also fixes behavior when writing watch_later configs, and mpv is installed in a not-writable path. It's possible that this will cause regressions for some users, if the change in preference suddenly prefers stale config files (which may happen to longer around in the appdata config dir) over the user's proper config. Also explicitly document the behavior.
* osdep: NetBSD pthread_setname_np()wm42014-10-221-0/+6
| | | | | | From: bugmen0t on github Fixes #1207.
* osdep: shorten thread name on glibc onlywm42014-10-201-3/+7
| | | | | Instead of affecting every platform, do this for glibc only (where it's known to be a problem), and only if the right error is returned.
* osdep: limit thread names to 16 characterswm42014-10-201-1/+1
| | | | | | | | | | | | | | | | It turns out the glibc people are very clever and return an error if the thread name exceeds the maximum supported kernel length, instead of truncating the name. So everyone has to hardcode the currently allowed Linux kernel name length limit, even if it gets extended later. Also the Lua script filenames could get too long; use the client name instead. Another strange thing is that on Linux, unrelated threads "inherit" the name by the thread they were created. This leads to random thread names, because there's not necessarily a strong relation between these threads (e.g. script command leads to filter recreation -> the filter's threads are tagged with the script's thread name). Unfortunate.
* Set thread name for debuggingwm42014-10-195-0/+25
| | | | | | | | | | Especially with other components (libavcodec, OSX stuff), the thread list can get quite populated. Setting the thread name helps when debugging. Since this is not portable, we check the OS variants in waf configure. old-configure just gets a special-case for glibc, since doing a full check here would probably be a waste of effort.
* win32: remove an unneeded mechanismwm42014-10-192-7/+3
| | | | | Instead of relying on the macro-defined lseek(), just use _lseeki64 directly, and avoid a minor mess.
* win32: remove outdated commentwm42014-10-191-3/+0
|
* win32: get rid of mp_stat in the normal source codewm42014-10-172-7/+54
| | | | | | | | | | | mp_stat() instead of stat() was used in the normal code (i.e. even on Unix), because MinGW-w64 has an unbelievable macro-mess in place, which prevents solving this elegantly. Add some dirty workarounds to hide mp_stat() from the normal code properly. This now requires replacing all functions that use the struct stat type. This includes fstat, lstat, fstatat, and possibly others. (mpv currently uses stat and fstat only.)
* win32: make lseek() fail on pipeswm42014-10-172-0/+19
| | | | | | On MingGW seeking on pipes succeeds. This fix is quite similar to Gnulib's (lib/lseek.c).
* cocoa: allow to disable apple remote at compile timeStefano Pigozzi2014-10-171-0/+9
| | | | | Actually doesn't remove the related flags so that one can still pass the option with the option doing nothing.
* terminal: recognize ^hwm42014-10-171-0/+1
| | | | | | Fixes #1185. CC: @mpv-player/stable
* cocoa: post keydown and keyup events without event monitorStefano Pigozzi2014-10-092-0/+6
| | | | | Our code worked under the assumption that the event monitor is always active and we did remove the keydown and keyup overrides from our cocoa view.
* libmpv/cocoa: don't start the event monitorStefano Pigozzi2014-10-092-10/+21
| | | | | | The event monitor is used to get keyboard events when there is no window, but since it is a global monitor to the current process, we don't want it in a library setting.
* Remove mpbswap.hwm42014-09-251-32/+0
| | | | | | This was once central, but now it's almost unused. Only vf_divtc still uses it for extremely weird and incomprehensible reasons. The use in stream.c is trivial. Replace these, and remove mpbswap.h.
* audio: drop swapped-endian audio formatswm42014-09-231-0/+6
| | | | | | | | | | | | | | | | | | | | Until now, the audio chain could handle both little endian and big endian formats. This actually doesn't make much sense, since the audio API and the HW will most likely prefer native formats. Or at the very least, it should be trivial for audio drivers to do the byte swapping themselves. From now on, the audio chain contains native-endian formats only. All AOs and some filters are adjusted. af_convertsignendian.c is now wrongly named, but the filter name is adjusted. In some cases, the audio infrastructure was reused on the demuxer side, but that is relatively easy to rectify. This is a quite intrusive and radical change. It's possible that it will break some things (especially if they're obscure or not Linux), so watch out for regressions. It's probably still better to do it the bulldozer way, since slow transition and researching foreign platforms would take a lot of time and effort.
* osdep: hack to fix build with low quality pthreads-w32 headerswm42014-09-201-0/+1
| | | | | | | | | | | | | | | | When compiling semaphore_osx.c on win32, the following error happened: /usr/i686-w64-mingw32/include/semaphore.h:160:6: error: unknown type name 'mode_t' This is because this system header references symbols that are not not defined anywhere. This is clearly a bug in pthreads-w32, but has been known and unfixed since 2012, so add a hack to fix it. We build semaphore_osx.c this way because it saves us an extra configure check. On win32, Linux, etc. it's empty and contains "#include <semaphore.h>" only. Should fix #1108.
* osdep/semaphore_osx.c: Include osdep/semaphore.h before #ifdefDiogo Franco (Kovensky)2014-09-101-3/+2
| | | | | osdep/semaphore.h is the file that defines the very #define that is tested in the #ifdef that wraps its inclusion, so it was never compiled.
* osdep: fix windows buildwm42014-09-101-1/+2
| | | | Oops.
* osdep: add POSIX semaphore emulation for OSXwm42014-09-102-0/+179
| | | | | | | | | | | | | | | | | | | | | | | OSX is POSIX conformant, but it's a sad joke: it provides the <semaphore.h> prototype as the standard demands, but they're empty wrappers, and all functions just return ENOSYS. Emulate them similar to how osdep/io.h emulate filesystem functions on Windows. By including the header, working sem_* functions become available. To make it async-signal safe, use a pipe for wakeup (write() is AS-safe, but mutexes can't be). Actually I'm not sure anymore if we really need AS-safety, but for now the emulation can do it. On Linux, the system provides a far more efficient and robust implementation. We definitely want to avoid using the emulation if possible, so this code is active on OSX only. For convenience we always build the source file though, even if the implementation is disabled and no actual code is generated. (Linux provides working semaphores, but is formally not POSIX conformant. On OSX it's the opposite. Is POSIX a complete joke?)
* terminal-unix: don't read from stdin if it's not a terminalwm42014-09-101-1/+1
| | | | | | I'm not quite sure what we should actually do (maybe read input commands?), but interpreting input as terminal key sequences is definitely weird. So just do nothing.
* terminal-unix: move to threadwm42014-09-103-37/+73
| | | | | | | Do terminal input with a thread, instead of using the central select() loop. This also changes some details how SIGTERM is handled. Part of my crusade against mp_input_add_fd().
* terminal-win: minor simplificationwm42014-09-101-2/+2
| | | | Code should be equivalent.
* win32: add tmpfile() replacementJames Ross-Gowan2014-09-052-0/+37
| | | | | | | | | | | The Windows version of tmpfile is actually pretty broken. It tries to create the file in the root directory of the current drive, which means on Vista and up, it normally fails due to insufficient permissions. Replace it with a version that uses GetTempPath. Also remove the Windows-specific note about automatic deletion of the cache file. FILE_FLAG_DELETE_ON_CLOSE is available in NT, and it should be pretty reliable.
* Move compat/ and bstr/ directory contents somewhere elsewm42014-08-294-2/+137
| | | | | | | | | bstr.c doesn't really deserve its own directory, and compat had just a few files, most of which may as well be in osdep. There isn't really any justification for these extra directories, so get rid of them. The compat/libav.h was empty - just delete it. We changed our approach to API compatibility, and will likely not need it anymore.
* bstr: preparation for next commitwm42014-08-291-0/+1
| | | | | | | | Just so I can move this file without modifying its contents in the next commit. compat/compiler.h is to be moved to osdep/ with the next commit, so add a dummy header.
* posix: use STD*_FILENO constantsBen Boeckel2014-08-281-4/+4
| | | | | Rather than "magic" numbers, use meaningful constant names provided by unistd.h.
* win32: correct SGR sequence handlingJames Ross-Gowan2014-08-241-5/+13
| | | | | | This should get colour working again on the Windows console. Fixes #1032.
* win32: correct HANDLE typeJames Ross-Gowan2014-08-243-5/+5
| | | | | The correct type is HANDLE, not HANDLE*, though this change shouldn't affect functionality.
* terminal-unix: new input handling codewm42014-08-211-33/+246
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is independent of terminfo/termcap, and supports more keys. Originally, the goal was just extending the set of supported key sequences, but since the terminfo stuff actually makes this much harder, and since it's a big blob of bloated legacy crap, just drop it. Instead, use hardcoded tables. It's pretty easy to get on the same level as the old code (with fewer LOC), and we avoid additional error situations, such as mallocs which could fail (the old code just ignores malloc failures). We also try to support some xterm escape sequences, which are in relatively widespread use. (I'm not sure about the urxvt ones.) Trying to deal with xterm shift/ctrl/alt modifiers is probably a bit overcomplicated, and only deals with prefixes - xterm randomly uses prefix sequences for some keys, and suffixes for others (what the heck). Additionally, try to drop unknown escape codes. This basically relies on a trick: in almost 100% of all situations, a read() call will actually return complete sequences (possibly because of pipe semantics and atomic writes from the terminal emulator?), so it's easy to drop unknown sequences. This prevents that they trigger random key bindings as the code interprets the part after ESC as normal keys. This also drops the use of terminfo for sending smkx/rmkx. It seems even vt100 (to which virtually everything non-legacy is reasonably compatible with) supports the codes we hardcode, so it should be fine. This commit actually changes only the code if terminfo/termcap are not found. The next commit will make this code default.
* terminal-win: read input from a threadwm42014-08-212-29/+51
| | | | | | | | | Surprisingly, WaitFor* works on console handles. We can simply run the code for reading the console in a thread, and don't have to worry about crazy win32 crap in the rest of the player's input code anymore. This also fixes the issue that you couldn't unpause the player from the terminal, because the player would stop polling for input.
* terminal: some cleanupswm42014-08-213-64/+32
| | | | In particular, remove all the stupid debug printfs from the win code.
* terminal-win: remove nonsensical codewm42014-08-211-9/+0
| | | | | Something about a non-working MinGW thing? Really, I don't care. It also prevents using the console API properly.
* win32: emulate some ANSI terminal escape codeswm42014-08-214-41/+82
| | | | | | | | | | | | | | We already redirect all terminal output through our own wrappers (for the sake of UTF-8), so we might as well use it to handle ANSI escape codes. This also changes behavior on UNIX: we don't retrieve some escape codes per terminfo anymore, and just hardcode them. Every terminal should understand them. The advantage is that we can pretend to have a real terminal in the normal player code, and Windows atrocities are locked away in glue code.
* terminal-unix: eliminate unnecessary variablewm42014-08-201-5/+2
|
* cocoa: move handleFilesArray: to macosx_eventsFRAU KOUJIRO2014-08-064-17/+18
|
* cocoa: move set_input_context to macosx_eventsFRAU KOUJIRO2014-08-064-9/+9
|
* cocoa: sync inputContext inside EventsResponderFRAU KOUJIRO2014-08-063-12/+28
|
* cocoa: decouple events from application somewhatFRAU KOUJIRO2014-08-064-64/+118
|
* Remove the last remains of slave modewm42014-08-013-32/+2
| | | | | | | | | | | Almost nothing was left of it. The only thing this commit actually removes is support for reading input commands from stdin. But you can emulate this via: --input-file=/dev/stdin --input-terminal=no However, this won't work on Windows. Just use a named pipe.
* cocoa: fix key equivalent dispatchingStefano Pigozzi2014-07-302-22/+7
| | | | | | | | | | Prior to this commit we had a list of key modifiers and checked against that. Actually, the Cocoa framework has a built in way to do it and it involves calling performKeyEquivalent: on the menu instance. Fixes #946 cc @mpv-player/stable: this should apply with no conflicts
* osdep: don't assume errno is positivewm42014-07-251-2/+2
| | | | | Apparently this is not necessarily the case, so just drop the silly idea that depended on this assumption.
* cocoa: fix compilation on OS X 10.8Stefano Pigozzi2014-07-142-4/+30
|
* build: deal with endian messwm42014-07-101-0/+31
| | | | | | | | | | | | | | | | | | | | There is no standard mechanism for detecting endianess. Doing it at compile time in a portable way is probably hard. Doing it properly with a configure check is probably hard too. Using the endian definitions in <sys/types.h> (usually includes <endian.h>, which is not available everywhere) works under circumstances, but the previous commit broke it on OSX. Ideally all code should be endian dependent, but that is not possible due to the dependencies (such as FFmpeg, some video output APIs, some audio output APIs). Create a header osdep/endian.h, which contains various fallbacks. Note that the last fallback uses libavutil; however, it's not clear whether AV_HAVE_BIGENDIAN is a public symbol, or whether including <libavutil/bswap.h> really makes it visible. And in fact we don't want to pollute the namespace with libavutil definitions either. Thus it's only the last fallback.
* config: use the same signature for win32/OSX specific path functionswm42014-06-263-8/+12
| | | | | | | | Seems like a good idea, even if it's basically unused (yet). Also document requirements on the functions (they're not obvious). OSX changes untested.
* config: make passing talloc context optional for some functionswm42014-06-262-14/+7
| | | | | | | | | | | | | | | | Until now, the config functions added various allocations to the user- provided talloc context. Make it so that they're all under the returned allocation instead. This allows avoiding having to create an extra temporary context for some callers, and also avoids adding random memory leaks by accidentally passing a NULL context. mp_find_all_config_files() has to be changed not to return a pointer into the middle array for this to work. Make it add paths in order (instead of reverse), and then reverse the array entries after that. Also remove the declarations for the win-specific private functions. Remove STRNULL(); it's barely needed anymore and the functions are not called with NULL filenames anymore.
* Basic xdg directory implementationKenneth Zhou2014-06-263-40/+39
| | | | | | | | | | Search $XDG_CONFIG_HOME and $XDG_CONFIG_DIRS for config files. This also negates the need to have separate user and global variants of mp_find_config_file() Closes #864, #109. Signed-off-by: wm4 <wm4@nowhere>
* win32: implement --priority differentlywm42014-06-122-94/+0
| | | | | | | Does anyone actually use this? For now, update it, because it's the only case left where an option points to a global variable (and not a struct offset).
* input: separate wakeup pipe creation into a separate functionwm42014-05-302-0/+26
| | | | | Error handling is slightly reduced: we assume that setting a pipe to non-blocking can never fail.
* timer: remove unneeded time_t overflow checkwm42014-05-241-12/+1
| | | | | | | This is mostly covered by the OSX workaround, if the timeout is very high. It also means that with systems using 32 bit time_t, the time will overflow 2036 already, instead of 2037, but we don't consider this a problem.
* timer: workaround for crappy operating systemswm42014-05-231-0/+1
| | | | | | | | | | Some operating systems apparently can't deal with really long timeouts in pthread_cond_timedwait(). Passing a time about 300000 in the future makes the call return immediately. (tv_sec/time_t doesn't overflow in this situation.) Reduce the wait time to about 100 days, which seems to work fine. The list of affected OSes follow