summaryrefslogtreecommitdiffstats
path: root/audio
Commit message (Collapse)AuthorAgeFilesLines
* Remove some mp_msg calls with no trailing \nwm42014-07-131-6/+6
| | | | | | | The final goal is all mp_msg calls produce complete lines. We want this because otherwise, race conditions could corrupt the terminal output, and it's inconvenient for the client API too. This commit works towards this goal. There's still code that has this not fixed yet, though.
* 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.
* build: deal with endian messwm42014-07-101-1/+1
| | | | | | | | | | | | | | | | | | | | There is no standard mechanism for detecting endianess. Doing it at compile time in a portable way is probably hard. Doing it properly with a configure check is probably hard too. Using the endian definitions in <sys/types.h> (usually includes <endian.h>, which is not available everywhere) works under circumstances, but the previous commit broke it on OSX. Ideally all code should be endian dependent, but that is not possible due to the dependencies (such as FFmpeg, some video output APIs, some audio output APIs). Create a header osdep/endian.h, which contains various fallbacks. Note that the last fallback uses libavutil; however, it's not clear whether AV_HAVE_BIGENDIAN is a public symbol, or whether including <libavutil/bswap.h> really makes it visible. And in fact we don't want to pollute the namespace with libavutil definitions either. Thus it's only the last fallback.
* 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.)
* af_volume: fix calculations including replay-gainMohammad Alsaleh2014-06-281-2/+2
| | | | | | | | | | | | | rgain is not an additive value. It's a multiplier/gain. Previous behaviour produced negative level values in some cases (when rgain < 1.0) which caused volume to be louder when its value was lowered. CC: @mpv-player/stable Signed-off-by: Mohammad Alsaleh <CE.Mohammad.AlSaleh@gmail.com> Signed-off-by: wm4 <wm4@nowhere>
* 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.
* ad_lavc: make option struct localwm42014-06-111-9/+23
| | | | Similar to previous commit.
* Add more constwm42014-06-1130-68/+68
| | | | | | | 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.
* player: show "neutral" position markers for OSD barswm42014-06-082-0/+7
| | | | This commit implements them for volume and some video properties.
* 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.
* player: hide audio/video codec and file format messageswm42014-05-311-2/+1
| | | | | None of these are very important usually. For error analysis, the plain log is useless anyway, and this information is still printed with "-v".
* 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.
* ad_lavc: don't overwrite lavc bitrateMarcoen Hirschberg2014-05-281-2/+3
| | | | | If the bitrate is already known in avcodec there is no need to overwrite it again with the value from sh_audio.
* 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-2811-20/+26
| | | | | | 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.
* audio: rename i_bps to 'bitrate' to avoid confusionMarcoen Hirschberg2014-05-283-6/+6
| | | | Since i_bps now contains bits/sec, rename it to reflect this change.
* audio: change values from bytes-per-second to bits-per-secondMarcoen Hirschberg2014-05-282-8/+10
| | | | | | | The i_bps members of the sh_audio and dev_video structs are mostly used for displaying the average audio and video bitrates. Keeping them in bits-per-second avoids truncating them to bytes-per-second and changing them back lateron.
* 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.)
* mixer: make code more readablewm42014-05-111-7/+3
| | | | | You wouldn't have guessed that the bottom-most "level[i] = 0.f;" line was actually required. It even confused cppcheck.
* 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.
* chmap_sel: add channel replacement for sl/sr <-> sdl/sdrStefano Pigozzi2014-05-101-16/+21
| | | | | This can be use useful for the 7.1 rear layout. In particular it looks like OS X likes to use sdl/sdr as opposed to sl/sr.
* 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.
* mixer: don't restore volume with different --softvol-max settingswm42014-05-061-8/+11
| | | | | | | | | | | Changing --softvol-max and then resuming would change the volume level on resume to something different than the original volume. This is because the user volume setting is always between 0-100, and 100 corresponds to --softvol-max gain. Avoid that changing -softvol-max and resuming an older file could lead to a too loud volume level by refusing to restore if --softvol-max changed.
* 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.
* options: remove deprecated --identifyMartin Herkt2014-05-041-3/+0
| | | | | | | Also remove MSGL_SMODE and friends. Note: The indent in options.rst was added to work around a bug in ReportLab that causes the PDF manual build to fail.
* ao_coreaudio: log even more info in verbose modeStefano Pigozzi2014-04-241-5/