Commit Graph

1442 Commits

Author SHA1 Message Date
wm4 f29bba1123 af: avoid rebuilding filter chain in another minor case
No need to create additional noise of we can trivially see that
rebuiding the chain won't change anything.
2016-07-15 13:04:17 +02:00
wm4 d191d76e52 ao_pulse: fix some volume control rounding issues
Volume could get easily "stuck" or making too huge steps when doing
things like "add ao-volume 1".
2016-07-14 18:11:14 +02:00
wm4 f53d73b9dc ao_creoaudio: print OSStatus as decimal signed integer too
OSStatus is quite inconsistent. Sometimes it's a FourCC, sometimes it
reads as decimal signed number.
2016-07-13 17:07:06 +02:00
wm4 79f48500e2 ao_coreaudio: use correct free function on errors 2016-07-13 16:34:00 +02:00
wm4 e246c3f060 audio: fix code for adjusting conversion filters
This code was supposed to adjust existing conversion filters (to make
them output a different format). But the code was just broken,
apparently a refactoring accident. It accessed af instead of af->prev.

The bug tended to add new conversion filters, even if an existing one
could have been used. (Can be tested by inserting a dummy lavrresample
filter followed by a format filter which forces conversion.)

In addition, it's probably better to return the actual error code if
reinitializing the filter fails. It would then respect an AF_FALSE
return value, which means format negotiation failed, instead of a
generic error.
2016-07-11 12:23:32 +02:00
wm4 61afe3820a af_volume: don't let softvol overwrite af_volume volumedb sub-option
af_volume has a volumedb sub-option, which allows the user to set an
explicit volume. Until recently, the player read back this value and
used it as initial softvol volume. But now it just overwrites it.

Instead of overwriting it, multiply the different gain values. Above
all, this will do the right thing if only softvol is used, or if the
user only adds the af_volume filter manually.
2016-07-11 11:03:36 +02:00
wm4 60048b7eb9 audio: add heuristic to move auto-downmixing before other filters
Normally, you want downmixing to happen first thing in the filter chain.
This is reflected in codec downmixing, which feeds the filter chain
downmixed audio in the first place. Doing this has the advantage of
needing less data to process. But the main motivation is that if there
is a drc filter in the chain, you want to process it the downmixed
audio.

Add an idiotic heuristic to achieve this. It tries to detect whether the
audio was indeed automatically downmixed (or upmixed). To detect what
the output format is going to be, it builds the filter chain normally,
and then retries with the heuristic applied (and for extra paranoia,
retries without the heuristic again if it fails to successfully rebuild
the filter chain for unknown reasons). This is simple and will work in
almost all cases.

Doing it in a more complete way is rather hard, because filters are so
generic. For example, we know absolutely nothing about the behavior of
af_lavfi, which creates an opaque filter graph with libavfilter. We
don't know why a filter would e.g. change the channel layout on its
output. (Our heuristic bails out in this case.) We're also slave to the
lowest common denominator of how our format negotiation works, and how
libavfilter's works.

In theory, we could make this mechanism explicit by introducing a
special dummy filter. The filter chain would then try to convert between
input and output formats at the dummy filter, which would give the user
more control over how downmix happens. On the other hand, the user could
just insert explicit conversion filters instead, so this would probably
have questionable value.
2016-07-10 19:53:53 +02:00
wm4 7be98ef1b2 audio: add auto-inserted flag to filter list logging
Like the video filter chain.
2016-07-10 19:51:09 +02:00
wm4 2eac58eaa9 audio: cleanup audio filter format negotiation
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.
2016-07-10 19:51:09 +02:00
wm4 e518bf2c72 audio: insert audio-inserted filters at end of chain
This happens to be better for the af_volume filter (for softvol), and
saves some code too. It's "better" because you want to affect the
final filtered audio, such as after a manually inserted drc filter.
2016-07-09 20:23:15 +02:00
wm4 d47b708f00 audio: don't crash when changing volume if no audio is initialized
Oversight.
2016-07-09 19:34:45 +02:00
wm4 995c47da9a audio: drop --softvol=no and --softvol=auto
Drop the code for switching the volume options and properties between
af_volume and AO volume controls. interface-changes.rst mentions the
changes in detail.

Do this because this was exceedingly complex and had other problems as
well. It was also very hard to test. It's just not worth the trouble.

Some leftovers like AOCONTROL_HAS_PER_APP_VOLUME will be removed at a
later point.

Fixes #3322.
2016-07-09 18:31:18 +02:00
wm4 885e991312 ao_coreaudio: error out when selecting invalid device
When selecting a device that simply doesn't exist with --audio-device,
AudioUnit will still initialize and start playback without complaining.
But it will never call the audio render callback, which leads to audio
playback simply not progressing.

I couldn't find a way to get AudioUnit to report an error at all, so
here's a crappy hack that takes care of this in most cases. We assume
that all devices have a kAudioDevicePropertyDeviceIsAlive property.
Invalid devices will error when querying the property (with 'obj!' as
status code).

This is not the correct fix, because we try to double-guess AudioUnit's
behavior by accessing a lower label API. Suggestions welcome.
2016-07-08 16:11:03 +02:00
wm4 5d2f1da7c5 vf, af: print filter labels in verbose mode 2016-07-06 14:13:03 +02:00
wm4 614efea3e6 ad_lavc: work around braindead ffmpeg behavior
The libavcodec wmapro decoder will skip some bytes at the start of the
first packet and return each time. It will not return any audio data in
this state.

Our own code as well as libavcodec's new API handling
(avcodec_send_packet() etc.) discard the PTS on the first return, which
means the PTS is never known for the first packet. This results in a
"Failed audio resync." message.

Fixy it by remember the PTS in next_pts. This field is used only if the
decoder outputs no PTS, and is updated after each frame - and thus
should be safe to set.

