Commit Graph

927 Commits

Author SHA1 Message Date
wm4 67b41f533e ao: align audio buffer size
Might or might not matter.
2015-03-13 20:49:22 +01:00
wm4 eb482140d9 audio: fix spdif packet size unit
In commit 5f8b060e I blindly assumed that the packet sizes were in
pseudo-samples, but they were actually in bytes. Oops.

(The effect was that cutting the audio was a bit less precise than it
can be.)

Also remove the packet size from ad_spdif.c; it didn't actually use it,
and simply takes what the spdif "muxer" returns.
2015-03-10 17:11:38 +01:00
wm4 69c61a882d audio: fix spdif DTS packet size
Broken in one of the previous commits.
2015-03-10 15:33:01 +01:00
wm4 5f8b060ec2 ad_spdif: move frame sizes to a general function
Needed for the next commit. This commit should probably be reverted as
soon as we're working with full audio frames internally, instead of
"flat" FIFOs.
2015-03-10 15:12:52 +01:00
wm4 2f5e31cf47 ao_coreaudio_exclusive: port to pull API, fix latency calculations
Instead of maintaining a private ring buffer, use the generic support
for audio APIs with pull callbacks (internally called AO pull API). This
also fixes latency calculations: instead of just returning the
ringbuffer status, the audio playback state is calculated better and
includes interpolation.

The main reason this wasn't done earlier was mid-stream format
switching. The pull API can now handle it (in a way) by destroying and
recreating the AO. This is a bit brutal, but quite simple. It's untested
in this new AO, though. Some details might not be right, like how ot
restores the old format when reloading.
2015-03-10 10:37:05 +01:00
wm4 fa75a7b6d7 ao_coreaudio: move some helpers to utils
Needed by ao_coreaudio_exclusive.c in the next commit.
2015-03-10 10:13:23 +01:00
wm4 ee14da2988 ao_coreaudio_exclusive: rip out pseudo volume control
This could mute a digital passthrough stream by writing zeros. All other
volume values did nothing.

The comment about MPlayer dying hasn't been true in mpv for quite a
while. It's even possible that it's fixed in upstream MPlayer. mpv will
print a scary error message when trying to change volume with spdif, and
continue normally.

If we really want to mute by writing zeros, we should do it in a
separate filter. But I'm not overly fascinated by this approach; is it
even guaranteed receivers will not be confused by a stream of zeros?

The main reason to remove this is that it's in the way of further
cleanups.
2015-03-10 10:08:15 +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 55f69605fb ad_spdif: remove per-packet message
It was annoying and didn't ever help with anything.
2015-03-04 17:31:42 +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
wm4 0035dbdbb8 audio: accept 1.0 and 2.0 as aliases for mono and stereo 2015-02-26 15:41:45 +01:00
Kevin Mitchell c52833bf16 ao/wasapi: move resume to audio thread
This echanges the two events hForceFeed/hFeedDone for hResume. This
like the last commit makes things more deterministic.

Importantly, the forcefeed is only done if there is not already a full
buffer yet to be played by the device. This should fix some of the
problems with exclusive mode.

This commit also removes the necessity to have a proxy to the
AudioClient object in the main thread.

fixes #1529
2015-02-23 14:02:08 -08:00
Kevin Mitchell 446fd5a43a ao_wasapi: move reset into audio thread
This makes things a bit more deterministic. It ensures that the audio
thread isn't doing anything between IAudioClient_Stop(),
IAudioClient_Reset() and setting the sample_count to 0.

Buffer overfilling on resume is still a problem in exclusive mode (see
next commit).
2015-02-23 14:01:05 -08:00
Stefano Pigozzi ecab0d6bb0 ao: fix null dereference 2015-02-14 16:41:08 +01:00
Stefano Pigozzi 70802d519f ao_coreaudio: add support for hotplug notifications
This commit adds notifications for hot plugging of devices. It also extends
the old behaviour of the `audio-out-detected-device` property which is now
backed by the hotplugging code. This allows clients to be notified when the
actual audio output device changes.

Maybe hotplugging should be supported for ao_coreaudio_exclusive too, but it's
device selection code is a bit fragile.
2015-02-14 12:51:15 +01:00
wm4 e01750020d ao_pulse: listen for hotplug events
This requires jumping through multiple hoops on fire. Since the
PulseAudio API is virtually undocumented, I'm not sure if this is
correct either. We only react to sink events, and only to the NEW/REMOVE
events. CHANGE events are ignored, because PulseAudio fires them far too
often - even if the system is completely idle! If pa_sink_info.name can
change, we're in trouble. pa_sink_info.description is not so important,
but it'd also be a bit un-nice if it can change, and we don't update it.

The weird way how the actual AO and the hotplug context share the same
struct (ao) comes in handy here, although context_success_cb() still had
to be duplicated from success_cb() - the unused argument has a different
type.
2015-02-12 17:18:43 +01:00
wm4 f061befb33 audio: add device change notification for hotplugging
Not very important for the command line player; but GUI applications
will want to know about this.

This only adds the internal API; support for specific audio outputs
comes later.

