Commit Graph

660 Commits

Author SHA1 Message Date
Rudolf Polzer 073b2becfe ao_lavc: Fix design of audio pts handling.
There was confusion about what should go into audio pts calculation and
what not (mainly due to the audio push thread). This has been fixed by
using the playing - not written - audio pts (which properly takes into
account the ao's buffer), and incrementing the samples count only by the
amount of samples actually taken from the buffer (unfortunately this
now forces us to keep the lock too long for my taste).
2014-07-16 16:18:34 +02:00
Rudolf Polzer e257cbfdbb ao_lavc: Add a missing newline for the log. 2014-07-16 16:18:34 +02:00
Rudolf Polzer 2a985716cd ao_lavc: Fix advancing of audio pts. 2014-07-16 16:18:34 +02:00
wm4 fb54a1436a audio: don't wait for draining if paused
Logic for this was missing from pull.c. For push.c it was missing if the
driver didn't support it. But even if the driver supported it (such as
with ao_alsa), strange behavior was observed by users. See issue #933.

Always check explicitly whether the AO is in paused mode, and if so,
don't drain.

Possibly fixes #933.

CC: @mpv-player/stable
2014-07-13 20:06:33 +02:00
wm4 f8c2dd1b78 build: include <strings.h> for strcasecmp()
It happens to work without strings.h on glibc or with _GNU_SOURCE, but
the POSIX standard requires including <strings.h>.

Hopefully fixes OSX build.
2014-07-10 08:29:32 +02:00
wm4 c07bae02e2 ao_null: disable latency emulation
Doesn't work quite right, and will pause for the latency duration after
seeking. Some users use --ao=null to disable audio (even though they
should probably use --no-audio), and this use-case is broken by this
issue too.

CC: @mpv-player/stable
2014-07-07 18:00:48 +02:00
atomnuker e6643abc98 ao_pulse: set icon name
Will replace the generic XDG video icon inherited from media role.
2014-07-05 17:07:16 +02:00
Stefano Pigozzi 97f6d7f4ec ao_coreaudio: report hardware latency to ao_read_data
Commit a6a4cd2c88 added reporting of playout latency, this commit also adds
support for reporting hardware and constant audio unit latency.
2014-07-03 20:05:15 +02:00
Stefano Pigozzi a6a4cd2c88 ao_coreaudio: report latency more correctly
Previous code was completly wrong. This still doesn't report the device
latency, but we report the buffer latency (as before the AO refactoring) and
the AudioUnit's latency (this is a new 'feature').

Apparently we can also report the device actual latency and we should also
calculate the actual sample rate of the audio device instead of using the
nominal sample rate, but I'll leave this for a later commit.
2014-07-02 23:17:44 +02:00
Stefano Pigozzi 4f5f034ba2 ao_coreaudio: move channel mapping away from utils
Channel mapping functions are only used in the AUHAL based coreaudio, so move
them there.
2014-07-02 21:43:08 +02:00
Stefano Pigozzi c8fc02612e ao_coreaudio: use mpv's internal pull API 2014-07-02 21:43:08 +02:00
Stefano Pigozzi d16e4b836a ao_coreaudio: remove useless comments 2014-07-02 21:43:08 +02:00
Stefano Pigozzi 0ffbd05e99 ao_coreaudio: rename init_lpcm -> init_audiounit 2014-07-02 21:43:08 +02:00
Stefano Pigozzi 80ec0ba6d0 ao_coreaudio: fill asbd with an helper function 2014-07-02 21:43:07 +02:00
Stefano Pigozzi fa85bfde69 ao_coreaudio: split control to helper functions 2014-07-02 21:43:07 +02:00
Stefano Pigozzi f317d24a39 ao_coreaudio: move device related functions to the new AO 2014-07-02 21:43:07 +02:00
Stefano Pigozzi a8ef70b0f8 ao_coreaudio: remove useless call to print_asbd 2014-07-02 21:43:07 +02:00
Stefano Pigozzi 041557b639 ao_coreaudio: move spdif code to a new AO
The mplayer1/2/mpv CoreAudio audio output historically contained both usage
of AUHAL APIs (these go through the CoreAudio audio server) and the Device
based APIs (used only for output of compressed formats in exclusive mode).

The latter is a very unwieldy and low level API and pretty much forces us to
write a lot of code for little workr. Also with the widespread of HDMI, the
actual need for outputting compressed audio directly to the device is getting
lower (it was very useful with S/PDIF for bandwidth constraints not allowing
a number if channels transmitted in LPCM).

Considering how invasive it is (uses hog/exclusive mode), the new AO
(`ao_coreaudio_device`) is not going to be autoprobed but the user will have
to select it.
2014-07-02 21:43:07 +02:00
wm4 9a210ca2d5 Audit and replace all ctype.h uses
Something like "char *s = ...; isdigit(s[0]);" triggers undefined
behavior, because char can be signed, and thus s[0] can be a negative
value. The is*() functions require unsigned char _or_ EOF. EOF is a
special value outside of unsigned char range, thus the argument to the
is*() functions can't be a char.

This undefined behavior can actually trigger crashes if the
implementation of these functions e.g. uses lookup tables, which are
then indexed with out-of-range values.

Replace all <ctype.h> uses with our own custom mp_is*() functions added
with misc/ctype.h. As a bonus, these functions are locale-independent.
(Although currently, we _require_ C locale for other reasons.)
2014-07-01 23:11:08 +02:00
Amos Onn 8593c4f70b ao_pcm: fix message strings
Signed-off-by: wm4 <wm4@nowhere>
2014-06-15 09:25:15 +02:00
Rudolf Polzer ee2e91dce1 encode: get rid of the recursion that led to a deadlock.
Instead, the recursive call has been flattened away by instead
overwriting a parameter and continuing.
2014-06-12 11:42:00 +02:00
wm4 9a0baa4c53 audio: more detailed debugging output
Dump what the AO does on driver->play().
2014-06-12 00:55:13 +02:00
wm4 d07cd11b14 audio: don't wait when draining and paused
A corner case that could possibly lead to infinite waiting. Though
I'm not aware that this actually happened in practice.
2014-06-12 00:55:13 +02:00
wm4 99f5fef0ea Add more const
While I'm not very fond of "const", it's important for declarations
(it decides whether a symbol is emitted in a read-only or read/write
section). Fix all these cases, so we have writeable global data only
when we really need.
2014-06-11 00:39:14 +02:00
wm4 35f87dc692 audio/out/push: don't attempt to fill AO buffer when paused
Doing so will implicitly resume playback. Broken in commit 5929dc45.
2014-06-03 15:58:25 +02:00
wm4 b8cb860471 audio: prefer dsound over wasapi
ao_wasapi has too many subtle failures that were reported, but there's
nobody to fix them. ao_dsound seems to be more robust; so prefer it.
2014-06-01 19:00:44 +02:00
wm4 9f6e8d64de ao_alsa: make device the first sub option
This is more convenient.
2014-05-31 01:40:12 +02:00
wm4 4fa3ffebfe audio/out/push: keep some extra buffer
So the device buffer can be refilled quickly. Fixes dropouts in certain
cases: if all data is moved from the soft buffer to the audio device
buffer, the waiting code thinks it has to enter the mode in which it
waits for new data from the decoder. This doesn't work, because the
get_space() logic tries to keep the total buffer size down. get_space()
will return 0 (or a very low value) because the device buffer is full,
and the decoder can't refill the soft buffer. But this means if the AO
buffer runs out, the device buffer can't be refilled from the soft
buffer. I guess this mess happened because the code is trying to deal
with both AOs with proper event handling, and AOs with arbitrary
behavior.

Unfortunately this increases latency, as the total buffered audio
becomes larger. There are other ways to fix this again, but not today.

Fixes #818.
2014-05-31 01:26:50 +02:00
wm4 9c9f23eee9 ao_alsa: reduce spurious wakeups
Apparently this can happen. So actually only return from waiting if ALSA
excplicitly signals that new output is available, or if we are woken up
externally.
2014-05-30 23:54:11 +02:00
wm4 8ba346a554 audio/out/push: handle draining correctly
This did not flush remaining audio in the buffer correctly (in case an
AO has an internal block size). So we have to make the audio feed thread
to write the remaining audio, and wait until it's done.

Checking the avoid_ao_wait variable should be enough to be sure that all
data that can be written was written to the AO driver.
2014-05-30 02:17:15 +02:00
wm4 c79689206c audio: change handling of an EOF corner case
This code handles buggy AOs (even if all AOs are bug-free, it's good for
robustness). Move handling of it to the AO feed thread. Now this check
doesn't require magic numbers and does exactly what's it supposed to do.
2014-05-30 02:16:43 +02:00
wm4 b7c6981278 ao_alsa: use poll() to wait for device
This means the audio feed thread is woken up exactly at the time new
data is needed, instead of using a time-based heuristic.
2014-05-30 02:16:35 +02:00
wm4 5dcfc4f604 audio/out/push: add a way to wait for the audio device with poll()
Will be used for ALSA.
2014-05-30 02:16:25 +02:00
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 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
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
wm4 8e7cf4bc99 atomics: switch to C11 stdatomic.h
In my opinion, we shouldn't use atomics at all, but ok.

This switches the mpv code to use C11 stdatomic.h, and for compilers
that don't support stdatomic.h yet, we emulate the subset used by mpv
using the builtins commonly provided by gcc and clang.

This supersedes an earlier similar attempt by Kovensky. That attempt
unfortunately relied on a big copypasted freebsd header (which also
depended on much more highly compiler-specific functionality, defined
reserved symbols, etc.), so it had to be NIH'ed.

Some issues:
- C11 says default initialization of atomics "produces a valid state",
  but it's not sure whether the stored value is really 0. But we rely on
  this.
- I'm pretty sure our use of the __atomic... builtins is/was incorrect.
  We don't use atomic load/store intrinsics, and access stuff directly.
- Our wrapper actually does stricter typechecking than the stdatomic.h
  implementation by gcc 4.9. We make the atomic types incompatible with
  normal types by wrapping them into structs. (The FreeBSD wrapper does
  the same.)
