Commit Graph

1203 Commits

Author SHA1 Message Date
wm4 a4d5c19355 ao_coreaudio_exclusive: fix some verbose output 2015-07-04 17:25:12 +02:00
wm4 fc79fd0474 ao: don't pass along AO arguments when redirecting
Only causes problems.
2015-07-03 19:28:01 +02:00
wm4 514af9fbd1 ao_coreaudio: add exclusive suboption 2015-07-03 19:28:00 +02:00
wm4 e9e323f35d ao_coreaudio_exclusive: support PCM
Until now, this was for AC3 only. For PCM, we used AudioUnit in
ao_coreaudio, and the only reason ao_coreaudio_exclusive exists
is that there is no other way to passthrough AC3.

PCM support is actually rather simple. The most complicated
issue is that modern OS X versions actually do not support
copying through the data; instead everything must go through
float. So we have to deal with virtual and physical format
being different, which causes some complications.

This possibly also doesn't support some other things correctly.
For one, if the device allows non-interleaved output only, we
will probably fail. (I couldn't test it, so I don't even know
what is required. Supporting it would probably be rather
simple, and we already do it with AudioUnit.)
2015-07-03 19:28:00 +02:00
wm4 65e3657bc4 ao_coraudio: reject all non-PCM formats
Currently this is equivalent. On the other hand, all audio code should
reject formats that is not in a category known to it.
2015-07-03 19:28:00 +02:00
wm4 74e2c8a6ef ao_coreaudio_utils: reduce spam 2015-07-03 19:28:00 +02:00
wm4 ae3e151b27 ao_coreaudio_utils: fix format back-mapping
Mapping of spdif formats was imperfect. Since the first format on the
list is somehow AAC, it was returned first, which is confusing, because
CoreAudio calls all spdif formats AC3. Since the spdif formats have some
rather arbitrary, reverse mapping the formats didn"t actually work
either. Fix by explicitly ignoring these when spdif is used.

Also, don't forget to set the samplerate in ca_asbd_to_mpformat(), or it
will work only in some cases.
2015-07-03 19:28:00 +02:00
wm4 d4ab91f016 ao_coreaudio_exclusive: do not set ao->bps
This field is basically deprecated or for convenience only, and
this code doesn't need it.
2015-07-03 19:28:00 +02:00
wm4 597657110f ao_coreaudio_exclusive: dump all latency info in verbose mode 2015-07-03 19:28:00 +02:00
wm4 ec21be498f ao_coreaudio_exclusive: factor format selection 2015-07-03 19:28:00 +02:00
wm4 8a20e5306c ao_coreaudio_exclusive: separate out stream selection 2015-07-03 19:28:00 +02:00
wm4 7faa80ace8 af_lavrresample: log actual channel layout conversions
With all the reordering etc. that can go on in this filter, it's useful
to see what upmix/downmix it's actually performing.
2015-06-30 22:39:57 +02:00
wm4 2f8eabe216 ao_coreaudio: restore physical format if it can't be set exactly
May help with (supposedly) bad drivers, which can put the device into
some sort of broken state when trying to set a different physical
format. When the previous format is restored, it apparently recovers.

This might make the change-physical-format suboption more robust.
2015-06-30 00:02:12 +02:00
wm4 302aaddc26 ao_coreaudio: support native mono output
We can be pretty sure that AudioUnit will remix for us.

Before this commit, we usually upmixed to stereo, because the
stereo and multichannel layouts were the only whitelisted ones.
2015-06-29 23:55:03 +02:00
wm4 956b8658fb ao_coreaudio: log hotplug events explicitly 2015-06-29 23:54:18 +02:00
wm4 6ffb1e2b66 ao_wasapi: fix regression
This probably fixes the regression introduced with commit 6147bcce.
2015-06-27 17:59:27 +02:00
wm4 0969502316 chmap_sel: add a mechanism for preferred conversions
And use it for the mono case. This is slightly more formal and will make
it easier to add more such cases.
2015-06-27 12:09:30 +02:00
wm4 e0a7e094bc chmap_sel: remove outdated incomplete comment 2015-06-27 11:13:12 +02:00
wm4 6147bcce35 audio: fix format function consistency issues
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".
2015-06-26 23:06:37 +02:00
wm4 d6737c5fab audio: replace format name table
Having a big switch() is simpler.
2015-06-26 23:06:21 +02:00
wm4 efb50cabe6 audio: remove bitmask format definition mess
Audio formats used a semi-clever schema to encode the properties of the
PCM encoding as bitfields into the format integer value.

The af_fmt_change_bits() implementation becomes a bit weird, but it's
an improvement to the rest of the code.