This reuses the ao struct as context for the hotplug event listener,
similar to how the "old" device listing API did. This is probably a bit
unclean and confusing. One argument got reusing it is that otherwise
rewriting parts of ao_pulse would be required (because the PulseAudio
API requires so damn much boilerplate). Another is that --ao-defaults is
applied to the hotplug dummy ao struct, which automatically applies such
defaults even to the hotplug context.

Notification works through the property observation mechanism in the
client API. The notification chain is a bit complicated: the AO notifies
the player, which in turn notifies the clients, which in turn will
actually retrieve the device list. (It still has the advantage that it's
slightly cleaner, since the AO stuff doesn't need to know about client
API issues.)

The weird handling of atomic flags in ao.c is because we still don't
require real atomics from the compiler. Otherwise we'd just use atomic
bitwise operations.
2015-02-12 17:17:41 +01:00
wm4 c152c59084 ao: set correct client name when listing devices
This is a small oversight. The client name (as set on command line
options or, more importantly, the client API) was not set when listing
devices e.g. via the "audio-device-list" property.

Might or might not fix #1578.

Also adjust the log level for an unrelated message.
2015-02-12 13:54:02 +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 67aeccc254 audio: fix pool allocation
It reallocated the pool on every request, making the pool completely
useless. Oops.
2015-02-11 11:36:07 +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
Stefano Pigozzi 5de7f1c5ac ao_coreaudio: fix small memory leak 2015-02-03 00:40:02 +01:00
Stefano Pigozzi de4f997752 ao_coreaudio: use device UID instead of ID for selection
Previously we let the user use the audio device ID, but this is not persistent
and can change when plugging in new devices. That of course made it quite
worthless for storing it as a user setting for GUIs, or for user scripts.

In theory getting the kAudioDevicePropertyDeviceUID can fail but it doesn't
on any of my devices, so I'm leaving the error reporting quite high and see if
someone complains.
2015-02-03 00:40:02 +01:00
Stefano Pigozzi a3be14683a command: add property returning detected audio device
This can be useful to adjust some other audio related properties
at runtime depending on the audio device being used.
2015-02-03 00:40:02 +01:00
wm4 12d822ce44 ao_null: add emulation for certain broken behavior
I'm not sure how common this behavior possibly is; well whatever. This
option will allow reproducing such behavior, and help debugging it.
2015-01-30 21:30:54 +01:00
Ben Boeckel b1d47786d8 ao_pulse: plug a memory leak 2015-01-25 01:26:11 +01:00
James Ross-Gowan 3c10ed540b ao_wasapi: fix try_format logic in shared mode
The MSDN documentation for IsFormatSupported says a return code of
AUDCLNT_E_UNSUPPORTED_FORMAT means the function "succeeded but the
specified format is not supported in exclusive mode." This seems to
imply that the format is supported in shared mode, and that's what the
old code assumed, however try_format would incorrectly return success
with some drivers.

The remarks section of the documentation contradicts that assumption. It
says that in shared mode, if the audio engine does not support the
caller-specified format or any similar format, ppClosestMatch is set to
NULL and the function returns AUDCLNT_E_UNSUPPORTED_FORMAT. This is the
same as in exclusive mode, so treat AUDCLNT_E_UNSUPPORTED_FORMAT the
same regardless of opt_exclusive. In shared mode, the format selection
code will fall back to the mix format, which should always be supported.
2015-01-23 22:02:15 +11:00
wm4 c0077ac936 ao_alsa: reinitialize if device got broken
Apparently, physically disconnecting the audio device (consider USB
audio) breaks the ALSA device handle forever. It will signal ENODEV.
Fortunately, it's easy for us to handle this, and we can just use
existing mechanisms that will make the playback core close and reopen
the AO. Whether the immediate reopening will actually succeeds really is
ALSA's problem, though.
2015-01-21 19:38:18 +01:00
wm4 1e6b4d31aa ao_coreaudio: reset possibly random errno value
In general, you need to check errno when using strtol(), but as far as I
know, strtol() won't reset errno on success. This has to be done
manually. The code could have failed sporadically if strtol() succeeded,
and errno was already set to one of the checked values.

(This strtol() still isn't fully error checked, but I don't know if it's
intentional, e.g. for parsing a numeric prefix only.)
2015-01-20 14:32:01 +01:00
wm4 d44b4ccba1 ao: never autoselect ao_null
Before this commit, ao_null was used as last fallback. This doesn't make
too much sense. Why would you decode audio just to discard it? Let audio
initialization fail instead. This also handles the weird but possible
corner-case that ao_null might fail initializing, in which case e.g.
ao_pcm could be autoselected. (This happened once, and had to be fixed
manually.)
2015-01-20 14:28:34 +01:00
wm4 3c2ca0cecc ao: refactor --audio-device selection code
This removes the slightly duplicated code for picking the required AO
driver if --audio-device forces one. Now --audio-device reuses the same
code as --ao for this.

As a consequence, ao_alloc_pb() and ao_create() can be merged into
ao_init(). Although the ao_init() argument list, which is already pretty
big, grows by one, it's better than having all these similar sounding
functions around.

Actually, I just wanted to do the change the following commit will do,
but I found this code was more of a mess than it had to be.
2015-01-20 14:25:47 +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 c757a06845 ao_alsa: fix a small memory leak 2015-01-14 22:16:36 +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