- I couldn't test on MinGW.
2014-05-21 02:21:18 +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 c78b8b2c0c audio/out: fix previous commit
This didn't quite work. The main issue was that get_space tries to be
clever to reduce overall buffering, so it will cause the playloop to
decode and queue only as much audio as is needed to refill the AO in
reasonable time. Also, even if ignoring the problem, the logic of the
previous commit was slightly broken. (This required a few retries,
because I couldn't reproduce the issue on my own machine.)
2014-05-11 20:51:49 +02:00
wm4 665c8b59be audio/out: avoid wakeup feedback loop
When the audio buffer went low, but could not be refilled yet, it could
happen that the AO playback thread and the decode thread could enter a
wakeup feedback loop, causing up to 100% CPU usage doing nothing. This
happened because the decoder thread would wake up the AO thread when
writing 0 bytes of newly decoded data, and the AO thread in reaction
wakes up the decoder thread after writing 0 bytes to the AO buffer.

Fix this by waking up the decoder thread only if data was actually
played or queued. (This will still cause some redundant wakeups, but
will eventually settle down, reducing CPU usage close to ideal.)
2014-05-11 19:00:05 +02:00
wm4 09ecf7a68a audio/out: more debugging info for --dump-stats 2014-05-11 16:41:19 +02:00
Stefano Pigozzi b4e598badf ao_coreaudio: skip unknown channel labels
I don't think this is really a very good idea because it is conceptually
incorrect but other prominent multimedia programs use this approach
(VLC and xbmc), and it seems to make the conversion more robust in certain
cases.

For example it has been reported, that configuring a receiver that can output
7.1 to output 5.1, will make CoreAudio report 8 channel descriptions, and the
last 2 descriptions will be tagged kAudioChannelLabel_Unknown.

Fixes #737
2014-05-10 14:07:45 +02:00
Stefano Pigozzi 1a4f4f80bf ao_coreaudio: remove useless code
This code doesn't actually makes much of a difference, and the AudioUnit
mostly wants layout tags anyway.
2014-05-10 14:07:45 +02:00
Stefano Pigozzi 2a0a13425f ao_coreaudio: don't fallback to full waveext
The code was falling back to the full waveext chmap_sel when less than 2
channels were detected. This new code is slightly more correct since it only
fills the chmap_sel with the stereo or mono chmap in the fallback case.
2014-05-10 14:07:45 +02:00
Stefano Pigozzi 39b316ff06 ao_coreaudio: cosmetic change of loop ending condition 2014-05-10 14:07:45 +02:00
Stefano Pigozzi eb9d7d5c78 ao_coreaudio: print an error when channel mapping fails 2014-05-10 14:07:45 +02:00
Stefano Pigozzi b46ffaec7c ao_coreaudio: use description-based channel layouts
CoreAudio supports 3 kinds of layouts: bitmap based, tag based, and speaker
description based (using either channel labels or positional data).

Previously we tried to convert everything to bitmap based channel layouts,
but it turns out description based ones are the most generic and there are
built-in CoreAudio APIs to perform the conversion in this direction.

Moreover description based layouts support waveext extensions (like SDL and
SDR), and are easier to map to mp_chmaps.
2014-05-10 14:07:45 +02:00
Stefano Pigozzi e2f26f01fe ao_coreaudio: pass layout by reference to logging function
Apparently passing the struct by value somehow messed with the value of some
fields.
2014-05-10 14:07:45 +02:00
wm4 fc385baf02 encode: fix PTS unit mismatch
This used MP_NOPTS_VALUE to compare with ffmpeg-style int64_t PTS
values. This probably happened to work, because both constants use the
same value.
2014-05-10 10:44:16 +02:00
wm4 040c050f2d audio: fix the exact value that is used for the wait time
The comment says that it wakes up the main thread if 50% has been
played, but in reality the value was 0.74/2 => 37.5%. Correct this. This
probably changes little, because it's a very fuzzy heuristic in the
first place.

Also move down the min_wait calculation to where it's actually used.
2014-05-04 20:41:00 +02:00
wm4 767bcdc322 ao_null: fix unit mismatch with latency option
It's in seconds, but the code used it as sample count.
2014-05-04 16:57:32 +02:00
Stefano Pigozzi 26ce2e750d ao_coreaudio: log even more info in verbose mode
This logs more info that can be used for debugging purposes, in particular
it prints all the AudioChannelDescription in the descriptions array.
2014-04-24 09:52:38 +02:00
Stefano Pigozzi 2f7cef117a ao_coreaudio: add verbose output of detected channel layouts
This can be useful for debugging purposes.
2014-04-23 23:30:35 +02:00
wm4 04c4927140 audio: minor simplification in wait code 2014-04-23 21:16:52 +02:00
wm4 5059039c95 player: unrangle one aspect of audio EOF handling
For some reason, the buffered_audio variable was used to "cache" the
ao_get_delay() result. But I can't really see any reason why this should
be done, and it just seems to complicate everything.

One reason might be that the value should be checked only if the AO
buffers have been recently filled (as otherwise the delay could go low
and trigger an accidental EOF condition), but this didn't work anyway,
since buffered_audio is set from ao_get_delay() anyway at a later point
if it was unset. And in both cases, the value is used _after_ filling
the audio buffers anyway.

Simplify it. Also, move the audio EOF condition to a separate function.
(Note that ao_eof_reached() probably could/should whether the last
ao_play() call had AOPLAY_FINAL_CHUNK set to avoid accidental EOF on
underflows, but for now let's keep the code equivalent.)
2014-04-17 23:48:09 +02:00
wm4 40a072480c audio: add hack against broken pulseaudio EOF condition
This was reported with PulseAudio 2.1. Apparently it still has problems
with reporting the correct delay. Since ao_pulse.c still has our custom
get_delay implementation, there's a possibility that this is our fault,
but this seems unlikely, because it's full of workarounds for issues
like this. It's also possible that this problem doesn't exist on
PulseAudio 5.0 anymore (I didn't explicitly retest it).

The check is general and works for all push based AOs. For pull based
AOs, this can't happen as pull.c implements all the logic correctly.
2014-04-17 22:50:49 +02:00
wm4 fe298bc2a5 audio: explicitly document audio EOF condition
This should probably be an AO function, but since the playloop still has
some strange stuff (using the buffered_audio variable instead of calling
ao_get_delay() directly), just leave it and make it more explicit.
2014-04-17 22:45:49 +02:00
wm4 1b92f3b472 ao_null: add simulated device latency, simulate EOF problems
This EOF problems happen at least with PulseAudio, but since it's hard
to reproduce, let ao_null optionally simulate it.
2014-04-17 22:35:05 +02:00
wm4 c5613aa8a2 ao: remove redundant get_delay check
It did nothing; the real check is in push.c.
2014-04-17 01:43:07 +02:00
wm4 5aeec9aa70 audio: wake up the core when audio buffer is running low (2)
Same change as in e2184fcb, but this time for pull based AOs. This is
slightly controversial, because it will make a fast syscall from e.g.
ao_jack. And according to JackAudio developers, syscalls are evil and
will destroy realtime operation. But I don't think this is an issue at
all.

Still avoid locking a mutex. I'm not sure what jackaudio does in the
worst case - but if they set the jackaudio thread (and only this thread)
to realtime, we might run into deadlock situations due to priority
inversion and such. I'm not quite sure whether this can happen, but I'll
readily follow the cargo cult if it makes hack happy.
2014-04-15 22:50:16 +02:00
wm4 ad75b8e339 ao_pulse: use ao_need_data()
I'm not quite sure why ao_pulse needs this. It was broken when a thread
to fill audio buffers was added to AO - the pulseaudio callback was
waking up the playback thread, not the audio thread. But nobody noticed,
so it can't be very important. In any case, this change makes it wake up
the audio thread instead (which in turn wakes up the playback thread if
needed).
2014-04-15 22:42:15 +02:00
wm4 e2184fcbfb audio: wake up the core when audio buffer is running low
And also add a function ao_need_data(), which AO drivers can call if
their audio buffer runs low.

This change intends to make it easier for the playback thread: instead
of making the playback thread calculate a timeout at which the audio
buffer should be refilled, make the push.c audio thread wakeup the core
instead.

ao_need_data() is going to be used by ao_pulse, and we need to
workaround a stupid situation with pulseaudio causing a deadlock because
its callback still holds the internal pulseaudio lock.

For AOs that don't call ao_need_data(), the deadline is calculated by
the buffer fill status and latency, as before.
2014-04-15 22:38:16 +02:00
wm4 856d2c2491 encode: add a missing \n to a log call 2014-04-10 23:58:12 +02:00
wm4 a1afc15786 ao_wasapi: make code shorter
Also fix a format string mistake in a log call using it.

I wonder if this code shouldn't use FormatMessage, but it looks kind
of involved [1], so: no, thanks.

[1] http://support.microsoft.com/kb/256348/en-us
2014-03-30 09:13:52 +02:00
wm4 05e3a5a2b4 ao_lavc: set AVFrame.format
Seems kind of wrong that this wasn't done, although it didn't have any
bad consequences.
2014-03-16 13:19:29 +01:00
wm4 62c88a52c4 encode: use new AVFrame API 2014-03-16 13:19:29 +01:00
wm4 822e040ddb ao_dsound: remove duplicated code 2014-03-16 13:19:28 +01:00
wm4 c7e620df96 af_lavrresample: remove avresample_set_channel_mapping() fallbacks
This function is now always available.

Also remove includes of reorder_ch.h from some AOs (these are just old
relicts).
2014-03-16 13:19:28 +01:00
wm4 16596d025a ao: print (estimated) device buffer size on init in verbose mode 2014-03-14 22:37:46 +01:00
Diogo Franco (Kovensky) a0347e0651 ao_wasapi: Use the character set conversion functions from io.h
...rather than rolling out our own. The only possible advantage is that
the "custom" ones didn't use talloc.
2014-03-11 16:37:22 -03:00
Diogo Franco (Kovensky) c5012946ee ao_wasapi: Implement AOCONTROL_UPDATE_STREAM_TITLE 2014-03-11 16:37:22 -03:00
Diogo Franco (Kovensky) f8bdada77f ao_wasapi: Implement per-application mixing
The volume controls in mpv now affect the session's volume (the
application's volume in the mixer). Since we do not request a
non-persistent session, the volume and mute status persist across mpv
invocations and system reboots.

In exclusive mode, WASAPI doesn't have access to a mixer so the endpoint
(sound card)'s master volume is modified instead. Since by definition
mpv is the only thing outputting audio in exclusive mode, this causes no
conflict, and ao_wasapi restores the last user-set volume when it's
uninitialized.
2014-03-11 16:37:21 -03:00
Diogo Franco (Kovensky) f3e9b94622 ao_wasapi: Move non-critical code outside of the event thread
Due to the COM Single-Threaded Apartment model, the thread owning the
objects will still do all the actual method calls (in the form of
message dispatches), but at least this will be COM's problem rather than
having to set up several handles and adding extra code to the event
thread.

Since the event thread still needs to own the WASAPI handles to avoid
waiting on another thread to dispatch the messages, the init and uninit
code still has to run in the thread.

This also removes a broken drain implementation and removes unused
headers from each of the files split from the original ao_wasapi.c.
2014-03-11 16:37:02 -03:00
Diogo Franco (Kovensky) 58011810e5 ao_wasapi: Split into 2 files
ao_wasapi.c was almost entirely init code mixed with option code and
occasionally actual audio handling code. Split most things to
ao_wasapi_utils.c and keep the audio handling code in ao_wasapi.c.
2014-03-11 16:37:02 -03:00
Diogo Franco (Kovensky) f3514fb4bd ao_wasapi: Initial conversion to the new pull model
Gets rid of the internal ring buffer and get_buffer. Corrects an
implementation error in thread_reset.

There is still a possible race condition on reset, and a few refactors
left to do. If feasible, the thread that handles everything
WASAPI-related will be made to only handle feed events.
2014-03-11 16:37:01 -03:00
wm4 7221d96ba3 ao_sdl: make sure our buffer is always larger than what SDL requests
Assume obtained.samples contains the number of samples the SDL audio
callback will request at once. Then make sure ao.c will set the buffer
size at least to 3 times that value (or more).

Might help with bad SDL audio backends like ESD, which supposedly uses a
500ms buffer.
2014-03-10 22:56:23 +01:00
wm4 b3f9d3750b ao_alsa: reduce default buffer size
In general, we don't need to have a large hw audio buffer size anymore,
because we can quickly fill it from the soft buffer.

Note that this probably doesn't change much anyway. On my system (dmix
enabled), the buffer size is only 170ms, and ALSA won't give more. Even
when using a hardware device the buffer size seems to be limited to
341ms.
2014-03-10 01:28:39 +01:00
wm4 2e10f536db ao_alsa: fix return value for volume operations with spdif
This AO pretended to support volume operations when in spdif passthrough
mode, but actually did nothing. This is wrong: at least the GET
operations must write their argument. Signal that volume is unsupported
instead.

This was probably a hack to prevent insertion of volume filters or so,
but it didn't work anyway, while recovering after failed volume filter
insertion does work, so this is not needed at all.
2014-03-10 01:18:10 +01:00
wm4 d842b017e4 audio/out: reduce amount of audio buffering
Since the addition of the AO feed thread, 200ms of latency (MIN_BUFFER)
was added to all push-based AOs. This is not so nice, because even AOs
with relatively small buffering (e.g. ao_alsa on my system with ~170ms
of buffer size), the additional latency becomes noticable when e.g.
toggling mute with softvol.

Fix this by trying to keep not only 200ms minimum buffer, but also 200ms
maximum buffer. In other words, never buffer beyond 200ms in total. Do
this by estimating the AO's buffer fill status using get_space and the
initially known AO buffer size (the get_space return value on
initialization, before any audio was played). We limit the maximum
amount of data written to the soft buffer so that soft buffer size and
audio buffer size equal to 200ms (MIN_BUFFER).

To avoid weird problems with weird AOs, we buffer beyond MIN_BUFFER if
the AO's get_space requests more data than that, and as long as the soft
buffer is large enough.

Note that this is just a hack to improve the latency. When the audio
chain gains the ability to refilter data, this won't be needed anymore,
and instead we can introduce some sort of buffer replacement function in
order to update data in the soft buffer.
2014-03-10 01:13:40 +01:00
wm4 4c19c71b85 ao_alsa: remove unneeded initializations
priv is 0-initialized, can_pause is always overwritten later.
2014-03-09 22:11:08 +01:00
foo86 d350181aaf ao_alsa: check ALSA PCM state before pause and resume
It is possible to have ao->reset() called between ao->pause() and
ao->resume() when seeking during the pause. If the underlying PCM
supports pausing, resuming an already reset PCM will produce an error.
Avoid that by explicitly checking PCM state before calling
snd_pcm_pause().

Signed-off-by: wm4 <wm4@nowhere>
2014-03-09 22:06:06 +01:00
Diogo Franco (Kovensky) 5c9c81efcc ao_wasapi: Use double math for QueryPerformanceCounter correction
The uint64_t math would cause overflow at long enough system uptimes
(...such as 3 days), and any precision error given by the double math will
be under one milisecond.
2014-03-09 17:56:29 -03:00
Hans-Kristian Arntzen a84e25eb59 ao_rsound: pass correct data type to rsd_set_param()
Signed-off-by: wm4 <wm4@nowhere>
2014-03-09 19:11:49 +01:00
wm4 346c687d5a ao_sdl: use new pull API helpers
One strange issue is that we apparently can't stop the audio API on
audio reset (ao_driver.reset). We could use SDL_PauseAudio, but that
doesn't specify whether remaining audio is dropped. We also could use
SDL_LockAudio, but holding that over a long time will probably be bad,
and it probably doesn't drop audio. This means we simply play silence
after a reset, instead of stopping the callback completely. (The
existing code ran into an underrun in this situation.)

The delay estimation works about the same. We simply assume that the
callback is locked to audio timing (like ao_jack), and that 1 callback
corresponds to 1 period. It seems this (removed) code fragment assumes
there 1 one period size delay:

// delay subcomponent: remaining audio from the next played buffer, as
// provided by the callback
buffer_interval += callback_interval;

so we explicitly do that too.
2014-03-09 19:08:47 +01:00
wm4 e16c91d07a audio/out: make draining a separate operation
Until now, this was always conflated with uninit. This was ugly, and
also many AOs emulated this manually (or just ignored it). Make draining
an explicit operation, so AOs which support it can provide it, and for
all others generic code will emulate it.

For ao_wasapi, we keep it simple and basically disable the internal
draining implementation (maybe it should be restored later).

Tested on Linux only.
2014-03-09 01:27:41 +01:00
wm4 2f03dc2599 ao_portaudio: use new pull API helpers
Same deal as with the previous commit. We don't lose any functionality,
except for waiting "properly" on audio end, instead of waiting using the
delay estimate.
2014-03-09 01:27:41 +01:00
wm4 e5e8608332 ao_jack: use new pull API helpers
This removes the ringbuffer management from the code, and uses the
generic code added with the previous commit. The result should be
pretty much the same.

The "estimate" sub-option goes away. This estimation is now always
active. The new code for delay estimation is slightly different, and
follows the claim of the jack framework that callbacks are timed
exactly.
2014-03-09 01:27:41 +01:00
wm4 a477481aab audio/out: feed AOs from a separate thread
This has 2 goals:
- Ensure that AOs have always enough data, even if the device buffers
  are very small.
- Reduce complexity in some AOs, which do their own buffering.

One disadvantage is that performance is slightly reduced due to more
copying.

Implementation-wise, we don't change ao.c much, and instead "redirect"
the driver's callback to an API wrapper in push.c.

Additionally, we add code for dealing with AOs that have a pull API.
These AOs usually do their own buffering (jack, coreaudio, portaudio),
and adding a thread is basically a waste. The code in pull.c manages
a ringbuffer, and allows callback-based AOs to read data directly.
2014-03-09 01:27:41 +01:00
wm4 5ffd6a9e9b encode: add locking
Since the AO will run in a thread, and there's lots of shared state with
encoding, we have to add locking.

One case this doesn't handle correctly are the encode_lavc_available()
calls in ao_lavc.c and vo_lavc.c. They don't do much (and usually only
to protect against doing --ao=lavc with normal playback), and changing
it would be a bit messy. So just leave them.
2014-03-09 00:19:35 +01:00
wm4 3cd1cfb51c ao_null: add option for simulated device speed
Helps with testing and debugging.
2014-03-09 00:19:34 +01:00
wm4 76eca81455 ao: remove opts field
Apparently unused.
2014-03-09 00:19:34 +01:00
wm4 41f2b26d11 audio/out: make ao struct opaque
We want to move the AO to its own thread. There's no technical reason
for making the ao struct opaque to do this. But it helps us sleep at
night, because we can control access to shared state better.
2014-03-09 00:19:31 +01:00
wm4 74b7001500 encode: don't access ao->pts
This field will be moved out of the ao struct. The encoding code was
basically using an invalid way of accessing this field.

Since the AO will be moved into its own thread too and will do its own
buffering, the AO and the playback core might not even agree which
sample a PTS timestamp belongs to. Add some extrapolation code to handle
this case.
2014-03-07 15:23:03 +01:00
Diogo Franco (Kovensky) fe03981bbc ao_wasapi: Slightly improve timer accuracy
Use QueryPerformanceCounter to improve the accuracy of
IAudioClock::GetPosition.

While this is mainly for "realtime correctness" (usually the delay is a
single sample or less), there are cases where IAudioClock::GetPosition
takes a long time to return from its call (though the documentation doesn't
define what a "long time" is), so correcting its value might be important in
case the documented possible delay happens.
2014-03-06 17:21:34 -03:00
Diogo Franco (Kovensky) 1d096f9f1b ao_wasapi: Add device latency to get_delay
The lack of device latency made get_delay report latencies shorter than
they should; on systems with fast enough drivers, the delay is not
perceptible, but high enough invisible delays would cause desyncs.

I'm not yet completely sure whether this is 100% accurate, there are
some issues involved when repeatedly pausing+unpausing (the delay might
jump around by several dozen miliseconds), but seeking seems to be
working correctly now.
2014-03-06 17:21:33 -03:00
wm4 d268d896d9 ao_jack: fix termination on the end of file
The player didn't quit when the end of a file was reached. The reason
for this is that jack reported a constant audio delay even when all
audio was done playing. Whether that was recognized as EOF by the player
depended whether the exact value was higher or lower than the player's
threshhold for what it considers no more audio.

get_delay() should return amount of time it takes until the last sample
written to the audio buffer reaches the speaker. Therefore, we have to
track the estimated time when the last sample is done, and subtract it
from the calculated latency. Basically, the latency is the only amount
of time left in the delay, and it should go towards 0 as audio reaches
ths speakers.

I'm not sure if this is correct, but at least it solves the problem. One
suspicious thing is that we use system time to estimate the end of the
audio time. Maybe using jack_frame_time() would be more correct. But
apart from this, there doesn't seem to be a better way to handle this.
2014-03-05 18:02:41 +01:00
wm4 6b2a929ca7 ao: document some functions 2014-02-28 00:56:10 +01:00
James Ross-Gowan d26ee98fa6 w32: use safe DLL search paths everywhere
Windows applications that use LoadLibrary are vulnerable to DLL
preloading attacks if a malicious DLL with the same name as a system DLL
is placed in the current directory. mpv had some code to avoid this in
ao_wasapi.c. This commit just moves it to main.c, since there's no
reason it can't be used process-wide.

This change can affect how plugins are loaded in AviSynth, but it
shouldn't be a problem since MPC-HC also does this and it's a very
popular AviSynth client.
2014-01-27 10:04:29 +01:00
Stefano Pigozzi 3137a1a7b5 build: fix usage of HAVE_SDL1 define
This is needed after fd1f8ed49.
2014-01-25 09:18:07 +01:00
wm4 e0d7876eca ao_pulse: lower default buffer size from 1000ms to 250ms
1000ms is a bit insane. It makes behavior on playback speed changes
worse (because the player has to catch up the dropped audio due to
audio-chain reset), and perhaps makes seeking slower.

Note that the problem of playback speed changes misbehaving will be
fixed in the future, but even then we don't want to have a buffer that
large.
2014-01-07 23:52:18 +01:00
wm4 a220a3aae6 ao_pulse: add suboption to control buffer size 2014-01-07 23:50:22 +01:00
wm4 d4588bf577 ao_alsa: remove 9 year old typo
Actually, remove the whole comment, because it's outdated and
get_space() returns the number of free samples now.
2014-01-02 21:29:33 +01:00
Martin Herkt 4350a76a01 ao_alsa: Unbreak pause/resume
Well that was dumb.
2014-01-02 18:46:11 +01:00
Martin Herkt 4083ae1de3 ao_alsa: Fix PCM resume after suspend
Fixes #324
2014-01-02 16:09:27 +01:00
wm4 eef36f03ea msg: rename mp_msg_log -> mp_msg
Same for companion functions.
2013-12-21 22:13:04 +01:00
wm4 9242c34fa2 m_option: add mp_log callback to OPT_STRING_VALIDATE options
And also convert a bunch of other code, especially ao_wasapi and
ao_portaudio.
2013-12-21 21:43:16 +01:00
wm4 d8d42b44fc m_option, m_config: mp_msg conversions
Always pass around mp_log contexts in the option parser code. This of
course affects all users of this API as well.

In stream.c, pass a mp_null_log, because we can't do it properly yet.
This will be fixed later.
2013-12-21 21:05:02 +01:00
wm4 138d183d83 ao: some missing mp_msg conversions 2013-12-21 20:50:12 +01:00
wm4 7cc3c3aeec ao_wasapi: mp_msg conversions
Remove the nonsensical print_lock too.

Things that are called from the option validator are not converted yet,
because the option parser doesn't provide a log context yet.
2013-12-21 20:50:12 +01:00
wm4 60c06fec1e audio/fmt-conversion.c: remove unknown audio format messages
Same deal as with video/fmt-conversion.c.
2013-12-21 20:50:12 +01:00
wm4 fdceef6cc5 ao_alsa: don't set ALSA message callback
This could output additional, potentially useful error messages. But the
callback is global and not library-safe, and would require us to add
additional state. Remove it, because it's obviously too much of a pain.
Also, it seems ALSA prints stuff to stderr anyway.
2013-12-21 17:36:56 +01:00
wm4 03e53ab430 ao_wasapi: fix includes
Broken due to recent header renaming. Untested.
2013-12-18 17:14:31 +01:00
wm4 0112143fda Split mpvcore/ into common/, misc/, bstr/ 2013-12-17 02:39:45 +01:00
wm4 eb15151705 Move options/config related files from mpvcore/ to options/
Since m_option.h and options.h are extremely often included, a lot of
files have to be changed.

Moving path.c/h to options/ is a bit questionable, but since this is
mainly about access to config files (which are also handled in
options/), it's probably ok.
2013-12-17 02:07:57 +01:00
wm4 8d5214de0a Move mpvcore/input/ to input/ 2013-12-17 01:23:09 +01:00
wm4 7dc7b900c6 Replace mp_tmsg, mp_dbg -> mp_msg, remove mp_gtext(), remove set_osd_tmsg
The tmsg stuff was for the internal gettext() based translation system,
which nobody ever attempted to use and thus was removed. mp_gtext() and
set_osd_tmsg() were also for this.

mp_dbg was once enabled in debug mode only, but since we have log level
for enabling debug messages, it seems utterly useless.
2013-12-16 20:41:08 +01:00
Diogo Franco (Kovensky) 04faf9a1cb ao_wasapi: Fix mistaken behavior on uninit
The parameter, when true, tells whether uninit should block for flushing
the buffers, not whether it should quit immediately without flushing.
2013-12-08 19:36:44 -03:00
Diogo Franco (Kovensky) c7064ce5e5 ao_wasapi: handle AOPLAY_FINAL_CHUNK
Used for writing down all samples to the audio driver, even if it's not
a full chunk; needed at EOF on weird files.
2013-12-08 19:36:43 -03:00
Diogo Franco (Kovensky) 8f4380d6d5 ao_wasapi: Reduce the buffer size to a sane value
The previous RING_BUFFER_COUNT value, 64, would have ao_wasapi buffer 64
frames of audio in the ring buffer; a delay of 1280ms, which is clearly
overkill for everything. A value of 8 buffers 8 frames for a total of
160ms.
2013-12-08 19:14:56 -03:00
Diogo Franco (Kovensky) 2329e46229 ao_wasapi: fix audio buffering delay calculation
When get_space was converted to returning samples instead of bytes, a
unit type mismatch in get_delay's calculation returned bogus values. Fix
by converting get_space's value back to bytes.

Fixes playback with ao_wasapi when reaching EOF, or seeking past it.
2013-12-08 19:03:26 -03:00
bugmen0t 7ee074813b ao_oss: when falling back from unknown prefer larger format 2013-12-04 00:07:40 +01:00
bugmen0t 9fcf88e42b ao_oss: add 24bit formats 2013-12-04 00:07:40 +01:00
wm4 b18f02d1ad options: add options that set defaults for af/vf/ao/vo
There are some use cases for this. For example, you can use it to set
defaults of automatically inserted filters (like af_lavrresample). It's
also useful if you have a non-trivial VO configuration, and want to use
--vo to quickly change between the drivers without repeating the whole
configuration in the --vo argument.
2013-12-01 00:12:10 +01:00
bugmen0t c8ab12ee4b ao_oss: add 6.1 and 7.1 speaker placement from FreeBSD 2013-11-30 19:07:17 +01:00
wm4 ac0cbd7c5e ao_oss: SNDCTL_DSP_CHANNELS takes int, not uint8_t
This caused weird issue, probably caused by setting up the wrong number
of channels, or similar. See github issue #383.

Patch by bugmen0t on github.
2013-11-30 18:58:18 +01:00
wm4 17d72de2ac ao_alsa: remove unneeded checks
If initialization succeeds, p->alsa should always be set. Additional
checks are not needed, and also this wasn't even done consistently.
2013-11-30 18:56:44 +01:00
wm4 557efff690 ao_alsa: enable "plug" for non-interleaved float formats too
I have no idea what this code does, but it seems logical it should be
active for all float formats, not just for float with interleaved
access.
2013-11-30 18:55:39 +01:00
wm4 f1072e7629 ao_alsa: disable ALSA resampling by default again
This partially reverts commit 7d152965. It turns out that at least some
ALSA drivers (at least snd-hda-intel) report incorrect audio delay with
non-native sample rates, even if the sample rate is only very slightly
different from the native one.

For example, 48000Hz is fine on my hda-intel system, while both 8000Hz
and 47999Hz lead to a delay off by 40ms (according to mpv's A/V
difference display), which suggests that something in ALSA is
calculating the delay using the wrong sample rate.

As an additional problem, with ALSA resampling enabled, using
48001Hz/float/2ch fails, while 49000Hz/float/2ch or 48001Hz/s16/2ch
work. With resampling disabled, all these cases work obviously, because
our own resampler doesn't just refuse any of these formats.

Since some people want to use the ALSA resampler (because it's highly
configurable, supports multiple backends, etc.), we still allow enabling
ALSA resampling with an ao_alsa suboption.
2013-11-29 15:59:53 +01:00
Stefano Pigozzi f10cca0e88 ao_coreaudio: simplify ch label to speaker id conversion
Previous code was using the values of the AudioChannelLabel enum directly to
create the channel bitmap. While this was quite smart it was pretty unreadable
and fragile (what if Apple changes the values of those enums?).

Change it to use a 'dumb' conversion table.
2013-11-27 23:15:17 +01:00
Stefano Pigozzi fb508105d1 ao_coreaudio: map channel labels needed for 8ch layouts
The code stopped at kAudioChannelLabel_TopBackRight and missed mapping for
5 more channel labels. These are in a completely different order that the mpv
ones so they must be mapped manually.
2013-11-27 00:51:48 +01:00
Martin Herkt 7d152965ce ao_alsa: do not forcibly disable ALSA resampling
Resampling with non-ancient ALSA setups works fine, so there is no
need to keep this around. Furthermore, as of writing, the default
builtin resampler used by many ALSA setups (taken from libspeex)
actually has higher quality than the default resampling modes of
avresample and swresample.
2013-11-26 02:48:00 +01:00
wm4 215b3cedda ao_rsound: fix option types
These are option values, and the option code expects char*.

Not actually tested.
2013-11-23 21:40:33 +01:00
wm4 b14a7da5d4 ao_null: fix simulated buffer size
The size accidentally defaulted to 200 seconds instead of 200
milliseconds, which had fatal consequences when trying to use it.
2013-11-19 22:14:23 +01:00
wm4 e403140201 ao_null: properly simulate final chunk, add buffer options
Simulate proper handling of AOPLAY_FINAL_CHUNK. Print when underruns
occur (i.e. running out of data). Add some options that control
simulated buffer and outburst sizes.

All this is useful for debugging and self-documentation. (Note that
ao_null always was supposed to simulate an ideal AO, which is the reason
why it fools people who try to use it for benchmarking video.)
2013-11-17 16:22:25 +01:00
wm4 ca455e65a3 ao_lavc: use af_format_conversion_score()
This should allow it to select better fallback formats, instead of
picking the first encoder sample format if ao->format is not equal to
any of the encoder sample formats.

Not sure what is supposed to happen if the encoder provides no
compatible sample format (or no sample format list at all), but in this
case ao_lavc.c still fails gracefully.
2013-11-16 21:46:17 +01:00
Rudolf Polzer 6391453fab ao_lavc: write the final audio chunks from uninit()
These must be written even if there was no "final frame", e.g. due to
the player being exited with "q".

Although the issue is mostly of theoretical nature, as most audio codecs
don't need the final encoding calls with NULL data. Maybe will be more
relevant in the future.
2013-11-16 18:50:07 +01:00
Rudolf Polzer 0d4628a7fd ao_lavc: fix crash with interleaved audio outputs. 2013-11-16 14:10:00 +01:00
wm4 514c454770 audio: drop "_NE"/"ne" suffix from audio formats
You get the native format by not appending any suffix to the format.

This change includes user-facing names, e.g. for the --format option.
2013-11-15 21:25:05 +01:00
wm4 53c6d97873 ao_alsa: non-interleaved access is not always available
I thought this would always work... how disappointing.

Revert to interleaved format if requesting non-interleaved fails.
2013-11-14 21:19:04 +01:00
wm4 e5fec0ad07 ao_null: add untimed sub-option 2013-11-13 20:10:17 +01:00
wm4 621cff80df ao_null: support pausing properly
ao_null should simulate a "perfect" AO, but framestepping behaved quite
badly with it. Framstepping usually exposes problems with AOs dropping
their buffers on pause, and that's what happened here.
2013-11-13 20:10:17 +01:00
wm4 933fbf7333 ao_lavc: support non-interleaved audio 2013-11-13 20:10:17 +01:00
wm4 e4bbb1d348 Merge branch 'planar_audio'
Conflicts:
	audio/out/ao_lavc.c
2013-11-12 23:42:04 +01:00
William Light e1656d369a ao_jack: switch from interleaved to planar audio 2013-11-12 23:35:12 +01:00
William Light 4bd690c998 ao_jack: refactoring, also fix "no-connect" option 2013-11-12 23:35:04 +01:00
wm4 7510caa0c5 ao_openal: support non-interleaved output
Since ao_openal simulates multi-channel audio by placing a bunch of
mono-sources in 3D space, non-interleaved audio is a perfect match for
it. We just have to remove the interleaving code.
2013-11-12 23:30:37 +01:00
wm4 dab6eaaa5e ao_alsa: support non-interleaved audio
ALSA supports non-interleaved audio natively using a separate API
function for writing audio. (Though you have to tell it about this on
initialization.) ALSA doesn't have separate sample formats for this,
so just pretend to negotiate the interleaved format, and assume that
all non-interleaved formats have an interleaved companion format.
2013-11-12 23:30:25 +01:00
wm4 fedb9229d5 ao_null: support non-interleaved audio
Simply change internals from using byte counts to sample counts.
2013-11-12 23:30:10 +01:00
wm4 347a86198b audio: switch output to mp_audio_buffer
Replace the code that used a single buffer with mp_audio_buffer. This
also enables non-interleaved output operation, although it's still
disabled, and no AO supports it yet.
2013-11-12 23:29:53 +01:00
wm4 380fc765e4 audio/out: prepare for non-interleaved audio
This comes with two internal AO API changes:

1. ao_driver.play now can take non-interleaved audio. For this purpose,
the data pointer is changed to void **data, where data[0] corresponds to
the pointer in the old API. Also, the len argument as well as the return
value are now in samples, not bytes. "Sample" in this context means the
unit of the smallest possible audio frame, i.e. sample_size * channels.

2. ao_driver.get_space now returns samples instead of bytes. (Similar to
the play function.)

Change all AOs to use the new API.

The AO API as exposed to the rest of the player still uses the old API.
It's emulated in ao.c. This is purely to split the commits changing all
AOs and the commits adding actual support for outputting N-I audio.
2013-11-12 23:27:51 +01:00
wm4 bf60281ffb audio/out: reject non-interleaved formats
No AO can handle these, so it would be a problem if they get added
later, and non-interleaved formats get accepted erroneously. Let them
gracefully fall back to other formats.

Most AOs actually would fall back, but to an unrelated formats. This is
covered by this commit too, and if possible they should pick the
interleaved variant if a non-interleaved format is requested.
2013-11-12 23:16:31 +01:00
Rudolf Polzer 149ab3afa2 ao_lavc: remove audio offset hack to ease supporting planar audio.
Now to shift audio pts when outputting to e.g. avi, you need an explicit
facility to insert/remove initial samples, to avoid initial regions of
the video to be sped up/slowed down.

One such facility is the delay filter in libavfilter.
2013-11-11 13:04:13 +01:00
wm4 3cb4116243 ao: add ao_play_silence, use for ao_alsa and ao_oss
Also add a corresponding function to audio/format.c, which fills an
audio block with silence.
2013-11-10 23:05:59 +01:00
wm4 1a5c863a32 player: set PulseAudio stream title to window title
Set the PulseAudio stream title, just like the VO window title is set.
Refactor update_vo_window_title() so that we can use it for AOs too.

The ao_pulse.c bit is stolen from MPlayer.
2013-11-10 00:49:13 +01:00
wm4 0f82107535 ao_alsa: use correct magic spdif flags
I accidentally copied the AES4/ORIGFS constants from the ALSA headers,
instead of the AES3/FS ones. The difference is probably important.
2013-11-09 23:32:58 +01:00
wm4 a3e2019c2d ao: print requested audio format on init
Also remove the rather bad/incomplete log calls from ao_alsa and ao_oss.
2013-11-09 23:32:50 +01:00
wm4 3af094062e ao_alsa: add magic spdif parameters
I have no idea what these do, but apparently they are needed to inform
ALSA about spdif configuration. First, replace the literal constant "6"
for the AES0 parameter with the symbolic constants from the ALSA
headers (the final value is the same). Second, copy paste some funky
looking parameter setup from VLC's alsa output for setting the AES1,
AES2, AES3 parameters. (The code is actually not literally copy-pasted,
but does exactly the same.)

My small but non-zero hope is that this could make DTS-HD work, or at
least work into that direction. I can't test spdif stuff though, and
for DTS-HD not even opening the ALSA device succeeds on my system.
2013-11-09 01:30:02 +01:00
wm4 d240aa367e ao_alsa: redo the way parameters are added in the spdif case
Using spdif with alsa requires adding magic parameters to the device
name, and the existing code tried to deal with the situation when the
user wanted to add parameters too.

Rewrite this code, in particular remove the duplicated parameter string
as preparation for the next commit. The new code is a bit stricter, e.g.
it doesn't skip spaces before and after '{' and '}'. (Just don't add
spaces.)
2013-11-09 01:30:00 +01:00
wm4 8125252399 audio: don't let ao_lavc access frontend internals, change gapless audio
ao_lavc.c accesses ao->buffer, which I consider internal. The access was
done in ao_lavc.c/uninit(), which tried to get the left-over audio in
order to write the last (possibly partial) audio frame. The play()
function didn't accept partial frames, because the AOPLAY_FINAL_CHUNK
flag was not correctly set, and handling it otherwise would require an
internal FIFO.

