Commit Graph

220 Commits

Author SHA1 Message Date
wm4 7205e75079 af_bs2b: fix option default value
--af=bs2b:help abort()ed because the default value of the "profile"
option is not represented by any choice. Fix it by adding an "unset"
choice. (It's a bit odd because there's already a "default" choice,
which is not default, but I don't care enough about this filter.)

Fixes #1712.
2015-03-22 13:28:20 +01:00
wm4 775a02aab5 af_lavfi: handle seeking
To handle seeking correctly, we need to flush the filter. libavfilter
does not support flushing, so we destroy and recreate it. We also need
to handle resume-after-EOF, because the mpv audio code sends an EOF
before and after seeking (the latter happens because the player drains
the filter chain in a generic way, which "causes" EOF).
2015-03-17 22:31:05 +01:00
wm4 89db92398e audio: refuse to change playback speed with spdif
Handle the failure gracefully, instead of exploding and disabling audio.
Just set the speed back to 1.0.

Also remove the AF_DETACH from af_scaletempo. This actually created a
dangling pointer in af_add(), a tricky consequence of af_add()
reconfiguring the filter chain and the newly added filter using
AF_DETACH. Fortunately the AF_DETACH is not needed (and probably never
worked - it comes from MPlayer times, and MPlayer also disables audio
when trying to change speed with spdif).
2015-03-07 20:34:05 +01:00
wm4 ddbecd09b0 af_scaletempo: minor simplification 2015-03-06 21:51:18 +01:00
wm4 c30d5f79b5 af_scaletempo: restore confusing mplayer behavior
This matters only when setting obscure scaletempo suboptions.

See #1653.

(But what we really should do is figuring out how to do this in a sane
way.)
2015-03-06 21:48:41 +01:00
wm4 89bc2975e9 audio: change playback speed directly in resampler
Although the libraries we use for resampling (libavresample and
libswresample) do not support changing sampelrate on the fly, this makes
it easier to make sure no audio buffers are implicitly dropped. In fact,
this commit adds additional code to drain the resampler explicitly.

Changing speed twice without feeding audio in-between made it crash
with libavresample inc ertain cases (libswresample is fine). This is
probably a libavresample bug. Hopefully this will be fixed, and also I
attempted to workaround the situation that crashes it. (It seems to
point in direction of random memory corruption, though.)
2015-03-02 19:09:44 +01:00
Martin Herkt a17ea73636 af_rubberband: actually fix deadlock
371e5d0 missed this one
2015-02-12 10:15:12 +01:00
wm4 371e5d0665 af_rubberband: fix filter error deadlock
rubberband_available() can return a negative value, which we assigned to
a size_t variable, leading to the frame allocation to fail. This could
spam "Error filtering frame.". (That it spams this instead of exiting
should probably also be considered a bug.)

At least in the realtime mode and in our case, a negative return value
should not have any different meaning from a 0 return value, in
particular because we call rubberband_get_samples_required() or set the
"final" parameter for rubberband_process() to continue/stop processing.
2015-02-12 09:47:01 +01:00
Martin Herkt 2dc49ea866 af_rubberband: change defaults
After some testing, I am fairly convinced that these defaults sound
better than the previous settings. This also eliminates some issue
with random crackling and noise.

Also remove the `stretch` option since it has no effect in
realtime mode.
2015-02-12 00:58:40 +01:00
wm4 6299da2047 af_rubberband: fix breakage
The previous commit on this filter accidentally removed the
RubberBandOptionProcessRealTime option. Without it, the lib prints a
warning and passes the audio through.

Also add the RubberBandOptionSmoothingOn option back. Though for some
reason the output sounds still very wrong.
2015-02-11 21:32:01 +01:00
wm4 df5548a754 af_rubberband: make all librubberband options configurable
librubberband exports a big load of options. Normally, the default
settings (whether they're librubberband defaults or our defaults) should
be sufficient, but since I'm not so sure about this, making it
configurable allows others to figure it out for me.
2015-02-11 17:11:05 +01:00
wm4 6f24a61d84 af_rubberband: attempt to fix audio position calculation
The problem here is that librubberband can buffer an arbitrary amount
of data, but at the same time doesn't provide a way to query how much
data is buffered. So we keep track of this manually, assuming that
librubberband tries to reach the requested time ratio for input and
output (which is probably true).

The disadvantage is that rounding errors could accumulate over time.
(Maybe it should try to round towards keeping the time ratio.)
2015-02-11 16:32:40 +01:00
wm4 76501f4f57 af_rubberband: always calculate and set delay
Basically, add an if and reindent the block instead of exiting early.
2015-02-11 16:32:40 +01:00
wm4 d85aa35ffb af: account for queued frames in audio position calculation
af_rubberband exposed this issue.
2015-02-11 16:32:40 +01:00
wm4 8c055f873f af_rubberband: improve EOF handling
In theory it could happen that draining on EOF happens incrementally,
and then the unconditional reset could have dropped the remaining
buffered audio.
2015-02-11 16:31:35 +01:00
wm4 b6ab34fc98 af_rubberband: pitch correction with librubberband
If "--af=rubberband" is used, librubberband will be used to speed up or
slow down audio with pitch correction.

This still has some problems: the audio delay is not calculated
correctly, so the audio position jitters around by a few milliseconds.
This will probably ruin video timing.
2015-02-11 00:29:12 +01:00
wm4 81d8c5d519 af_scaletempo: allow changing speed at runtime without reinit
Staring at the code a bit, it turns out that changing speed without
losing state is quite easy. The initialization code is big and
complicated, but most of it is specific only to the configured audio
format, not the speed.

Refactor the code so that changing speed at runtime could work. (It's
not actually used yet - the player code still does a complete reinit.
This will be fixed in the next commit.)

The "if (s->speed_tempo == s->speed_pitch)" looks a bit strange, but
does the same thing as the code did before: speed can be changed only if
exactly one flag is set. If both are set or none, speed can't be
changed.
2015-02-10 22:34:07 +01:00
wm4 2a3d19a9df af_scaletempo: drop detaching or skipping init on speed=1
This code skipped initialization if no speed/pitch change was to be
applied.

It also didn't force conversion of the audio to a supported format,
which is probably the most important case in context of compatibility.
With this change applied, af_scaletempo will always force format
conversion.

To make the change less disruptive, make the filter detach if
unconvertable formats are used. Some users use spdif and also have
"af=scaletempo" in their config, so better not completely break this.

In the case the filter was added with the "speed=both" suboption, the
filter also detached itself in this case; but it's an obscure case, so I
don't care about that.
2015-02-10 22:14:26 +01:00
wm4 ae641d200a af: remove old filter compatibility hack 2015-01-15 20:13:15 +01:00
wm4 388cf6dc96 audio/filter: switch remaining filters to refcounting
All of these filters are very similar in frame management, and copy data
to a new frame during filtering.
2015-01-15 20:13:14 +01:00
wm4 87fe7d8788 audio/filter: switch remaining in-place filters to refcounting
Adds about 7 lines of boilerplate per filter. This could be avoided by
providing a different entrypoint (something like af->filter_inplace),
which would basically mirror the old interface exactly for this kind of
filter. But I feel like it would just be a hack to support all those
old, useless filters better. (The ideal solution would be using a
language that can do closures to provide a compat. wrapper, but
whatever.)

af_bs2b has terribly repetitious code for setting up filter functions
for each format (most of them useless, in addition to bs2b being
useless), so I did something terrible with macros.

af_sinesuppress had commented code for float filtering (maybe it was
broken; it has been commented every since it was added in 2006). Remove
this code.
2015-01-15 20:13:12 +01:00
wm4 ba0e8b754c af: verify filter input formats
Just to make sure all filters get the correct format. Together wih the
check in af_add_output_frame(), this asserts that

    af->prev->fmt_out == af->fmt_in

This also requires setting the "in" pseudo-filter (s->first) formats
correctly. Before this commit, the fmt_in/fmt_out fields weren't used
for this filter.
2015-01-15 20:10:46 +01:00
wm4 e865d255d0 af_lavcac3enc: use refcounted frames 2015-01-14 22:16:30 +01:00
wm4 5d972491bb af_lavfi: use refcounted frames 2015-01-14 22:15:56 +01:00
wm4 9c974b2a1b audio/filter: actually set fmt_in/fmt_out fields 2015-01-14 22:15:51 +01:00
wm4 f6a0a1554c af_scaletempo: use refcounted frames 2015-01-14 22:15:39 +01:00
wm4 218c749a16 af_lavrresample: use refcounted frames 2015-01-14 22:15:31 +01:00
wm4 ecca64e182 af_convert24: use refcounted frames
This requires allocating a fully new frame. 32->24 could be in-place,
but this is not possible for 24->32.
2015-01-13 20:17:08 +01:00
wm4 983f5efa3c audio/filters: use refcounted frames for some in-place filters
These are also quite simple, but require requesting write access to the
frames. The error handling (for OOM) is a bit annoying.
2015-01-13 20:17:03 +01:00
wm4 1fde40732e audio/filters: use refcounted frames for some simple filters
These are read-only, and very trivial to convert.
2015-01-13 20:16:59 +01:00
wm4 772c42a95c af_volume: use refcounted frames 2015-01-13 20:15:53 +01:00
wm4 5e25a3d216 audio: use refcounted frames in the filter chain
The goal is switching the whole audio chain to using refcounted frames.
This brings the architecture closer to FFmpeg, enables better
integration with libavfilter, will reduce useless copying somewhat, and
will probably allow better timestamp tracking.

For now, every filter goes through a semi-awful wrapper in
af_do_filter(), though. This will be fixed step by step, and the wrapper
should eventually be removed. Another thing that will have to be done is
improving the timestamp handling and avoiding extra copies for the AO.

Some of the new code is rather similar to the video filter code (the
core filter code basically just has types replaced). Such code
duplication is normally very unwanted, but in this case there's probably
no other choice. On the other hand, this code is pretty simple (even if
somewhat tricky). Maybe there will be unified filter code in the future,
but this is still far away.
2015-01-13 20:15:43 +01:00
wm4 0bbd65b09c audio/filter: remove unused af_calc_filter_multiplier()
The purpose of this function was to filter only as much audio input as
needed to produce a certain amount of audio output. This could (in
theory) avoid excessive buffering when e.g. changing playback speed with
resampling.

Use of this was already removed in commit 5fd8a1e0. No problems were
experienced, so let's assume this feature is practically worthless.
(Though it's possible that it was quite useful over a decade ago, or in
some cornercases with evil files.)
2015-01-13 20:14:02 +01:00
wm4 fda44ecc92 af_volume: dump applied replaygain in verbose mode 2015-01-04 01:35:48 +01:00
wm4 3fdb6be316 win32: add mmap() emulation
Makes all of overlay_add work on windows/mingw.

Since we now don't explicitly check for mmap() anymore (it's always
present), this also requires us to make af_export.c compile, but I
haven't tested it.
2014-12-26 17:30:10 +01:00
reimar 13b4fb9d28 af_hrtf: Fix out-of-range read.
Based on patch by Yuriy Kaminskiy [yumkam gmail].

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@37330 b3059339-0415-0410-9bf9-f77b7e298cf2
Signed-off-by: wm4 <wm4@nowhere>
2014-12-06 17:09:57 +01:00
wm4 7d6e58471f audio: make mp_audio_config_to_str return a stack-allocated string
Simpler overall.
2014-11-25 11:11:31 +01:00
wm4 c01a62efbc af_scaletempo: use float division for rate
From what I understand the division is to align the dimension of the
value from seconds to milliseconds. Hard to tell whether the "rounding"
was intentional or not; I'm tipping on "not".

Found by Coverity.
2014-11-21 10:09:15 +01:00
wm4 e082c2c3df Remove some unneeded NULL checks
Found by Coverity; also see commit 85fb2af3.
2014-11-21 09:58:09 +01:00
wm4 be9eb08389 af: remove redundant function 2014-11-12 20:19:21 +01:00
wm4 a669a1d0dd af: check audio params for validity
Normally, these should be valid anyway, so this is just being cautious.
2014-11-12 20:03:04 +01:00
wm4 5fd8a1e04c audio: make decoders output refcounted frames
This rewrites the audio decode loop to some degree. Audio filters don't
do refcounted frames yet, so af.c contains a hacky "emulation".

Remove some of the weird heuristic-heavy code in dec_audio.c. Instead of
estimating how much audio we need to filter, we always filter full
frames. Maybe this should be adjusted later: in case filtering increases
the volume of the audio data, we should try not to buffer too much
filter output by reducing the input that is fed at once.

For ad_spdif.c and ad_mpg123.c, we don't avoid extra copying yet - it
doesn't seem worth the trouble.
2014-11-10 22:02:05 +01:00
wm4 e094e9cb75 audio: change how filters are inserted on playback speed changes
Use a pseudo-filter when changing speed with resampling, instead of
somehow changing a samplerate somewhere. This uses the same underlying
mechanism, but is a bit more structured and cleaner. It also makes some
of the following changes easier.

Since we now always use filters to change audio speed, move most of the
work set_playback_speed() does to recreate_audio_filters().
2014-11-10 22:02:05 +01:00
wm4 995a6af787 af_format: remove redundant message prefixes 2014-11-10 22:02:04 +01:00
wm4 240266d12c af_lavcac3enc: fix byte order
Oops.

Fixes #1172.

CC: @mpv-player/stable
2014-10-12 11:33:35 +02:00
wm4 b5942f80de audio/filter: allow removing filters by label
Although the "af" command already could do this, it seems it's better
to introduce a lower level mechanism for now. This avoids some messy
issues, since that code would recursive call reinit_audio_chain().

To be used by the next commit.
2014-10-02 02:50:12 +02:00
wm4 7dd3822d09 audio: refactor some aspects of filter chain setup
There's no real reason why audio_init_filter() should exist. Just use
af_init or af_reinit directly. (We lose a useless message; the same
information is printed in a quite close place with more details.)

Requires less code, and the way the filter chain is marked as having
failed to initialize allows just switching off audio instead of
crashing if trying to insert a volume filter in mixer.c fails, and
recreating the old filter chain fails too.
2014-10-02 02:42:23 +02:00
wm4 2e16dfbf93 audio/filter: don't wipe full filter chain if adding a filter fails
There's no need for that, and in fact makes it more likely that it
recovers normally.
2014-10-02 01:20:01 +02:00
wm4 81bf9a1963 audio: cleanup spdif format definitions
Before this commit, there was AF_FORMAT_AC3 (the original spdif format,
used for AC3 and DTS core), and AF_FORMAT_IEC61937 (used for AC3, DTS
and DTS-HD), which was handled as some sort of superset for
AF_FORMAT_AC3. There also was AF_FORMAT_MPEG2, which used
IEC61937-framing, but still was handled as something "separate".

Technically, all of them are pretty similar, but may use different
bitrates. Since digital passthrough pretends to be PCM (just with
special headers that wrap digital packets), this is easily detectable by
the higher samplerate or higher number of channels, so I don't know why
you'd need a separate "class" of sample formats (AF_FORMAT_AC3 vs.
AF_FORMAT_IEC61937) to distinguish them. Actually, this whole thing is
just a mess.