(I've always disliked it, so why not get rid of it.)
2015-06-26 23:05:16 +02:00
wm4 554b4217a0 ao_coreaudio_utils: use a macro
This is actually the last line of code outside of format.c/h which still
tries to fiddle with the format bitfields.
2015-06-26 23:04:44 +02:00
wm4 e4e7fade96 ao_sndio: fix comment
So whoever (nobody?) would want to deal with this broken and obscure AO
for an obscure audio API could add support for some more channel
layouts.
2015-06-26 23:03:37 +02:00
wm4 cd6d846b70 ao_coreaudio: support non-interleaved output
This saves us the trouble of interleaving the audio data for
no reason.
2015-06-26 15:58:11 +02:00
wm4 8134a0601b ao_coreaudio: explicitly skip input streams
This may or may not fix some issues with the format switching
code. Actually, it seems somewhat unlikely, but then checking
the stream type isn't incorrect either, and is probably
something the API user should always be doing.
2015-06-26 15:56:19 +02:00
wm4 3c61e6eb4e ao_coreaudio_utils: compare full AudioStreamBasicDescription
Originally, this was written for comparing the sample format only, but
ca_change_physical_format_sync() actually expects that the full format
is compared. (For all other uses it doesn't matter.)
2015-06-25 20:17:14 +02:00
wm4 5a3cdb8f1e audio: output human-readable channel layouts too
This gets you the "logical" channel layout, instead of the exact thing
we're sending to the AO. (Tired of the cryptic shit ALSA gives me.)
2015-06-25 19:10:24 +02:00
wm4 fd1194de3c audio: fix channel map fallback selection (again)
The speaker replacement nonsense sometimes made blatantly incorrect
decisions. In this case, it prefered a 7.1(rear) upmix over outputting
5.1(side) as 5.1, which makes no sense at all. This happened because 5.1
and 7.1(rear) appeared equivalent to the final selection, as both of
them lose the sl-sr channels. The old code was too stupid to select the
one with the lower number of channels as well.

Redo this. There's really no reason why there should be a separate final
decision, so move the speaker replacement logic into the
mp_chmap_is_better() function.

Improve some other details. For example, we never should compare the
plain number of channels for deciding upmix/downmix, because due to NA
channels this is essentially meaningless. Remove the NA channels when
doing this comparison. Also, explicitly handle exact matches.
Conceptually this is not necessary, but it avoids that we have to
needlessly shuffle audio data around.
2015-06-25 17:32:00 +02:00
wm4 5d71188c99 ao: standardize channel layout name in debug output further 2015-06-25 13:15:32 +02:00
wm4 62269871aa af: move af_from_dB() function to af_volume.c
And also simplify it (it certainly had the most awkward API you could
think of for such a simple function).
2015-06-23 15:11:23 +02:00
wm4 4c6a600943 af_volume: add a replaygain fallback option 2015-06-23 15:07:19 +02:00
wm4 e7d5a5e688 af_lavrresample: free and reallocate resample context on reconfig
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.
2015-06-22 17:05:42 +02:00
wm4 cd78e0c5bf af_lavrresample: fix comment
mp_format is not a libavresample input format here, and the comment was
more confusing than it helped.
2015-06-22 16:06:40 +02:00
wm4 3d55340c6d af: restore detaching of PCM filters when using spdif
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.
2015-06-22 16:03:07 +02:00
wm4 17e8815e37 af_lavrresample: don't flush in uninitialized state
libswresample verbosely complains.
2015-06-22 16:03:03 +02:00
wm4 872b19dfcb ao_alsa: fix a log message
So apparently, this essentially happens when the kernel driver doesn't
implement write accesses in the channel map control. Which doesn't
necessarily mean that the channel map is unsupported, or that there is a
bug - it's just lazyness and a consequence of the terrible ALSA kernel
API for the channel mapping stuff.

In these cases, the channel count implicitly selects the channel map,
and snd_pcm_set_chmap() always fails with ENXIO.

I'm actually not sure what happens if dmix is on top of e.g. HDMI, which
actually lets you change the channel mapping.

I'm also not sure why commit d20e24e5d1614354e9c8195ed0b11fe089c489e4
(alsa-lib git repository) does not take care of this.
2015-06-21 18:32:38 +02:00
wm4 be882175d8 demux: merge extradata fields
MPlayer traditionally had completely separate sh_ structs for
audio/video/subs, without a good way to share fields. This meant that
fields shared across all these headers had to be duplicated. This commit
deduplicates essentially the last remaining duplicated fields.
2015-06-21 18:06:14 +02:00
wm4 2b64eee8d5 demux: rename sh_stream.format to sh_stream.codec_tag
Why not. "format" sounds too misleading for the actual importance and
meaning of this field.
2015-06-21 16:56:35 +02:00
Marcin Kurczewski 797277a233 Various spelling fixes
Signed-off-by: wm4 <wm4@nowhere>
2015-06-18 19:36:58 +02:00
wm4 d4aaf29a05 ao_wasapi: fix crash on hotplug init error
On init error, the mp_msg macros are actually called. They could cause
a crash because state->log was NULL.
2015-06-17 13:42:31 +02:00
wm4 762623cdef af_lavrresample: include osdep/endian.h
The 24 bit conversion code needs the relevant preprocessor symbols.
2015-06-17 13:41:45 +02:00
wm4 b2781c11ed af: remove conversion filter search
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.
2015-06-16 22:49:21 +02:00
wm4 552dc0d564 af_convert24: remove this filter 2015-06-16 22:40:37 +02:00
wm4 5a9f817bfd af_lavrresample: integrate 24 bit (3 bytes per sample) output
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.
2015-06-16 22:38:37 +02:00
wm4 8ee9c170be af_lavrresample: always fill reorder
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.
2015-06-16 21:40:29 +02:00
wm4 831d7c3c40 audio: remove S8, U16, U24, U32 formats
They are useless. Not only are they actually rarely in use; but
libavcodec doesn't even output them, as libavcodec has no such sample
formats for decoded audio.

Even if it should happen that we actually still need them (e.g. if doing
direct hardware output), there are better solutions. Swapping the sign
is a fast and lossless operation and can be done inplace, so AO actually
needing it could do this directly.

If you wonder why we keep U8 instead of S8: because libavcodec does it.
2015-06-16 21:11:59 +02:00
wm4 82ff32ffac audio: fix crash on uninit
Shit.
2015-06-15 20:28:05 +02:00
wm4 30f5ba9422 af_lavcac3enc: fix A/V sync
The filter can buffer singificant amounts of audio.

(The proper fix is making the filter chain PTS-aware.)
2015-06-15 14:33:48 +02:00
wm4 74a73752c2 af: fix an aspect of filter chain flushing
Even if we flush the current filter, we have to read the remaining
output from the frame we previously fed to the filter.
2015-06-15 14:33:07 +02:00
wm4 5eae20fc0f audio: remove unused readonly field
Its last use was removed in 433402b5.
2015-06-15 14:32:14 +02:00
wm4 9909234abe chmap: make up some channel layout names
Going by the existing names, these should make sense. HDMI knows about
these layouts, but does not name them.
2015-06-12 23:57:32 +02:00
wm4 6cc02658fa ao_alsa: if possible, reorder device maps to std layouts
Channel maps reported by the device as SND_CHMAP_TYPE_VAR can be freely
reordered. We don't use this much (out of laziness), but in this case
it's a simple way to reduce necessary reordering (which would be an
extra libavresample invocation), and to make debug output more readable.
2015-06-12 23:15:44 +02:00
wm4 5b269ce696 ao_alsa: make it accept 7.1 over HDMI
SDR/SDL is what lavc outputs for 7.1(rear), while RRC/RLC is what ALSA
uses for some 7.1 layouts, so this makes sense to me.
2015-06-12 23:08:09 +02:00
wm4 afdc060bb3 chmap_sel: improve speaker replacement handling
This didn't really work since the last time the channel map fallback
code was touched. In some cases, quite bad results were selected.
2015-06-12 19:23:46 +02:00
wm4 55624a70ee chmap_sel: do naive speaker replacements last
This prevents that the potentially better pick by
mp_chmap_sel_fallback() is overridden.
2015-06-12 19:21:01 +02:00
wm4 433402b56c audio: fill NA channels with silence
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.
2015-06-12 17:53:23 +02:00
wm4 c890eeac47 audio: use unknown channel layouts if there is no standard layout
This is just a conceptual issue, since for now every channel count has
an associated standard layout.

But should the max. channel count ever be bumped, some things would stop
function if mp_chmap_from_channels() refused to work for any channel
count within the allowed range.
2015-06-12 17:45:56 +02:00
wm4 11fee81a7a audio: fix messed up channel reordering
Quite a blunder, really.
2015-06-12 17:45:47 +02:00
wm4 627b87b0d8 audio: deal with AVFrame-style buffer assignments
In the AVFrame-style system (which we inreasingly map our internal data
stuctures on), buffers and plane pointers don't necessarily have a 1:1
correspondence. For example, a single buffer could cover 2 or more
planes, all while other planes are covered by a second buffer, and so
on. They don't need to be ordered in the same way.

Change mp_audio_get_allocated_size() to retrieve the maximum size all
planes provide. This also considers the case of planes not pointing to
buffer start.

Change mp_audio_realloc() to reset all planes, even if corresponding
buffers are not reallocated. (The caller has to be careful anyway if it
wants to be sure the contents are preserved on realloc calls.)
2015-06-12 17:44:40 +02:00
wm4 478ea1d0f3 ao_alsa: change ALSA braindeath heuristic
If you try to play surround with dmix, it will advertise surround and
lets you set more than 2 channels, but will report a stereo channel map,
with the extra channels identified as NA. We could handle this now, but
we don't want to (because it's excessively stupid).

