summaryrefslogtreecommitdiffstats
path: root/audio/out
Commit message (Collapse)AuthorAgeFilesLines
* ao_dsound: reduce default buffer sizewm42014-08-081-1/+1
| | | | | | Reduce from 1000ms to 100ms. Since there is an audio thread updating AOs quickly enough now, requesting such a large buffer size makes no sense anymore.
* ao_alsa: disable use of non-interleaved formats by defaultwm42014-07-301-0/+6
| | | | | | | | Some ALSA plugins take non-interleaved audio, but treat it as interleaved, which results in various funny bugs. Users keep hitting this issue, and it just doesn't seem worth the trouble. CC: @mpv-player/stable
* ao_pulse: allow disabling timing bug workaroundswm42014-07-261-3/+38
| | | | | | | | | | | | | | | | Add an option that enables using native PulseAudio auto-updated timing information, instead of the manual calculations added in mplayer2 times. You can use --ao=pulse:no-latency-hacks to enable the new code. The code is almost the same as the code that was removed with commit de435ed5, but I didn't readd some bits I didn't understand. Likewise, the option will disable the code added with that commit. In my tests this seemed to work well, though the A/V sync display looks funny when seeking. The default is still the old behavior. See issue #959.
* ao_pulse: remove hacks for ancient PulseAudio versionswm42014-07-261-21/+0
| | | | | | | | | | | This was needed by very old (0.9) versions only. Get rid of it. Unfortunately, I can't cross-check with the original bug report, since the bug URL leads to this: Internal Server Error TracError: IOError: [Errno 2] No such file or directory: '/home/lennart/svn/trac/pulseaudio/VERSION'
* ao_null: never fail at initializationwm42014-07-261-1/+1
| | | | | | | | | ao_null is used to stop autoprobing (if all AOs before fail to init). After it come things like ao_pcm, which should never be automatically selected. Remove a certain theoretically possible failure case, and force "some" fallback.
* audio/out: fix initialization failure with win32wm42014-07-261-2/+1
| | | | | | | mp_make_wakeup_pipe() always fails on win32. If this call fails on Linux (and e.g. ao_alsa is used), this will probably burn CPU since poll() won't work on the invalid file descriptor, but whatever, the failure case is obscure enough.
* audio, client API: check mp_make_wakeup_pipe() return valuewm42014-07-251-5/+7
| | | | Could fail e.g. due to FD exhaustion.
* encode: deal even more with codec->time_base deprecation.Rudolf Polzer2014-07-231-6/+5
| | | | I assume this works too with Libav 10 and FFmpeg d3e51b41.
* ao_pulse: fix potential compilation problemwm42014-07-221-2/+2
| | | | | | It seems at least on some platforms (OSX 10.9), the POSIX wait() function becomes visible, and conflicts with this unrelated function. Just rename it.
* ao_lavc: Fix design of audio pts handling.Rudolf Polzer2014-07-161-2/+5
| | | | | | | | | 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).
* ao_lavc: Add a missing newline for the log.Rudolf Polzer2014-07-161-1/+1
|
* ao_lavc: Fix advancing of audio pts.Rudolf Polzer2014-07-161-1/+1
|
* audio: don't wait for draining if pausedwm42014-07-134-15/+16
| | | | | | | | | | | | | 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
* build: include <strings.h> for strcasecmp()wm42014-07-101-0/+1
| | | | | | | 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.
* ao_null: disable latency emulationwm42014-07-071-1/+0
| | | | | | | | | 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
* ao_pulse: set icon nameatomnuker2014-07-051-0/+2
| | | | Will replace the generic XDG video icon inherited from media role.
* ao_coreaudio: report hardware latency to ao_read_dataStefano Pigozzi2014-07-032-3/+43
| | | | | Commit a6a4cd2c88 added reporting of playout latency, this commit also adds support for reporting hardware and constant audio unit latency.
* ao_coreaudio: report latency more correctlyStefano Pigozzi2014-07-021-1/+19
| | | | | | | | | | 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.
* ao_coreaudio: move channel mapping away from utilsStefano Pigozzi2014-07-023-126/+128
| | | | | Channel mapping functions are only used in the AUHAL based coreaudio, so move them there.
* ao_coreaudio: use mpv's internal pull APIStefano Pigozzi2014-07-021-82/+9
|
* ao_coreaudio: remove useless commentsStefano Pigozzi2014-07-021-5/+3
|
* ao_coreaudio: rename init_lpcm -> init_audiounitStefano Pigozzi2014-07-021-6/+9
|
* ao_coreaudio: fill asbd with an helper functionStefano Pigozzi2014-07-024-39/+29
|
* ao_coreaudio: split control to helper functionsStefano Pigozzi2014-07-021-23/+30
|
* ao_coreaudio: move device related functions to the new AOStefano Pigozzi2014-07-023-277/+255
|
* ao_coreaudio: remove useless call to print_asbdStefano Pigozzi2014-07-022-4/+0
|
* ao_coreaudio: move spdif code to a new AOStefano Pigozzi2014-07-025-433/+595
| | | | | | | | | | | | | | | | 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.
* Audit and replace all ctype.h useswm42014-07-012-3/+2
| | | | | | | | | | | | | | | | 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.)
* ao_pcm: fix message stringsAmos Onn2014-06-151-2/+2
| | | | Signed-off-by: wm4 <wm4@nowhere>
* encode: get rid of the recursion that led to a deadlock.Rudolf Polzer2014-06-121-23/+28
| | | | | Instead, the recursive call has been flattened away by instead overwriting a parameter and continuing.
* audio: more detailed debugging outputwm42014-06-121-0/+2
| | | | Dump what the AO does on driver->play().
* audio: don't wait when draining and pausedwm42014-06-121-1/+1
| | | | | A corner case that could possibly lead to infinite waiting. Though I'm not aware that this actually happened in practice.
* Add more constwm42014-06-112-3/+3
| | | | | | | 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.
* audio/out/push: don't attempt to fill AO buffer when pausedwm42014-06-031-2/+3
| | | | Doing so will implicitly resume playback. Broken in commit 5929dc45.
* audio: prefer dsound over wasapiwm42014-06-011-3/+3
| | | | | 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.
* ao_alsa: make device the first sub optionwm42014-05-311-1/+1
| | | | This is more convenient.
* audio/out/push: keep some extra bufferwm42014-05-311-6/+4
| | | | | | | | | | | | | | | | | | | 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.
* ao_alsa: reduce spurious wakeupswm42014-05-302-10/+18
| | | | | | 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.
* audio/out/push: handle draining correctlywm42014-05-301-7/+22
| | | | | | | | | 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.
* audio: change handling of an EOF corner casewm42014-05-301-5/+9
| | | | | | 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.
* ao_alsa: use poll() to wait for devicewm42014-05-301-0/+30
| | | | | This means the audio feed thread is woken up exactly at the time new data is needed, instead of using a time-based heuristic.
* audio/out/push: add a way to wait for the audio device with poll()wm42014-05-302-3/+68
| | | | Will be used for ALSA.
* audio/out/push: add mechanism for event-based waitingwm42014-05-303-76/+143
| | | | | | | | | | | | | | | | 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).
* audio/out: adjust documentation commentswm42014-05-301-11/+19
|
* audio/out/pull: remove race conditionswm42014-05-296-57/+68
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* ao_wasapi: simplify nAvgBytesPerSec calculationMarcoen Hirschberg2014-05-281-4/+3
| | | | | Calculate nBlockAlign seperately to reuse in the calculation of nAvgBytesPerSec.
* af_fmt2bits: change to af_fmt2bps (bytes/sample) where appropriateMarcoen Hirschberg2014-05-286-9/+9
| | | | | | 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.
* atomics: switch to C11 stdatomic.hwm42014-05-214-35/+24
| | | | | | | | | | | | | | | | | | | | | | | | | 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.
* threads: use mpv time for mpthread_cond_timedwait wrapperwm42014-05-181-1/+1
| | | | | | 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.
* audio/out: fix previous commitwm42014-05-111-9/+11
| | | | | | | | | 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.)
* audio/out: avoid wakeup feedback loopwm42014-05-111-2/+7
| | | | | | | | | | | | | 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.)
* audio/out: more debugging info for --dump-statswm42014-05-111-1/+5
|
* ao_coreaudio: skip unknown channel labelsStefano Pigozzi2014-05-101-0/+2
| | | | | | | | | | | | | 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
* ao_coreaudio: remove useless codeStefano Pigozzi2014-05-101-15/+0
| | | | | This code doesn't actually makes much of a difference, and the AudioUnit mostly wants layout tags anyway.
* ao_coreaudio: don't fallback to full waveextStefano Pigozzi2014-05-101-4/+5
| | | | | | 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.
* ao_coreaudio: cosmetic change of loop ending conditionStefano Pigozzi2014-05-101-1/+1
|
* ao_coreaudio: print an error when channel mapping failsStefano Pigozzi2014-05-101-1/+5
|
* ao_coreaudio: use description-based channel layoutsStefano Pigozzi2014-05-103-89/+54
| | | | | | | | | | | | 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.
* ao_coreaudio: pass layout by reference to logging functionStefano Pigozzi2014-05-101-7/+7
| | | | | Apparently passing the struct by value somehow messed with the value of some fields.
* encode: fix PTS unit mismatchwm42014-05-101-5/+5
| | | | | | 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.
* audio: fix the exact value that is used for the wait timewm42014-05-041-3/+2
| | | | | | | | | 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.
* ao_null: fix unit mismatch with latency optionwm42014-05-041-5/+8
| | | | It's in seconds, but the code used it as sample count.
* ao_coreaudio: log even more info in verbose modeStefano Pigozzi2014-04-241-5/+27
| | | | |