(Possibly this should be fixed in libavcodec new API handling by not
setting the PTS to NOPTS as long as no real data has been output. It
could even interpolate the PTS if the timebase is known.)

Fixes the failure message seen in #3297.
2016-07-01 15:51:34 +02:00
wm4 c6953bfa8c ao_oss: do not add an entry to audio-device-list if device file missing
This effectively makes it go away on Linux (unless you have OSS
emulation loaded).
2016-06-29 17:40:04 +02:00
wm4 deb1c3c7a8 audio: don't add default entry to audio-device-list if AO support listing
In such cases there isn't really a reason to do so, and using such an
entry would probably fail anyway.

Also convenient for the following commit.
2016-06-29 17:38:57 +02:00
wm4 4ce53025cb audio: add a helper for getting frame end PTS
Although I don't see any use for it yet, why not.
2016-06-27 15:12:21 +02:00
wm4 3e58ce96ac dec_audio: fix segment boudnary switching
Some bugs in this code are exposed by e.g. playing lossless audio files
with --ad-lavc-threads=16. (libavcodec doesn't really support threaded
audio decoding, except for lossless files.) In these cases, a major
amount of audio can be buffered, which makes incorrect handling of this
buffering obvious.

For one, draining the decoder can take a while, so if there's a new
segment, we shouldn't read audio.

The segment end check was completely wrong, and used the start value.
2016-06-27 15:12:21 +02:00
Rudolf Polzer acb74236ac ao_lavc, vo_lavc: Migrate to new encoding API.
Also marked some places for possible later refactoring, as they became
quite similar in this commit.
2016-06-27 08:33:12 -04:00
stepshal c5094206ce Fix misspellings 2016-06-26 13:47:21 +02:00
wm4 1c3bbd9318 af_lavcac3enc: use av_err2str() call (fixes Libav build)
I added this call because I thought it'd be nice, but Libav doesn't have
this function (macro, actually).
2016-06-23 12:41:41 +02:00
wm4 e911e208b8 af_lavcac3enc: make encoder configurable 2016-06-23 12:14:45 +02:00
wm4 5c74da4503 af_lavcac3enc: implement flushing on seek
There's a lot of data that could have been buffered, and which has to be
discarded.
2016-06-23 12:07:05 +02:00
wm4 c071c30bcd af_lavcac3enc: port to new encode API 2016-06-23 12:04:04 +02:00
wm4 b01855714b af_lavcac3enc: automatically configure most encoder parameters
Instead of hardcoding what the libavcodec ac3 encoder expects, configure
it based on the AVCodec fields.

Unfortunately, it doesn't export the list of sample rates, so that is
done manually. This commit actually fixes the rate always to 48Khz. I
don't even know whether the other rates worked. (Possibly did, but
they'd still change the spdif parameters, and would work differently
from ad_spdif.c.)
2016-06-23 12:02:36 +02:00
wm4 5a60f594e5 af_lavcac3enc: drop log message prefixes
MPlayer leftover. They're already added by the logging code.
2016-06-23 10:45:56 +02:00
wm4 31b73d5ca0 af_lavcac3enc: fix custom bitrates
Probably has been broken for ages.

(Not sure why anyone would use this feature, though.)
2016-06-23 10:43:54 +02:00
wm4 7ea22fe889 ad_lavc: resume from mid-stream EOF conditions with new decode API
Workaround for an awful corner-case. The new decode API "locks" the
decoder into the EOF state once a drain packet has been sent. The
problem starts with a file containing a 0-sized packet, which is
interpreted as drain packet.

This should probably be changed in libavcodec (not treating 0-sized
packets as drain packets with the new API) or in libavformat (discard
0-sized packets as invalid), but efforts to do so have been fruitless.

Note that vd_lavc.c already does something similar, but originally for
other reasons.

Fixes #3106.
2016-06-22 21:37:36 +02:00
wm4 b00eab525a audio: apply an upper bound timeout when draining
This helps with shitty APIs and even shittier drivers (I'm looking at
you, ALSA). Sometimes they won't send proper wakeups. This can be fine
during playback, when for example playing video, because mpv still will
wakeup the AO outside of its own wakeup mechanisms when sending new data
to it. But when draining, it entirely relies on the driver's wakeup
mechanism. So when the driver wakeup mechanism didn't work, it could
hard freeze while waiting for the audio thread to play the rest of the
data.

Avoid this by waiting for an upper bound. We set this upper bound at the
total mpv audio buffer size plus 1 second. We don't use the get_delay
value, because the audio API could return crap for it, and we're being
paranoid here. I couldn't confirm whether this works correctly, because
my driver issue fixed itself.

(In the case that happened to me, the driver somehow stopped getting
interrupts. aplay froze instead of playing audio, and playing audio-only
files resulted in a chop party. Video worked, for reasons mentioned
above, but drainign froze hard. The driver problem was solved when
closing all audio output streams in the system. Might have been a dmix
related problem too.)
2016-06-12 21:05:10 +02:00
wm4 972ea9ca59 audio: do not wake up core during EOF
When we're draining, don't wakeup the core on every buffer fill, since
unlike during normal playback, we won't actually get more data. The
wakeup here conceptually works like wakeups with condition variables, so
redundant wakeups do not hurt, so this is just a minor change and
nothing of consequence.

(Final EOF also requires waking up the core, but there is separate code
to send this notification.)

Also dump the p->still_playing field in trace logging.
2016-06-12 20:59:11 +02:00
Niklas Haas 5b5db336e9 build: silence -Wunused-result
For clang, it's enough to just put (void) around usages we are
intentionally ignoring the result of.

