summaryrefslogtreecommitdiffstats
path: root/audio
Commit message (Collapse)AuthorAgeFilesLines
* ao_wasapi: make wait for audio thread termination infiniteKevin Mitchell2016-02-261-4/+3
| | | | | The time-out was a terrible hack for marginally better behaviour when encountering #1773, which appears to have been resolved by a previous commit.
* ao_wasapi: further flatten/simplify volume controlKevin Mitchell2016-02-261-39/+34
|
* ao_wasapi: use MP_FATAL for stuff that leads to init failureKevin Mitchell2016-02-262-5/+5
|
* ao_wasapi: move pre-resume reset into resume functionKevin Mitchell2016-02-261-16/+14
|
* ao_wasapi: move resetting the thread state into main loopKevin Mitchell2016-02-261-11/+3
| | | | | This was previously duplicated between the reset/resume functions, and not properly handled in the "impossible" invalid thread state case.
* ao_wasapi: set buffer size to device period in exclusive modeKevin Mitchell2016-02-261-7/+12
| | | | | | | | | | | | | This eliminates some intermittent pops heard in a HRT MicroStreamer DAC uncorrelated with user interaction. As a bonus, this resolves #1773 which I can o longer reproduce as of this commit. Leave the 50ms buffer for shared mode since that seems to be working quite well. This is also the way exclusive mode is done in the MSDN example code: https://msdn.microsoft.com/en-us/library/windows/desktop/dd370844%28v=vs.85%29.aspx This was originally increased in c545c40 to mitigate glitches that subsequent refactorings have eliminated.
* ao_wasapi: replace laggy COM messaging with mp_dispatch_queueKevin Mitchell2016-02-263-175/+80
| | | | | | | | | | A COM message loop is apparently totally inappropriate for a low latency thread. It leads to audio glitches because the thread doesn't wake up fast enough when it should. It also causes mysterious correlations between the vo and ao thread (i.e., toggling fullscreen delays audio feed events). Instead use an mp_dispatch_queue to set/get volume/mute/session display name from the audio thread. This has the added benefit of obviating the need to marshal the associated interfaces from the audio thread.
* ao_wasapi: avoid under-run cascade in exclusive mode.Kevin Mitchell2016-02-261-24/+36
| | | | | | | | | | | | | | | | Don't wait for WASAPI to send another feed event if we detect an underfull buffer. It seems that WASAPI doesn't always send extra feed events if something causes rendering to fall behind. This causes every subsequent playback buffer to under-run until playback is reset. The fix is simply to do a one-shot double feed when this happens, which allows rendering to catch up with playback. This was observed to happen when using MsgWaitForMultipleObjects to wait for the feed event and toggling fullscreen with vo=opengl:backend=win. This commit improves the behaviour in that specific case and more generally makes exclusive mode significantly more robust. This commit also moves the logic to avoid *over*filling the exclusive mode buffer into thread_feed right next to the above described underfil logic.
* ao_wasapi: fix typo in commentKevin Mitchell2016-02-261-1/+1
|
* ao_wasapi: use SUCCEEDED/FAILED macrosKevin Mitchell2016-02-262-13/+9
|
* ao: initial OpenSL ES supportIlya Zhuravlev2016-02-272-0/+254
| | | | | | | | OpenSL ES is used on Android. At the moment only stereo output is supported. Two options are supported: 'frames-per-buffer' and 'sample-rate'. To get better latency the user of libmpv should pass values obtained from AudioManager.getProperty(PROPERTY_OUTPUT_FRAMES_PER_BUFFER) and AudioManager.getProperty(PROPERTY_OUTPUT_SAMPLE_RATE).
* audio: make mp_audio_skip_samples() adjust the PTSwm42016-02-222-3/+3
| | | | Slight simplification/cleanup.
* ad_lavc: skip AVCodecContext.delay samples at beginningwm42016-02-221-0/+9
| | | | | | | | Fixes correctness_trimming_nobeeps.opus. One nasty thing is that this mechanism interferes with the container-signalled mechanism with AV_FRAME_DATA_SKIP_SAMPLES. So apply it only if that is apparently not present. It's a mess, and it's still broken in FFmpeg CLI, so I'm sure this will get fucked up later again.
* ad_lavc: make sample trimming symmetric to skippingwm42016-02-221-6/+8
| | | | | | I'm not quite sure what the FFmpeg AV_FRAME_DATA_SKIP_SAMPLES API demands here. The code so far assumed that skipping can be more than a frame, but not trimming. Extend it to trimming too.
* ad_lavc: move skipping logic out of the HAVE_AVFRAME_SKIP_SAMPLES blockwm42016-02-221-10/+13
|
* ad_lavc: interpolate missing timestampswm42016-02-221-0/+9
| | | | | | | | | | This is actually already done by dec_audio.c. But if AV_FRAME_DATA_SKIP_SAMPLES is applied, this happens too late here. The problem is that this will slice off samples, and make it impossible for later code to reconstruct the timestamp properly. Missing timestamps can still happen with some demuxers, e.g. demux_mkv.c with Opus tracks. (Although libavformat interpolates these itself.)
* audio: move frame clipping to a generic functionwm42016-02-213-33/+37
|
* Rewrite ordered chapters and timeline stuffwm42016-02-152-1/+75
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This uses a different method to piece segments together. The old approach basically changes to a new file (with a new start offset) any time a segment ends. This meant waiting for audio/video end on segment end, and then changing to the new segment all at once. It had a very weird impact on the playback core, and some things (like truly gapless segment transitions, or frame backstepping) just didn't work. The new approach adds the demux_timeline pseudo-demuxer, which presents an uniform packet stream from the many segments. This is pretty similar to how ordered chapters are implemented everywhere else. It also reminds of the FFmpeg concat pseudo-demuxer. The "pure" version of this approach doesn't work though. Segments can actually have different codec configurations (different extradata), and subtitles are most likely broken too. (Subtitles have multiple corner cases which break the pure stream-concatenation approach completely.) To counter this, we do two things: - Reinit the decoder with each segment. We go as far as allowing concatenating files with completely different codecs for the sake of EDL (which also uses the timeline infrastructure). A "lighter" approach would try to make use of decoder mechanism to update e.g. the extradata, but that seems fragile. - Clip decoded data to segment boundaries. This is equivalent to normal playback core mechanisms like hr-seek, but now the playback core doesn't need to care about these things. These two mechanisms are equivalent to what happened in the old implementation, except they don't happen in the playback core anymore. In other words, the playback core is completely relieved from timeline implementation details. (Which honestly is exactly what I'm trying to do here. I don't think ordered chapter behavior deserves improvement, even if it's bad - but I want to get it out from the playback core.) There is code duplication between audio and video decoder common code. This is awful and could be shareable - but this will happen later. Note that the audio path has some code to clip audio frames for the purpose of codec preroll/gapless handling, but it's not shared as sharing it would cause more pain than it would help.
* audio/video: expose codec info as separate fieldwm42016-02-153-6/+6
| | | | | Preparation for the timeline rewrite. The codec will be able to change, the stream header not.
* ad_lavc: fix --ad-lavc-threads rangewm42016-02-111-1/+1
| | | | | | | The code is shared with the --vd-lavc-threads option, so using 0 for auto-detection just works. But no, this is not useful. Just change it for orthogonality.
* Initial Android supportJan Ekström2016-02-101-0/+1
| | | | | * Adds an 'android' feature, which is automatically detected. * Android has a broken strnlen, so a wrapper is added from FreeBSD.
* audio: minor simplificationwm42016-02-051-3/+0
| | | | | These fields are already deallocated by uninit_decoder(). Also remove the wrong/useless log message.
* build: make libavfilter mandatorywm42016-02-051-2/+0
| | | | | | The complex filter support that will be added makes much more complex use of libavfilter, and I'm not going to bother with adding hacks to keep libavfilter optional.
* ao_coreaudio: fix 7.1(rear) channel mappingwm42016-02-041-0/+27
| | | | | | | | | | | | | | I can't explain this, but it seems to be a similar case to the ALSA HDMI one. I find it hard to tell because of the slightly different names and conventions in use in libavcodec, WAVEEXT channel masks, decoders, codec specifications, HDMI, and platform audio APIs. The fix is the same as the one for ao_alsa (see commit be49da72). This should fix at least playing 7.1 sources on OSX with 7.1(rear) selected in Audio MIDI Setup. The ao_alsa commit mentions XBMC, but I couldn't find out where it does that or if it also does that for CoreAudio. It's woth noting that PHT (essentially an old XBMC fork) also exhibited the incorrect behavior (i.e. side and back speakers were swapped).
* af_lavrresample: change fudged channelswm42016-02-041-2/+2
| | | | | | | | | | | | | Remove flc-frc <-> sl<->sr. This was just plain wrong, and a mistaken change to make 7.1 work properly on CoreAudio with 7.1(rear) layout. Also see the following commit. Add br-br <-> sl<->sr, because we decided that it makes sense. Note that this "fudging" is applied only if the channel pairs are replaced, i.e. they would get dropped and be replaced with silence. This is done to compensate for libswresample's default rematrixing (which takes care of some more common cases).
* audio/video: merge decoder return valueswm42016-02-012-16/+11
| | | | | | Will be helpful for the coming filter support. I planned on merging audio/video decoding, but this will have to wait a bit longer, so only remove the duplicate status codes.
* Fix build on Libavwm42016-01-301-0/+1
| | | | I hope.
* audio: move pts reset checkwm42016-01-292-14/+1
| | | | Reduces the dependency of the filter/output code on the decoder.
* audio: move mp_audio->AVFrame conversion to a functionwm42016-01-293-20/+76
| | | | | | | | | This also makes it refcounted, i.e. the new AVFrame will reference the mp_audio buffers, instead of potentially forcing the consumer of the AVFrame to copy the data. All the extra code is for handling the >8 channels case, which requires very messy dealing with the extended_ fields (not our fault).
* ao_wasapi: add "wasapi" prefix to non-static find_deviceID functionKevin Mitchell2016-01-283-3/+3
|
* ao_wasapi: correct check for specified device on default changeKevin Mitchell2016-01-283-5/+11
| | | | | | Correctly avoid a reload if the current device was specified by the user through --audio-device. Previously, we only recognized if the user had specified --ao=wasapi:device=.
* ao_wasapi: fix check for already found deviceKevin Mitchell2016-01-281-1/+1
| | | | | oops, forgot to change this when I made get_deviceID a more proper function. state->deviceID is not set or read here - that's for the caller to do.
* command: always allow setting volume/mute propertieswm42016-01-261-0/+1
| | | | | | | | | | | | | | | | | | | | | | | This seems generally easier when using libmpv (and was already requested and implemented before: see commit 327a779a; it was reverted some time later). With the weird internal logic we have to deal with, in particular the --softvol=no case (using system volume), and using the audio API's mixer (--softvol=auto on some systems), we still can't avoid all glitches and corner cases that complicate this issue so much. The API user is either recommended to use --softvol=yes or auto, or to watch the new mixer-active property, and assume the volume/mute properties have significant values if the mixer is active. Remaining glitches: - changing the volume/mute properties has no effect if no internal mixer is used (--softvol=no) and the mixer is not active; the actual mixer controls do not change, only the property values - --volume/--mute do not have an effect on the volume/mute properties before mixer initialization (the options strictly are only applied during mixer init) - volume-max is 100 while the mixer is not active
* af_lavfi, vf_lavfi: fix compilation on Libavwm42016-01-221-0/+1
| | | | It has no avfilter_graph_send_command().
* command: add af-command commandwm42016-01-223-0/+21
| | | | Similar to vf-command. Requested. Untested.
* ao_wasapi: use correct UINT type for device enumerationKevin Mitchell2016-01-221-5/+5
| | | | | | Notably, the address of the enumerator->count member is passed to IMMDeviceCollection::GetCount(), which expects a UINT variable, not an int. How did this ever work?
* ao_wasapi: exit earlier if there are zero playback devices foundKevin Mitchell2016-01-221-0/+5
| | | | | | | | Previously, if the enumerator found no devices, attempting to get the default device with IMMDeviceEnumerator::GetDefaultAudioEndpoint would result in the cryptic (and undocumented) E_PROP_ID_UNSUPPORTED. This way, the user is given a better indication of what exactly is wrong and isolates any other possible triggers for this error.
* audio: refactor: work towards unentangling audio decoding and filteringwm42016-01-224-148/+102
| | | | | | | | | Similar to the video path. dec_audio.c now handles decoding only. It also looks very similar to dec_video.c, and actually contains some of the rewritten code from it. (A further goal might be unifying the decoders, I guess.) High potential for regressions.
* ad_spdif: if DTS-HD is requested, and profile unknown, use DTS-HDwm42016-01-201-1/+2
| | | | | This means there will be no loss if profile detection failed for some reason.
* audio: change downmix behavior, add --audio-normalize-downmixwm42016-01-203-4/+10
| | | | | | This is probably the 3rd time the user-visible behavior changes. This time, switch back because not normalizing seems to be the more expected behavior from users.
* audio: remove initial decoding retry limitationwm42016-01-191-3/+0
| | | | | | | | | | | | | | | Seems useless. This only helped in one case: one audio stream in the sample av_find_best_stream_fails.ts had a AC3 packets which couldn't be decoded, and for which avcodec_decode_audio4() returned 0 forever. In this specific case, playback will now not start, and you have to deselect audio manually. (If someone complains, the old behavior might be restored, but differently.) Also remove the stale "bitrate" field.
* audio: move direct packet reading from decoders to common codewm42016-01-195-29/+27
| | | | Another bit of preparation.
* audio: move dec_audio.pool to ad_spdifwm42016-01-192-2/+3
| | | | That's where its only use is.
* ao_coreaudio_chmap: change license to LGPLwm42016-01-192-14/+14
| | | | | | While the situation is not really clear for the other rewritten coreaudio code, it's very clear for the channel mapping code. It was all written by us. (MPlayer doesn't even have any channel map handling.)
* Relicense some non-MPlayer source files to LGPL 2.1 or laterwm42016-01-1915-105/+105
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This covers source files which were added in mplayer2 and mpv times only, and where all code is covered by LGPL relicensing agreements. There are probably more files to which this applies, but I'm being conservative here. A file named ao_sdl.c exists in MPlayer too, but the mpv one is a complete rewrite, and was added some time after the original ao_sdl.c was removed. The same applies to vo_sdl.c, for which the SDL2 API is radically different in addition (MPlayer supports SDL 1.2 only). common.c contains only code written by me. But common.h is a strange case: although it originally was named mp_common.h and exists in MPlayer too, by now it contains only definitions written by uau and me. The exceptions are the CONTROL_ defines - thus not changing the license of common.h yet. codec_tags.c contained once large tables generated from MPlayer's codecs.conf, but all of these tables were removed. From demux_playlist.c I'm removing a code fragment from someone who was not asked; this probably could be done later (see commit 15dccc37). misc.c is a bit complicated to reason about (it was split off mplayer.c and thus contains random functions out of this file), but actually all functions have been added post-MPlayer. Except get_relative_time(), which was written by uau, but looks similar to 3 different versions of something similar in each of the Unix/win32/OSX timer source files. I'm not sure what that means in regards to copyright, so I've just moved it into another still-GPL source file for now. screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but they're all gone.
* ao_wasapi: use share_mode value instead of raw option opt_exclusiveKevin Mitchell2016-01-181-1/+1
| | | | | | | Previously used opt_exclusive option to decide which volume control code to run. The might not always reflect the actual state, for example if passthrough is used. Admittedly, none of the volume controls will work anyway with passthrough, but this is the right thing to do.
* ao_openal: wipe out global context on init errorKevin Mitchell2016-01-181-0/+1
| | | | | Previously this would break all further attempts to init the driver after one had failed.
* af_lavrresample: fudge some channel layout conversionwm42016-01-181-0/+33
| | | | | | | | | | | | Prevents channels from being dropped, e.g. when going 7.1 -> 7.1(wide) and similar cases. The reasoning here is that channel layouts over HDMI don't work anyway, and not dropping a channel and playing it on a slightly "wrong" (but expected) speaker is preferable to playing silence on these speakers. Do this to remove issues with ao_coreaudio. Frankly I'm not sure whether our mapping (between CA and mpv/FFmpeg speakers) is correct, but on the other hand due to the reasons stated above it's not all that meaningful.
* demux: merge sh_video/sh_audio/sh_subwm42016-01-122-18/+17
| | | | | | | | | | This is mainly a refactor. I'm hoping it will make some things easier in the future due to cleanly separating codec metadata and stream metadata. Also, declare that the "codec" field can not be NULL anymore. demux.c will set it to "" if it's NULL when added. This gets rid of a corner case everything had to handle, but which rarely happened.
* mpv_talloc.h: rename from talloc.hDmitrij D. Czarkoff2016-01-1110-10/+10
| | | | This change helps avoiding conflict with talloc.h from libtalloc.
* ao_coreaudio: replace fourcc_repr()wm42016-01-113-35/+7
| | | | Replace with the more general mp_tag_str().
* ao_wasapi: move out some utility functionswm42016-01-112-76/+1
| | | | | | Note that hresult_to_str() (coming from wasapi_explain_err()) is mostly wasapi-specific, but since HRESULT error codes are unique, it can be extended for any other use.
* player: detect audio PTS jumps, make video PTS heuristic less aggressivewm42016-01-092-1/+14
| | | | | | | | | | | | | | | | | | | | | | This is another attempt at making files with sparse video frames work better. The problem is that you generally can't know whether a jump in video timestamps is just a (very) long video frame, or a timestamp reset. Due to the existence of files with sparse video frames (new frame only every few seconds or longer), every heuristic will be arbitrary (in general, at least). But we can use the fact that if video is continuous, audio should also be continuous. Audio discontinuities can be easily detected, and if that happens, reset some of the playback state. The way the playback state is reset is rather radical (resets decoders as well), but it's just better not to cause too much obscure stuff to happen here. If the A/V sync code were to be rewritten, it should probably strictly use PTS values (not this strange time_frame/delay stuff), which would make it much easier to detect such situations and to react to them.
* ao_dsound: remove this audio outputwm42016-01-062-711/+0
| | | | | | | It existed for XP-compatibility only. There was also a time where ao_wasapi caused issues, but we're relatively confident that ao_wasapi works better or at least as good as ao_dsound on Windows Vista and later.
* ao_wasapi: remove unnecessary header fileKevin Mitchell2016-01-055-74/+31
| | | | | All the wasapi files were including both ao_wasapi.h and ao_wasapi_utils.h. Just merge them into a single file.
* ao_wasapi: initialize change notify in main threadKevin Mitchell2016-01-052-3/+6
| | | | This is something else that has nothing to do with audio rendering.
* ao_wasapi: remove old vistablob prototypeKevin Mitchell2016-01-051-2/+0
| | | | this function was removed earlier, but the prototype was missed
* ao_wasapi: make find_deviceID read only wrt struct aoKevin Mitchell2016-01-053-19/+20
| | | | This makes it clearer that state->device is being allocated.
* ao_wasapi: move device selection to main threadKevin Mitchell2016-01-053-8/+10
| | | | In attempt to simplify the audio event thread, this can now be moved out.
* ao_wasapi: avoid some redundant error messages in device selectionKevin Mitchell2016-01-051-15/+7
| | | | | If these error conditions are triggered, the called function will have already output a sufficiently informantive error message.
* ao_wasapi: alloc later to avoid free on errorKevin Mitchell2016-01-051-2/+1
| | | | | In get_device_desc, don't alloc the return value until we know there wasn't an error.