Fix this by making sure that with gapless audio (used with encoding),
the AOPLAY_FINAL_CHUNK is set only once, instead when each file ends.
Basically, move the hack in ao_lavc's uninit to uninit_player.

One thing can not be entirely correctly handled: if gapless audio is
active, we don't know really whether the AO is closed because the file
ended playing (i.e. we want to send the buffered remainder of the audio
to the AO), or whether the user is quitting the player. (The stop_play
flag is overwritten, fixing that is perhaps not worth it.) Handle this
by adding additional code to drain the AO and the buffers when playback
is quit (see play_current_file() change).

Test case: mpv avdevice://lavfi:sine=441 avdevice://lavfi:sine=441 -length 0.2267  -gapless-audio
2013-11-08 20:00:58 +01:00
wm4 91626b1c06 audio: replace af_fmt2str_short -> af_fmt_to_str
Also, remove all af_fmt2str usages.
2013-11-07 22:12:36 +01:00
wm4 dbb7927a1e ao_oss: fix previous ao_oss commit
Basically I introduced an inverted condition, and the line removed was
inactive before commit ce72aaa.
2013-11-06 22:28:17 +01:00
wm4 ce72aaae7b ao_oss: hide warning 2013-11-06 20:33:48 +01:00
bugmen0t 9db560b9a9 ao_oss: don't enable -softvol by default on OSSv4 2013-11-06 20:31:38 +01:00
bugmen0t 0cffd98e8e ao_oss: make no_persistent_volume volume work when seeking 2013-11-06 20:31:36 +01:00
Stefano Pigozzi 78a9bc4a7d osx: fix -Wshadow warnings on platform specific code 2013-11-04 08:33:35 +01:00
Stefano Pigozzi 37388ebb0e configure: uniform the defines to #define HAVE_xxx (0|1)
The configure followed 5 different convetions of defines because the next guy
always wanted to introduce a new better way to uniform it[1]. For an
hypothetic feature 'hurr' you could have had:

  * #define HAVE_HURR 1   / #undef HAVE_DURR
  * #define HAVE_HURR     / #undef HAVE_DURR
  * #define CONFIG_HURR 1 / #undef CONFIG_DURR
  * #define HAVE_HURR 1   / #define HAVE_DURR 0
  * #define CONFIG_HURR 1 / #define CONFIG_DURR 0