Since GCC does not seem to want to respect this decision, we are forced
to disable the warning globally.
2016-06-07 14:12:33 +02:00
Kevin Mitchell b3e74f652b ao_wasapi: initialize COM in main thread with MTA
Since the main thread is shared by other things in the player, using STA (single
threaded aparement) may have caused problems. Instead initialize in MTA
(multithreaded apartment).
2016-06-05 16:31:03 -07:00
Josh de Kock 4aa017e301 ao_opensles: remove 32bit audio
It's unsupported by android, and can cause problems when trying to play 32bit audio. Removing 32bit fixes it by forcing 16 bit or 8 bit audio.
2016-05-22 14:31:37 +02:00
wm4 a93fb460cd ao_alsa: add more shitty workarounds
This reportedly makes it work on ODROID-C2. The idea for this hack is
taken from kodi; they unconditionally set some or all of those flags.
I don't trust ALSA enough to hope that setting these flags couldn't
break something else, so we try without them first.

It's not clear whether this is a driver bug or a bug in the ALSA libs.
There is no ALSA bug tracker (the ALSA website has had a dead link to
a deleted bug tracker fo years). There's not much we can do other than
piling up ridiculous hacks. At least I think that at this point invalid
API usage by mpv can be excluded as a cause.

ALSA might be the worst audio API ever.
2016-05-06 17:20:02 +02:00
wm4 51e4c065ff ao_alsa: log final hwparams too
snd_pcm_hw_params() updates them.
2016-05-03 11:24:47 +02:00
James Ross-Gowan 622bcb0e37 win32: replace libuuid.a usage with initguid.h
Including initguid.h at the top of a file that uses references to GUIDs
causes the GUIDs to be declared globally with __declspec(selectany). The
'selectany' attribute tells the linker to consolidate multiple
definitions of each GUID, which would be great except that, in Cygwin
and MinGW GCC 6.1, this method of linking makes the GUIDs conflict with
the ones declared in libuuid.a.

Since initguid.h obsoletes libuuid.a in modern compilers that support
__declspec(selectany), add initguid.h to all files that use GUIDs and
remove libuuid.a from the build.

Fixes #3097
2016-05-01 21:10:24 +10:00
wm4 d30634b104 ao_alsa: log hwparams while restricting them
They can sometimes fail, so I want logging to determine what's going on.

Most of them are at debug log-level, except the final hwparams.
2016-04-28 13:31:13 +02:00
wm4 66a958bb4f ao_coreaudio: remove detected_device
Setting this here is a race condition. It's called from a CoreAudio
callbacks, and there are no locks. It's a string, so this can be
potentially severe.

It's hard to fix and only CoreAudio supported it, so remove it.

This causes the "audio-out-detected-device" property to return nothing
on all platforms.
2016-04-26 18:35:37 +02:00
wm4 78346e9c9a ad_spdif: take care of deprecated libavcodec API usage 2016-04-20 19:37:45 +02:00
wm4 607ba5f235 ao_coreaudio_exclusive: list formats when searching substream
Should help debug problems with AC3 passthrough not working.
2016-04-15 14:19:22 +02:00
wm4 1aa943d8ab ao_coreaudio: remove unused function 2016-04-15 14:14:42 +02:00
Rudolf Polzer 160497b8ff encode_lavc: Migrate to codecpar API. 2016-04-11 14:57:20 -04:00
wm4 64791a0832 ao_coreaudio_exclusive: add missing newline to log message 2016-04-01 12:24:39 +02:00
wm4 c971220cdd demux_lavf, ad_lavc, ad_spdif, vd_lavc: handle FFmpeg codecpar API change
AVFormatContext.codec is deprecated now, and you're supposed to use
AVFormatContext.codecpar instead.

Handle this for all of the normal playback code.

Encoding mode isn't touched.
2016-03-31 22:00:45 +02:00
wm4 4300bfd518 ad_lavc, vd_lavc: support new Libav decoding API
For now only found in Libav.
2016-03-24 17:53:30 +01:00
wm4 f0febc35eb ad_lavc: add codec_timebase hack too
vd_lavc.c had this, and soon I'll need it in ad_lavc.c too. For now it's
unused.
2016-03-24 16:39:15 +01:00
Kevin Mitchell e26462599b ao_lavc: use new af_select_best_samplerate function
This is particularly useful for opus which allows only a fairly restrictive set
of samplerates. If the codec doesn't provide a list of samplerates, just
continue to try the requsted one and hope for the best.

fixes #2957
2016-03-17 02:31:05 -07:00
Kevin Mitchell 96053d53a7 ao_wasapi: use new af_select_best_samplerate function
It duplicates the logic that was previously used here.
2016-03-17 02:31:05 -07:00
Kevin Mitchell a0884c82a9 audio: add af_select_best_samplerate function
This function chooses the best match to a given samplerate from a provided
list. This can be used, for example, by the ao to decide what samplerate to use
for output.
2016-03-17 02:31:05 -07:00
Kevin Mitchell 183e2cda30 ao_wasapi: make wait for audio thread termination infinite
The time-out was a terrible hack for marginally better behaviour when
encountering #1773, which appears to have been resolved by a previous commit.
2016-02-26 15:43:51 -08:00
Kevin Mitchell 67b7038be3 ao_wasapi: further flatten/simplify volume control 2016-02-26 15:43:51 -08:00
Kevin Mitchell 534571f794 ao_wasapi: use MP_FATAL for stuff that leads to init failure 2016-02-26 15:43:51 -08:00
Kevin Mitchell af90616ebe ao_wasapi: move pre-resume reset into resume function 2016-02-26 15:43:51 -08:00
Kevin Mitchell 1841cac9f8 ao_wasapi: move resetting the thread state into main loop
This was previously duplicated between the reset/resume functions, and
not properly handled in the "impossible" invalid thread state case.
2016-02-26 15:43:51 -08:00
Kevin Mitchell 82f102cfe3 ao_wasapi: set buffer size to device period in exclusive mode
This eliminates some intermittent pops heard in a HRT MicroStreamer DAC
uncorrelated with user interaction. As a bonus, this resolves #1773 which I can
o longer reproduce as of this commit. Leave the 50ms buffer for shared mode
since that seems to be working quite well.