Simplify this by handling all these formats the same way.
AF_FORMAT_IS_IEC61937() now returns 1 for all spdif formats (even MP3).
All AOs just accept all spdif formats now - whether that works or not is
not really clear (seems inconsistent due to earlier attempts to make
DTS-HD work). But on the other hand, enabling spdif requires manual user
interaction, so it doesn't matter much if initialization fails in
slightly less graceful ways if it can't work at all.

At a later point, we will support passthrough with ao_pulse. It seems
the PulseAudio API wants to know the codec type (or maybe not - feeding
it DTS while telling it it's AC3 works), add separate formats for each
codecs. While this reminds of the earlier chaos, it's stricter, and most
code just uses AF_FORMAT_IS_IEC61937().

Also, modify AF_FORMAT_TYPE_MASK (renamed from AF_FORMAT_POINT_MASK) to
include special formats, so that it always describes the fundamental
sample format type. This also ensures valid AF formats are never 0 (this
was probably broken in one of the earlier commits from today).
2014-09-23 23:11:54 +02:00
wm4 b745c2d005 audio: drop swapped-endian audio formats
Until now, the audio chain could handle both little endian and big
endian formats. This actually doesn't make much sense, since the audio
API and the HW will most likely prefer native formats. Or at the very
least, it should be trivial for audio drivers to do the byte swapping
themselves.

From now on, the audio chain contains native-endian formats only. All
AOs and some filters are adjusted. af_convertsignendian.c is now wrongly
named, but the filter name is adjusted. In some cases, the audio
infrastructure was reused on the demuxer side, but that is relatively
easy to rectify.

This is a quite intrusive and radical change. It's possible that it will
break some things (especially if they're obscure or not Linux), so watch
out for regressions. It's probably still better to do it the bulldozer
way, since slow transition and researching foreign platforms would take
a lot of time and effort.
2014-09-23 23:09:25 +02:00