Commit Graph

427 Commits

Author SHA1 Message Date
wm4 3e631b9cb8 config: use the same signature for win32/OSX specific path functions
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.
2014-06-26 19:56:45 +02:00
wm4 3e1c0e5853 config: make passing talloc context optional for some functions
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.
2014-06-26 19:56:45 +02:00
Kenneth Zhou cb250d490c Basic xdg directory implementation
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>
2014-06-26 19:37:25 +02:00
wm4 8ad8dedca8 win32: implement --priority differently
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).
2014-06-12 00:55:14 +02:00
wm4 ec18df8466 input: separate wakeup pipe creation into a separate function
Error handling is slightly reduced: we assume that setting a pipe
to non-blocking can never fail.
2014-05-30 02:16:20 +02:00
wm4 6ca8a67f96 timer: remove unneeded time_t overflow check
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.
2014-05-24 16:17:45 +02:00
wm4 b69d57ebe8 timer: workaround for crappy operating systems
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 follows: OSX
2014-05-23 00:20:57 +02:00
wm4 2e6b0b4ee4 timer: fix previous commit
Sigh... of course the type of the (?:) exprsssion is double, so
INT64_MAX was converted to double, which is a problem.
2014-05-22 22:50:39 +02:00
wm4 c9b68957c9 timer: improve overflow checks
Probably more correct and better readable. Although the special-casing
of 0x1p63 is weird in terms of readability (the value itself is
INT64_MAX+1, so it's already outside of range, but INT64_MAX is not
exactly representable with double precision).
2014-05-22 22:36:42 +02:00
wm4 d31b594f77 timer: fix (usually impossible) timespec.tv_sec overflow
This usually can't happen, because even if time_us (first input value)
is INT64_MAX, the value added to tv_sec will be about 2^43, and tv_sec
will be <2^31, far below a possible overflow in 64 bits. But should
time_t be 32 bits (32 bit Linux/Windows?), an overflow could happen.
2014-05-22 20:59:31 +02:00
wm4 c0641c63fc osdep: silence a -Wshadow warning 2014-05-21 02:21:18 +02:00
wm4 42a51310c1 timer: account for negative time values
It can easily happen that mp_time_us_to_timespec() gets a time in the
past, and then the time difference will be negative. Regression
introduced in commit f47a4fc3.

Also fix an underflow check in mp_add_timeout().
2014-05-18 21:44:45 +02:00
wm4 f47a4fc3d9 threads: use mpv time for mpthread_cond_timedwait wrapper
Use the time as returned by mp_time_us() for mpthread_cond_timedwait(),
instead of calculating the struct timespec value based on a timeout.
This (probably) makes it easier to wait for a specific deadline.
2014-05-18 19:20:32 +02:00
wm4 cdafc2f7d7 terminal: always use SA_RESTART with sigaction()
One problem is that for example stdio functions won't restart syscalls
manually, and instead treat EINTR as an error. So passing SA_RESTART is
the only sane thing to do, unless you have special requirements, which
we don't.
2014-04-26 22:52:26 +02:00
wm4 cd10af4db6 threads: fix function name
Closer to the corresponding standard function pthread_cond_timedwait.
2014-04-23 21:16:52 +02:00
wm4 2b26517ef7 dispatch: move into its own source file
This was part of osdep/threads.c out of laziness. But it doesn't contain
anything OS dependent. Note that the rest of threads.c actually isn't
all that OS dependent either (just some minor ifdeffery to work around
the lack of clock_gettime() on OSX).
2014-04-23 21:16:51 +02:00
James Ross-Gowan 0cef033d48 glob-win: support Unicode
glob-win.c wasn't big, so it was easier to rewrite it. The new version
supports Unicode, handles directories properly, sorts the output and
puts all its allocations in the same talloc context to simplify the
implementation of globfree.

Notably, the old glob had error checking code, but didn't do anything
with the errors since the error reporting code was commented out. The
new glob doesn't copy this behaviour. It just treats errors as if there
were no more matching files, which shouldn't matter for mpv, since it
ignores glob errors too.

To match the other Windows I/O helper functions, the definition is moved
to osdep/io.h.
2014-04-21 02:57:16 +02:00
wm4 78128bddda Kill all tabs
I hate tabs.

This replaces all tabs in all source files with spaces. The only
exception is old-makefile. The replacement was made by running the
GNU coreutils "expand" command on every file. Since the replacement was
automatic, it's possible that some formatting was destroyed (but perhaps
only if it was assuming that the end of a tab does not correspond to
aligning the end to multiples of 8 spaces).
2014-04-13 18:03:01 +02:00
wm4 4e5cea86c2 client API: add mpv_get_wakeup_pipe convenience function
Should make integreating with some event loops easier. Untested.
2014-04-12 20:13:07 +02:00
wm4 f0e08c01ff terminal-unix: reject overlong termcap strings
Our own tables have size for only 8 chars, so these sequences must be
rejected. It seems strings of length 8 are still ok, because the code
uses memcmp and not strcmp, so still allow these.