This is also the way exclusive mode is done in the MSDN example code:
https://msdn.microsoft.com/en-us/library/windows/desktop/dd370844%28v=vs.85%29.aspx

This was originally increased in c545c40 to mitigate glitches that subsequent
refactorings have eliminated.
2016-02-26 15:43:51 -08:00
Kevin Mitchell 84a3c21beb ao_wasapi: replace laggy COM messaging with mp_dispatch_queue
A COM message loop is apparently totally inappropriate for a low latency
thread. It leads to audio glitches because the thread doesn't wake up fast
enough when it should. It also causes mysterious correlations between the vo
and ao thread (i.e., toggling fullscreen delays audio feed events). Instead use
an mp_dispatch_queue to set/get volume/mute/session display name from the audio
thread. This has the added benefit of obviating the need to marshal the
associated interfaces from the audio thread.
2016-02-26 15:43:51 -08:00
Kevin Mitchell 31539884c8 ao_wasapi: avoid under-run cascade in exclusive mode.
Don't wait for WASAPI to send another feed event if we detect an underfull
buffer. It seems that WASAPI doesn't always send extra feed events if
something causes rendering to fall behind. This causes every subsequent playback
buffer to under-run until playback is reset. The fix is simply to do a one-shot
double feed when this happens, which allows rendering to catch up with playback.

This was observed to happen when using MsgWaitForMultipleObjects to wait for the
feed event and toggling fullscreen with vo=opengl:backend=win. This commit
improves the behaviour in that specific case and more generally makes exclusive
mode significantly more robust.

This commit also moves the logic to avoid *over*filling the exclusive mode
buffer into thread_feed right next to the above described underfil logic.
2016-02-26 15:43:51 -08:00
Kevin Mitchell 5e124a4ac3 ao_wasapi: fix typo in comment 2016-02-26 15:43:51 -08:00
Kevin Mitchell a842ad8f50 ao_wasapi: use SUCCEEDED/FAILED macros 2016-02-26 15:43:51 -08:00
Ilya Zhuravlev 72aea5a12b ao: initial OpenSL ES support
OpenSL ES is used on Android. At the moment only stereo output is
supported. Two options are supported: 'frames-per-buffer' and
'sample-rate'. To get better latency the user of libmpv should pass
values obtained from AudioManager.getProperty(PROPERTY_OUTPUT_FRAMES_PER_BUFFER)
and AudioManager.getProperty(PROPERTY_OUTPUT_SAMPLE_RATE).
2016-02-27 00:00:36 +01:00
wm4 7c181e5b9b audio: make mp_audio_skip_samples() adjust the PTS
Slight simplification/cleanup.
2016-02-22 20:13:31 +01:00
wm4 9ee340c3af ad_lavc: skip AVCodecContext.delay samples at beginning
Fixes correctness_trimming_nobeeps.opus. One nasty thing is that this
mechanism interferes with the container-signalled mechanism with
AV_FRAME_DATA_SKIP_SAMPLES. So apply it only if that is apparently not
present. It's a mess, and it's still broken in FFmpeg CLI, so I'm sure
this will get fucked up later again.
2016-02-22 20:10:38 +01:00
wm4 289edadb8d ad_lavc: make sample trimming symmetric to skipping
I'm not quite sure what the FFmpeg AV_FRAME_DATA_SKIP_SAMPLES API
demands here. The code so far assumed that skipping can be more than a
frame, but not trimming. Extend it to trimming too.
2016-02-22 19:58:11 +01:00
wm4 d52b2981c0 ad_lavc: move skipping logic out of the HAVE_AVFRAME_SKIP_SAMPLES block 2016-02-22 19:50:09 +01:00
wm4 65b858f7d3 ad_lavc: interpolate missing timestamps
This is actually already done by dec_audio.c. But if
AV_FRAME_DATA_SKIP_SAMPLES is applied, this happens too late here. The
problem is that this will slice off samples, and make it impossible for
later code to reconstruct the timestamp properly.

Missing timestamps can still happen with some demuxers, e.g. demux_mkv.c
with Opus tracks. (Although libavformat interpolates these itself.)
2016-02-22 13:08:36 +01:00
wm4 1bb1543a88 audio: move frame clipping to a generic function 2016-02-21 18:16:41 +01:00
wm4 0af5335383 Rewrite ordered chapters and timeline stuff
This uses a different method to piece segments together. The old
approach basically changes to a new file (with a new start offset) any
time a segment ends. This meant waiting for audio/video end on segment
end, and then changing to the new segment all at once. It had a very
weird impact on the playback core, and some things (like truly gapless
segment transitions, or frame backstepping) just didn't work.

The new approach adds the demux_timeline pseudo-demuxer, which presents
an uniform packet stream from the many segments. This is pretty similar
to how ordered chapters are implemented everywhere else. It also reminds
of the FFmpeg concat pseudo-demuxer.

The "pure" version of this approach doesn't work though. Segments can
actually have different codec configurations (different extradata), and
subtitles are most likely broken too. (Subtitles have multiple corner
cases which break the pure stream-concatenation approach completely.)

To counter this, we do two things:
- Reinit the decoder with each segment. We go as far as allowing
  concatenating files with completely different codecs for the sake
  of EDL (which also uses the timeline infrastructure). A "lighter"
  approach would try to make use of decoder mechanism to update e.g.
  the extradata, but that seems fragile.
- Clip decoded data to segment boundaries. This is equivalent to
  normal playback core mechanisms like hr-seek, but now the playback
  core doesn't need to care about these things.