All is now uniform and uses:
  * #define HAVE_HURR 1
  * #define HAVE_DURR 0

We like definining to 0 as opposed to `undef` bcause it can help spot typos
and is very helpful when doing big reorganizations in the code.

[1]: http://xkcd.com/927/ related
2013-11-03 21:59:54 +01:00
wm4 75261165af ao_pulse: fix channel layouts
The code was selecting PA_CHANNEL_POSITION_MONO for MP_SPEAKER_ID_FC,
which is correct only with the "mono" channel layout, but not anything
else. Remove the mono entry, and handle mono separately.

See github issue #326.
2013-10-31 18:17:14 +01:00
wm4 a17b5364ea ao_alsa: return negative value on error in play()
No functional change, because the only user of ao_play() ignores return
values below 1.
2013-10-30 22:19:15 +01:00
wm4 d8896f0dba ao_alsa: don't include alloca.h
It's true that ALSA uses alloca() in some of its API functions, but
since this is hidden behind macros in the ALSA headers, we have no
reason to include alloca.h ourselves.

Might help with portability (FreeBSD).
2013-10-25 21:25:54 +02:00
wm4 d58d4ec93c audio/out: remove useless info struct and redundant fields 2013-10-23 19:30:02 +02:00
wm4 bb5fe4d874 ao_pcm: big endian AC3 in wav doesn't work
At least not with ffmpeg.

