summaryrefslogtreecommitdiffstats
path: root/audio
Commit message (Collapse)AuthorAgeFilesLines
* audio: preallocate audio buffers on resizewm42014-04-181-2/+7
| | | | | | This avoids too many realloc() calls if the caller is appending to an audo buffer. This case is actually quite noticeable when using something that buffers a large amount of audio.
* player: unrangle one aspect of audio EOF handlingwm42014-04-173-5/+11
| | | | | | | | | | | | | | | | | | 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.)
* audio: add hack against broken pulseaudio EOF conditionwm42014-04-171-1/+16
| | | | | | | | | | | | 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.
* audio: explicitly document audio EOF conditionwm42014-04-171-0/+5
| | | | | | 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.
* ao_null: add simulated device latency, simulate EOF problemswm42014-04-171-3/+19
| | | | | This EOF problems happen at least with PulseAudio, but since it's hard to reproduce, let ao_null optionally simulate it.
* player: add a --dump-stats optionwm42014-04-171-5/+6
| | | | | | | | | | | | | | | | | | | | | | | This collects statistics and other things. The option dumps raw data into a file. A script to visualize this data is included too. Litter some of the player code with calls that generate these statistics. In general, this will be helpful to debug timing dependent issues, such as A/V sync problems. Normally, one could argue that this is the task of a real profiler, but then we'd have a hard time to include extra information like audio/video PTS differences. We could also just hardcode all statistics collection and processing in the player code, but then we'd end up with something like mplayer's status line, which was cluttered and required a centralized approach (i.e. getting the data to the status line; so it was all in mplayer.c). Some players can visualize such statistics on OSD, but that sounds even more complicated. So the approach added with this commit sounds sensible. The stats-conv.py script is rather primitive at the moment and its output is semi-ugly. It uses matplotlib, so it could probably be extended to do a lot, so it's not a dead-end.
* ao: remove redundant get_delay checkwm42014-04-171-4/+0
| | | | It did nothing; the real check is in push.c.
* af_lavcac3enc: detach on any passthrough format, not just ac3wm42014-04-161-1/+1
|
* audio: wake up the core when audio buffer is running low (2)wm42014-04-151-2/+9
| | | | | | | | | | | | | | 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.
* ao_pulse: use ao_need_data()wm42014-04-151-2/+2
| | | | | | | | | 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).
* audio: wake up the core when audio buffer is running lowwm42014-04-152-15/+61
| | | | | | | | | | | | | | | | | 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.
* Kill all tabswm42014-04-1321-524/+524
| | | | | | | | | | | I hate tabs. This replaces all tabs in all source files with spaces. The only exception is old-makefile. The replacement was made by running the GNU coreutils "expand" command on every file. Since the replacement was automatic, it's possible that some formatting was destroyed (but perhaps only if it was assuming that the end of a tab does not correspond to aligning the end to multiples of 8 spaces).
* af_volume: fix clang -Wsometimes-uninitializedKevin Mitchell2014-04-131-1/+1
|
* af_lavfi: fix graph parse deprecation warningKevin Mitchell2014-04-131-1/+1
|
* encode: add a missing \n to a log callwm42014-04-101-1/+1
|
* demux: move metadata-based replaygain decoding out of af_volumeAlessandro Ghedini2014-04-041-80/+9
|
* af_volume: use replaygain side dataAlessandro Ghedini2014-04-041-7/+19
|
* af: add replaygain_data field to af_stream and af_instanceAlessandro Ghedini2014-04-044-0/+6
| | | | Closes #664
* ao_wasapi: make code shorterwm42014-03-301-65/+36
| | | | | | | | | 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
* af_volume: fix replaygainwm42014-03-271-2/+3
| | | | | | | | This was accidentally broken in commit b72ba3f7. I somehow made the wild assumption that replaygain adjusted the volume relative to 0% instead of 100%. The detach suboption was similarly broken.
* af_lavcac3enc: use new AVFrame APIwm42014-03-161-3/+3
|
* ao_lavc: set AVFrame.formatwm42014-03-161-0/+1
| | | | | Seems kind of wrong that this wasn't done, although it didn't have any bad consequences.
* encode: use new AVFrame APIwm42014-03-161-5/+3
|
* ad_lavc: use new AVFrame APIwm42014-03-161-2/+4
| | | | | | | Set refcounted_frames, because in some versions of libavcodec mixing the new AVFrame API and non-refcounted decoding could cause memory corruption. Likewise, it's probably still required to unref a frame before calling the decoder.
* build: simplify libavfilter configure checkswm42014-03-161-1/+1
| | | | | This is all not needed anymore. In particular, remove all configure switches except --enable-libavfilter.
* Remove some more unneeded version checkswm42014-03-161-13/+3
| | | | | All of these check against things that happened before the latest supported FFmpeg/Libav release.
* ad_lavc: remove deprecated downmixing by channel countwm42014-03-161-4/+0
| | | | | Downmixing by channel layout now hopefully works with all supported libavcodec versions.
* ao_dsound: remove duplicated codewm42014-03-161-17/+6
|
* af_lavrresample: remove avresample_set_channel_mapping() fallbackswm42014-03-166-135/+0
| | | | | | | This function is now always available. Also remove includes of reorder_ch.h from some AOs (these are just old relicts).
* options: fix off-by-1 error in option help outputwm42014-03-151-1/+1
|
* ao: print (estimated) device buffer size on init in verbose modewm42014-03-141-1/+3
|
* af_volume: don't print missing replaygain tags as errorwm42014-03-141-1/+1
| | | | There's no reason to. Audio files often lack them.
* af_volume: add detach optionwm42014-03-141-0/+4
| | | | | | Maybe this should be default. On the other hand, this filter does something even if the volume is neutral: it clips samples against the allowed range, should the decoder or a previous filter output garbage.
* af_volume: separate softvol volume control from replaygain levelwm42014-03-141-5/+8
| | | | | | | | | Currently, both replaygain adjustment and user volume control (if softvol is enabled) share the same variable. Sharing the variable would cause especially if --volume is used; then the replaygain volume would always be overwritten. Now both gain values are simple added right before doing filtering.
* af_volume: remove double-negated suboptionwm42014-03-141-3/+3
| | | | | You had to use "no-replaygain-noclip" to set this option. Rename it, so that only one negation is needed.
* af_volume: add support for replaygain pre-amp and clipping preventionAlessandro Ghedini2014-03-131-11/+74
|
* af_volume: add replaygain supportAlessandro Ghedini2014-03-131-0/+22
| | | | | | | | | This adds the options replaygain-track and replaygain-album. If either is set, the replaygain track or album gain will be automatically read from the track metadata and the volume adjusted accordingly. This only supports reading REPLAYGAIN_(TRACK|ALBUM)_GAIN tags. Other formats like LAME's info header would probably require support from libav.
* af: add metadata field to af_stream and af_instanceAlessandro Ghedini2014-03-134-0/+7
| | | | | | This allows to propagate metadata information to audio filters. Closes #632
* af_lavfi: beat it into working with Libavwm42014-03-131-23/+39
| | | | | | | | | | | | | | | | | | | The main incompatibility was that Libav didn't have av_opt_set_int_list. But since that function is excessively ugly and idiotic (look how it handles types), I'm not missing it much. Use an aformat filter instead to handle the functionality that was indirectly provided by it. This is similar to how vf_lavfi works. The other incompatibility was channel handling. Libav consistently uses channel layouts only, why ffmpeg still requires messing with channel counts to some degree. Get rid of most channel count uses (and hope channel layouts are "exact" enough). Only in one case FFmpeg fails with a runtime check if we feed it AVFrames with channel count unset. Another issue were AVFrame accessor functions. FFmpeg introduced these for ABI compatibility with Libav. I refuse to use them, and it's not my problem if FFmpeg doesn't manage to provide a stable ABI for fields provided both by FFmpeg and Libav.
* ao_wasapi: Use the character set conversion functions from io.hDiogo Franco (Kovensky)2014-03-112-37/+19
| | | | | ...rather than rolling out our own. The only possible advantage is that the "custom" ones didn't use talloc.
* ao_wasapi: Implement AOCONTROL_UPDATE_STREAM_TITLEDiogo Franco (Kovensky)2014-03-113-34/+89
|
* ao_wasapi: Implement per-application mixingDiogo Franco (Kovensky)2014-03-113-16/+95
| | | | | | | | | | | | | 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.
* ao_wasapi: Move non-critical code outside of the event threadDiogo Franco (Kovensky)2014-03-114-271/+203
| | | | | | | | | | | | | | | 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.
* ao_wasapi: Split into 2 filesDiogo Franco (Kovensky)2014-03-114-900/+1030
| | | | | | 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.
* ao_wasapi: Initial conversion to the new pull modelDiogo Franco (Kovensky)2014-03-111-154/+73
| | | | | | | | | 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.
* ao_sdl: make sure our buffer is always larger than what SDL requestswm42014-03-101-0/+6
| | | | | | | | | 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.
* ao_alsa: reduce default buffer sizewm42014-03-101-1/+1
| | | | | | | | | | 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.
* ao_alsa: fix return value for volume operations with spdifwm42014-03-101-1/+1
| | | | | | | | | | | 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.
* audio/out: reduce amount of audio bufferingwm42014-03-103-5/+19
| | | | | | | | | | | | | | | | | | | | | | | | | 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.
* ao_alsa: remove unneeded initializationswm42014-03-091-6/+0
| | | | priv is 0-initialized, can_pause is always overwritten later.
* ao_alsa: check ALSA PCM state before pause and resumefoo862014-03-091-5/+9
| | | | | | | | | | 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>
* ao_wasapi: Use double math for QueryPerformanceCounter correctionDiogo Franco (Kovensky)2014-03-091-2/+2
| | | | | | 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.
* ao_rsound: pass correct data type to rsd_set_param()Hans-Kristian Arntzen2014-03-091-2/+2
| | | | Signed-off-by: wm4 <wm4@nowhere>
* ao_sdl: use new pull API helperswm42014-03-091-165/+15
| | | | | | | | | | | | | | | | | | | | | 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.
* audio/out: make draining a separate operationwm42014-03-0920-79/+114
| | | | | | | | | | | | 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.
* ao_portaudio: use new pull API helperswm42014-03-091-147/+13
| | | | | | 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.
* ao_jack: use new pull API helperswm42014-03-091-196/+16
| | | | | | | | | | | 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.
* audio/out: feed AOs from a separate threadwm42014-03-095-31/+589
| | | | | | | | | | | | | | | | | | 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.
* encode: add lockingwm42014-03-091-4/+19
| | | | | | | | | | 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.
* ao_null: add option for simulated device speedwm42014-03-091-2/+8
| | | | Helps with testing and debugging.
* ao: remove opts fieldwm42014-03-092-2/+0
| | | | Apparently unused.
* audio/out: make ao struct opaquewm42014-03-0921-66/+147
| | | | | | We want to move the AO to its own thread. There's no technical reason for making the ao