Commit Graph

38383 Commits

Author SHA1 Message Date
wm4 5929dc458f audio/out/push: add mechanism for event-based waiting
Until now, we've always calculated a timeout based on a heuristic when
to refill the audio buffers. Allow AOs to do it completely event-based
by providing wait and wakeup callbacks.

This also shuffles around the heuristic used for other AOs, and there is
a minor possibility that behavior slightly changes in real-world cases.
But in general it should be much more robust now.

ao_pulse.c now makes use of event-based waiting. It already did before,
but the code for time-based waiting was also involved. This commit also
removes one awkward artifact of the PulseAudio API out of the generic
code: the callback asking for more data can be reentrant, and thus
requires a separate lock for waiting (or a recursive mutex).
2014-05-30 02:15:47 +02:00
wm4 35aba9675d audio/out: adjust documentation comments 2014-05-30 02:15:38 +02:00
wm4 d87a84ca89 ring: use a different type for read/write pointers
uint_least32_t could be larger than uint32_t, so the return values of
mp_ring_get_wpos/rpos must be adjusted. Actually just use unsigned long
as type instead, because that is less awkward than uint_least32_t.
2014-05-30 02:15:25 +02:00
wm4 e127cfa0b5 build: disable PortAudio by default
This was originally added because we thought this would make a good
portable audio API, which would give us good behavior on Windows, Linux,
and OSX. But this hope was disappointed: it's not reliable enough (nice
deadlocks on Linux when seeking, i.e. resetting the audio device),
doesn't have enough features (no channel maps, no digital passthrough),
and in general just is not very good.
2014-05-29 02:24:21 +02:00
wm4 c36faf8c49 audio/out/pull: remove race conditions
There were subtle and minor race conditions in the pull.c code, and AOs
using it (jack, portaudio, sdl, wasapi). Attempt to remove these.

There was at least a race condition in the ao_reset() implementation:
mp_ring_reset() was called concurrently to the audio callback. While the
ringbuffer uses atomics to allow concurrent access, the reset function
wasn't concurrency-safe (and can't easily be made to).

Fix this by stopping the audio callback before doing a reset. After
that, we can do anything without needing synchronization. The callback
is resumed when resuming playback at a later point.

Don't call driver->pause, and make driver->resume and driver->reset
start/stop the audio callback. In the initial state, the audio callback
must be disabled.

JackAudio of course is different. Maybe there is no way to suspend the
audio callback without "disconnecting" it (what jack_deactivate() would
do), so I'm not trying my luck, and implemented a really bad hack doing
active waiting until we get the audio callback into a state where it
won't interfere. Once the callback goes from AO_STATE_WAIT to NONE, we
can be sure that the callback doesn't access the ringbuffer or anything
else anymore. Since both sched_yield() and pthread_yield() apparently
are not always available, use mp_sleep_us(1) to avoid burning CPU during
active waiting.

The ao_jack.c change also removes a race condition: apparently we didn't
initialize _all_ ao fields before starting the audio callback.

In ao_wasapi.c, I'm not sure whether reset really waits for the audio
callback to return. Kovensky says it's not guaranteed, so disable the
reset callback - for now the behavior of ao_wasapi.c is like with
ao_jack.c, and active waiting is used to deal with the audio callback.
2014-05-29 02:24:17 +02:00
wm4 690ea07b7a ring: implement drain in terms of read
I think this makes it easier to reason about it and avoids duplicate
logic.
2014-05-29 02:24:05 +02:00
wm4 3238cd3dac atomics: some corrections to __sync builtins usage
We don't need to combine __sync_add_and_fetch with a memory barrier,
since these intrinsics are documented as using a full barrier already.