These two mechanisms are equivalent to what happened in the old
implementation, except they don't happen in the playback core anymore.
In other words, the playback core is completely relieved from timeline
implementation details. (Which honestly is exactly what I'm trying to
do here. I don't think ordered chapter behavior deserves improvement,
even if it's bad - but I want to get it out from the playback core.)

There is code duplication between audio and video decoder common code.
This is awful and could be shareable - but this will happen later.

Note that the audio path has some code to clip audio frames for the
purpose of codec preroll/gapless handling, but it's not shared as
sharing it would cause more pain than it would help.
2016-02-15 21:04:07 +01:00
wm4 f2b039da77 audio/video: expose codec info as separate field
Preparation for the timeline rewrite. The codec will be able to change,
the stream header not.
2016-02-15 20:34:45 +01:00
wm4 6eae6a785c ad_lavc: fix --ad-lavc-threads range
The code is shared with the --vd-lavc-threads option, so using 0 for
auto-detection just works.

But no, this is not useful. Just change it for orthogonality.
2016-02-11 22:06:58 +01:00
Jan Ekström ff0112e08d Initial Android support
* Adds an 'android' feature, which is automatically detected.
* Android has a broken strnlen, so a wrapper is added from FreeBSD.
2016-02-10 21:29:36 +01:00
wm4 bb6ae0e50b audio: minor simplification
These fields are already deallocated by uninit_decoder(). Also remove
the wrong/useless log message.
2016-02-05 23:43:25 +01:00
wm4 45345d9c41 build: make libavfilter mandatory
The complex filter support that will be added makes much more complex
use of libavfilter, and I'm not going to bother with adding hacks to
keep libavfilter optional.
2016-02-05 23:17:33 +01:00
wm4 363a225364 ao_coreaudio: fix 7.1(rear) channel mapping
I can't explain this, but it seems to be a similar case to the ALSA HDMI
one. I find it hard to tell because of the slightly different names and
conventions in use in libavcodec, WAVEEXT channel masks, decoders, codec
specifications, HDMI, and platform audio APIs.

The fix is the same as the one for ao_alsa (see commit be49da72). This
should fix at least playing 7.1 sources on OSX with 7.1(rear) selected
in Audio MIDI Setup. The ao_alsa commit mentions XBMC, but I couldn't
find out where it does that or if it also does that for CoreAudio. It's
woth noting that PHT (essentially an old XBMC fork) also exhibited the
incorrect behavior (i.e. side and back speakers were swapped).
2016-02-04 12:29:32 +01:00
wm4 54d0f5bc9a af_lavrresample: change fudged channels
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).
2016-02-04 12:28:54 +01:00
wm4 ab318aeea8 audio/video: merge decoder return values
Will be helpful for the coming filter support. I planned on merging
audio/video decoding, but this will have to wait a bit longer, so only
remove the duplicate status codes.
2016-02-01 22:03:04 +01:00
wm4 effc466222 Fix build on Libav
I hope.
2016-01-30 14:14:59 +01:00
wm4 c5a48c6332 audio: move pts reset check
Reduces the dependency of the filter/output code on the decoder.
2016-01-29 22:44:20 +01:00
wm4 354c1fc06d audio: move mp_audio->AVFrame conversion to a function
This also makes it refcounted, i.e. the new AVFrame will reference the
mp_audio buffers, instead of potentially forcing the consumer of the
AVFrame to copy the data.

All the extra code is for handling the >8 channels case, which requires
very messy dealing with the extended_ fields (not our fault).
2016-01-29 22:43:00 +01:00
Kevin Mitchell 4d5d25fdbb ao_wasapi: add "wasapi" prefix to non-static find_deviceID function 2016-01-28 00:56:03 -08:00
Kevin Mitchell e927ff1666 ao_wasapi: correct check for specified device on default change
Correctly avoid a reload if the current device was specified by the user through
--audio-device. Previously, we only recognized if the user had specified
--ao=wasapi:device=.
2016-01-28 00:55:58 -08:00
Kevin Mitchell f1072be3b7 ao_wasapi: fix check for already found device
oops, forgot to change this when I made get_deviceID a more proper function.
state->deviceID is not set or read here - that's for the caller to do.
2016-01-28 00:24:58 -08:00
wm4 d8aeeaa4b1 command: always allow setting volume/mute properties
This seems generally easier when using libmpv (and was already requested
and implemented before: see commit 327a779a; it was reverted some time
later).

With the weird internal logic we have to deal with, in particular the
--softvol=no case (using system volume), and using the audio API's mixer
(--softvol=auto on some systems), we still can't avoid all glitches and
corner cases that complicate this issue so much. The API user is either
recommended to use --softvol=yes or auto, or to watch the new
mixer-active property, and assume the volume/mute properties have
significant values if the mixer is active.

Remaining glitches:
- changing the volume/mute properties has no effect if no internal mixer
  is used (--softvol=no) and the mixer is not active; the actual mixer
  controls do not change, only the property values
- --volume/--mute do not have an effect on the volume/mute properties
  before mixer initialization (the options strictly are only applied
  during mixer init)
- volume-max is 100 while the mixer is not active
2016-01-26 15:23:09 +01:00
wm4 2e3a508387 af_lavfi, vf_lavfi: fix compilation on Libav
It has no avfilter_graph_send_command().
2016-01-22 20:53:52 +01:00
wm4 f176104ed5 command: add af-command command
Similar to vf-command. Requested. Untested.
2016-01-22 20:36:54 +01:00
Kevin Mitchell ce0b26c60f ao_wasapi: use correct UINT type for device enumeration
Notably, the address of the enumerator->count member is passed to
IMMDeviceCollection::GetCount(), which expects a UINT variable, not an int. How
did this ever work?
2016-01-22 03:21:21 -08:00
Kevin Mitchell ff7884e635 ao_wasapi: exit earlier if there are zero playback devices found
Previously, if the enumerator found no devices, attempting to get the default
device with IMMDeviceEnumerator::GetDefaultAudioEndpoint would result in the
cryptic (and undocumented) E_PROP_ID_UNSUPPORTED. This way, the user is given a
better indication of what exactly is wrong and isolates any other possible
triggers for this error.
2016-01-22 03:21:21 -08:00
wm4 fef8b7984b audio: refactor: work towards unentangling audio decoding and filtering
Similar to the video path. dec_audio.c now handles decoding only. It
also looks very similar to dec_video.c, and actually contains some of
the rewritten code from it. (A further goal might be unifying the
decoders, I guess.)

