summaryrefslogtreecommitdiffstats
path: root/audio/filter/af_lavrresample.c
Commit message (Collapse)AuthorAgeFilesLines
* audio: remove unreferenced af_lavrresamplewm42019-09-191-112/+0
| | | | | | | | | | | | | | This filter wasn't referenced anywhere and thus was dead code. It should have been in the audio filter list in user_filters.c. This was intended as compatibility wrapper (to avoid breaking old command lines and config files), and has no real use. Apparently I forgot to add it to the filter list (did I even test this shit?), and so it was rotting around for 1.5 years doing nothing (just like myself). Note that users can just use the libavfilter provided filter to force resampling, just that it has a different name and different options. There's also af_format to force inserting auto conversion through the internal f_swsresample filter.
* audio: rewrite filtering glue codewm42018-01-301-141/+46
| | | | Use the new filtering code for audio too.
* af_lavrresample: deprecate this filterwm42018-01-131-0/+8
| | | | | | The future direction might be not having such a user-visible filter at all, similar to how vf_scale went away (or actually, redirects to libavfilter's vf_scale).
* audio: add global options for resampler defaultswm42018-01-131-0/+26
| | | | | | | | This is part of trying to get rid of --af-defaults, and the af resample filter. It requires a complicated mechanism to set the defaults on the resample filter for backwards compatibility.
* audio: move libswresample wrapper out of audio filter codewm42017-09-211-458/+34
| | | | | | | | | Move it from af_lavrresample.c to a new aconverter.c file, which is independent from the filter chain code. It also doesn't use mp_audio, and thus has no GPL dependencies. Preparation for later commits. Not particularly well tested, so have fun.
* af_lavrresample: don't call swr_set_compensation() unless necessarywm42017-08-121-5/+9
| | | | | | | | | | | | | | This was _always_ called, even if the resampling was static, or the filter was inserted for format conversion only. This should have been fine, as I expected the function not to enable resampling when the compensation is unset, and the source/target rates are the same. But this is not the case, and it always enables resampling. So explicitly avoid the call. If we have already called it successfully, it's better not do avoid it (to overwrite the previous compensation value), but it will also be cheap/no-op then. Probably fixes #4716.
* audio: drop AF_FORMAT_S24wm42017-07-071-26/+2
| | | | | | | | | | | This is the last sample format that was only in mpv and not in FFmpeg (except the spdif special formats). It was a huge pain, even if the removed code in af_lavrresample is pretty small after all. Note that this drops S24 from the ao_coreaudio AOs too. I'm not sure about the impact, but I expect it doesn't matter. af_fmt_change_bytes() was unused as well, so remove that too.
* build: explicitly check for FFmpeg vs. Libav, and their exact versionswm42017-01-271-0/+3
| | | | | | | | | | | | | | | | | | In a first pass, we check whether libavcodec is present. Then we try to compile a snippet and check for FFmpeg vs. Libav. (This could probably also be done by somehow checking the pkgconfig version. But pkg-config can't deal with that idiotic FFmpeg idea that a micro version number >= 100 identifies FFmpeg vs. Libav.) After that we check the project-specific version numbers. This means it can no longer happen that we accidentally allow older, unsupported versions of FFmpeg, just because the Libav version numbers are somehow this way. Also drop the resampler checks. We hardcode which resampler to each with each project. A user can no longer force use of libavresample with FFmpeg.
* Remove compatibility thingswm42016-12-071-5/+0
| | | | | | Possible with bumped FFmpeg/Libav. These are just the simple cases.
* af_lavrresample: better swr reinitializationPaul B Mahol2016-08-201-4/+5
|
* af_lavrresample: fix error if resampler could not be recreatedwm42016-08-191-4/+5
| | | | | | | | There are situations where the resampler is destroyed and recreated during playback. If recreating the resampler unexpectedly fails, the filter function is supposed to return an error. This wasn't done correctly, because get_out_samples() accessed the resampler before the check. Move the check up to fix this.
* af_lavrresample: work around libswresample misbehaviorwm42016-08-161-10/+10
| | | | | | | | | | | | | | | | | | The touched code is for seek resets and such - we simply want to reset the entire resample state. But I noticed after a seek a tiny bit of audio is missing (mpv's audio sync code inserted silence to compensate). It turns out swr_drop_output() either does not reset some internal state as we expect, or it's designed to drop not only buffered samples, but also future samples. On the other hand, libavresample's avresample_read(), does not have this problem. (It is also pretty explicit in what it does - return/skip buffered data, nothing else.) Is the libswresample behavior a bug? Or a feature? Does nobody even know? Who cares - use the hammer to unfuck the situation. Destroy and deallocate the libswresample context and recreate it. On every seek.
* audio: cleanup audio filter format negotiationwm42016-07-101-21/+0
| | | | | | | | | | | | | | | | | | The algorithm and functionality is the same, but the code becomes much simpler and easier to follow. The assumption that there is only 1 conversion filter (lavrresample) helps with the simplification, but the main change is to use the same code for format/channels/rate. Get rid of the different AF_CONTROL_SET_* controls, and change the af->data parameters directly. (af->data is badly named, but essentially is a placeholder for the output format.) Also, instead of trying to use the af_reinit() loop to init inserted conversion filters or filters with changed output formats, do it inline, and move the common code to a filter_reinit() function. This gets rid of the awful retry variable. In general, this should not change any runtime behavior.
* 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: change downmix behavior, add --audio-normalize-downmixwm42016-01-201-4/+8
| | | | | | 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.
* 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.
* af_lavrresample: fix build on Libavwm42015-11-261-1/+1
| | | | | | | Of course, only FFmpeg has av_clipd(), while Libav does not. (Nevermind that it doesn't do much more than the mpv MPCLAMP() macro. Supposedly, libavutil can provide optimized platform-specific versions for av_clip*, but of course nothing actually does for av_clipf() or av_clipd().)
* af_lavrresample: clamp float output to rangewm42015-11-251-0/+12
| | | | | | | libswresample doesn't do it - although it should, but the patch is stuck in limbo. Probably reduces problems with artifacts on downmixing in some cases.
* af_lavrresample: simplify set_compensation usagewm42015-11-111-13/+12
| | | | | | | | | | | | | Just set the ratio directly by working around the intended semantics of the API function. The silly rounding stuff we had isn't needed anymore (and not entirely correct anyway). Note that since the compensation is virtually active forever, we need to reset if it's not needed. So always run this code to be sure to reset it. Also note that libswresample itself had a precision issue, until it was fixed in FFmpeg commit 351e625d.
* Revert "af_lavrresample: don't drop sl/sr channels for 7.1 on ALSA"wm42015-11-041-28/+5
| | | | | | | | | | | This reverts commit 4e358a963604af8746a059d7388cb202be0f919d. Testing shows the channel pairs must indeed be swapped (details see commit message of the reverted commit). Making the downmix code move sl/sr to sdl/sdr is not an appropriate solution anymore, and it's better to fix the unusual channel layout in ao_alsa.c directly. (Not reverting the change in chmap.c; this is still correct.)
* af_lavrresample: don't drop sl/sr channels for 7.1 on ALSAwm42015-11-031-5/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ao_alsa: attempt to fix 7.1 over HDMI The last 2 channels of 7.1 (RLC/RRC in ALSA) were exported as sdl/sdr instead of sl/sr (I don't even know why I chose sdl/sdr, but SL/SR and RLC/RRC are different in the ALSA API). libsw/avresample do not move the sl/sr channels to sdl/sdr when rematrixing, so silence was sent for 2 channels. If my selection of sdl/sdr is essentially API abuse, there's no reason why they should do this differently. The mess here is really that ALSa doesn't map the HDMI layouts cleanly. Most ALSA drivers export 7.1 in a way compatible to our expectations, but Intel HDA/HDMI does not: mpv/ffmpeg: fl-fr-fc-lfe-bl-br-sl-sr ALSA/generic: FL FR FC LFE RL RR SL SR [1] ALSA/HDMI: FL FR LFE FC RL RR RLC RRC [2] The HDMI layout is layout 0x13 (going by CEA-861-B). The comment in the kernel code has to be correct too. The early standard defines only 1 other layout, which replaces RLC/RRC with FRC/FLC - this probably corresponds to what we call "7.1(wide)". So it appears when ALSA requests RLC/RRC, we should feed it sl/sr. To make it more complicated, Kodi/xbmc apparently also have to deal with ALSA being special, but instead of sending sl/sr to RLC/RRC, they swap the last two pairs of the layout, and send sl/sr to RL/RR and bl/br to RLC/RRC. Or I might have misunderstood their code. I don't have a 7.1-capable A/V receiver, so I can't test this. For now, go with the simpler solution, and wait until someone tests it. If the speakers end up swapped, a completely different solution will be needed. [1] https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/sound/core/pcm_lib.c?id=refs/tags/v4.3#n2434 [2] https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/sound/pci/hda/patch_hdmi.c?id=refs/tags/v4.3#n307
* af_lavrresample: make planarization pass work with >8 channelswm42015-10-261-4/+5
| | | | | | | | | | av_get_default_channel_layout() fails with channel counts larger than 8. The channel layout doesn't need to make sense, so pick an arbitrary fallback. libswresample also has options for setting the channel counts directly, but better not introduce new concepts in the code. Also, libavresample doesn't have these options.
* af_lavrresample: fix unintended audio drift when setting playback speedwm42015-10-141-3/+9
| | | | | | | | | | | | | | Small adjustments to the playback speed use swr_set_compensation() to stretch the audio as it is required. But since large adjustments are now handled by actually reinitializing libswresample, the small adjustments get rounded off completely with typical frame sizes. Compensate for this by accounting for the rounding error and keeping track of fractional samples that should have been output to achieve the correct ratio. This fixes display sync mode behavior, which requires these adjustments to be relatively accurate.
* af_lavrresample: reinit resampler on large speed changeswm42015-10-121-15/+19
| | | | | | swr/avresample_set_compensation() was made for small speed adjustments. Non-documentation says it should be used for changes not larger than 1%, so reinitialize the sampler if the change is larger than that.
* af_lavrresample: use libswsresample dynamic rate adjustment featurewm42015-10-071-9/+26
| | | | | | | | | | swr_set_compensation() changes the apparent sample rate on the fly (who would have guessed). It is thus very well-suited for adjusting audio speed on the fly during playback (like needed by the display-sync mode). It skips the relatively slow resampler reinitialization. If this doesn't work (libswresample soxr backend), then fall back to the old method.
* af_lavrresample: remove unnecessary indirectionswm42015-09-081-35/+30
| | | | | | | Not sure why struct af_resample_opts even exists. It seems useful to group the fields set by user options. But storing the current format conversion parameters doesn't seem very elegant, and having a separate instance in the "ctx" field isn't helpful either.
* af_lavrresample: add normalize suboptionwm42015-09-081-1/+6
|
* af_lavrresample: add missing include statementwm42015-09-041-0/+1
| | | | | | Apparently, this broke compilation with Libav under some circumstances. Looking at it again, it shouldn't have, but this change doesn't hurt anyway.
* audio: remove unused legacy libavutil headerwm42015-08-071-1/+0
| | | | It was never used, but is a leftover from old times.
* af_lavrresample: always reinit resampler on filter reinitwm42015-07-191-18/+1
| | | | | | | | This was a minor optimization to potentially avoid resampler reconfiguration when the filter is reinitialized. But filter reinitialization is a rare event, and the case when no reconfiguration is needed is even rarer. As such, this is an unnecessary micro- optimization and only adds potential for bugs.
* af_lavrresample: don't unnecessarily print remix messagewm42015-07-191-8/+8
| | | | | | | | | This message bloats verbose log output if e.g. audio speed is frequently readjusted, such as when syncing audio to video. So don't print the message if only speed is changed. (This case requires reconfiguration, but can't change the input/output channel maps.) Also do not print the message if no remixing is done at all.
* af_lavrresample: log actual channel layout conversionswm42015-06-301-3/+6
| | | | | With all the reordering etc. that can go on in this filter, it's useful to see what upmix/downmix it's actually performing.
* audio: fix format function consistency issueswm42015-06-261-1/+1
| | | | | | | | | | | Replace all the check macros with function calls. Give them all the same case and naming schema. Drop af_fmt2bits(). Only af_fmt2bps() survives as af_fmt_to_bytes(). Introduce af_fmt_is_pcm(), and use it in situations that used !AF_FORMAT_IS_SPECIAL. Nobody really knew what a "special" format was. It simply meant "not PCM".
* af_lavrresample: free and reallocate resample context on reconfigwm42015-06-221-30/+35
| | | | | | | | This avoids keeping "bad" state from previous reconfig calls, such as the internal_sample_format option (which is set only on the first reconfig call). There's no advantage to keeping the resample contexts around anyway.
* af_lavrresample: fix commentwm42015-06-221-4/+4
| | | | | mp_format is not a libavresample input format here, and the comment was more confusing than it helped.
* af: restore detaching of PCM filters when using spdifwm42015-06-221-0/+6
| | | | | | Basically, af_fix_format_conversion() behaves stupid you insert a conversion filter that won't work, and adding back the conversion test function is the simplest fix to it.
* af_lavrresample: don't flush in uninitialized statewm42015-06-221-1/+2
| | | | libswresample verbosely complains.
* af_lavrresample: include osdep/endian.hwm42015-06-171-0/+1
| | | | The 24 bit conversion code needs the relevant preprocessor symbols.
* af: remove conversion filter searchwm42015-06-161-7/+0
| | | | | | This attempted to find a minimal filter graph for a format conversion involving multiple conversion filters. With the last 2 commits it becomes dead code - remove it.
* af_lavrresample: integrate 24 bit (3 bytes per sample) outputwm42015-06-161-9/+48
| | | | | | | | | | | | Now af_lavrresample can output 24 bit samples directly, by doing the conversion "inline". Luckily, S32->S24 can be done in-place, so this isn't too much work. But the output conversion logic (which seems to be adding up) gets slightly more complicated again. Normally this is done by af_convert24. But having multiple conversion filters complicates some aspects of the filter chain. S24 output is the only thing the code for multiple conversion filters is still needed for, and getting rid of that is preferable.
* af_lavrresample: always fill reorderwm42015-06-161-1/+1
| | | | | | If the code path for additional output conversion is active, reorder_planes() is always called, even if the reorder_out array wasn't filled. This is obviously wrong - always fill this array.
* audio: fill NA channels with silencewm42015-06-121-11/+29
| | | | | | | | | | | | | | | Until now, we didn't do this, because it required some effort, and didn't seem to be necessary. It probably still isn't, but it sounds like a good idea not to output arbitrary data on these channels. The situation is complicated by the fact that just adding new channels to a planar frame would require messing with buffers. So we would have to allocate new buffers and add them to the frame. We could have to maintain an extra buffer pool for this. Avoid this by being "clever", and just allocate a frame with enough channels in the first place. libav/swresample won't know about these channels and won't write to them, but we can grab them in reorder_planes() and use them for the NA channels.
* af_lavrresample: slightly better computation of total delaywm42015-06-041-6/+9
| | | | | | | On libavresample, don't ignore the buffered output data. On libswresample, don't round the total buffer size to the input samplerate.
* af_lavrresample: use a new libswresample function if availablewm42015-06-041-0/+4
| | | | | It was recently added to libswresample, and it does exactly what we need.
* af_lavrresample: change output samples calculationwm42015-06-041-2/+2
| | | | | | This is better, because now we call swr_get_delay() with the output samplerate, instead of with the input samplerate and then multiplying it with the ratio and rounding it up.
* af_lavrresample: use native libavresample function for output sizewm42015-06-021-7/+6
| | | | This also drops the unused get_drain_samples() function.
* af_lavrresample: fix and simplify flushing on playback speed changewm42015-06-021-23/+1
| | | | | | | | | | | This manually retrieved the remaining audio from the resampler. It subtly missed a conversion which could leave to an unsubtle crash. This could happen if reorder_planes() was supposed to insert NA channels, and the resampler/actual output format were different. Simplify it by reusing the normal drain path. One oddness is that the filter will add an output frame outside of normal filtering, but that should be fine.
* af_lavrresample: remove dead undefswm42015-05-051-3/+0
|
* audio: introduce support for padding channelswm42015-05-051-37/+82
| | | | | | | | | | | | | | | | | | | Some audio APIs explicitly require you to add dummy channels. These are not rendered, and only exist for the sake of the audio API or hardware strangeness. At least ALSA, Sndio, and CoreAudio seem to have them. This commit is preparation for using them with ao_coreaudio. The result is a bit messy. libavresample/libswresample don't have good API for this; avresample_set_channel_mapping() is pretty useless. Although in theory you can use it to add and remove channels, you can't set the channel counts. So we do the ordering ourselves by making sure the audio data is planar, and by swapping the plane pointers. This requires lots of messiness to get the conversions in place. Also, the input reordering is still done with the "old" method, and doesn't support padded channels - hopefully this will never be needed. (I tried to come up with cleaner solutions, but compared to my other attempts, the final commit is not that bad.)
* af_lavrresample: fix drainingwm42015-04-181-8/+8
| | | | | configure_lavrr() clears s->pending, so we have to assign it after that call.
* Update license headersMarcin Kurczewski2015-04-131-5/+5
| | | | Signed-off-by: wm4 <wm4@nowhere>
* af_lavrresample: minor simplificationwm42015-04-121-4/+4
| | | | | The in/out pointers usually have not much meaning outside of AF_CONTROL_REINIT. Also remove the redundant casts.
* af_lavrresample: allow resetting output sample formatwm42015-04-121-2/+3
| | | | It must be allowed to set format==0.
* audio: make all format query shortcuts macrosKevin Mitchell2015-04-031-1/+1
| | | | | af_fmt_is_float and af_fmt_is_planar were previously inconsistent with AF_FORAMT_IS_SPECIAL/AF_FORMAT_IS_IEC61937
* af_lavrresample: always normalize (libswresample is stupid)wm42015-04-021-0/+4
| | | | | | | | | | libswresample doesn't normalize when remixing to a float format. This will cause clipping due to float samples being out of the allowed range. Fortunately this extremely bad default can be changed. This does not happen with libavresample: it normalizes by default. Fixes #1752.
* audio: change playback speed directly in resamplerwm42015-03-021-17/+73
| | | | | | | |