summaryrefslogtreecommitdiffstats
path: root/audio
Commit message (Collapse)AuthorAgeFilesLines
* 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 struct opaque to do this. But it helps us sleep at night, because we can control access to shared state better.
* encode: don't access ao->ptswm42014-03-071-1/+4
| | | | | | | | | | 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.
* ao_wasapi: Slightly improve timer accuracyDiogo Franco (Kovensky)2014-03-061-3/+12
| | | | | | | | | | | 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.
* ao_wasapi: Add device latency to get_delayDiogo Franco (Kovensky)2014-03-061-4/+78
| | | | | | | | | | | 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.
* ao_jack: fix termination on the end of filewm42014-03-051-3/+19
| | | | | | | | | | | | | | | | | | | | 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.
* audio: add enum name for speaker idxylosper2014-02-281-1/+1
|
* ao: document some functionswm42014-02-282-3/+35
|
* command: use the step size for "add volume" commandswm42014-02-272-14/+3
| | | | | | | | | | | | The step argument for "add volume <step>" was ignored until now. Fix it. There is one problem: by defualt, "add volume" should use the value set with --volstep. This value is 3 by default. Since the default volue for the step argument is always 1 (and we don't really want to make the generic code more complicated by introducing custom step sizes), we simply multiply the step argument with --volstep to keep it compatible. The --volstep option should probably be just removed in the future.
* audio: fix signedness of AF_FORMAT_S32Pwm42014-02-051-1/+1
| | | | This was marked as unsigned, but it's signed. Found by xylosper.
* w32: use safe DLL search paths everywhereJames Ross-Gowan2014-01-271-17/+0
| | | | | | | | | | | | 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.
* build: fix usage of HAVE_SDL1 defineStefano Pigozzi2014-01-251-1/+1
| | | | This is needed after fd1f8ed49.
* audio/filter: remove redundant log message prefixeswm42014-01-2413-44/+44
| | | | | These are now appended automatically, so you'd get them twice before this commit.
* audio: fix balance controlwm42014-01-231-2/+2
| | | | | | | | Balance controls as used by mixer.c was broken, because af_pan.c stopped accepting its arguments. We have to allow 0 channels explicitly. Also, fix null pointer access if the matrix parameter is not used. Regression from commit 82983970.
* af: fixed out-of-bounds accesses caused by NUM_FMT and co.11rcombs2014-01-191-18/+18
| | | | | | | | | Signed-off-by: wm4 <wm4@nowhere> This merges pull request #496. The problem was that at least the initialization of the distance[] array accessed af_fmtstr_table[] entries that were out of bounds. Small cosmetic changes applied to the original pull request.
* Factor out setting AVCodecContext extradatawm42014-01-111-10/+4
|
* ao_pulse: lower default buffer size from 1000ms to 250mswm42014-01-071-1/+1
| | | | | | | | | | 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.
* ao_pulse: add suboption to control buffer sizewm42014-01-071-1/+8
|
* audio: check for overflowswm42014-01-031-0/+5
|
* ao_alsa: remove 9 year old typowm42014-01-021-1/+0
| | | | | Actually, remove the whole comment, because it's outdated and get_space() returns the number of free samples now.
* ao_alsa: Unbreak pause/resumeMartin Herkt2014-01-021-11/+10
| | | | Well that was dumb.
* ao_alsa: Fix PCM resume after suspendMartin Herkt2014-01-021-15/+15
| | | | Fixes #324
* audio: fix format ID conversionwm42013-12-231-1/+1
| | | | | AV_SAMPLE_FMT_NONE != 0, could apparently cause crashes in certain situations.
* msg: rename mp_msg_log -> mp_msgwm42013-12-213-3/+3
| | | | Same for companion functions.
* af_export: require filename argumentwm42013-12-211-4/+3
| | | | | | Since mp_find_user_config_file() is going to get a context argument, which would be annoying to do in the audio chain (actually I'm just lazy).
* m_option: add mp_log callback to OPT_STRING_VALIDATE optionswm42013-12-213-60/+62
| | | | | And also convert a bunch of other code, especially ao_wasapi and ao_portaudio.
* m_option, m_config: mp_msg conversionswm42013-12-214-11/+13
| | | | | | | | 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.
* codecs: mp_msg conversionwm42013-12-211-1/+1
|
* ao: some missing mp_msg conversionswm42013-12-211-13/+17
|
* ao_wasapi: mp_msg conversionswm42013-12-211-67/+34
| | | | | | | 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.
* audio/fmt-conversion.c: remove unknown audio format messageswm42013-12-214-15/+19
| | | | Same deal as with video/fmt-conversion.c.
* audio: mp_msg conversionswm42013-12-2123-194/+178
|
* mixer: mp_msg conversionswm42013-12-212-13/+12
|
* ao_alsa: don't set ALSA message callbackwm42013-12-211-21/+0
| | | | | | | 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.
* ao_wasapi: fix includeswm42013-12-181-3/+2
| | | | Broken due to recent header renaming. Untested.
* ad_lavc: work around deprecation warningwm42013-12-181-1/+4
| | | | | | | | | | request_channels has been deprecated for years (request_channel_layout is the replacement), but it appears it's still needed despite the deprecation at least on older libavcodec versions. So still set request_channels, but to it with the avoption API, which hides the deprecation warning. This should also prevent mpv getting trashed when libavcodec happens to bump its major version.
* Reduce recursive config.h inclusions in headerswm42013-12-184-4/+4
| | | | | | In my opinion, config.h inclusions should be kept to a minimum. MPlayer code really liked including config.h everywhere, though, even in often used header files. Try to reduce this.
* Remove the _ macrowm42013-12-181-0/+2
| | | | | This was a gettext-style macro to mark strings that should be translated.
* Split mpvcore/ into common/, misc/, bstr/wm42013-12-1744-60/+60
|
* Merge mp_talloc.h into ta/ta_talloc.hwm42013-12-171-1/+1
|
* Move options/config related files from mpvcore/ to options/wm42013-12-1725-28/+28
| | | | | | | | | 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.
* Move mpvcore/input/ to input/wm42013-12-171-1/+1
|
* Replace mp_tmsg, mp_dbg -> mp_msg, remove mp_gtext(), remove set_osd_tmsgwm42013-12-167-23/+23
| | | | | | | | | 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.
* ao_wasapi: Fix mistaken behavior on uninitDiogo Franco (Kovensky)2013-12-081-2/+2
| | | | | The parameter, when true, tells whether uninit should block for flushing the buffers, not whether it should quit immediately without flushing.
* ao_wasapi: handle AOPLAY_FINAL_CHUNKDiogo Franco (Kovensky)2013-12-081-2/+6
| | |</