High potential for regressions.
2016-01-22 00:25:44 +01:00
wm4 ca00e347fc ad_spdif: if DTS-HD is requested, and profile unknown, use DTS-HD
This means there will be no loss if profile detection failed for some
reason.
2016-01-20 17:18:28 +01:00
wm4 ac966ded11 audio: change downmix behavior, add --audio-normalize-downmix
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.
2016-01-20 17:14:04 +01:00
wm4 aaafbfcc06 audio: remove initial decoding retry limitation
Seems useless.

This only helped in one case: one audio stream in the sample
av_find_best_stream_fails.ts had a AC3 packets which couldn't be
decoded, and for which avcodec_decode_audio4() returned 0 forever. In
this specific case, playback will now not start, and you have to
deselect audio manually.

(If someone complains, the old behavior might be restored, but
differently.)

Also remove the stale "bitrate" field.
2016-01-19 22:49:05 +01:00
wm4 30031edce3 audio: move direct packet reading from decoders to common code
Another bit of preparation.
2016-01-19 22:24:38 +01:00
wm4 c365b44e19 audio: move dec_audio.pool to ad_spdif
That's where its only use is.
2016-01-19 21:33:05 +01:00
wm4 7737499a74 ao_coreaudio_chmap: change license to LGPL
While the situation is not really clear for the other rewritten
coreaudio code, it's very clear for the channel mapping code. It was all
written by us. (MPlayer doesn't even have any channel map handling.)
2016-01-19 21:21:49 +01:00
wm4 8a9b64329c Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.

There are probably more files to which this applies, but I'm being
conservative here.

A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).

common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.

codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.

From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).

misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.

screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 18:36:06 +01:00
Kevin Mitchell a99b63db08 ao_wasapi: use share_mode value instead of raw option opt_exclusive
Previously used opt_exclusive option to decide which volume control code to run.
The might not always reflect the actual state, for example if passthrough
is used. Admittedly, none of the volume controls will work anyway with
passthrough, but this is the right thing to do.
2016-01-18 20:50:54 -08:00
Kevin Mitchell cd5eb1bb19 ao_openal: wipe out global context on init error
Previously this would break all further attempts to init the driver after one
had failed.
2016-01-18 20:46:22 -08:00
wm4 418c98dec7 af_lavrresample: fudge some channel layout conversion
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.
2016-01-18 16:31:50 +01:00
wm4 671df54e4d demux: merge sh_video/sh_audio/sh_sub
This is mainly a refactor. I'm hoping it will make some things easier
in the future due to cleanly separating codec metadata and stream
metadata.

Also, declare that the "codec" field can not be NULL anymore. demux.c
will set it to "" if it's NULL when added. This gets rid of a corner
case everything had to handle, but which rarely happened.
2016-01-12 23:48:19 +01:00
Dmitrij D. Czarkoff ea442fa047 mpv_talloc.h: rename from talloc.h
This change helps avoiding conflict with talloc.h from libtalloc.
2016-01-11 21:05:55 +01:00
wm4 9fee7077d4 ao_coreaudio: replace fourcc_repr()
Replace with the more general mp_tag_str().
2016-01-11 20:25:00 +01:00
wm4 31a4547187 ao_wasapi: move out some utility functions
Note that hresult_to_str() (coming from wasapi_explain_err()) is mostly
wasapi-specific, but since HRESULT error codes are unique, it can be
extended for any other use.
2016-01-11 16:24:13 +01:00
wm4 bd5a02d080 player: detect audio PTS jumps, make video PTS heuristic less aggressive
This is another attempt at making files with sparse video frames work
better.

The problem is that you generally can't know whether a jump in video
timestamps is just a (very) long video frame, or a timestamp reset. Due
to the existence of files with sparse video frames (new frame only every
few seconds or longer), every heuristic will be arbitrary (in general,
at least).

But we can use the fact that if video is continuous, audio should also
be continuous. Audio discontinuities can be easily detected, and if that
happens, reset some of the playback state.

The way the playback state is reset is rather radical (resets decoders
as well), but it's just better not to cause too much obscure stuff to
happen here. If the A/V sync code were to be rewritten, it should
probably strictly use PTS values (not this strange time_frame/delay
stuff), which would make it much easier to detect such situations and
to react to them.
2016-01-09 20:39:28 +01:00
wm4 3e90a5fe81 ao_dsound: remove this audio output
It existed for XP-compatibility only. There was also a time where
ao_wasapi caused issues, but we're relatively confident that ao_wasapi
works better or at least as good as ao_dsound on Windows Vista and
later.
2016-01-06 13:52:15 +01:00
Kevin Mitchell 27ccad541a ao_wasapi: remove unnecessary header file
All the wasapi files were including both ao_wasapi.h and ao_wasapi_utils.h.
Just merge them into a single file.
2016-01-05 17:47:55 -08:00
Kevin Mitchell bf611ff0f6 ao_wasapi: initialize change notify in main thread
This is something else that has nothing to do with audio rendering.
2016-01-05 17:47:55 -08:00
Kevin Mitchell 0c877d2fdc ao_wasapi: remove old vistablob prototype
this function was removed earlier, but the prototype was missed
2016-01-05 17:47:55 -08:00
Kevin Mitchell 8368ead1fa ao_wasapi: make find_deviceID read only wrt struct ao
This makes it clearer that state->device is being allocated.
2016-01-05 17:47:55 -08:00
Kevin Mitchell d22d24a6d5 ao_wasapi: move device selection to main thread
In attempt to simplify the audio event thread, this can now be moved out.
2016-01-05 17:47:55 -08:00
Kevin Mitchell fb84c6974d ao_wasapi: avoid some redundant error messages in device selection
If these error conditions are triggered, the called function will have already
output a sufficiently informantive error message.
2016-01-05 17:47:55 -08:00
Kevin Mitchell 92ded6c6fd ao_wasapi: alloc later to avoid free on error
In get_device_desc, don't alloc the return value until we know there
wasn't an error.
2016-01-05 17:47:55 -08:00
wm4 c1002f6a28 ao_pulse: attempt to fall back to an arbitrary sample format
Normally, PulseAudio accepts any combination of sample format, sample
rate, channel count/map. Sometimes it does not. For example, the channel
rate or channel count have fixed maximum values. We should not fail
fatally in such cases, but attempt to fall back to a working format.