Based on mplayer-svn commit r37129.
2014-04-10 00:18:26 +02:00
wm4 3ca034228d timer: reduce ifdef headsplitting-factor
I'd rather duplicate some trivial code, rather than split functions in
the middle with ifdefs.
2014-03-09 16:58:00 +01:00
wm4 3620cf97ad timer: switch to CLOCK_MONOTONIC
Apparently, this is always _really_ monotonic, despite what the Linux
manpages say. So this should be much better than gettimeofday(). (At
times there were kernel bugs which broke the monotonic property.)

From the perspective of the player, time can still be discontinuous
(you could just stop the process with ^Z), but at least it's guaranteed
to be monotonic without further hacks required.

Also note that clock_gettime() returns the time in nanoseconds. We want
microseconds only, because that's the unit we chose internally. Another
problem is that nanoseconds can wrap pretty quickly (less than 300 years
in 63 bits), so it's just better to use microseconds. The devision won't
make the code that much slower (compilers can avoid a real division).

Note: this expects that the system provides clock_gettime() as well as
CLOCK_MONOTONIC. Both are optional according to POSIX. The only system
I know which doesn't have these, OSX, has seperate timer code anyway,
but I still don't know whether more obscure (yet supported) platforms
have a problem with this, so I'm playing safely. But this still expects
that CLOCK_MONOTONIC always works at runtime if it's defined.
2014-03-09 16:49:02 +01:00
wm4 1f8a400ad7 timer: add utility function to get relative time 2014-02-28 23:18:52 +01:00
wm4 9ccbc03ab1 threads: fix wait time overflow check
When passing a very large timeout to mpthread_cond_timed_wait(), the
calculations could overflow, setting tv_sec to a negative value, and
making the pthread_cond_timed_wait() call return immediately. This
accidentally made Lua support poll and burn CPU for no reason.

The existing overflow check was ineffective on 32 bit systems. tv_sec is
usually a long, so adding INT_MAX to it will usually not overflow on 64
bit systems, but on 32 bit systems it's guaranteed to overflow. Simply
fix by clamping against a relatively high value. This will work until 1
week before the UNIX time wraps around in 32 bits.
2014-02-26 21:03:35 +01:00
elevengu 792c1750ec win32: restore support for exe directory as config directory
Same rationale as b2c2fe7a but updated to work with path-win.c

Signed-off-by: wm4 <wm4@nowhere>

Merges/closes #543.
2014-02-14 21:55:04 +01:00
Stefano Pigozzi 2705c66799 cocoa: fix deadlock during initialization [2]
Fixup commit for 20fa191ad.
2014-02-13 22:22:44 +01:00
Stefano Pigozzi 20fa191adb cocoa: fix deadlock during initialization
Thanks to @wm4 for catching the bug.

Fixes #405
2014-02-13 13:01:51 +01:00
wm4 c6166ff448 timer: init only once
This avoids trouble if another mpv instance is initialized in the same
process.

Since timeBeginPeriod/timeEndPeriod are hereby not easily matched
anymore, use an atexit() handler to call timeEndPeriod, so that we
can be sure these calls are matched, even if we allow multiple
initializations later when introducing the client API.
2014-02-10 01:12:34 +01:00
wm4 20fbe2fb8c threads: add a dispatch queue thing
Makes working with the (still) single-threaded playback thread easier.

Might be reusable for other stuff.
2014-02-10 00:04:39 +01:00
wm4 dd264ebe9d threads: avoid timeout calculation overflow
It's quite possible to overflow the calculation by setting the timeout
to high values. Limit it to INT_MAX, which should be safe. The issue is
mainly the secs variable.

timespec.tv_sec will normally be 64 bit on sane systems, and we assume
it can't overflow by adding INT_MAX to it.
2014-02-10 00:04:39 +01:00
wm4 8edf2cda4b io: make MP_PATH_MAX private to win32 code
The win32 code is the only thing which actually needs this (and it's
used to make emulation of UTF-8 filename APIs easier).
2014-02-03 22:12:30 +01:00
wm4 d8dd9a6725 threads: add function to calculate deadline for timed waits
Usually, you have to call pthread_cond_timedwait() in a loop (because it
can wake up sporadically). If this function is used by another higher
level function, which uses a relative timeout, we actually have to
reduce the timeout on each iteration - or, simpler, compute the
"deadline" at the beginning of the function, and always pass the same
absolute time to the waiting function.