Honestly, I have no idea how little endian AC3 works at all, since
ao_pcm doesn't do anything special about it, and treats it like s16le.
Maybe it's broken and ffmpeg has special logic to detect it.
2013-10-22 01:01:07 +02:00
wm4 e046fa584a mp_msg: remove gettext() support
Was disabled by default, was never used, internal support was
inconsistent and poor, and there has been virtually no interest in
creating translations.

And I don't even think that a terminal program should be translated.
This is something for (hypothetical) GUIs.
2013-10-18 22:38:10 +02:00
Stefano Pigozzi 683e212a77 ao_coreaudio: clear output buffer on buffer underrun
Output silence to the output buffer during underruns. This removes small
occasional glitches that happen before the AUHAL is actually paused from the
`audio_pause` call.

Fixes #269
2013-10-03 23:43:07 +02:00
Christian Neukirchen 3289473678 audio/out: add sndio support
Based on an earlier patch for mplayer by Alexandre Ratchov <alex@caoua.org>
2013-10-03 23:14:03 +02:00
Stefano Pigozzi 94d6babb95 ao_coreaudio: fetch device name only for verbose log level
The previous code fetched the device name regardless of log level and then
only printed it if log level was verbose.
2013-10-01 11:00:43 +02:00
Martin Herkt f210244a1c ao_jack: don’t force exact client name
Trying to connect multiple mpv clients to JACK with the
JackUseExactName option would fail unless the user manually
specifies a unique client name. This changes the behavior
to automatically generate a unique name if the requested
one is already in use.
2013-09-30 14:42:55 +02:00
Paul B Mahol 20b2d7cb6f ao_oss: add support for SNDCTL_DSP_RESET and use it when pausing
Signed-off-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: wm4 <wm4@nowhere>
2013-09-23 01:21:37 +02:00
Johan Kiviniemi 912f609403 ao_pulse: bug fix: goto the correct error handler 2013-09-20 13:50:45 +02:00
Johan Kiviniemi e5710ccc5d ao_pulse: set the property media.role=video 2013-09-20 13:50:13 +02:00
wm4 0162271725 mixer: make struct opaque
Also remove stray include statements from ao_alsa and ao_oss.
2013-09-20 13:23:25 +02:00
wm4 0d8a62c08d Some more mp_msg conversions
Also add a note to mp_msg.h, since it might be not clear which of the
two mechanisms is preferred.
2013-08-23 23:30:09 +02:00
wm4 edd36a3afc audio/out: do some mp_msg conversions
Use the new MP_ macros for some AOs instead of mp_msg.

Not all AOs are converted, and some only partially. In some cases, some
additional cosmetic changes are made.
2013-08-22 23:12:35 +02:00
wm4 cb54c2dda8 ao: remove some leftovers 2013-08-22 22:45:24 +02:00
Stefano Pigozzi 406241005e core: move contents to mpvcore (2/2)
Followup commit. Fixes all the files references.
2013-08-06 22:52:31 +02:00
Diogo Franco 57ec67a6cc Merge pull request #154 from rossy2401/wasapi-pause
WASAPI stops working after pause
2013-08-05 18:22:46 -07:00
Stefano Pigozzi 0bd09da570 ao_coreaudio: move to new log API 2013-08-01 20:32:49 +02:00
Stefano Pigozzi 5cd5f0cf70 ao_coreaudio: remove useless defines
They are already defined in the header file
2013-08-01 20:32:49 +02:00
Stefano Pigozzi 3449e893e1 audio/out: add support for new logging API 2013-08-01 20:32:49 +02:00
Jonathan Yong 29b0be400c Fix some warnings 2013-07-30 11:05:39 -03:00
Stefano Pigozzi e777a86b69 ao_coreaudio: use default output unit when no device is specified
Using the default output audio unit should provide a much better user
exeperience since it changes automatically the output device based on which
becomes the default one.
2013-07-29 08:22:33 +02:00
Stefano Pigozzi ca678dce4d ao_coreaudio: prevent buffer underruns to output garbage
This was removed in d427b4fd. I now found a sample that causes underruns when
moving to a chapter and apparently this is also a problem when taking
screenshots.
2013-07-28 11:21:03 +02:00
Dmitry Kalinkin 721071a5ec ao_coreaudio: fix compilation on OS X 10.7
Reverts one of the changes from 18777ecf. `kAudioObjectPropertyScopeOutput`
was introduced in the 10.8 SDK while `kAudioDevicePropertyScopeOutput` was
moved to `AudioHardwareDeprecated.h`. Since the deprecation is silent for now
(no warnings), just use the old constant.

Either way, they both evaluate to 'outp', and in the 10.8 SDK the deprecated
constant is defined in terms of the non-deprecated one.

Fixes #155
2013-07-28 09:48:49 +02:00
James Ross-Gowan 8e1461b9f8 ao_wasapi: don't check the audio feed while paused 2013-07-27 14:28:42 +10:00
wm4 f32a90a839 audio/out: remove options argument from init()
Same as with VOs in the previous commit.
2013-07-22 22:58:09 +02:00
wm4 1df2ad7e03 Remove subopt-helper
Finally not used by anything anymore. Farewell.
2013-07-22 22:42:55 +02:00
Stefano Pigozzi 14f1a25a8e ao_coreaudio: fix ifdef'd conditional
The big endian case was not covered. Doesn't make much difference since mpv
runs on Macs with x86 only, but for the sake of correctness.
2013-07-22 22:35:44 +02:00
Stefano Pigozzi cd10936357 ao_coreaudio: use new option API 2013-07-22 22:27:08 +02:00
Stefano Pigozzi 7d58c51fd6 ao_coreaudio: switch properties getters to talloc 2013-07-22 21:53:18 +02:00
Stefano Pigozzi af6ad6717f ao_coreaudio: reduce verbosity of the chmapping code 2013-07-22 21:53:18 +02:00
Stefano Pigozzi df39121206 ao_coreaudio: revert to original device format on digital uninit
This is not done automatically by CoreAudio. I am told that it would a PITA
to have to switch back the format manually on the device (especially if the
same device is used for lpcm output).
2013-07-22 21:53:18 +02:00
Stefano Pigozzi c11c744998 ao_coreaudio: refactor chmap detection
b2f9e0610 introduced this functionality with code that was quite 'monolithic'.
Split the functionality over several functions and ose the new macros to get
array properties.
2013-07-22 21:53:18 +02:00
Stefano Pigozzi 18777ecfe8 ao_coreaudio: refactor properties code
Introduce some macros to deal with properties. These allow to work around the
limitation of CoreAudio's API being `void **` based. The macros allow to keep
their client's code DRY, by not asking size and other details which can be
derived by the macro itself. I have no idea why Apple didn't design their API
like this in the first place.
2013-07-22 21:53:18 +02:00
Stefano Pigozzi 1ed1175636 ao_coreaudio: move utils functions to snake_case 2013-07-22 21:53:18 +02:00
Stefano Pigozzi 1e37965597 ao_coreaudio: split ao_coreaudio_common in two files
* ao_coreaudio_utils: contains several utility function
 * ao_coreaudio_properties: contains functions to set and get  audio object
   properties.

Conflicts:
	audio/out/ao_coreaudio.c