We could just send pass an "unset" format to Pulse, but this is not too
attractive. Pulse could use a format which we do not support, and also
doing so much for an obscure corner case is not reasonable. So just pick
a format that is very likely supported.

This still could fail at runtime (the stream could fail instead of going
to the ready state), but this sounds also too complicated. In
particular, it doesn't look like pulse will tell us the cause of the
stream failure. (Or maybe it does - but I didn't find anything.)

Last but not least, our fallback could be less dumb, and e.g. try to fix
only one of samplerate or channel count first to reduce the loss, but
this is also not particularly worthy the effort.

Fixes #2654.
2016-01-05 19:52:05 +01:00
wm4 861c126b08 ao_pulse: check for sample rate bounds
pa_format_info_valid() does not do this. (Although there is a proposed
patch on the PulseAudio mailing list.)

See #2654.
2016-01-05 19:37:08 +01:00
wm4 8fda7247ff ao_pulse: move format setting into a function
No real functional changes.
2016-01-05 19:34:34 +01:00
wm4 09f0f68959 ao_wasapi: remove +x flag from files 2016-01-04 19:18:02 +01:00
wm4 dac5b598f5 chmap_sel: prefer inexact equivalents over perfect upmix
Given 5.1(side), this lets it pick 5.1 from [5.1, 7.1]. Which was
probably the original intention of this replacement stuff. Until now,
the opposite was done in some cases.

Keep the old heuristic if the replacement is not perfect. This would
mean that a subset of the channel layout is an inexact equivalent, but
not all of it.

(My conclusion is that audio output APIs should be designed to simply
take any channel layout, like the PulseAudio API does.)
2016-01-04 19:17:56 +01:00
Kevin Mitchell cb8b0cc329 ao_wasapi: just use a pointer to the deviceID in change_notify
Rather than creating a new string from the device instance. This will allow
moving the change_init to the main thread before the device is loaded.
2016-01-04 07:41:21 -08:00
Kevin Mitchell 029e31f1c5 ao_wasapi: correctly name the IMMNotificationClientVtbl 2016-01-04 07:41:21 -08:00
Kevin Mitchell efb9943637 ao_wasapi: make persistent enumerator local to change_notify
This is no longer required by anything else
2016-01-04 07:41:21 -08:00
Kevin Mitchell 243a2976a8 ao_wasapi: rewrite device listing and selection
Unify and clean up listing and selection. Use common enumerator code for both
operations to avoid duplication or inconsistencies.

Maintain, but significatnly simplify manual device selection by id, name or
number. This actually fixes loading by name which didn't really work before
since the "name" displayed by --audio-device=help differed from that used to
match the selection, which used the device "description" instead.

Save the selected deviceID in the private structure for later loading. This will
permit moving the device selection into the main thread in a future commit.
2016-01-04 07:41:21 -08:00
Kevin Mitchell 9163bdc38a ao_wasapi: fix delay calculation again
Apparently it's only wine where the qpc_position returned by
IAudioClock_GetPosition can be overflowed. So actually do the rescaling
correctly, but throw away the result if it looks unreasonable.

this fixes a regression in 5afa68835a
2016-01-02 08:10:52 -08:00
Kevin Mitchell 5afa68835a ao_wasapi: fix delay calculation
Make sure that subtraction of performance counters is done correctly.
Follow the *exact* instructions for converting performance counter to something
comparable to the QPCposition returned by IAudioClient::GetPosition
https://msdn.microsoft.com/en-us/library/windows/desktop/dd370889%28v=vs.85%29.aspx

Also make sure that subtraction of unsigned integers is stored into a signed
integer to avoid nastiness. Also be more careful about overflow in the
conversion of the device position into number of samples.

Avoid casting mp_time_us() to a double, and use llrint to convert the
double precision delay_us back to integer for ao_read_data.

Finally, actually check the return value of ao_read_data and add a verbose
message if it is not the expected value. Unfortunately,
there is no way to tell WASAPI when this happens since the frame_count in
ReleaseBuffer must match GetBuffer.
2015-12-21 16:58:51 -08:00
Aman Gupta fccc3d3894 Fix some typos in code comments
Signed-off-by: wm4 <wm4@nowhere>
2015-12-21 22:28:12 +01:00
Kevin Mitchell 0afb1acab3 ao_wasapi: move volume control init to it's own function
also make failure non-fatal
2015-12-21 05:23:26 -08:00
Kevin Mitchell 05b6646d7a ao_wasapi: correctly handle audio session display failure
In particular, try and release/null the interface so that it won't be
marshalled.
2015-12-21 05:23:26 -08:00
Kevin Mitchell 35296c1f33 ao_wasapi: non-fatal error handling for COM marshalling
Also make sure that CoReleaseMarshalData is called if errors occur before
unmarshalling.
2015-12-21 05:23:22 -08:00
Kevin Mitchell 3ae726e8dd ao_wasapi: wrap long lines and use only c99 comment style
also remove a log message in AOCONTROL_UPDATE_STREAM_TITLE since
none of the other controls have one.
2015-12-21 05:03:09 -08:00
Kevin Mitchell c188240ab9 ao_wasapi: reorganize private structure 2015-12-21 05:03:09 -08:00
Kevin Mitchell 099fdde7a4 ao_wasapi: remove useless buffer_block_size
this was only ever used for a verbose message
2015-12-21 05:03:09 -08:00
Kevin Mitchell cbc951d491 ao_wasapi: move exclusive and shared-specific controls to functions 2015-12-21 05:03:03 -08:00
Kevin Mitchell a191712169 ao_wasapi: call the class-specific release functions
IUnknown_Release() might be alright, but stay on the safe
side.
2015-12-20 03:30:28 -08:00
Kevin Mitchell 517a35da94 ao_wasapi: check for proxy availability in control
Make sure that the proxy has been created before using it. This will be
used when a future commit makes proxy setup optional.
2015-12-20 03:30:28 -08:00
Kevin Mitchell 821e8fb9d0 ao_wasapi: actually use hw volume support information for exclusive mode
Do not try and set/get master volume in exclusive if there is no
hardware support. This would just uselessly change the master slider,
but have no effect on the actual volume.

Furthermore if getting hardware volume support information fails, then assume
it has none.
2015-12-20 03:30:28 -08:00
Kevin Mitchell 4b81398b4e ao_wasapi: don't cast control arg to something it isn't
the ao_control_vol_t cast was happening outside AOCONTROL_GET/SET_VOLUME
which is the only place that would be valid
2015-12-20 03:30:28 -08:00
Kevin Mitchell d1cbff37be ao_wasapi: remove volume "restore" on exit
It was complicated and not even very intuitive to the user.
If you are controlling the master volume, you just have to be
prepared to deal with the consequences.
2015-12-20 03:30:28 -08:00
Kevin Mitchell aa5f04c7a0 ao_wasapi: split exclusive/shared specific ao controls
this avoids having to check if we're exclusive or
shared for every control
2015-12-20 03:30:28 -08:00
Kevin Mitchell e15526153e ao_wasapi: add E_NOINTERFACE to error list
this is encountered trying to set up COM proxies in wine
2015-12-20 03:30:28 -08:00
wm4 000285ee8e mixer: fix volume initialization with --af=volume
A manually added af_volume could lead to muted audio when switching to a
new file. af_volume keeps the last volume set by AF_CONTROL_SET_VOLUME
to return it with AF_CONTROL_GET_VOLUME, but the initial value is 0. So
the mixer volume was forced to 0 when unintializing the filter chain and
reading back the previously set volume.
2015-12-11 20:52:37 +01:00
wm4 67a4892ee3 mixer: minor simplification
(Why is this code so complex?)
2015-12-11 20:52:37 +01:00
wm4 eec844a06e ao: disambiguate default device list entries
If there were many AO drivers without device selection, this added a
"Default" entry for each AO. These entries were not distinguishable, as
the device list feature is meant not to require to display the "raw"
device name in GUIs.

Disambiguate them by adding the driver name. If the AO is the first, the
name will remain just "Default". (The condition checks "num > 1",
because the very first entry is the dummy for AO autoselection.)
2015-11-27 14:42:10 +01:00
wm4 4c111fbcde af_lavrresample: fix build on Libav
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().)
2015-11-26 00:25:28 +01:00
wm4 0425741754 af_lavrresample: clamp float output to range
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.
2015-11-25 22:07:18 +01:00
wm4 06df54a111 ao_alsa: filter audio device list
Remove known useless device entries from the --audio-device list (and
corresponding property). Do this because the list is supposed to be a
high level list of devices the user can select. ALSA does not provide
such a list (in an useable manner), and ao_alsa.c is still in the best
position to improve the situation somewhat.
2015-11-24 19:47:58 +01:00
wm4 ef918b239e ao_alsa: list bidirectional devices too
The ALSA doxygen says:

    IOID - input / output identification ("Input" or "Output"), NULL
    means both