Might be unsafe if the system time is changed. On the other hand, this
is a fundamental race condition with these APIs.
2014-01-31 22:17:43 +01:00
wm4 a17be5576f threads: add wrapper for initializing recursive mutexes
Damn this overly verbose pthread API.
2014-01-31 19:50:25 +01:00
Bilal Syed Hussain 32fea9e607 cocoa: sort files opened from Finder the same way Finder does
Fixes #497
2014-01-20 09:06:30 +01:00
James Ross-Gowan 32c0df1b53 w32: use the w32_common keymap in terminal-win too 2014-01-19 14:42:15 +01:00
Martin Herkt 26d6eb4a8a io/win32: move mp_attach_console to terminal-win.c
Why didn't I put it there from the start?
2014-01-16 11:25:52 +01:00
Stefano Pigozzi 9dc9254da2 cocoa: add application icon to the Dock when run from CLI
Application icon was added to the Dock only when run inside of a bundle. That
was handled automatically by OS X using the Info.plist definition.

To add the Application icon when run as a CLI program, I used the samme
approach in the X11 code and loaded the icon as a static binary blob inside
of mpv's binary. This is the simplest approach as it avoid headackes when
relocating the binary and such.
2014-01-14 20:42:12 +01:00
wm4 f3133e8704 terminal-unix: fix terminfo/termcap name for cursor up
"ku" is for input, not output. This happened to work on urxvt, but broke
on xterm (and probably a dozen of other terminals).
2014-01-14 17:37:40 +01:00
wm4 1cd1fb9e5c terminal-unix: add fallback for enter key
This worked just fine if terminfo or termcap was available.
2014-01-13 23:12:14 +01:00
wm4 d52fc906c3 terminal-unix: fix fallbacks in case terminfo/termcap are disabled
These two escape sequences were swapped. (They are used only if
terminfo/termcap are not available.)
2014-01-13 23:11:46 +01:00
wm4 710a45a386 terminal-unix: add termcap/terminfo documentation links
Apparently, some people are not clever enough to google this
information.

Proper googling to find these links done by Kovensky.
2014-01-13 20:13:16 +01:00
wm4 6759941fca player: redo terminal OSD and status line handling
The terminal OSD code includes the handling of the terminal status line,
showing player OSD messages on the terminal, and showing subtitles on
terminal (the latter two only if there is no video window, or if
terminal OSD is forced).

This didn't handle some corner cases correctly. For example, showing an
OSD message on the terminal always cleared the previous line, even if
the line was an important message (or even just the command prompt, if
most other messages were silenced).

Attempt to handle this correctly by keeping track of how many lines the
terminal OSD currently consists of. Since there could be race conditions
with other messages being printed, implement this in msg.c. Now msg.c
expects that MSGL_STATUS messages rewrite the status line, so the caller
is forced to use a single mp_msg() call to set the status line.

Instead of littering print_status() all over the place, update the
status only once per playloop iteration in update_osd_msg(). In audio-
only mode, the status line might now be a little bit off, but it's
perhaps ok.

Print the status line only if it has changed, or if another message was
printed. This might help with extremely slow terminals, although in
audio+video mode, it'll still be updated very often (A-V sync display
changes on every frame).

Instead of hardcoding the terminal sequences, use
terminfo/termcap to get the sequences. Remove the --term-osd-esc option,
which allowed to override the hardcoded escapes - it's useless now.

The fallback for terminals with no escape sequences for moving the
cursor and clearing a line is removed. This somewhat breaks status line
display on these terminals, including the MS Windows console: instead of
querying the terminal size and clearing the line manually by padding the
output with spaces, the line is simply not cleared. I don't expect this
to be a problem on UNIX, and on MS Windows we could emulate escape
sequences. Note that terminal OSD (other than the status line) was
broken anyway on these terminals.

In osd.c, the function get_term_width() is not used anymore, so remove
it. To remind us that the MS Windows console apparently adds a line
break when writint the last column, adjust screen_width in terminal-
win.c accordingly.
2014-01-13 20:08:13 +01:00
wm4 49646f10f0 terminal: don't initialize termcap etc. if stdout is not a terminal
Otherwise, it seems one of the term* libraries will write escape
sequences to stdout, for whatever reason.
2014-01-07 23:57:46 +01:00
Martin Herkt a857aa8828 Windows: use roaming AppData instead of local
Whatever. Fixes #458.
2014-01-06 13:44:48 +01:00
Martin Herkt 7d8cdc810c win32-console-wrapper: use child process exit code 2014-01-06 13:31:15 +01:00
Martin Herkt c849f1aa23 win32-console-wrapper: remove command line mangling
This wasn't really necessary and caused a lot of problems.
2014-01-06 13:18:02 +01:00
Martin Herkt 995d1c4d98 win32-console-wrapper: Fix heap corruption
FUCK the Windows API.
2014-01-06 11:09:08 +01:00
Stefano Pigozzi 1e988c595b cocoa: handle files drag and drop on the player video view 2014-01-04 17:29:53 +01:00
Stefano Pigozzi 69d44d992c cocoa: refactor files drag and drop on the Dock icon
Use the newly added `mp_event_drop_files` core function instead of having
logic in the platform dependent code.
2014-01-04 17:29:41 +01:00
Martin Herkt 1437d9b8bc Add Windows console wrapper program (mpv.com) 2014-01-02 05:30:49 +01:00