2013-07-22 21:53:18 +02:00
Stefano Pigozzi 5a195845e3 ao_coreaudio: store asbd only when selected
Previous code needlessly stored the input asbd before actually testing it's
support against the hardware.
2013-07-22 21:53:18 +02:00
Stefano Pigozzi 4e0618dab9 ao_coreaudio: fallback to waveext on non surround inputs 2013-07-22 21:53:18 +02:00
Stefano Pigozzi c2de6fdf34 ao_coreaudio: set channel layout based on hardware query
this is a wip
2013-07-22 21:53:18 +02:00
Stefano Pigozzi 9652245ef0 ao_coreaudio: fix regression in digital stream selection
The condition was checked wrongly on asbd which is the input format
description. This lead to the condition always being true, thus selecting lpcm
streams for digital input.
2013-07-22 21:53:18 +02:00
Stefano Pigozzi e61102e637 ao_coreaudio: return errors instead false in init functions 2013-07-22 21:53:18 +02:00
Stefano Pigozzi b41fcc1e2c ao_coreaudio: remove useless function declaration 2013-07-22 21:53:18 +02:00
Stefano Pigozzi b174d647e5 ao_coreaudio: only set chmap_sel info for lpcm 2013-07-22 21:53:18 +02:00
Stefano Pigozzi 4d15f1bb60 ao_coreaudio: set channel layout bitmap 2013-07-22 21:53:18 +02:00
Stefano Pigozzi 24cad42363 ao_coreaudio: move digital detection before asbd creation 2013-07-22 21:53:18 +02:00
Stefano Pigozzi 6473cc59b1 ao_coreaudio: remove chmap selection if format is digital 2013-07-22 21:53:18 +02:00
Stefano Pigozzi 6d2f9a2804 ao_coreaudio: remove volume multiplication by 4
kHALOutputParam_Volume is the linear gain so it should be at maximum 1 to
keep the audio quality good. No idea why it was more than that.
2013-07-22 21:53:18 +02:00
Stefano Pigozzi a2d106cb31 ao_coreaudio: remove device property listener on uninit
Also extract this functionality inside a function in coreaudio_common
2013-07-22 21:53:18 +02:00
Stefano Pigozzi 7b2b292343 ao_coreaudio: print help string in one go 2013-07-22 21:53:18 +02:00
Stefano Pigozzi 5a4ae42892 ao_coreaudio: change all ++var to var++
Luckily they all were inside for loops so the functionality does not actually
change.
2013-07-22 21:53:18 +02:00
Stefano Pigozzi d3fb585b58 ao_coreaudio: change private vars names to match mpv conventions 2013-07-22 21:53:17 +02:00
Stefano Pigozzi d9c0dc7733 ao_coreaudio: remove packetSize private variable 2013-07-22 21:53:17 +02:00
Stefano Pigozzi 7d7381f9cf ao_coreaudio: refactor play/pause 2013-07-22 21:53:17 +02:00
Stefano Pigozzi d4b161f37d ao_coreaudio: refactor uninit 2013-07-22 21:53:17 +02:00
Stefano Pigozzi f392ffe95c ao_coreaudio: remove a fixme since that seems fixed 2013-07-22 21:53:17 +02:00
Stefano Pigozzi 6e44b12240 ao_coreaudio: ca_msg: add trailing \n where missing 2013-07-22 21:53:17 +02:00
Stefano Pigozzi 88425625cf ao_coreaudio: refactor play 2013-07-22 21:53:17 +02:00
Stefano Pigozzi 065e446e04 ao_coreaudio: extract mixmode set/unset in utility functions 2013-07-22 21:53:17 +02:00
Stefano Pigozzi 838fa07376 ao_coreaudio: move AudioStreamChangeFormat to common file and refactor 2013-07-22 21:53:17 +02:00
Stefano Pigozzi 40f6e2e041 ao_coreaudio: extract methods to lock/unlock device for digital output 2013-07-22 21:53:17 +02:00
Stefano Pigozzi e3ce0f0f8e ao_coreaudio: lpcm: remove buffer size calculation depending on audio unit 2013-07-22 21:53:17 +02:00
Stefano Pigozzi 1640ce3262 ao_coreaudio: refactor initialization
The initialization is split more clearly between compressed and lpcm case.
For the compressed case, format selection is simplified a lot and negotiation
removed. The way it was written it just passed back to the core the original
requested format, not what was found available on hardware.

Since this is most likely useless for the compressed case, I didn't bother
with this. In the future I'd like to split this AO in two one that only uses
the AUHAL and the other with direct access to the hardware so that even
passthrough of lcpm can be possible. This would decrease the latency,
audiophiles would like that.
2013-07-22 21:53:17 +02:00
Stefano Pigozzi f9a31bc3d9 ao_coreaudio: refactor print_help 2013-07-22 21:53:17 +02:00
Stefano Pigozzi f35f6a34b5 ao_coreaudio: split out some utility functions and refactor them
Split out some utility functions that use the CoreAudio API but are not related
the main task of the AOs (which is to move data correctly to the ringbuffer).
These are mainly need for the verbosity of the CoreAudio API and are just
obscuring the 'real' code.
2013-07-22 21:53:17 +02:00
Stefano Pigozzi dc8eb9d77a ao_coreaudio: make variable names shorter
property_address -> p_addr
2013-07-22 21:53:17 +02:00
Stefano Pigozzi 45479825ba ao_coreaudio: add error check function and macro
WIP
2013-07-22 21:53:17 +02:00
Stefano Pigozzi 3edb605172 ao_coreaudio: dry up ca_msg and use it everywhere
Change the ca_msg macro to pass along MSGT_AO automatically. Also use it for
every output for consistency.
2013-07-22 21:53:17 +02:00
Stefano Pigozzi c4bed92280 ao_coreaudio: simplify digital render callback
It was reported that it also works by not setting the read size in the
AudioBuffer (now idea how, but I will discover it later).
2013-07-22 21:53:17 +02:00
Stefano Pigozzi 8cf36cf950 ao_coreaudio: rewrite spdif render callback 2013-07-22 21:53:17 +02:00
Stefano Pigozzi d427b4fd1c ao_coreaudio: simplify render callback
Read only the requested amount by the AUHAL (instead of all the buffered data).
No idea what the deal is with pausing the audio units if there is no audio to
play, maybe to avoid underruns of some sort. Anyway from my tests this
condition never occurred so I'm removing it all.
2013-07-22 21:53:16 +02:00
Diogo Franco (Kovensky) 58338f9240 ao_wasapi: Make default on Windows.
Ahead of OSS because cygwin provides OSS.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) 1b2dc3613f ao_wasapi: Fix S/PDIF passthrough init
MSDN tells me to multiply the samplerates by 4 (for setting up the S/PDIF
signal frequency), but doesn't mention that I'm only supposed to do it
on the new, NT6.1+ IEC 61937 structs. Works on my Realtek Digital Output,
but as I can't connect any hardware to it I can't hear the result.

Also, always ask for little-endian AC3. I'm not sure if this is supposed
to be LE or NE, but Windows is LE on all platforms, so we go with LE.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) 9fe2772780 ao_wasapi: Log the passthrough format in MSGL_V 2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) a8b4be274c ao_wasapi: Also do passthrough for AF_FORMAT_MPEG2
That's the sample format ad_spdif uses when the source is MP3.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) dcf38e0190 ao_wasapi: Support S/PDIF passthrough
Entirely untested as this troper has no S/PDIF hardware.

Refuses trying any other format if we can't use passthrough, or we would
end up sending white noise at the user.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) 58e3d3f207 ao_wasapi: Fix double free on uninit
Caused by incorrect conversion to the m_option API: since we don't allocate
the state ourselves, we also don't free it ourselves.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) c62395dc09 ao_wasapi: Support loading devices by name
Do an strstr match against the device description and, if we have only
a single match, take it. This works as long as the devices in the system
don't change, but it's not supposed to be reliable; if one wants
reliability, one uses the device ID string.

Formatting.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) ad6acddbcf ao_wasapi: Don't search for devices as part of validation
This could turn valid parameters into syntax errors by the mere presence
or abscence of a device (e.g. USB audio devices), so don't do that.

We do validate that, if the parameter is an integer, it is not negative.
We also respond to the "help" parameter, which does the same as the "list"
suboption but exits after listing.

Demote the validation logging to MSGL_DBG2.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) d68fa0531f ao_wasapi: Change function macros to require semicolon after invocation
Add semicolons where they were missing.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) 964341b02d ao_wasapi: Use OPT_STRING_VALIDATE for device suboption
Validates by trying to pick the device using the device enumerator and
aborting with out of range on failure.

Refactors find_and_load_device to not use the wasapi_state; it might be
called during validation. Adds missing CoInitialize/CoUninitialize calls.
Remove unused variables (the SAFE_RELEASE macros keep them referenced so
compiler warnings don't help finding them...).

Remove the IMMDeviceEnumerator from the wasapi_state, it's only needed
during initialization and initialization is now well factored enough to
get rid of it.

Try and connect to unplugged devices as well when using the device ID
string.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) d42c3e51b4 ao_wasapi: Fully convert to m_option API 2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) 56274c6664 ao_wasapi: Don't leak the default device's ID when listing devices
Also remove unused variable.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) 32cb190855 ao_wasapi: Annotate the default device when listing devices 2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) efc3668fbe ao_wasapi: Refactor device listing/loading
Omit "{0.0.0.00000000}." on devices that start with that substring,
re-add when searching for devices by ID.

Log the device ID of the default device.

Log the friendly name of the used device.

Consistently refer to endpoints/devices as devices, as this is more
consistent with mpv terminology.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) d5adaed9d8 ao_wasapi0: Rename to ao_wasapi
Nobody knows what the 0 was for. There's no "WASAPI version 0". Just take
it out.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) 553ed6b32f ao_wasapi0: Use the mix format directly in try_mix_format 2013-07-22 02:42:37 +02:00
Diogo Franco (Kovensky) d9a1358505 ao_wasapi0: Don't complain about failed init during AO probing
Only if the user specifically asked for ao_wasapi0.
2013-07-22 02:42:37 +02:00
Diogo Franco (Kovensky) 4cf1fc678f ao_wasapi0: Don't fail init when listing devices 2013-07-22 02:42:37 +02:00
Diogo Franco (Kovensky) 0081f1facd ao_wasapi0: Demote "negotiation failed" message to MSGL_V
Could spam the console with what may be harmless in some cases. We already
complain loudly if we're stuck checking this too many times.
2013-07-22 02:42:37 +02:00
Diogo Franco (Kovensky) df1922babe ao_wasapi0: Support shared mode, better format guessing method
Uses WASAPI in shared mode by default, add :exclusive flag to choose
exclusive mode (duh). WASAPI works somewhat different in shared mode:
the OS suggests the sample format to use, and the GetBuffer call is
done slightly differently.

The shared mode driver does not consume audio as fast as it notifies
the thread; we need to check how much we're allowed to write. Not doing
this correctly results in spamming the console with
AUDCLNT_E_BUFFER_TOO_LARGE errors.

When guessing formats for exclusive mode, try several sample size and
sample rate combinations instead of just falling back to s16le@44100hz.
If none of the rates are accepted, tries remixing >6 channels to 5.1
channels. Failing that, tries remixing to stereo. Failing everything,
including the CD Red Book format, what else is left to test?

Calculate buffer_block_size based on the configured channels and bytes
per sample; MSDN docs say nBlockAlign is not guaranteed to be set for
anything but integer PCM formats.
2013-07-22 02:42:37 +02:00
Diogo Franco (Kovensky) f12e14849d ao_wasapi0: Support device enumeration and selection
Adds the :list suboption to ao_wasapi0, which enumerates the audio endpoints
in the system.

Adds the :device=<n> suboption, which either takes an ID string (as output by
list) or a device number and uses the requested device instead of the system
default.
2013-07-22 02:42:37 +02:00
wm4 15ab75c7a0 ao_dsound: use new option API 2013-07-22 00:11:06 +02:00
wm4 0c28dc6adc ao_jack: use new option API 2013-07-22 00:03:57 +02:00
wm4 ecc5cb67f8 ao_oss: switch to new option API 2013-07-21 23:52:40 +02:00
wm4 5b91ba0a8d options: remove --mixer and --mixer-channel, turn them into alsa/oss subopts
These two options were supported by ALSA and OSS only. Further, their
values were specific to the respective audio systems, so it doesn't make
sense to keep them as top-level options.
2013-07-21 23:35:14 +02:00
wm4 5c610836cd ao_rsound: use new option API
Untested. I don't even know if this compiles. I have no clue what rsound
even is.
2013-07-21 23:27:32 +02:00
wm4 12e645fc24 ao_sdl: use new option API 2013-07-21 23:27:32 +02:00
wm4 73dc678c25 ao_openal: use new option API 2013-07-21 23:27:32 +02:00
wm4 ce89ba6d75 ao_pulse: use new option API
Untested, but should be fine.
2013-07-21 23:27:31 +02:00
wm4 3cdf4cf14d options: hide encoding AO/VO in help output
These can't be used manually. Encoding is enabled with -o instead, and
the encoding AO/VO is selected using internal mechanisms.
2013-07-21 23:27:31 +02:00
wm4 2111d7bc05 ao_alsa: use new option API (changes syntax)
This changes how device names are handled. Before this commit, device
names were mangled in strange ways to avoid clashing with the option
parser syntax. "." was replaced with ",", and "=" with ":" (the user had
to do the inverse to get the correct device name).