Use __sync_fetch_and_add instead of __sync_add_and_fetch; this gives
atomic_fetch_add() the correct return value (although we don't use it).

Use __sync_fetch_and_add to emulate atomic_load(). This should enforce
the full barrier semantics better. (This trick is stolen from the
FreeBSD based stdatomic.h emulation.)
2014-05-28 22:44:43 +02:00
Paweł Forysiuk f289060259 Fix gcc 4.7 warning about shadowing talloc_parent in mp_dispact_queue 2014-05-28 22:44:43 +02:00
Marcoen Hirschberg 696733d077 ad_lavc: don't overwrite lavc bitrate
If the bitrate is already known in avcodec there is no need to overwrite
it again with the value from sh_audio.
2014-05-28 21:38:20 +02:00
Marcoen Hirschberg ecea66e8dc vd_lavc: set video bitrate if available
Set the bitrate of dec_video if it is available in avcodec.
2014-05-28 21:38:20 +02:00
Marcoen Hirschberg 1fa48a2452 ao_wasapi: simplify nAvgBytesPerSec calculation
Calculate nBlockAlign seperately to reuse in the calculation of
nAvgBytesPerSec.
2014-05-28 21:38:15 +02:00
Marcoen Hirschberg 31a10f7c38 af_fmt2bits: change to af_fmt2bps (bytes/sample) where appropriate
In most places where af_fmt2bits is called to get the bits/sample, the
result is immediately converted to bytes/sample. Avoid this by getting
bytes/sample directly by introducing af_fmt2bps.
2014-05-28 21:38:00 +02:00
Marcoen Hirschberg 434242adb5 audio: rename i_bps to 'bitrate' to avoid confusion
Since i_bps now contains bits/sec, rename it to reflect this change.
2014-05-28 21:37:50 +02:00
Marcoen Hirschberg 6e58b20cce audio: change values from bytes-per-second to bits-per-second
The i_bps members of the sh_audio and dev_video structs are mostly used
for displaying the average audio and video bitrates. Keeping them in
bits-per-second avoids truncating them to bytes-per-second and changing
them back lateron.
2014-05-28 21:37:44 +02:00
wm4 b442b522f6 vaapi: fix destruction with --hwdec=haapi-copy
This is incomplete; the video chain will still hold some vaapi objects
after destroying the decoder and thus the vaapi context. This is very
bad. Fixing it would require something like refcounting the vaapi
context, but I don't really want to.
2014-05-28 02:08:45 +02:00
wm4 d99f30d726 video: warn if an emulated hwdec API is used
mpv supports two hardware decoding APIs on Linux: vdpau and vaapi. Each
of these has emulation wrappers. The wrappers are usually slower and
have fewer features than their native opposites. In particular the libva
vdpau driver is practically unmaintained.

Check the vendor string and print a warning if emulation is detected.
Checking vendor strings is a very stupid thing to do, but I find the
thought of people using an emulated API for no reason worse.

Also, make --hwdec=auto never use an API that is detected as emulated.
This doesn't work quite right yet, because once one API is loaded,
vo_opengl doesn't unload it, so no hardware decoding will be used if the
first probed API (usually vdpau) is rejected. But good enough.
2014-05-28 02:08:45 +02:00
wm4 8dfd93c6fb vo_vaapi: cleanup error handling on init
Close the X connection if initializing vaapi fails.
2014-05-28 02:08:45 +02:00
ChrisK2 ff73d25308 osc: correct calculation of slider position
calculation the mouse position on the slider relied on how the
hitbox is positioned, change it according to new hitbox size.
2014-05-28 01:55:52 +02:00
ChrisK2 518e0b7320 osc: extend hitbox of seekbars to include gap
should make usage a bit easy

Fixes #810
2014-05-27 22:52:34 +02:00
wm4 baaa32621e stream: unbreak writeable streams
So, basically this worked only with streams that were not local files,
because stream_dvd.c "intercepts" local files to check whether they
point to DVD images. This means if a stream is not writeable, we have to
try the next stream implementation.

Unbreaks 2-pass encoding.
2014-05-27 22:05:22 +02:00
wm4 22b16a40e5 video: better handling for (very) broken timestamps
Sometimes, Matroska files store monotonic PTS for h264 tracks with
b-frames, which means the decoder actually returns non-monotonic PTS.

Handle this with an evil trick: if DTS is missing, set it to the PTS.
Then the existing logic, which deals with falling back to DTS if PTS is
broken. Actually, this trick is not so evil at all, because usually, PTS
has no errors, and DTS is either always set, or always unset. So this
_should_ provoke no regressions (famous last words).

libavformat actually does something similar: it derives DTS from PTS in
ways unknown to me. The result is very broken, but it causes the DTS
fallback to become active, and thus happens to work.

Also, prevent the heuristic from being active if PTS is merely monotonic
instead of strictly-monotonic. Non-unique PTS is broken, but we can't
fallback to DTS anyway in these cases.

The specific mkv file that is fixed with this commit had the following
fields set:

  Muxing application: libebml v1.3.0 + libmatroska v1.4.1
  Writing application: mkvmerge v6.7.0 ('Back to the Ground') [...]

But I know that this should also fix playback of mencoder produced mkv
files.
2014-05-27 21:58:07 +02:00
wm4 96bc188172 manpage: document write_watch_later_config command 2014-05-27 21:58:06 +02:00
Rudolf Polzer c0cd58e3f5 idet.sh: An alternative to ildetect.sh.
This script uses ffmpeg's "idet" filter for interlace detection. In the
long run this should replace ildetect.sh+ildetect.sh.
2014-05-27 18:41:40 +02:00
wm4 799b5e1a5d lua: slightly nicer diagnostics output
When Lua itself prints errors such as:

  Error: [string "mp.defaults"]:387: syntax error near 'function'

It's unclear why the location is prefixed with "string ". And for some
reason, it disappears if you prefix the name with '@'. I suppose this is
done for the sake of luaL_loadstring. With the '@' prefix added, the
output is now:

  Error: mp.defaults:387: syntax error near 'function'
2014-05-27 00:02:34 +02:00
wm4 9acd263542 gl_common: minor cosmetic changes
Why are you reading this message.
2014-05-26 23:08:07 +02:00
wm4 66f3e93ed3 gl_common: correct a type
We pass a pointer to a GLint to sscanf, using the %d format. That format
_always_ takes int, and not GLint (whatever the heck that is). If GLint
is always int, then it doesn't make a difference, but is still better
because it doesn't play russian roulette with pointers.
2014-05-26 23:05:22 +02:00
wm4 53445d3b44 gl_w32: remove some non-sense
Really now...
2014-05-26 23:00:39 +02:00
wm4 7248988714 vo_opengl: always dynamically load OpenGL symbols
Don't emit "hard" references to OpenGL functions. Always use the
platform specific function to lookup OpenGL functions, such as
glXGetProcAddress() with GLX (x11).

This actually fixes the build if only Wayland is enabled (e.g. using
--disable-gl-x11 on Linux).

Note that some sources claim that wglGetProcAddress() (win32) does not
return function pointers for OpenGL 1.1 functions (even if they are
valid and necessary in OpenGL 3.0). But if that happens, the fallback
employed in gl_w32.c/w32gpa() should catch this.
2014-05-26 22:56:13 +02:00
wm4 d04ce8a7c2 x11: fix restoring position when leaving fullscreen
Accidentally broken in commit 7163bf7d by inverting the condition.
2014-05-26 21:59:30 +02:00
wm4 44e8a4085e x11: fix datatype for _NET_WM_PID
Setting this property was added 12 years ago, and the code was always
incorrect. The underlying data type is "long", not "pid_t". It's well
possible that the data types are different, and the pointer to the pid
variable is directly passed to XChangeProperty, possibly invoking
undefined behavior.

It's funny, because in theory using pid_t for PIDs sounds more correct.
2014-05-26 21:59:30 +02:00
wm4 6710527a83 input: make combined commands repeatable
Binding multiple commands at once where always considered not
repeatable, because the MP_CMD_COMMAND_LIST wasn't considered
repeatable.

Fixes #807 (probably).
2014-05-26 21:59:30 +02:00
wm4 fbe59b23b1 lua: add missing include files
These are actually already included in osdep/io.h, but I think it's
cleaner to repeat them in the file where they are actually needed.
(osdep/io.h needs to have them for other reasons.)
2014-05-26 21:59:30 +02:00
wm4 6f20d6b74e lua: fix compilation with lua 5.2
Commit e2e450f9 started making use of luaL_register(), but OF COURSE
this function disappeared in Lua 5.2, and was replaced with a 5.2-only
alternative, slightly different mechanism.

So just NIH our own function. This is actually slightly more correct,
since it forces the user to call "require" to actually make the module
visible for builtin C-only modules other than "mp". Fix autoload.lua
accordingly.
2014-05-26 21:59:29 +02:00
Martin 9c18a920ff command: add write_watch_later_config command
Closes #808.

Signed-off-by: wm4 <wm4@nowhere>
2014-05-26 21:59:17 +02:00
wm4 0e1ab2a8da autoload.lua: fix autoloading of files to prepend
This used the wrong index variable, and thus didn't work.
2014-05-25 20:17:03 +02:00
wm4 2309bb91cc DOCS/coding-style: add a hint that new features should be documented 2014-05-25 19:52:51 +02:00
wm4 fea1bad856 TOOLS: add a Lua script to autoload playlist entries
This will load other files in the same directory when a single file is
played. It's an often requested feature, but we definitely don't want it
in the core.
2014-05-25 19:52:26 +02:00
wm4 e2e450f961 lua: add some filesystem utility functions
We need this only because Lua's stdlib is so scarce. Lua doesn't intend
to include a complete stdlib - they confine themselves to standard C,
both for portability reasons and to keep the code minimal. But standard
C does not provide much either.

It would be possible to use Lua POSIX wrapper libraries, but that would
be a messy (and unobvious) dependency. It's better to implement the
missing functions ourselves, as long as they're small in number.
2014-05-25 19:51:11 +02:00
wm4 e648f7e783 manpage: lua: cosmetic changes to mp.options section 2014-05-25 19:43:25 +02:00
wm4 9d0e5f6da6 playlist: fix playlist_move on itself
A playlist_move command that moves an entry onto itself (both arguments
have the same index) should do nothing, but it did something broken. The
underlying reason is that it checks the prev pointer of the entry which
is temporarily removed for moving.
2014-05-25 19:42:51 +02:00
wm4 ba1447822c vf_vdpaupp: cosmetics: rename function 2014-05-25 16:01:33 +02:00
Tsukasa OMOTO 0304c4f92d osxbundle: fix recursion termination
Prevents the binary from being copied over to the lib directory.
2014-05-25 07:42:40 +02:00
ChrisK2 30fc1a42be osc: fix chapter list display
also fix small typo in DOCS
2014-05-24 17:47:31 +02:00
wm4 7cc48f26e0 build: disable cdda and vcd by default
Let's see if anyone complains. cdda is relatively inoffensive, but the
vcd code is the definition of ifdef-hell.
2014-05-24 17:09:29 +02:00
wm4 f5eb209ce9 stream_cdda: fix compilation
See previous commit. Sigh...
2014-05-24 17:07:13 +02:00
wm4 e47e818356 stream_smb: fix compilation
Accidentally forgotten in commit a4d487.
2014-05-24 17:00:30 +02:00
wm4 01c3847b80 client API: fix mpv_observe_property with MP_FORMAT_NONE
It returned only 1 change event (after registration), and then went
silent. This was accidentally broken some time ago.
2014-05-24 16:17:52 +02:00
wm4 6125ba613f video: add --video-rotate option for controlling auto-rotation 2014-05-24 16:17:52 +02:00
wm4 8665f78018 stream_file: readjust some windows ifdeffery
Also sneak in some cosmetics.

setmode() exists on Windows/msvcrt only, so there's no need for a
config test.

I couldn't reproduce the problem with seekable pipes on wine, so axe
it. (I'm aware that it still could be an issue on real Windows.)
2014-05-24 16:17:52 +02:00
wm4 aa87c143cb stream: remove chaos related to writeable streams
For some reason, we support writeable streams. (Only encoding uses that,
and the use of it looks messy enough that I want to replace it with FILE
or avio today.)

It's a chaos: most streams do not actually check the mode parameter like
they should. Simplify it, and let streams signal availability of write
mode by setting a flag in the stream info struct.
2014-05-24 16:17:52 +02:00