This bug was blatantly introduced with commit cf94fce4.
2015-11-24 19:21:41 +01:00
Kevin Mitchell 00b7fb3023 ao_wasapi: get rid of Vistablob hack
This was required to work around XP linking issues and is no longer
required.
2015-11-24 04:42:37 -08:00
Kevin Mitchell e10727baa7 ao_wasapi: only report per-app volume in shared mode
otherwise we were incorrectly adjusting the hardware master volume
in exclusive mode with softvol=auto
2015-11-19 07:14:50 -08:00
wm4 7e285a6f71 ao_wasapi: work around DTS passthrough failure
Apparently, some audio drivers do not support the DTS subtype, but
passthrough works anyway if the AC3 subtype is set. Just retry with
AC3 if the proper format doesn't work. The audio device which
exposed this behavior reported itself as
"M601d-A3/A3R (Intel(R) Display Audio)".

xbmc/kodi even always passes DTS as AC3.
2015-11-19 00:08:07 +01:00
Kevin Mitchell 9f858cc759 ao_openal: fix sign of speaker angle in comment 2015-11-18 08:27:47 -08:00
Justas Lavišius ca77bcd543 ao_openal: fix virtual speaker positioning
Place speakers in standard positions equidistant from the listener.

use standard coordinate system
2015-11-18 08:26:07 -08:00
Kevin Mitchell 0e0f07bbef ao_openal: accommodate more sample formats
Try and and choose the closest sample format to the one requested.

fixes #2494
2015-11-17 01:54:38 -08:00