The "new" option parser has multiple ways to escape option strings, so
we don't need this confusing hack anymore.

Add an explicit note to the manpage as well.
2013-07-21 23:27:31 +02:00
wm4 38f81c618e ao_pcm: use new option API 2013-07-21 23:27:31 +02:00
wm4 38f712d96d ao_portaudio: use new option API
This basically serves as example. All other AOs should be ported as
well.
2013-07-21 23:27:31 +02:00
wm4 7eba27c125 options: use new option code for --ao
This requires completely refactoring the AO creation code too.
2013-07-21 23:27:31 +02:00
Diogo Franco (Kovensky) d0b129971a ao_wasapi0: Don't starve the WASAPI thread on seeks
Seeking calls thread_reset, but doesn't call thread_play. thread_reset
would disable WASAPI events, but they would never get re-enabled unless
the user paused and then unpaused.

Keep track of whether the stream is paused or not (there already was a
field for that, but it was apparently unused), and if it's not paused,
call thread_play after thread_reset. Fixes mpv freezing after seeks.
2013-07-20 02:21:04 +02:00
Diogo Franco (Kovensky) 20c2947cbb ao_wasapi0: Don't release WASAPI buffer twice
Would cause bogus AUDCLNT_E_OUT_OF_ORDER errors.
2013-07-20 02:21:00 +02:00
Diogo Franco (Kovensky) 9ab73b6373 ao_wasapi0: Make it compile on cygwin64
Fixes format specifies that assume windows TYPEDEFS are as long as they look
like they are.

Remove calls to _beginthreadex and _endthreadex, these are only present on
microsoft's C runtimes. Replace by the otherwise identical CreateThread and
ExitThread calls.

This actually requires fixes to devicetopology.h, but the problem has been
(kinda) reported to mingw-w64:

<Kovensky> I see that those KSJACK* structs are supposedly declared in
  devicetopology.h itself, but for some reason (some of?) the decls that use
  them aren't seeing them?
<Kovensky> ok, it seems that it expects ks.h and ksmedia.h to declare those
  structs, but it doesn't
<Kovensky> the included files declare KDATAFORMAT, KSIDENTIFIER and LUID (and
  the associated pointer typedefs)