Do it only if the channel map is not what we requested, instead of just
acting if it contains NA entries at all. This avoids that we hurt
ourselves in the unlikely but possible case we actually have to use
channel maps with NA entries.
2015-06-11 21:42:09 +02:00
wm4 b7d833c2a6 ao_coreaudio: change physical stream format synchronously 2015-06-09 18:26:14 +02:00
wm4 211088943c audio/out/pull: avoid dropping some audio when draining
If the audio API takes a while for starting the audio callback, the
current heuristic can be off. In particular, with very short files, it
can happen that the audio callback is not called before playback is
stopped, so no audio is output at all.

Change draining so that it essentially waits for the ringbuffer to
empty. The assumption is that once the audio API has read the data
via the callback, it will always output it, even if the audio API
is stopped right after the callback has returned.
2015-06-09 18:26:14 +02:00
wm4 a2b1c6d3f6 audio/out/pull: correctly pad partial frames with silence
If a frame could only be partially filled with real audio data, the
silence wasn't written at the correct offset. It could have happened
that the remainder of the frame contained garbage.

(This didn't happen in the more common case of playing dummy silence.)
2015-06-09 18:26:14 +02:00
wm4 8653ed2183 ao_alsa: refine channel count mismatch error message
I suspect we need to hand this more gracefully in some cases.
2015-06-09 18:21:56 +02:00
wm4 57048c7393 audio: add --audio-spdif as new method for enabling passthrough
This provides a new method for enabling spdif passthrough. The old
method via --ad (--ad=spdif:ac3 etc.) is deprecated. The deprecated
method will probably stop working at some point.

This also supports PCM fallback. One caveat is that it will lose at
least 1 audio packet in doing so. (I don't care enough to prevent this.)

(This is named after the old S/PDIF connector, because it uses the same
underlying technology as far as the higher level protoco is concerned.
Also, the user should be renamed that passthrough is backwards.)
2015-06-05 22:42:59 +02:00
wm4 14ac4f0bd6 ad_spdif: use a pseudo codec entry to select DTS-HD instead of an option
This deprecates the --ad-spdif-dtshd option, and replaces it with a
pseudo decoder. This means ad_spdif will report two decoders, "dts" and
"dts-hd", of which the second simply enables what the option did.

The --ad-spdif-dtshd option will actually be deprecated in the next
commit.
2015-06-05 22:34:48 +02:00
wm4 b2d058ef00 ao_alsa: refuse to use spdif if AES flags can't be set
Seems like a good idea to avoid accidentally playing noise by writing
spdif data to pure PCM devices.
2015-06-04 21:54:08 +02:00
wm4 fd96bddca9 af_lavrresample: slightly better computation of total delay
On libavresample, don't ignore the buffered output data.

On libswresample, don't round the total buffer size to the input
samplerate.
2015-06-04 21:23:46 +02:00
wm4 935997d4d6 af_lavrresample: use a new libswresample function if available
It was recently added to libswresample, and it does exactly what we
need.
2015-06-04 19:22:45 +02:00
wm4 2dc46423d6 af_lavrresample: change output samples calculation
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.
2015-06-04 19:08:40 +02:00
wm4 c277c17a93 ao_alsa: hack against potential spdif failure 2015-06-04 13:10:33 +02:00
wm4 e40b663da3 af_lavrresample: use native libavresample function for output size
This also drops the unused get_drain_samples() function.
2015-06-02 22:25:34 +02:00
wm4 7556f367d6 ao_coreaudio_exclusive: move generic functions to utils 2015-06-02 22:25:34 +02:00
wm4 7c0d3b9a50 ao_coreaudio_exclusive: react to device removal
Listening to kAudioDevicePropertyDeviceHasChanged does not send any
property change notifications when the device dies. Makes no sense,
but I suppose in CoreAudio logic a dead/removed device can't send
any notifications.

This caused the player to essentially pause playback if the audio
device was removed during playback.

Fix by listening to the kAudioHardwarePropertyDevices property too,
which will actually be sent in this specific case. Then, if
querying the already dead device fails, we know we have to reload.
2015-06-02 22:25:30 +02:00
wm4 87a94a5655 ao_coreaudio_exclusive: make property listeners event-based
In short, instead of letting the coreaudio property listener set atomic
flags (which are then polled), make the property listeners actually
active.

The format change listener used during audio output now simply calls
ao_request_reload() on its own. All code involved is thread-safe, so
there's no need to do it during this audio callback (we assumed the
callback was never run concurrently with itself).

The listener installed temporarily during ca_change_format() is changed
to post a semaphore. Get rid of the weird retry logic and replace it
with a flat loop + timeout. It appears the maximum wait time could be
2500ms; reduce the total timeout to 500ms instead.
2015-06-02 21:04:40 +02:00
wm4 37d505f363 ao: allow ao_uninit(NULL) 2015-06-02 21:03:04 +02:00
wm4 fe8634ea90 af_lavrresample: fix and simplify flushing on playback speed change
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.
2015-06-02 20:30:30 +02:00
wm4 302901ddaf ao_alsa: hack back mono output
The ALSA API is inconsistent and doesn't report support. Just requesting
1 channel actually works. Whatever.
2015-05-25 22:10:35 +02:00
wm4 a165a61415 audio: make softvol scale cubic
This brings the volume control closer to what is percepted as linear
volume change.

Adjust the --softvol-max default to roughly the old maximum (roughly
doubles the gain).
2015-05-22 19:16:42 +02:00
wm4 68bbab0e42 audio: change range of volume option/property
Now --volume takes an absolute volume, meaning it doesn't depend on
--softvol-max. 0 is still silence, and 100 now always means unchanged
volume. The OSD and the "volume" property are changed accordingly.

Also raise the minimum value of --softvol-max. A value below 100 makes
no sense and breaks the OSD.
2015-05-22 18:35:03 +02:00
wm4 7412995c94 chmap: use av_popcount64()
Saves us some code, and also happens to fix #1968.
2015-05-21 20:37:17 +02:00
wm4 1919f1e05b ad_spdif: use DTS-HD passthrough only if the audio is really DTS-HD
Apparently some A/V receivers do not behave well if "normal" DTS is
passed through using the high bitrate spdif format normally used for
DTS-HD (other receivers are fine with it).

Parse the first packet passed to ad_spdif by decoding it with libavcodec
in order to get the profile. Ignore the --ad-spdif-dtshd if it's not
DTS-HD. (If the codec profile changes midstream, the user is out of
luck. But this is probably an insignificant corner case.)

I thought about parsing the bitstream, but let's not. While it probably
wouldn't be that much effort, we are trying to keep it down on codec
details here - otherwise we could just do our own spdif framing instead
of using libavformat's spdif pseudo-muxer.

Another possibility, using the codec parameters signalled by
libavformat, is disregarded. Our builtin Matroska decoder doesn't do
this, and also we do not want on the demuxer having to decode some
packets in order to retrieve codec params (as libavformat does).

Fixes #1949.
2015-05-19 21:35:43 +02:00
wm4 a6d3a6919a ad_spdif: set output format lazily
Preparation for the following commit, which looks at the packet data
before deciding what to output.
2015-05-19 21:34:30 +02:00
wm4 92b9d75d72 threads: use utility+POSIX functions instead of weird wrappers
There is not much of a reason to have these wrappers around. Use POSIX
standard functions directly, and use a separate utility function to take
care of the timespec calculations. (Course POSIX for using this weird
format for time values.)
2015-05-11 23:44:36 +02:00
wm4 ca9964a4fb ao: make better use of atomics
The main reason for this was compatibility; but some associated problems
have been solved in the previous commit.
2015-05-11 23:27:41 +02:00
wm4 00130651da audio: simplify further
Drop mp_chmap_diff() (which is unused too now), and implement
mp_chmap_diffn() in a slightly simpler way. (Too bad there is no
standard function for counting set bits.)
2015-05-08 21:22:39 +02:00
wm4 8d5924f2c9 audio: remove mp_chmap_contains()
It's unsued now.
2015-05-08 21:14:23 +02:00
wm4 8b7035c8ff ao: log reordered versions of channel maps
Useful for debugging cases when no standard orders are used.
2015-05-08 19:45:16 +02:00
wm4 3560a50029 audio: redo channel map fallback selection
Instead of somehow having 4 different cases with each their own weight,
do it with a single function that decides which channel layout is the
better fallback.

This is simpler, and also introduces new (fixed) semantics. The new test
added to test/chmap_sel.c actually works now. This is a mixed case with
no perfect upmix or downmix, but the better choice is the one which
loses the least channels from the original layout.

One test also changes. If the input is 7.1(wide-side), and the available
layouts are 7.1 and 5.1(side), the latter is now chosen instead of the
former. This makes sense: both layouts contain 6 out of 8 channels from
the original layout, but the 5.1(side) one is smaller. This follows the
general logic. The 7.1 layout has FLC/RLC speakers instead of BL/BR,
and judging by the names, "front left center" is completely different
from "back left". If these should be exchangeable, a separate exception
would have to be added.
2015-05-08 19:33:17 +02:00
wm4 d32b71d52e audio: add chmap utility function 2015-05-08 19:33:08 +02:00
wm4 ad9bce2a5c ao_alsa: log requested numbers of channels if ALSA rejects them 2015-05-08 14:24:20 +02:00
wm4 7b09654c33 audio: fix messed up assert()
This made no sense and always evaluated to true.
2015-05-07 23:26:33 +02:00
wm4 55e777f10b audio: remove UNKNOWN pseudo speakers
Reuse MP_SPEAKER_ID_NA for this. If all mp_chmap entries are set to NA,
the channel layout has special "unknown channel layout" semantics, which
are used to deal with some corner cases.
2015-05-07 23:20:06 +02:00
wm4 b91b4944bd audio: define only a single NA speaker ID
Remove the requirement from mp_chmap that speaker entries must be
unique. Use this to get rid of all the redundant NA speaker IDs.
2015-05-07 23:07:14 +02:00
wm4 1bcb82ec93 ao_coreaudio_utils: don't list some formats as "unusable"
While mpv has no internal equivalent representation, they can still be
used as physical CoreAudio formats. Thus this label is confusing.
2015-05-07 20:55:00 +02:00
wm4 cd5ab98ff9 ao_sndio: add notice about padding channels
(I won't do this, but someone else seeing this might.)
2015-05-06 21:48:40 +02:00
wm4 85fc6b2a05 ao_alsa: use new padding channels support
Sometimes, ALSA will return channel layouts with padded channels (NA
speakers). Use them instead of failing.

This still includes the old "braindeath" code to retry with a layout
without NA channels. This might be helpful for performance, and also the
padded channel layout string looks confusing.

To be fair, I have not encountered a case yet which would really need
this, and for which the old "braindeath" code did not fix it.
2015-05-06 21:48:40 +02:00
wm4 d577872a28 ao_alsa: move ALSA -> mp channel map to a function
One side effect is that the warning about too many channels goes away,
and is replaced with printing the ALSA channel map as "unknown".
2015-05-06 21:48:40 +02:00
wm4 0ae0e90eb5 ao_coreaudio_exclusive: check new format before waiting for change
It seems if the format was already set, setting the same format will
not cause a property change.
2015-05-06 21:48:39 +02:00
wm4 4444ff48fa ao_coreaudio_exclusive: use atomics instead of volatile
volatile barely means anything.

The polling is kind of bad too, but relatively harmless as device
opening/closing is a rare event, and the format change is not expected
to take long.

Remove the pointless talloc call too (must have been a leftover
from previous refactoring).
2015-05-06 21:48:36 +02:00
wm4 028739932b ao_coreaudio_exclusive: rename "digital" -> "compressed"
PCM is digital too.
2015-05-06 18:54:53 +02:00
wm4 1e1045b13e ao_coreaudio_exclusive: explicitly check for spdif formats 2015-05-06 18:51:31 +02:00
wm4 32bc61ae07 ao_coreaudio_exclusive: merge init_digital() function
No reason to keep them separate. It's an artifact from the old
ao_coreaudio.c, which kept usage of two different APIs in the same file.
Removes a forward reference too.
2015-05-06 18:46:51 +02:00
wm4 4ffcf2531b ao_coreaudio_utils: decide formats by comparing raw bits
Instead of trying to use af_format_conversion_score() (which tries to be
all kinds of clever), just compare the raw bits as a quality measure. Do
this because otherwise, weird formats like padded 24 bit formats will be
excluded, even though they might be the highest precision formats for
some hardware.

This means that for now, the user would have to check whether the format
is usable at all before calling ca_asbd_is_better(). But since this is
currently only used for ao_coreaudio.c and for the physical format, it
doesn't matter.

If coreaudio-exclusive should get PCM support, the best would be to
revert this change, and to add support for 24 bit formats directly.
2015-05-05 22:10:33 +02:00
wm4 656703e279 ao_coreaudio: log considered physical formats 2015-05-05 22:09:44 +02:00
wm4 86d65c80e1 ao_coreaudio: restore old physical format if format was changed 2015-05-05 22:09:39 +02:00
wm4 0025030cef af: don't attempt to remove last filter for spdif filter removal
Some time ago, a mechanism was added for automatically removing PCM-only
filters if the input format is spdif.

This could cause an infinite loop if the AO did not support spdif, but
was falling back to some PCM format. Then this code tried to remove the
last filter, which is a dummy filter for receiving and queuing filter
output. af_remove() simply fails gracefully in this case, so this
happens over and over again.

Fix by explicitly checking whether the filter to remove is a dummy
filter. (af_remove() also fails only if the dummy filters are attempted
to be removed - checking this directly is simpler.)
2015-05-05 21:47:48 +02:00
wm4 d76f9a484e audio: minor cosmetics
These ( ) were probably not removed when the format constants were
changed from defines to an enum.
2015-05-05 21:47:36 +02:00
wm4 934109a35b ao_coreaudio: move channel mapping code to a separate file
Move all of the channel map retrieval/negotiation code to a separate
file. This will (probably) be helpful when extending
ao_coreaudio_exclusive.c.

Nothing else changes, other than some minor cosmetics and renaming,
and changing some details for decoupling it from the ao_coreaudio.c
internals.
2015-05-05 21:47:19 +02:00
wm4 399267393b ao_coreaudio_utils: don't require talloc for fourcc_repr()
Instead, apply a trick to make the caller allocate enough space on the
stack.
2015-05-05 21:47:04 +02:00
wm4 7a5f5a8adf ao_coreaudio_utils: unbreak default device selection
It appears this is the reason coreaudio-exclusive does not work without
explicitly specifying a device, even if the default device maps to
something passthrough-capable.
2015-05-05 21:46:54 +02:00
wm4 bbedceb467 ao_coreaudio_exclusive: fix latency calculation non-sense
Didn't use the properties it was supposed to use.
2015-05-05 21:46:39 +02:00
wm4 fd6809f98a ao_coreaudio_utils: refine format selection
Instead of always picking a somehow better format over the previous one,
select a format that is equal to or better the requested format, but is
also reasonably close.

Drop the mFormatID comparison - checking the sample format handles this
already.

Make sure to exclude channel counts that can't be used.
2015-05-05 21:46:17 +02:00
wm4 66f4e7cce4 ao_coreaudio: change physical format before channel negotiation
If for example the physical format is set to stereo, the reported
multichannel layout will actually be stereo. It fixes itself only after
the physical format is changed.
2015-05-05 21:45:55 +02:00
wm4 8121529a6c ao_coreaudio: add an option for changing the physical format
ao_coreaudio uses AudioUnit - the OSX software mixer. In theory, it
supports multichannel audio just fine. But in practice, this might be
disabled by default, and the user is supposed to select a multichannel
base format in the "Audio MIDI Setup" utility.

This option attempts to change this setting automatically. Some possible
disadvantages and caveats are listed in the manpage additions. It is off
by default, since changing this might be rather bad behavior for a
normal application.
2015-05-05 01:11:16 +02:00
wm4 305a85cc9a ao_coreaudio_utils: add a format negotiation helper function 2015-05-05 01:11:16 +02:00
wm4 f719b8164d af_lavrresample: remove dead undefs 2015-05-05 01:11:16 +02:00
wm4 4d8a7e0394 ao_coreaudio: support padded channel layouts
If for example the audio settings are set to 5.1 output, but the
hardware does 8 channels natively (HDMI), the reported channel
layout will have 2 dummy channels. To avoid falling back to stereo,
we have to write audio in this format to the device.
2015-05-05 01:11:16 +02:00
wm4 06050aed99 audio: introduce support for padding channels
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.)
2015-05-05 01:11:16 +02:00
wm4 1b0b094ca2 audio: introduce mp_audio readonly bit
Convenience for the following commit.
2015-05-04 23:57:25 +02:00
wm4 937c8e513f audio: chmap: explicitly drop channels not supported by lavc
Basically as before, but avoid undefined behavior.
2015-05-04 23:56:27 +02:00
wm4 548cd826c2 audio: drop unused function 2015-05-04 23:54:53 +02:00
wm4 eead97f103 ao_coreaudio: fix out of bounds access
ca_label_to_mp_speaker_id() checked whether the last entry was >= 0, but
actually this condition was never true, and MP_SPEAKER_ID_UNKNOWN0 is
not negative.
2015-05-04 23:54:38 +02:00
wm4 382434d45a ao_coreaudio_exclusive: check format explicitly on change notifcation
This should for now be equivalent; it's merely more explicit and will
be required if we add PCM support.

Note that the property listeners actually tell you what property
exactly changed, but resolving the current listener mess would be too
hard. So check for changes manually.
2015-04-29 23:10:45 +02:00
wm4 34a5229b23 ao_coreaudio_utils: log mp format with CoreAudio format description
As a consequence, it also logs whether mpv can a this format at all.
2015-04-29 23:07:36 +02:00
wm4 32b835c03b ao_coreaudio_utils: add function for ASBD -> mp format lookup
Useful with some of the following commits.

ca_fill_asbd() should behave exactly as before.

Instead of actually implementing the inverse function of ca_fill_asbd(),
just loop over the (small) list of mpv functions and check if any mpv
equivalent to a given ASBD exists.
2015-04-29 23:06:10 +02:00
wm4 3295ce48ab ao_coreaudio_utils: float is not a signed integer format
kAudioFormatFlagIsSignedInteger implicates that it's only used with
integer formats. The mpv internal flag on the other hand signals the
presence of a sign, and this is set on float formats.

Until now, this probably worked fine, because at least AudioUnit is
ignoring the uncorrect flag.
2015-04-29 22:39:28 +02:00
wm4 8b4ca58062 ao_coreaudio_exclusive: move code for getting original format
Should be almost equivalent, unless there are streams on which this call
does not work for unknown reasons.
2015-04-28 22:11:43 +02:00
wm4 d5e9bf66a1 ao_coreaudio_utils: change audio format logging
Make it easier to distinguish the fields.
2015-04-28 22:11:05 +02:00
wm4 5f86fad2f0 ao_coreaudio_exclusive: account for additional latency
Whether this is correct is unknown. This change tripples the latency
from ~15ms to ~45ms.

XBMC does this, VLC does not from what I could see.
2015-04-28 22:09:51 +02:00
wm4 c4aa136155 audio: separate fallbacks for upmix and downmix cases
We always want to prefer upmix to downmix, as long as it makes sense.
Even if the upmix is not "perfect" (not just adding channels), we want
to prefer the upmix.

Cleanup for commit d3c7fd9d.
2015-04-28 22:01:55 +02:00
wm4 d3c7fd9d7c audio: avoid downmixing in a certain special-case
As indicated by the added test. In this case, fallback and downmix have
the same score, but fallback happens to give better results. So prefer
fallback over downmix.

(This is probably not a correct solution.)
2015-04-27 23:21:58 +02:00
wm4 570f4b136f ao_null: add an option for testing channel layout selection 2015-04-27 23:21:58 +02:00
wm4 c6d046414b player: change video-bitrate and audio-bitrate properties
Remove the old implementation for these properties. It was never very
good, often returned very innaccurate values or just 0, and was static
even if the source was variable bitrate. Replace it with the
implementation of "packet-video-bitrate". Mark the "packet-..."
properties as deprecated. (The effective difference is different
formatting, and returning the raw value in bits instead of kilobits.)

Also extend the documentation a little.

It appears at least some decoders (sipr?) need the
AVCodecContext.bit_rate field set, so this one is still passed through.
2015-04-20 20:52:16 +02:00
wm4 d8dd4b6c39 af_lavrresample: fix draining
configure_lavrr() clears s->pending, so we have to assign it after that
call.
2015-04-18 13:39:40 +02:00
wm4 2896afaa39 ao_alsa: fallback to stereo channel layout if everything else fails
mp_chmap_from_channels_alsa() doesn't always succeed - there are a bunch
of channel counts for which no defined ALSA layout exists. Fallback to
stereo in this case. (Normally, this code path shouldn't happen at all.)
2015-04-14 21:19:01 +02:00
Marcin Kurczewski f43017bfe9 Update license headers
Signed-off-by: wm4 <wm4@nowhere>
2015-04-13 12:10:01 +02:00
wm4 ab2a27ae01 af_lavrresample: minor simplification
The in/out pointers usually have not much meaning outside of
AF_CONTROL_REINIT. Also remove the redundant casts.
2015-04-12 18:07:05 +02:00
wm4 f8a98fc133 af_lavrresample: allow resetting output sample format
It must be allowed to set format==0.
2015-04-12 18:07:05 +02:00
wm4 e466a735a3 audio/filter: fully renegotiate audio formats on every reconfig
It could happen that a lavrresample filter would keep its old output
format when the decoder changed its output format. This simply happened
because the output format was never reset.

Normally, this was not an issue, because lavrresample filters only
inserted for format conversion were removed on format changes. But if
--no-audio-pitch-correction is set and playback speed is changed, then
there is a "permanent" lavrresample filter in the filter chain, which
shows this behavior.

Fix by explicitly resetting output formats for all filters which support
it.

Note: this can crash with libswresample in some cases. I'm not sure if
this is mpv's fault or libswresample's, but since it works with
libavresample, I'm going to assume it's not our's.
2015-04-12 18:06:23 +02:00
wm4 77869e5914 ao_coreaudio: fix inverted condition
And also use the correct type for the printf call below.
2015-04-10 13:51:13 +02:00
wm4 36ae8a6cab audio: automatically deatch filters if spdif prevents their use
Fixes #1743 and partially #1780.
2015-04-07 21:38:39 +02:00
wm4 579c4dac34 audio: change a detail about filter insertion
The af_add() function has a problem: if the inserted filter returns
AF_DETACH during init, the function will have a dangling pointer. Until
now this was avoided by making sure none of the used filters actually
return AF_DETACH, but it's getting infeasible.

Solve this by requiring passing an unique label to af_add(), which is
then used instead of the pointer.
2015-04-07 21:24:22 +02:00
wm4 e98ab5e596 ao_alsa: change log output
Silence the usually user-visible warning about unsupported channel maps.
This might be an ALSA bug, but ALSA will never fix this behavior anyway.
(Or maybe it's a feature.)

Log some other information that might be useful.
2015-04-07 18:11:27 +02:00
wm4 5574820f13 ao_coreaudio: do not error if retrieving info for verbose mode fails
The message log level shouldn't get to decide whether something fails
or not. So replace the fatal error check on the verbose output code
path with a warning.
2015-04-07 12:23:24 +02:00
Kevin Mitchell 642f84f922 ao/wasapi: use atomic state variable instead of different events
Unfortunately, because we have proxy objects (pAudioVolumeProxy,
pEndpointVolumeProxy, pSessionControlProxy) it looks like we still
have to use MsgWaitForMultipleObjects and watch for and dispatch
pending messages:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms680112%28v=vs.85%29.aspx
2015-04-04 16:31:14 -07:00
Kevin Mitchell fe60cff03b ao/wasapi: reorder priv members 2015-04-04 16:31:14 -07:00
Kevin Mitchell bf3e0bc1da ao_wasapi: code formatting and alignment 2015-04-03 15:40:01 -07:00
Kevin Mitchell 46b9df9f9e audio: make all format query shortcuts macros
af_fmt_is_float and af_fmt_is_planar were previously inconsistent with
AF_FORAMT_IS_SPECIAL/AF_FORMAT_IS_IEC61937
2015-04-03 15:40:01 -07:00
Kevin Mitchell 07671ac57b ao_wasapi: passthrough rework
* unify passthrough and pcm exclusive mode format setting/testing
* set passthrough format parameters correctly
* support all of mpv's existing passthrough formats
* automatically test passthrough with exclusive mode and enable
  exclusive if it succeeds, even if it was not explictly requested.
  this obviates the need for --ao=wasapi,wasapi=exclusive
* if passthrough fails (such as the device doesn't support the
  format), fallback to either exclusive pcm or shared mode depending
  on what the user specified. Right now this isn't very useful as
  it still fails due to the decoder path remainin stuck on spdif.

fixes #1742
2015-04-03 15:39:51 -07:00