<Kovensky> but everything else is essentially inside #if 0
<Kovensky> changing the #ifndef _KS_ to only include KDATAFORMAT, KSIDENTIFIER
  and LUID (and putting the KSJACK stuff outside that #ifndef) makes the
  header compile
<Kovensky> it solves my immediate problem, but if that happened to begin with
  there's probably something more wrong with the ks headers :S
2013-07-20 02:20:46 +02:00
Jonathan Yong 27d352afbd ao_wasapi0: use new mp_ring buffer 2013-07-12 20:01:23 +02:00
wm4 2c732a46ba ao_jack: allow more control about channel layouts 2013-07-07 18:37:55 +02:00
wm4 886d982aa3 ao_jack: increase buffer size, always round up buffer size
This should help with github issue #128, which reported stuttering
distorted sound with 6 channel audio, but not with 2 channels.
2013-07-06 13:11:22 +02:00
Jonathan Yong a9f76c6d86 ao_wasapi0: add new wasapi event mode ao 2013-06-18 13:16:58 +02:00
wm4 16211268b4 ao_dsound: fix compilation 2013-06-16 22:19:00 +02:00
wm4 4d3a2c7e0d audio/out: remove ao->outburst/buffersize fields
The core didn't use these fields, and use of them was inconsistent
accross AOs. Some didn't use them at all. Some only set them; the values
were completely unused by the core. Some made full use of them.

Remove these fields. In places where they are still needed, make them
private AO state.

Remove the --abs option. It set the buffer size for ao_oss and ao_dsound
(being ignored by all other AOs), and was already marked as obsolete. If
it turns out that it's still needed for ao_oss or ao_dsound, their
default buffer sizes could be adjusted, and if even that doesn't help,
AO suboptions could be added in these cases.
2013-06-16 19:36:56 +02:00
wm4 f88193091b audio/out: don't require AOs to set ao->bps
Some still do, because they use the value in other places of the init
function. ao_portaudio is tricky and reads ao->bps in the stream
thread, which might be started on initialization (not sure about that,
but better safe than sorry).
2013-06-16 19:32:18 +02:00
Stefano Pigozzi c8c70dce57 audio: fix af_fmt_seconds_to_bytes
Was missing samplerate
2013-06-16 19:28:04 +02:00
wm4 b24bb7076d audio/out: remove wrapper for old AOs
It's unused now.
2013-06-16 18:33:19 +02:00
Stefano Pigozzi 953b3b3699 ao_jack: use mp_ring 2013-06-16 18:20:39 +02:00
Stefano Pigozzi c5ee7740c4 ao_portaudio: use mp_ring 2013-06-16 18:20:39 +02:00
Stefano Pigozzi bff03a181f core: add a spsc ringbuffer implementation
Currently every single AO was implementing it's own ringbuffer, many times
with slightly different semantics. This is an attempt to fix the problem.

I stole some good ideas from ao_portaudio's ringbuffer and went from there.
The main difference is this one stores wpos and rpos which are absolute
positions in an "infinite" buffer. To find the actual position for writing /
reading just apply modulo size.

The producer only modifies wpos while the consumer only modifies rpos. This
makes it pretty easy to reason about and make the operations thread safe by
using barriers (thread safety is guaranteed only in the Single-Producer/Single-
Consumer case).

Also adapted ao_coreaudio to use this ringbuffer.
2013-06-16 18:20:39 +02:00
Stefano Pigozzi b537467fd3 ao_coreaudio: fix output with spdif
The mute condition was inverted...
2013-06-16 18:20:39 +02:00
Stefano Pigozzi a66041a332 ao_coreaudio: split ringbuffer in it's own file
This is hopefully the start of something good. ca_ringbuffer_read and
ca_ringbuffer_write can probably cleaned up from all the NULL checks once
ao_coreaudio.c gets simplyfied.

Conflicts:
	audio/out/ao_coreaudio.c
2013-06-16 18:20:39 +02:00
Stefano Pigozzi 6807906177 ao_coreaudio: move to new libao API
This is just a first pass and the bare minimum to make it compile and work.
SPDIF is untested for lack of hardware.
2013-06-16 18:20:38 +02:00
Stefano Pigozzi 74eb98279a ao_coreaudio: uncrustify
uncrustify -l C -c TOOLS/uncrustify.cfg --no-backup --replace \
  audio/out/ao_coreaudio.c
2013-06-16 18:20:38 +02:00
Rudolf Polzer dcd36c79c7 encode_lavc strings: use new option syntax 2013-06-16 17:14:47 +02:00
wm4 d2d9ba326a ao_oss: fix compilation on BSD
This was overlooked with commit 32a898f, because OSS4 volume control is
typically not available on Linux. BSD does have this feature, so the
broken code broke compilation there.
2013-06-11 12:24:11 +02:00
wm4 925662b193 ao_jack: remove global variables 2013-06-07 16:42:29 +02:00
wm4 e54ab16d1a ao_jack: align data sizes on audio frame size
Fixes crashes when playing with certain numbers of channels. The core
assumes AOs accept data aligned on channels * samplesize, and ao_jack's
play() function broke that assumption:

    mpv: core/mplayer.c:2348: fill_audio_out_buffers: Assertion `played % unitsize == 0' failed.

Fix by aligning the buffer and chunk sizes as needed.
2013-06-07 15:58:28 +02:00
wm4 4e6098ed49 ao_jack: switch to new AO API 2013-06-07 15:44:49 +02:00
wm4 5dec12f525 ao_jack: uncrustify 2013-06-07 15:39:32 +02:00
wm4 6cc60710e4 ao_oss: remove duplicated format info
Instead of having two big switch statements to convert between two
audio formats, use a single table.
2013-06-07 15:30:40 +02:00
wm4 32a898ff5d ao_oss: remove global variables 2013-06-07 15:20:07 +02:00
wm4 15202ebc76 ao_oss: switch to new AO API 2013-06-07 15:05:34 +02:00
wm4 f8f4285671 ao_oss: uncrustify 2013-06-07 14:29:59 +02:00
wm4 1b6888ae8e ao_openal: switch to new AO API 2013-06-04 01:42:57 +02:00
wm4 a933cf28f2 ao_openal: uncrustify 2013-06-04 01:34:53 +02:00
reimar 774dc23ab3 ao_jack: add (no-)connect suboption
Add (no)connect option to ao_jack.

Patch by Markus Appel [masolomaster3000 googlemail com].

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@36297 b3059339-0415-0410-9bf9-f77b7e298cf2

Conflicts:
	DOCS/man/de/mplayer.1
	DOCS/man/en/mplayer.1
	audio/out/ao_jack.c
2013-06-04 01:31:20 +02:00
wm4 3725ab980c ao_dsound: remove global variables 2013-06-04 01:22:50 +02:00
wm4 8afcb84ee5 ao_dsound: switch to new AO API 2013-06-04 01:07:56 +02:00
wm4 cee56e8623 ao_dsound: uncrustify 2013-06-04 00:56:28 +02:00
wm4 f44a242258 Replace calls to usec_sleep()
This is just dumb sed replacement to mp_sleep_us().

Also remove the now unused usec_sleep() wrapper.
2013-05-26 16:44:20 +02:00
wm4 e56d8a200d Replace all calls to GetTimer()/GetTimerMS()
GetTimer() is generally replaced with mp_time_us(). Both calls return
microseconds, but the latter uses int64_t, us defined to never wrap,
and never returns 0 or negative values.

GetTimerMS() has no direct replacement. Instead the other functions are
used.

For some code, switch to mp_time_sec(), which returns the time as double
float value in seconds. The returned time is offset to program start
time, so there is enough precision left to deliver microsecond
resolution for at least 100 years. Unless it's casted to a float
(or the CPU reduces precision), which is why we still use mp_time_us()
out of paranoia in places where precision is clearly needed.

Always switch to the correct time. The whole point of the new timer
calls is that they don't wrap, and storing microseconds in unsigned int
variables would negate this.

In some cases, remove wrap-around handling for time values.
2013-05-26 16:44:20 +02:00
wm4 3546188a41 ao_alsa: always unset ALSA error handler, cleanup on init error
The ALSA device was not closed when initialization failed.

The ALSA error handler (set with snd_lib_error_set_handler()) was not
unset when closing ao_alsa. If this is not done, the handler will still
be called when other libraries using ALSA cause errors, even though
ao_alsa was long closed. Since these messages were prefixed with
"[AO_ALSA]", they were misleading and implying ao_alsa was still used.

For some reason, our error handler is still called even after doing
snd_lib_error_set_handler(NULL), which should be impossible. Checking
with the debuggers, inserting printf(), as well as the alsa-lib source
code all suggest our error handler should not be called, but it still
happens. It's a complete mystery.
2013-05-26 16:44:18 +02:00
wm4 a39d369c25 audio: fix ALSA 4 channel surround output
It turns out that ALSA's 4 channel layout is different from mpv's and
ffmpeg's 4.0 layout. Thus trying to do 4 channel output led to incorrect
remixing via lib{av,sw}resample.

Fix the default layouts for the internal filter chain as well, although
I'm not sure if it matters at all.
2013-05-13 18:27:09 +02:00
wm4 bb569b56de ao_coreaudio: fix switched parameters 2013-05-12 22:00:32 +02:00
wm4 e6e5a7b221 Merge branch 'audio_changes'
Conflicts:
	audio/out/ao_lavc.c
2013-05-12 21:47:55 +02:00
wm4 f5aec5a2a7 ao_alsa: set fallback if format unknown
The snd_pcm_hw_params_test_format() call actually crashes in alsa-lib if
called with SND_PCM_FORMAT_UNKNOWN, so the already existing fallback
code won't work in this case.
2013-05-12 21:24:57 +02:00
wm4 ecc6e379b2 audio/out: channel map selection
Make all AOs use what has been introduced in the previous commit.

Note that even AOs which can handle all possible layouts (like ao_null)
use the new functions. This might be important if in the future
ao_select_champ() possibly honors global user options about downmixing
and so on.
2013-05-12 21:24:57 +02:00
wm4 ab8f28a672 audio: add channel map selection function
The point is selecting a minimal fallback. The AOs will call this
through the AO API, so it will be possible to add options affecting
the general channel layout selection.

It provides the following mechanism to AOs:
- forcing the correct channel order
- downmixing to stereo if no layout is available
- allow 5.1 <-> 5.1(side) fallback
- handling "unknown" channel layouts

This is quite weak and lots of code/complexity for little gain. All AOs
already made sure the channel order was correct, and the fallback is of
little value, and could perhaps be done in the frontend instead, like
stereo downmixing with --channels=2 is handled. But I'm not really sure
how this stuff should _really_ work, and the new code will hopefully
provides enough flexibility to make radical changes to channel layout
negotiation easier.
2013-05-12 21:24:57 +02:00
wm4 34a139d495 ao_pulse: move format setup code 2013-05-12 21:24:57 +02:00
wm4 20a1d0bc5b ao_openal: use channel map instead of ALSA fixed layout
Now mpv's channel map is used to map each channel to a speaker. This
allows in theory for playback of any layout for which ao_openal
actually has a speaker defined. Also add the back-center (BC) speaker,
which allows playback of 6.0 audio. Enabling more layouts by adding
other speakers would be possible, but I'm not sure about the speaker
positions.
2013-05-12 21:24:56 +02:00
wm4 ce2515ddb8 ao: remove ao_driver.is_new field
Is unused, is completely pointless.
2013-05-12 21:24:56 +02:00
wm4 56c295e2ca ao_alsa: remove global variables 2013-05-12 21:24:56 +02:00
wm4 e1207f2ceb ao_alsa: switch to new AO API 2013-05-12 21:24:56 +02:00
wm4 bc03eb0295 ao_alsa: map to exact channel layout
This allows supporting 5 channel audio (which can be eother 5.0 or 4.1).

Fallback doesn't work yet. It will do nonsense if the channel layout
doesn't match perfectly, even though it's similar.
2013-05-12 21:24:56 +02:00
wm4 7828048d65 ao_alsa: move format lookup into separate function 2013-05-12 21:24:56 +02:00
wm4 c6076b5de5 ao_alsa: more reformat 2013-05-12 21:24:56 +02:00
wm4 d2e5b50041 ao_alsa: cosmetics, macro-fy error reporting
Add a CHECK_ALSA_ERROR macro to report ALSA errors. This is similar to
what vo_vdpau does. This removes lots of boiler plate, it almost gives
me the feeling the ao_alsa initialization code is now readable. This
change is squashed with the reformatting, because both changes are
just as noisy and useless.
2013-05-12 21:24:55 +02:00
wm4 7f0f33fc8f ao_alsa: uncrustify 2013-05-12 21:24:55 +02:00
wm4 ade08d676f ao_coreaudio: switch to WAVEEXT channel order
This used ALSA order, which was not correct. Most likely this has been
wrong since forever.
2013-05-12 21:24:55 +02:00
wm4 bf014677ce ao_pulse: try to set correct channel layout
Like most other AOs, ao_pulse set the channel count only, always using a
default layout. Try to set the exact layout.

For this, we need a big lookup table to map waveex/lavc/mpv speaker
position to PulseAudio's, since PA_CHANNEL_POSITION_ is apparently not
compatible to waveext, and I haven't seen any API functions that would
help mapping them.

Completely untested. (Let's leave that to someone else...)
2013-05-12 21:24:55 +02:00
wm4 aea2328906 audio/out: switch to channel map
This actually breaks audio for 5/6/8 channels. There's no reordering
done yet. The actual reordering will be done inside of af_lavrresample
and has to be made part of the format negotiation.
2013-05-12 21:24:54 +02:00
wm4 f7a427676c audio: add some setters for mp_audio, and require filters to use them
mp_audio has some redundant fields. Setters like mp_audio_set_format()
initialize these properly.

Also move the mp_audio struct to a the file audio.c.

We can remove a mysterious line of code from af.c:

    in.format |= af_bits2fmt(in.bps * 8);

I'm not sure if this was ever actually needed, or if it was some kind of
"make it work" quick-fix that works against the way things were supposed
to work. All filters etc. now set the format correctly, so if there ever
was a need for this code, it's definitely gone.
2013-05-12 21:24:54 +02:00
Stefano Pigozzi afdc9c4ae2 OSX: use native Cocoa's event loop
Schedule mpv's playloop as a high frequency timer inside the main Cocoa event
loop. This has the benefit to allow accessing menus as well as resizing the
window without the playback being blocked and allows to remove countless hacks
from the code that involved manually pumping the event loop as well simulating
manually some of the Cocoa default behaviours.

A huge improvement consists in removing NSApplicationLoad. This is a C function
defined in the Cocoa header and implements a minimal OSX application under ther
hood so that you can use the Cocoa GUI toolkit from C/C++ without having to
respect the Cocoa standards in terms of application initialization. This was
bad because the behaviour implemented by NSApplicationLoad was hard to customize
and had several gotchas especially in the menu department.

mpv was changed to be just a nib-less application. All the Cocoa part is still
generated in code but the event handling is now not dissimilar to what is
present in a stock Mac application.

As a part of reviewing the initialization process, I also removed all of
`osdep/macosx_finder_args`. The useful parts of the code were moved to
`osdep/macosx_appication` which has the broaded responsibility of managing the
full lifecycle of the Cocoa application. By consequence the
`--enable-macosx-finder` configure switch was killed as well, as this feature
is always enabled.

Another change the users will notice is that when using a bundle the `--quiet`
option will be inserted much earlier in the initializaion process. This results
in mpv not spamming mpv.log anymore with all the initialization outputs.
2013-05-12 15:27:54 +02:00
Rudolf Polzer 2d8783075f encoding: fix final audio frame sync
When --ocopyts was used, the final audio frame got improper pts. Fixed
by now using the play() logic to play the final frame too.
2013-04-28 11:39:38 +02:00
wm4 41aefce730 audio: switch to libavcodec channel order, use libavresample for mixing
Switch the internal channel order to libavcodec's. If the channel number
mismatches at some point, use libavresample for up- or downmixing.
Remove the old af_pan automatic downmixing.

The libavcodec channel order should be equivalent to WAVEFORMATEX order,
at least nowadays. reorder_ch.h assumes that WAVEFORMATEX and libavcodec
might be different, but all defined channels have the same mappings.

Remove the downmixing with af_pan as well as the channel conversion with
af_channels from af.c, and prefer af_lavrresample for this. The
automatic downmixing behavior should be the same as before (if the
--channels option is set to 2, which is the default, the audio output
is forced to 2 channels, and libavresample does all downmixing).

Note that mpv still can't do channel layouts. It will pick the default
channel layout according to the channel count. This will be fixed later
by passing down the channel layout as well.

af_hrtf depends on the order of the input channels, so reorder to ALSA
(for which this code was written). This is better than changing the
filter code, which is more risky.

ao_pulse can accept waveext order directly, so set that as channel
mapping.
2013-04-13 04:21:28 +02:00
wm4 f54909d4df ao_alsa: reorder channels from internal to alsa order
Currently, internal and alsa order are exactly the same, so this will do
absolutely nothing.
2013-04-13 04:21:28 +02:00
Stefano Pigozzi ed48c657ee ao_jack: fix deprecation warning
jack_port_get_total_latency is deprecated: use the "new" API based on
jack_port_get_latency_range instead.
2013-04-12 00:10:39 +02:00
Kovensky 16b15885ff ao_dsound: add missing include
libavutil/common.h is needed for FF_ARRAY_ELEMS.
2013-03-23 21:04:27 +01:00
wm4 4d016a92c8 core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)

The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)

demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.

Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.

Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-10 17:25:56 +01:00
wm4 ae070a6f1e audio/out, video/out: hide encoding VO/AO
mpv -ao help and mpv -vo help shouldn't show the encoding outputs (named
"lavc" on both cases). Also make it impossible to select these manually
when not encoding.
2013-02-06 23:04:18 +01:00
wm4 13d97077ec audio/out: prefer ao_dsound over ao_portaudio
On Linux, ao_portaudio has weird freezing issues (possibly specific to
the ALSA backend, though). Also ao_dsound is more likely to get multi-
channel audio output right, and ao_portaudio probably mangles these.
2013-02-06 23:04:18 +01:00
wm4 7a6d26370c mixer: prefer AO softvol control over volume filter
This partially reverts earlier decisions, when I thought it would
always be better to prefer the audio volume filter over the AO's,
because the AO's relies on the underlying audio-API, which could
be broken or exhibit unusual behavior (like it happened with ao_dsound).

However, since the audio buffer can be quite large (500 ms), and we
don't attempt to flush & refilter the audio on volume changes, always
prefer AO volume control (as long as the AO mixer doesn't control the
system mixer).

Also document what the mixer.c related AO fields mean (hopefully not
too brief).
2013-02-06 23:04:18 +01:00
wm4 94f72b1e59 ao_dsound: support 6.1 and 7.1 channel configurations
Instead of doing the channel reordering manually, use the existing
support in reorder_ch.c.

Untested.
2013-02-06 23:04:12 +01:00
Mad Fish 5b7327920b ao_coreaudio: use 0 as timeout for CFRunLoopRunInMode
Handle all pending events and exit instead of waiting. When there are lots of
input events (for example, scrolling with trackpad), timeout can add up
to make a huge frame delay. In my tests, if I scroll fast enough, that loop
would never exit.
2013-01-20 16:37:30 +01:00
wm4 9b3bf76d27 ao_alsa: do not call snd_pcm_delay() when paused
This causes trouble when a hw device is used:

    pcm_hw.c:514:(snd_pcm_hw_delay) SNDRV_PCM_IOCTL_DELAY failed (-77): File descriptor in bad state

when running mpv test.mkv --ao=alsa:device=iec958,alsa and pausing
during playback.

Historically, mplayer usually did not call snd_pcm_delay() (which is
called by get_delay()) while paused, so this problem never showed up.
But at least mpv has changes that cause get_delay() to be called when
updating the status line (see commit 3f949cf).

It's possible that calling snd_pcm_delay() is not always legal when the
audio is paused, and at least fails with the error message mentioned
above is the device is a hardware device. Change get_delay() to return
the last delay before the audio was paused. The intention is to get a
continuous playback status display, even when pausing or frame stepping,
otherwise we could just return the audio buffer fill status in
get_delay() or even just 0 when paused.
2013-01-06 19:28:08 +01:00
wm4 fe8d3e70b2 ao_sdl: fix compilation with Libav
On Libav, <libavutil/fifo.h> doesn't recursively include common.h, but
the code in ao_sdl.c uses some macros defined by this header.
2013-01-06 16:04:17 +01:00
Rudolf Polzer 6be50fa773 sdl, encode_lavc: fix copyright headers
Some of them had changes in 2012; extend their header.

Fix project name.
2012-12-28 11:41:30 +01:00
Rudolf Polzer c3cc38e4c4 vo/ao: SDL 1.2+ audio driver, SDL 2.0+ accelerated video driver
This mainly serves as a fallback for platforms where nothing better is
available; also as a debugging help. Both the audio and video driver are
not first class - the audio driver lacks delay detection, and the video
driver only supports a single YUV color space.

Configure options: --disable-sdl2 to disable SDL 2.0+ detection,
--disable-sdl to disable SDL 1.2+ detection. Both options need to be
specified to turn off SDL support entirely.
2012-12-28 08:40:28 +01:00
Rudolf Polzer 925c3af928 ao_lavc: stop using av_get_alt_sample_fmt
Use av_get_planar_sample_fmt instead.
2012-12-13 12:58:16 +01:00
wm4 b0558e48b1 cleanup: remove ao.brokenpts
This field was used by ao_v4l2, and is now unused.
2012-12-12 23:05:57 +01:00