Commit Graph

1757 Commits

Author SHA1 Message Date
tomty89 ba68e570de ao_opensles: clear buffer queue in reset()
Avoid resume() from causing SL_RESULT_BUFFER_INSUFFICIENT ("Failed to Enqueue: 7" when seek or resume from pause).
2018-03-07 01:40:05 +02:00
wm4 0ec0c147ed audio: don't touch spdif frames in mp_aframe_clip_timestamps()
It can't work for this type of format.
2018-02-13 17:45:29 -08:00
wm4 1dcf511376 build: drop support for SDL1
For some reason it was supported for ao_sdl because we've only used SDL1
API.
2018-02-13 17:45:29 -08:00
wm4 171ec0a7e4
af_scaletempo: output minimally sized audio frame
This helps the filter to adapt much faster to speed changes. Before this
commit, the filter just converted and output the full input frame, which
could cause problems with large input frames. This was made worse by
certain filters like dynaudnorm or loudnorm outputting pretty large
frames.

This commit changes the filter from trying to convert all input at once
to only outputting a single internally filtered frame. Internally, this
filter already output data in units of 60ms by default (controlled by
the "stride" sub-option), and concatenated as many output frames as
necessary to consume all input.

Behavior is still kind of bad when inserting the filter. This is because
the large frames can be buffered up after the insertion point, so the
speed change will be performed with a larger latency. The scaletempo
filter can't do anything against this, although it can be fixed by
inserting scaletempo as user filter as part of --af.
2018-02-03 05:01:29 -08:00
wm4 8b3306924d codecs: remove unused family field
MPlayer used this to distinguish multiple decoder wrappers (such as
libavcodec vs. binary codec loader vs. builtin decoders). It lost
meaning in mpv as non-libavcodec things were dropped. Now it doesn't
serve any purpose anymore.

Parsing was removed quite a while ago, and the recent filter change
removed any use of the internal family field. Get rid of it.
2018-02-01 10:21:55 +01:00
wm4 76e7e78ce9 audio: move to decoder wrapper
Use the decoder wrapper that was introduced for video. This removes all
code duplication the old audio decoder wrapper had with the video code.

(The audio wrapper was copy pasted from the video one over a decade ago,
and has been kept in sync ever since by the power of copy&paste. Since
the original copy&paste was possibly done by someone who did not answer
to the LGPL relicensing, this should also remove all doubts about
whether any of this code is left, since we now completely remove any
code that could possibly have been based on it.)

There is some complication with spdif handling, and a minor behavior
change (it will restrict the list of codecs to spdif if spdif is to be
used), but there should not be any difference in practice.
2018-01-30 03:10:27 -08:00
wm4 054c02ad64 ao_null: add --ao-null-format option for debugging
Helpful especially to test spdif fallback and so on.
2018-01-30 03:10:27 -08:00
wm4 b9f804b566 audio: rewrite filtering glue code
Use the new filtering code for audio too.
2018-01-30 03:10:27 -08:00
wm4 bd25fc5307 ao_alsa: reduce verbosity at -v
Always make the hw params dump function use MSGL_DEBUG, and remove the
MSGL_V use. That means you need -v -v to see them. The detailed
information is usually not very interesting, so this reduces the log
noise.
2018-01-25 20:18:32 -08:00
wm4 d36ff64b29 audio: fix annyoing af_get_best_sample_formats() definition
The af_get_best_sample_formats() function had an argument of
int[AF_FORMAT_COUNT], which is slightly incorrect, because it's 0
terminated and should in theory have AF_FORMAT_COUNT+1 entries. It won't
actually write this many formats (since some formats are fundamentally
incompatible), but it still feels annoying and incorrect. So fix it, and
require that callers pass an AF_FORMAT_COUNT+1 array.

Note that the array size has no meaning in C function arguments (just
another issue with C static arrays being weird and stupid), so get rid
of it completely.

Not changing the af_lavcac3enc use, since that is rewritten in another
branch anyway.
2018-01-25 20:18:32 -08:00
wm4 da662ef182 Fix undefined preprocessor behavior
This commit eliminates the following clang warning:

  warning: macro expansion producing 'defined' has undefined behavior [-Wexpansion-to-defined]

Going by the clang commit message, this seems to be explicitly specified
as UB by the standard, and they added this warning because MSVC
apparently results in different behavior. Whatever, we can just avoid
the warning with some small changes.
2018-01-18 00:25:00 -08:00
Vobe e7ea893c2f af_rubberband: add af-command to multiply current pitch
This commit introduces the multiply-pitch af-command. Users may bind
keys to this command in order to incrementally adjust the pitch of a
track. This will probably mostly be useful for musicians trying to
transpose up and down by semi tones without having to calculate
the correct ratio beforehand.

As an example, here is an input.conf to test this feature:

    { af-command all multiply-pitch 0.9438743126816935
    } af-command all multiply-pitch 1.059463094352953
2018-01-15 23:14:01 -08:00
wm4 a5f53da229 af_lavrresample: deprecate this filter
The future direction might be not having such a user-visible filter at
all, similar to how vf_scale went away (or actually, redirects to
libavfilter's vf_scale).
2018-01-13 03:26:45 -08:00
wm4 6d4b4c0de3 audio: add global options for resampler defaults
This is part of trying to get rid of --af-defaults, and the af
resample filter.

It requires a complicated mechanism to set the defaults on the resample
filter for backwards compatibility.
2018-01-13 03:26:45 -08:00
wm4 23edaf4412 audio/aframe: add missing include statements
Otherwise it doesn't compile if they are not indirectly included before.
2018-01-13 03:26:45 -08:00
wm4 0a406f97e0 video, audio: don't actively wait for demuxer input
If feed_packet() ended with DATA_WAIT, the player should have gone to
sleep, until the demuxer wakes it up again when there is new data. But
the call to read_frame() unconditionally overwrote this status code, so
it never waited. The consequence was that the core burned CPU by
effectively polling the demuxer status, which was noticeable especially
when seeking in network streams (since seeking is async, decoders will
start out with having to wait for network).

Regression since commit 33e5755c.
2018-01-09 09:19:56 +01:00
wm4 33e5755c23 video, audio: always read all frames before getting next packet
The old code tried to make sure at all times to try to read a new
packet. Only once that was read, it tried to retrieve new video or audio
frames the decoder might already have decoded.

Change this to strictly read frames from the decoder until it signals
that it wants a new packet, and only then read and feed a new packet.
This is in theory nicer, follows the libavcodec recommended data flow,
and and reduces the minimum latency by 1 frame.

This merely requires switching the order in which those calls are done.
Normally, the decoder will return only 1 frame until a new packet is
required. If we would just feed it 1 packet, return DATA_AGAIN, and wait
until the next frame is decoded, we would run the playloop 1 time too
often for no reason (which is fine but might have some overhead). To
avoid this, try to read a frame again after possibly feeding a packet.
For this reason, move the feed/read code to its own functions each,
instead of merely moving the code.

The audio and video code for this particular thing is basically
duplicated. The idea is to unify them one day, so make the change to
both. (Doing this for video is the real motivation for this change, see
below.)

The video code change is slightly more complicated, because we have to
care about the framedrop counting (which is just a heuristic, but for
now considered better than nothing, and possibly considered required to
warn the user of framedrops happening - maybe).

Apparently this change helps with stalling streams on Android with the
mediacodec wrapper and mpeg2 decoder implementations which deinterlace on
decoding (and return 2 frames per packet).

Based on an idea and observations by tmm1.
2018-01-01 23:17:56 -08:00
wm4 69ae23fdd1 options: drop some previously deprecated options
A release has been made, so drop options deprecated for that release.
Also drop some options which have been deprecated a much longer time
before.

Also fix a typo in client-api-changes.rst.
2017-12-25 04:06:17 -07:00
Nicolas F 744b67d9e5 Fix various typos in log messages 2017-12-03 21:24:18 +01:00
wm4 b56f109219 ao: minor simplification to gain processing code
Cosmetic move of a variable, and consider an adjustment below 1/256 or
so not worth applying (even in the float case).
2017-11-30 01:31:37 +01:00
wm4 6f8cf73f54 ao: simplify hack for float atomics
stdatomic.h defines no atomic_float typedef. We can't just use _Atomic
unconditionally, because we support compilers without C11 atomics. So
just create a custom atomic_float typedef in the wrapper, which uses
_Atomic in the C11 code path.
2017-11-30 01:20:03 +01:00
wm4 d725630b5f audio: add audio softvol processing to AO
This does what af_volume used to do. Since we couldn't relicense it,
just rewrite it. Since we don't have a new filter mechanism yet, and the
libavfilter is too inconvenient, do applying the volume gain in ao.c
directly. This is done before handling the audio data to the driver.

Since push.c runs a separate thread, and pull.c is called asynchronously
from the audio driver's thread, the volume value needs to be
synchronized. There's no existing central mutex, so do some shit with
atomics. Since there's no atomic_float type predefined (which is at
least needed when using the legacy wrapper), do some nonsense about
reinterpret casting the float value to an int for the purpose of atomic
access. Not sure if using memcpy() is undefined behavior, but for now I
don't care.

The advantage of not using a filter is lower complexity (no filter auto
insertion), and lower latency (gain processing is done after our
internal audio buffer of at least 200ms).

Disavdantages include inability to use native volume control _before_
other filters with custom filter chains, and the need to add new
processing for each new sample type.

Since this doesn't reuse any of the old GPL code, nor does indirectly
rely on it, volume and replaygain handling now works in LGPL mode.

How to process the gain is inspired by libavfilter's af_volume (LGPL).
In particular, we use exactly the same rounding, and we quantize
processing for integer sample types by 256 steps. Some of libavfilter's
copyright may or may not apply, but I think not, and it's the same
license anyway.
2017-11-29 21:30:51 +01:00
wm4 3d27a0792b af: remove deprecated audio filters
These couldn't be relicensed, and won't survive the LGPL transition. The
other existing filters are mostly LGPL (except libaf glue code).

This remove the deprecated pan option. I guess it could be restored by
inserting a libavfilter filter (if there's one), but for now let it be
gone.

This temporarily breaks volume control (and things related to it, like
replaygain).
2017-11-29 21:30:51 +01:00
wm4 274cc06aaf ao_alsa: change license to LGPL
Looks like this is covered by LGPL relicensing agreements now.

Notes about contributors who could not be reached or who didn't agree:

Commit 7fccb6486e has tons of mp_msg changes look like they are not
copyrightable (even if they were, all mp_msg calls were rewritten in
mpv times again). The additional play() change looks suspicious, but
the function was rewritten several times anyway (first time after that
commit in 4f40ec312).

Commit 89ed1748ae was rewritten in commit 325311af3 and then again
several times after that. Basically all this code is unnecessary in
modern mpv and has been removed.

No code survived from the following commits: 4d31c3c53, 61ecf838f2,
d38968bd, 4deb67c3f. At least two cosmetic typo fixes are not
considered as well.

Commit 22bb046ad is reverted (this wasn't a valid warning anyway, just
a C++-ism icc applied to C). Using the constants is nicer, but at least
I don't have to decide whether that change was copyrightable.
2017-11-23 16:43:59 +01:00
wm4 b2a08db71a ao_alsa: don't convert twice on retry
Obscure corner case.
2017-11-23 16:43:59 +01:00
wm4 a7a1ae0b3d build: make it easier to force FFmpeg upstream
Apparently some people want this. Actually making it compile is still
their problem, though, and I expect that build with FFmpeg upstream will
occasionally be broken (as it is right now). This is because mpv also
relies on API provided by Libav, and if FFmpeg hasn't merged that yet,
it's not our problem - we provide a version of FFmpeg upstream with
those changes merged, and it's called ffmpeg-mpv.

Also adjust the README which still talked about FFmpeg releases.
2017-11-01 16:50:18 +01:00
wm4 a7f4ecb012 Bump libav* API use
(Not tested on Windows and OSX.)
2017-10-30 20:55:42 +01:00
wm4 d6ebb2df47 Get rid of deprecated AVFrame accessors
Fist we were required to use them for ABI compat. reasons (and other
BS), now they're deprecated and we're supposed to access them directly
again.
2017-10-30 13:36:44 +01:00
wm4 6a9f457102 audio/out: initialize an array to avoid confusing static analyzer
I _think_ this confuses Coverity and it thinks there is uninitialized
data to be read. Initialize the array to change/remove the warning, or
if there's a real problem, to make it easier to detect. (Basically apply
defensive coding.)
2017-10-27 14:11:33 +02:00
wm4 c54673b86f af_lavfi: fix small memory leak
Plus restructure the error path to make this simpler.
2017-10-27 13:54:40 +02:00
wm4 a5b51f75dc demux: get rid of demux_packet.new_segment field
The new_segment field was used to track the decoder data flow handler of
timeline boundaries, which are used for ordered chapters etc. (anything
that sets demuxer_desc.load_timeline). This broke seeking with the
demuxer cache enabled. The demuxer is expected to set the new_segment
field after every seek or segment boundary switch, so the cached packets
basically contained incorrect values for this, and the decoders were not
initialized correctly.

Fix this by getting rid of the flag completely. Let the decoders instead
compare the segment information by content, which is hopefully enough.
(In theory, two segments with same information could perhaps appear in
broken-ish corner cases, or in an attempt to simulate looping, and such.
I preferred the simple solution over others, such as generating unique
and stable segment IDs.)

We still add a "segmented" field to make it explicit whether segments
are used, instead of doing something silly like testing arbitrary other
segment fields for validity.

Cached seeking with timeline stuff is still slightly broken even with
this commit: the seek logic is not aware of the overlap that segments
can have, and the timestamp clamping that needs to be performed in
theory to account for the fact that a packet might contain a frame that
is always clipped off by segment handling. This can be fixed later.
2017-10-24 19:35:55 +02:00
wm4 14f01bd398 aframe: fix logically dead code
Detected by a well known static analyzer.
2017-10-18 12:11:37 +02:00
wm4 14541ae258 Add checks for HAVE_GPL to various GPL-only source files
This should actually cover all of them, if you take into account that
some unchanged GPL source files include header files with such checks.
Also this was done already for the libaf derived code.

This is only for "safety" and to avoid misunderstandings.
2017-10-10 15:51:16 +02:00
wm4 b6af3db568 command: drop "audio-out-detected-device" property
Coreaudio stopped setting it a few releases ago (66a958bb4f). There is
not much of a user- or API-visible change, so remove it without
deprecation.
2017-10-09 15:48:47 +02:00
wm4 4582b8993d audio: fix channel conversion with NA channels
The case at hand was 5.1 -> fl-fr-fc-lfe-na-na (apparently triggered by
ALSA). That means only the NA channels have to be cleared, but the
result was actually that fc and lfe were cleared. This is due to a
simple regression in the reorder code, which quite obviously got the
index of the first NA channel wrong.
2017-09-27 16:22:06 +02:00
wm4 20f958c977 audio: fix resampling
Let's blame FFmpeg for just overwriting the samplerate in
av_frame_copy_props(). Can't fully hide my own brain damage though,
since mp_aframe_config_copy() expected that the rate is copied (that
function also copies format and channel layout).
2017-09-21 14:34:50 +02:00
wm4 bfa9b62858 build: add preliminary LGPL mode
See "Copyright" file for caveats.

This changes the remaining "almost LGPL" files to LGPL, because we think
that the conditions the author set for these was finally fulfilled.
2017-09-21 13:56:27 +02:00
wm4 fdb300b983 audio: make libaf derived code optional
This code could not be relicensed. The intention was to write new filter
code (which could handle both audio and video), but that's a bit of
work. Write some code that can do audio conversion (resampling,
downmixing, etc.) without the old audio filter chain code in order to
speed up the LGPL relicensing.

If you build with --disable-libaf, nothing in audio/filter/* is compiled
in. It breaks a few features, such as --volume, --af, pitch correction
on speed changes, replaygain.

Most likely this adds some bugs, even if --disable-libaf is not used.
(How the fuck does EOF notification work again anyway?)
2017-09-21 12:48:30 +02:00
wm4 3a2d5e68ac audio: move libswresample wrapper out of audio filter code
Move it from af_lavrresample.c to a new aconverter.c file, which is
independent from the filter chain code. It also doesn't use mp_audio,
and thus has no GPL dependencies.

Preparation for later commits. Not particularly well tested, so have
fun.
2017-09-21 12:42:09 +02:00
wm4 caaa1189ba audio_buffer: remove dependency on mp_audio
Just reimplement it in some way, as mp_audio is GPL-only.

Actually I wanted to get rid of audio_buffer.c completely (and instead
have a list of mp_aframes), but to do so would require rewriting some
more player core audio code. So to get this LGPL relicensing over
quickly, just do some extra work.
2017-09-21 04:10:19 +02:00
wm4 997e1fb621 audio: fix spdif mode
Not sure how this was not caught before. It crashed when trying to use
spdif mode.
2017-08-23 12:14:11 +02:00
wm4 b21e0746f6 ao_rsound: allow setting the host
Completely untested (rsound dev libs unavailable on my system). Trivial
enough that it's very likely that it'll just work. No port selection,
but could be added by parsing it as part of the device name.

Should fix #4714.
2017-08-21 15:46:00 +02:00
wm4 1f7fe1597d audio: fix uninitialized data access
dst was not supposed to be initialized, the mp_audio_ setters (which
initialize dst's fields) assume it is -> shit happens. Regression from
recent changes. Was probably harmless.
2017-08-18 17:53:38 +02:00
wm4 158768513c audio: fix build on Libav
Sigh...
2017-08-16 21:26:16 +02:00
wm4 1f593beeb4 audio: introduce a new type to hold audio frames
This is pretty pointless, but I believe it allows us to claim that the
new code is not affected by the copyright of the old code. This is
needed, because the original mp_audio struct was written by someone who
has disagreed with LGPL relicensing (it was called af_data at the time,
and was defined in af.h).

The "GPL'ed" struct contents that surive are pretty trivial: just the
data pointer, and some metadata like the format, samplerate, etc. - but
at least in this case, any new code would be extremely similar anyway,
and I'm not really sure whether it's OK to claim different copyright. So
what we do is we just use AVFrame (which of course is LGPL with 100%
certainty), and add some accessors around it to adapt it to mpv
conventions.

Also, this gets rid of some annoying conventions of mp_audio, like the
struct fields that require using an accessor to write to them anyway.

For the most part, this change is only dumb replacements of mp_audio
related functions and fields. One minor actual change is that you can't
allocate the new type on the stack anymore.

Some code still uses mp_audio. All audio filter code will be deleted, so
it makes no sense to convert this code. (Audio filters which are LGPL
and which we keep will have to be ported to a new filter infrastructure
anyway.) player/audio.c uses it because it interacts with the old filter
code. push.c has some complex use of mp_audio and mp_audio_buffer, but
this and pull.c will most likely be rewritten to do something else.
2017-08-16 21:10:54 +02:00
wm4 baead23ea0 af_lavrresample: don't call swr_set_compensation() unless necessary
This was _always_ called, even if the resampling was static, or the
filter was inserted for format conversion only. This should have been
fine, as I expected the function not to enable resampling when the
compensation is unset, and the source/target rates are the same. But
this is not the case, and it always enables resampling.

So explicitly avoid the call. If we have already called it successfully,
it's better not do avoid it (to overwrite the previous compensation
value), but it will also be cheap/no-op then.

Probably fixes #4716.
2017-08-12 12:12:52 +02:00
Kevin Mitchell 12cafdc868 ao_wasapi: remove old comment 2017-08-07 16:33:29 -07:00
Kevin Mitchell 6f40c211a5 ao_wasapi: reorganize wasapi.h
Remove dead declarations. Move macro only used in wasapi_utils.c closer to use.
Rearrange declaration order.
2017-08-07 14:33:03 -07:00
Kevin Mitchell 434d3d4976 ao_wasapi: deduplicate wasapi sample format selection 2017-08-07 14:33:03 -07:00
Kevin Mitchell 15eb1e1ad3 ao_wasapi: clean up find_formats logic
There were too many functions within functions, too much going on in if
clauses and duplicated code. Fix it.
2017-08-07 14:33:03 -07:00
Kevin Mitchell bee602da82 ao_wasapi: return bool instead of HRESULT from thread_init
Any bad HRESULTs should have been printed already and lots of failure modes
don't have an HRESULT leading to awkward hr = E_FAIL business.

This also checks the exit status of GetBufferSize in the align hack. A final
fatal message is added if either of the retry hacks fail.
2017-08-07 14:33:03 -07:00
wm4 8c82555e41 ao_oss: fix a dumb calculation
period_size used the wrong unit, and even if the unit had been correct,
was assigned the wrong value.

Probably fixes #4642.
2017-07-21 19:45:59 +02:00
wm4 ddd068491c Replace remaining avcodec_close() calls
This API isn't deprecated (yet?), but it's still inferior and harder to
use than avcodec_free_context().

Leave the call only in 1 case in af_lavcac3enc.c, where we apparently
seriously close and reopen the encoder for whatever reason.
2017-07-16 12:51:48 +02:00
Kevin Mitchell c5dfd66e14 ao_wasapi: remove redundant / outdated comment
Where this was moved from, it made slightly more sense. Here what the comment is
trying to say is already pretty obvious from the code.
2017-07-10 21:01:39 -07:00
Kevin Mitchell 63b6aa3f57 ao_waspi: use switch for handling fix_format errors 2017-07-10 21:01:39 -07:00
Kevin Mitchell 4389ddcc34 ao_wasapi: don't repeat format negotiation on align hack
Even if it did return a different result, the bufferFrameCount from the align
hack would be wrong anyway.
2017-07-10 21:01:39 -07:00
Kevin Mitchell 71cc28b804 ao_wasapi: fix leak on align hack 2017-07-10 21:01:39 -07:00
wm4 b016760a28 ad_spdif: minor cleanups
Use avcodec_free_context() unstead of random other calls. Actually it
was already used in the second case, but calling avcodec_close() is
redundant.

Don't crash if allocating a codec context fails.
2017-07-10 16:40:52 +02:00
Kevin Mitchell e9f729c17c audio/out: fix comment typo 2017-07-09 13:46:13 -07:00
Kevin Mitchell 6666b25b73 ao_wasapi: enable packed 24 bit output 2017-07-09 13:46:13 -07:00
Kevin Mitchell a081c8d372 audio/out: correct copy length in ao_read_data_converted
Previously, the entire convert_buffer was being copied to the desination without
regard to the fact that it may be packed and therefore smaller.

The allocated conversion buffer was also way to big

bytes * (channels * samples) ** 2

instead of

bytes * channels * samples
2017-07-09 13:46:13 -07:00
Kevin Mitchell 03abd704ec ao_wasapi: reorder channels and samplerates to speed up search
This shouldn't affect which are chosen, but it should speed up the search by
putting more common configurations earlier so that a working sample format and
sample rates can be found sooner obviating the need to search them for each
iteration of the outer loops.
2017-07-09 13:46:13 -07:00
Kevin Mitchell 7568715563 ao_wasapi: minor cosmetic fixes 2017-07-09 13:44:09 -07:00
Kevin Mitchell 2514e542e5 ao_wasapi: try correct initial format
The loop to select the native wasapi_format for the incoming audio was
not breaking correctly when it found the most desirable format. It
therefore executed completely leaving the least desirable format (u8) as
the choice.

fixes #4582
2017-07-09 13:43:54 -07:00
wm4 03596ac551 audio: drop AF_FORMAT_S24
This is the last sample format that was only in mpv and not in FFmpeg
(except the spdif special formats). It was a huge pain, even if the
removed code in af_lavrresample is pretty small after all.

Note that this drops S24 from the ao_coreaudio AOs too. I'm not sure
about the impact, but I expect it doesn't matter.

af_fmt_change_bytes() was unused as well, so remove that too.
2017-07-07 17:56:22 +02:00
wm4 300097536d ao_pcm: drop AF_FORMAT_S24 usage
I'd actually be somewhat interested in supporting this, as it could help
testing the S24 conversion code. But then again it's only a pain,
there's no immediate need, and it would require new options to make
ao_pcm.c select this output format at all.
2017-07-07 17:56:18 +02:00
wm4 2e1eb8b37c ao_oss: drop AF_FORMAT_S24 usage
Can't test / don't care.
2017-07-07 17:56:18 +02:00
wm4 adbb429296 ao_sndio: drop AF_FORMAT_S24 usage
I can't test it, so I'm dropping it without replacement. If anyone is
interested in readding support, it would be done like the ao_alsa.c
change.
2017-07-07 17:56:18 +02:00
wm4 4e11549593 ao_wasapi_utils: be slightly more clever when converting channel map 2017-07-07 17:56:18 +02:00
wm4 951c1a4907 ao_wasapi: drop use of AF_FORMAT_S24
Do conversion directly, using the infrastructure that was added before.

This also rewrites part of format negotation, I guess.

I couldn't test the format that was used for S24 - my hardware does not
report support for it. So I commented it, as it could be buggy. Testing
this with the wasapi_formats[] entry for 24/24 uncommented would be
appreciated.
2017-07-07 17:56:18 +02:00
wm4 4cb5e53ada ao_alsa: drop use of AF_FORMAT_S24
Instead of the infrastructure added in the previous commit to do the
conversion within the AO.

If this is used, and snd_pcm_status_get_avail() returns more frames than
snd_pcm_write*() actually accepts, you will get some nice audio
corruption.

Also, this mutates the data passed via play(), which is rather fishy,
but sort of doesn't matter for now. Surely this will cause unintended
bugs and WTFs.
2017-07-07 17:56:18 +02:00
wm4 90dd229871 audio/out: add helper code to do 24 bit conversion in AO
I plan to remove the S24 sample formats in mpv. It seems like we should
still support this _somehow_ in AOs though. So the idea is to convert
the data to more obscure representations (that would not be useful for
filtering etc. anyway) within the AO.

This commit adds helper to enable this. ao_convert_fmt is meant to
provide mechanisms for this, rather than a generic audio format
description (as the latter leads only to overly generic misery). The
conversion also supports only cases which we think will be needed at
all.

The main advantage of this approach is that we get S24 out of sight,
and that we could support other crazy formats (like S20). The main
disadvantage is that usually S32 will be selected (if both S32 and S24
are available), and there's no user control to force S24. That doesn't
really matter though, and at worst makes testing harder or will lead
to unpleasant arguments with audiophiles (they'd be wrong anyway).

ao_convert_fmt.pad_lsb is ignored, although if we ever find a case in
which playing S32 with data in the LSBs breaks when playing it as padded
24 bit format. (For example, WAVEFORMATEXTENSIBLE recommends setting the
unused bits to 0 if wValidBitsPerSample implies LSB padding.)
2017-07-07 17:54:05 +02:00
wm4 d5702d3b95 ad_lavc, vd_lavc, sd_lavc: consistently use avcodec_free_context()
Instead of various ad-hoc ways to achieve the same thing. (The API was
added only later.)
2017-07-06 16:25:42 +02:00
wm4 d0e8d6114b ao_coreaudio: insane hack for passing through AC3 as float PCM
This uses the same hack as Kodi uses, and I suspect MPlayer/ancient mpv
also did this (but didn't research that).
2017-06-30 09:06:01 +02:00
wm4 3e9075787f ao_wasapi: UWP wrapper hack support
UWP does not support the whole IMMDevice API. Instead, you need to use a
new API (available starting from Windows 8), which is in addition not in
MinGW, and extremely unpleasant to use.

The wasapiuwp2.dll wrapper is a small custom MSVC DLL, which does this
instead, and returns a normal IAudioClient.

Before this, ao_wasapi did not initialize on UWP.
2017-06-29 10:38:05 +02:00
Pedro Pombeiro 4637b029cd Universal Windows Plaform (UWP) support
libmpv only. Some things are still missing.

Heavily reworked.

Signed-off-by: wm4 <wm4@nowhere>
2017-06-29 10:36:16 +02:00
Pedro Pombeiro f22d12ac51 ao_wasapi: do not use deprecated wchar functions
These break on UWP. Based on a patch by Pedro Pombeiro.
2017-06-29 10:35:25 +02:00
wm4 cd25d98bfa Avoid calling close(-1)
While this is perfectly OK on Unix, it causes annoying valgrind
warnings, and might be otherwise confusing to others.

On Windows, the runtime can actually abort the process if this is
called.

push.c part taken from a patch by Pedro Pombeiro.
2017-06-29 10:31:13 +02:00
wm4 3a3a0aced2 ao_wasapi: remove subtly duplicated code
Seems like this can be slightly simplified.
2017-06-28 18:43:19 +02:00
wm4 3b7e292844 ao_wasapi: remove duplicate code for creating IAudioClient
The code accounting for the terrible AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED
semantics (which MSDN claims can happen "starting with Windows 7" - so
probably on Windows 10 too) duplicated the call for creating the
IAudioClient. That's not great, so get rid of it.

Let wasapi_thread_init() handle this. It has a retry loop anyway. This
redoes device lookup and format negotiation, but potential failures due
to race conditions (what if the driver decides to change behavior)
shouldn't be worse than before.
2017-06-28 18:43:18 +02:00
wm4 c5a82f729b audio/out/pull: detect and log underflows
Mostly for debugging, I guess.
2017-06-28 13:18:59 +02:00
wm4 037c37519b audio/out: require AO drivers to report period size and correct buffer
Before this change, AOs could have internal alignment, and play() would
not consume the trailing data if the size passed to it is not aligned.
Change this to require AOs to report their alignment (via period_size),
and make sure to always send aligned data.

The buffer reported by get_space() now always has to be correct and
reliable. If play() does not consume all data provided (which is bounded
by get_space()), an error is printed.

This is preparation for potential further AO changes.

I casually checked alsa/lavc/null/pcm, the other AOs might or might not
work.
2017-06-25 15:57:43 +02:00
wm4 4abd5683d5 ao_openal: change license to LGPL
All authors have agreed.
2017-06-24 14:10:14 +02:00
wm4 8922c7b84a chmap: remove misleading "downmix" channel layout name
I'm not even sure when/if FFmpeg produces those. It's just confusing. If
you really need this, you can still use dl-dr. I expect that most use is
unintentional.

Probably fixes #4545.
2017-06-24 11:36:10 +02:00
Niklas Haas bbe8bb0ae9
ao_pulse: reorder format choice
Right now, the current order pretty much means that pulse defaults to
S16 for arbitrary unsupported formats, but fallback to float would make
more sense since it's the easiest to convert everything to without
requiring dithering, and PA will probably just internally convert things
to float anyway.

Also move S32 above S16, which essentially means format_maps is sorted
by preference. (Although ao_pulse currently ignores this and always
picks the first as a fallback)
2017-06-23 21:12:44 +02:00
wm4 5c038e6999 build: simplify OSS checks and remove changes by "bugmen0t"
The user bugmen0t was apparently a shared github account with publicly
available login. Thus, we can't get LGPL relicensing permission from the
people who used this account. To relicense successfully, we have to
remove all their changes.

This commit should remove 20d1fc13, f26fb009, defbe48d. It also should
remove whatever test fragments were copied from the ancient configure,
as well as some configure logic (potentially that device path stuff).

I think this change still preserves the most important use-cases of OSS:
BSDs, and the Linux OSS emulation (the latter for testing only).
According to an OSS user, the 4front checks were probably broken anyway.
The SunAudio stuff was probably for (Open)Solaris, which is dead.

ao_oss.c itself will remain GPL, and still contains bugmen0t changes.
2017-06-22 13:17:14 +02:00
wm4 eec7f61b5f audio/format: change license to LGPL
Although the origins lie somewhere in libaf, which was written by
"anders" and who explicitly disagreed with the LGPL relicensing, we can
change the license of these files, because all code was written by
"alex", who agreed with the relicensing.

The only things that remain from anders' code is the AF_FORMAT_ and af_
prefixes (see e.g. 66f4e563). It was alex who redid this file and added
the format identifiers we have today (507121f7). It's also nice to see
that alex actually claimed copyright on format.c (221a599f). In commit
efb50cab even the bitmask concept (which anders introduced with his
early af_format.c code) was removed, and essentially all lines and
symbols by anders were dropped.

To put it into perspective: the original af_format code was for
converting actual sample data and relied on OSS sample format
identifiers, mpv's format.c/h provides its own sample formats, but
does not do any data conversion.

Remove an now inaccurate comment from format.c (it somehow even survived
the typo that was present in the original commit). Also remove most of
the format.c include statements - most of them are technically anders'
code. We keep limits.h though.
2017-06-20 15:37:28 +02:00
wm4 6489b112ad dec_audio, ad_lavc: change license to LGPL
All relevant authors of the current code have agreed.

As always, there are the usual historical artifacts that could be
mentioned. For example, there used to be a large number of decoders
by various authors who were not asked, but whose code was all 100%
removed. (Mostly due to FFmpeg providing all codecs.)

One point of contention is that Nick Kurshev might have refactored the
old audio decoder code in 2001. Basically, there are hints that it might
have been done by him, such as Arpi's commit message stating that the
code was imported from MPlayerXP (Nick's fork), or all the files having
his name in the "maintainer" field. On the other hand, the murky history
of ad.h weakens this - it could be that Arpi started this work, and Nick
took it (and possibly finished it).

In any case, Nick could not be reached, so there is no agreement for
LGPL relicensing from him. We're changing the license anyway, and assume
that his change in itself is not copyrightable. He only moved code, and
in addition used the equivalent video decoder framework (done by Arpi,
who agreed) as template. For example, ad_functions_s was basically
vd_functions_s, which the signature of the decode callback changed to
the same as audio_decode(). ad_functions_s also had a comment that said
it interfaces with "video decoder drivers" (I'm fixing this comment in
this commit).

I verified that no additional code was added that is copyright-relevant,
still in today's code, and not copied from the existing code at the time
(either from the previous audio decoder code or the video framework
code). What apparently matters here is that none of the old code was not
written by Nick, and the authors of the old code have given his
agreement, and (probably) that Nick didn't add actual new code (none
that would have survived), that was not trivially based on the old one
(i.e. no new copyrightable "work").

A copyright expert told me that this kind of change can be considered
not relevant for copyright, so here we go.

Rewriting this would end with the same code anyway, and the naming
conventions can't be copyrighted.
2017-06-14 21:08:59 +02:00
Rudolf Polzer e2573e5b8d encode_lavc: move from GPL 2+ to LGPL 2.1+. 2017-06-13 14:22:15 -04:00
wm4 cc69650e76 af, vf: improvements to libavfilter bridge
Add the "lavfi-" prefix (details see manpage additons).

Tag the filter name as "(lavfi)" in the verbose filter list output.
2017-05-31 17:42:55 +02:00
wm4 e77ed53459 ad_spdif: change license to LGPL
All authors have agreed. (Even the main author, if you wonder about the
entry in the Copyright file.)
2017-05-21 12:35:53 +02:00
wm4 43aaba4f73 ao_pcm: change license to LGPL
All relevant authors have agreed to the relicensing.

Problem cases:

eca47b1a5edae: someone else gets credited for the "idea" of this change,
but it doesn't seem like it was a patch (otherwise reimar would have
said "patch"). Also, the associated code got essentially removed again
anyway. (The option parsing was rewritten fully.)

ffb529e4eb2a9: anonymous/unknown author, but the code was fully removed
anyway. The struct was removed, and the modern code does explicit
read/write calls.

40789473d215b: author was not contacted, but this code was removed
anyway. The magic number (0x7ffff000) is still in the new code, but I
don't think that is copyright relevant.

c750b8ab2d3c8: the message was entirely removed.
2017-05-20 12:46:08 +02:00
wm4 7840125e22 audio/out: change license of some core files to LGPL
All contributors of the current code have agreed. ao.c requires a
"driver" entry for each audio output - we assume that if someone who
didn't agree to LGPL added a line, it's fine for ao.c to be LGPL
anyway. If the affected audio output is not disabled at compilation
time, the resulting binary will be GPL anyway, and ootherwise the
code is not included.

The audio output code itself was inspired or partially copied from
libao in 7a2eec4b59 (thus why MPlayer's audio code is named libao2).
Just to be sure we got permission from Aaron Holtzman, Jack Moffitt, and
Stan Seibert, who according to libao's SVN history and README are the
initial author. (Something similar was done for libvo, although the
commit relicensing it forgot to mention it.)

242aa6ebd40: anders mostly disagreed with the LGPL relicensing, but we
got permission for this particular commit.

0ef8e555735: nick could not be reached, but the include statement was
removed again anyway.

879e05a7c17: iive agreed to LGPL v3+ only, but this line of code was
removed anyway, so ao_null.c can be LGPL v2.1+.

9dd8f241ac2: patch author could not be reached, but the corresponding
code (old slave mode interface) was completely removed later.
2017-05-20 11:43:57 +02:00
James Ross-Gowan 3a7b4df4bf ao_wasapi: set name of event thread 2017-05-18 00:11:14 +10:00
wm4 faefbbaaa5 af_format: change license to LGPL
This case is a bit weird, because MPlayer certainly also has a file
named af_format.c. Both appear to have the function of converting audio
data between sample formats.

However, mpv's af_format.c is a rewrite, and doesn't actually do
conversion by itself. It's similar to vf_format.c, and forces the
generic filter chain code to insert conversion filters, instead of doing
conversion explicitly.

mpv's current af_format.c started out as af_force.c in d9582ad0a4. It
was renamed to af_format.c in e60b8f181d, while the old af_format.c was
split into two new filters. In 943c785619 the filename was changed to
af_format.c as well.

The new af_format.c does not contain any libaf code, except for some
potentially copy & pasted skeleton and boilerplate code. (We don't
account for this in per-filter file licenses, as the old libaf code
has to be removed fully, at which point the filters will have to be
ported to another framework, which will removed that boilerplate code.)

The old filters based on af_format.c were progressively replaced and
removed. Support for non-native endian and formats with signedness
different from native FFmpeg was completely removed in 831d7c3c40.
The old 24 bit conversion code was removed in 552dc0d564 (made
unnecessary by 5a9f817bfd).

Also list hwdec_vaglx.c as GPL-only, which doesn't have anything to do
with this commit.
2017-05-11 11:25:45 +02:00
wm4 bda25e17b6 af_scaletempo: change license to LGPL
All authors have agreed.

The initial commit d33703496c as well as the current code contain this
line:

  * inspired by SoundTouch library by Olli Parviainen

We assume this is about the algorithm (not the code), and the author of
the original patch actually wrote all code himself.
2017-05-09 12:53:37 +02:00
wm4 5eec3d08d5 af_lavcac3enc: change license to LGPL
All authors have agreed.

As usual with these things, this probably does not include residues from
the libaf framework.
2017-05-09 12:46:40 +02:00
wm4 04df16bfd3 ao_pulse, ao_rsound: change license to LGPL
All authors have agreed.

One exception is 71247a97b3, whose author was not asked, but we deem
the change as trivial. (And technically it was replaced when the audio
chain dropped non-native endian sample formats.)
2017-05-08 14:09:49 +02:00
wm4 c87224bf1b ao_coreaudio: change license to LGPL
All authors have agreed to the relicensing.

The code was pretty much rewritten by Stefano Pigozzi. Since the rewrite
happened incrementally, and seems to include refactored portions of
older code, this relicensing was done on the pre-refactor code do.

The original commit adding this AO (as ao_macosx.c) credits Timothy J.
Wood as original author. He was asked and agreed to LGPL. It's not
entirely sure from which project this code came from, but it's probably
libao. In that project, Stanley Seibert made some changes to it (who as
a major developer of libao was asked just to be sure), and also Ralph
Giles and Ben Hines made two small changes. The latter were not asked,
but none of their code survived anyway.
2017-05-08 13:57:40 +02:00
wm4 380bc03823 ad.h: change license to LGPL
All authors have agreed.

Commit 94d3170bd0 is a bit murky: Nick could not be reached, and arpi's
changes were obviously inspired or copied from Nick's. However, the
changed symbols were removed and do not exist anymore.
2017-05-05 07:32:35 +02:00
wm4 1db603efc3 audio/fmt-conversion: change license to LGPL
Although pretty similar to the probably unrelicensable
video/fmt-conversion.c/h (basically using the same idea, but for audio),
it was written by someone else. The format mapping was first added in
commit ad95e046c2.
2017-05-05 07:25:55 +02:00
wm4 7f78929050 af: remove unused GET_VOLUME code
The entire af code is going to be removed, but Ordnung muss sein.
2017-04-27 00:22:30 +02:00
wm4 90a1ca02a2 audio: fix replaygain volume scale
The new replaygain code accidentally applied the linear gain as cubic
volume level. Fix this by moving the computation of the volume scale out
of the af_volume filter.

(Still haven't verified whether the replaygain code works correctly.)
2017-04-27 00:15:32 +02:00
wm4 809d160c1e options: remove remaining deprecated audio device selection options 2017-04-23 17:51:55 +02:00
wm4 f34de63450 ao_openal: kill off device listing
Probably helps with #4311. It surely is not the correct fix, of course.
But ao_openal has no business of causing trouble anyway.
2017-04-23 17:44:26 +02:00
wm4 5a33242854 ao_wasapi_changenotify: use %ls instead of %S for wchar_t
%ls is C99. %S is supported by some systems, including MinGW/MSVC, but
no reason to use it.
2017-04-20 07:38:03 +02:00
wm4 05e6d423d9 ao_wasapi_changenotify: fix potential race condition
IMMDeviceEnumerator_RegisterEndpointNotificationCallback() will start
listening for notifications, and is the point at which callbacks can
start firing. These callbacks will read the fields we set after the
register calls, which is a potential race condition. Move it upwards.
2017-04-20 07:33:13 +02:00
wm4 451e1f0db3 vf_lavfi, af_lavfi: remove unused/deprecated include
Looks like Libav is going to drop it, unnecessarily making compilation
fail.
2017-04-05 16:12:47 +02:00
wm4 b96a74ec2a audio: deprecate most audio filters
Well, ok, only 4 filters. The rest will survive in one or the other
form.
2017-04-04 15:04:07 +02:00
wm4 98f8c4f36d af: implement generic lavfi option bridge too
Literally copy-pasted from the same commit for video filters. (Once new
code for filters is implemented, this will all go away or at least get
unified anyway.)
2017-04-04 14:57:00 +02:00
wm4 d018028fdb af_lavfi: remove forced "format" filter
This was supposed to restrict output to formats supported by us. But we
usually support all FFmpeg sample formats anyway (if not, it will error
out gracefully, and we would add the missing format). Basically, it's
just useless bloat.
2017-04-04 14:47:42 +02:00
wm4 6b9d3f4f7b audio: lower "Disabling multichannel output." warning to verbose
Not sure why it was a warning in the first place.
2017-04-02 17:23:11 +02:00
wm4 c68be80a63 ao_wasapi: do not pass nonsense to drivers with double
This tried to use AF_FORMAT_DOUBLE as KSDATAFORMAT_SUBTYPE_IEEE_FLOAT,
with wBitsPerSample==64. This is probably not allowed, and drivers
appear to react inconsistently to it. (With one user, the format was
accepted during format negotiation, but then rejected on actual init.)

Remove it, which essentially forces it to fall back to some other
format. (Looks like it'll use af_select_best_samplerate(), which would
probably make it try S32 next.)

The af_fmt_from_planar() is so that we don't have to care about
AF_FORMAT_FLOATP. Wasapi always requires packed data anyway.

This should actually handle other potentially unknown sample formats
better.

This changes that set_waveformat() always set the exact format. Now it
might set a "close" format instead. But all callers seem to deal with
this well. Although in theory, callers should probably handle the
fallback. The next cleanup (if ever) can take care of this.
2017-03-29 15:19:25 +02:00
wm4 7d424b4ce4 command: add better runtime filter toggling method
Basically, see the example in input.rst.

This is better than the "old" vf-toggle method, because it doesn't
require the user to duplicate the filter string in mpv.conf and
input.conf.

Some aspects of this changes are untested, so enjoy your alpha testing.
2017-03-25 17:07:40 +01:00
Jan Janssen 222899fbbe af_drc: remove
Remove low quality drc filter. Anyone whishing to have dynamic range
compression should use the much more powerful acompressor ffmpeg filter:

    mpv --af=lavfi=[acompressor] INPUT

Or with parameters:

    mpv --af=lavfi=[acompressor=threshold=-25dB:ratio=3:makeup=8dB] INPUT

Refer to https://ffmpeg.org/ffmpeg-filters.html#acompressor for a full
list of supported parameters.

Signed-off-by: wm4 <wm4@nowhere>
2017-03-25 12:57:10 +01:00
Cheng Sun d17a719f4e ao_jack: update latency on buffer_size/graph change
The buffer_size may be updated before the process callback is called for
the first time. Or, the connection graph could change, which changes the
latency of the pipeline after mpv's output. Ensure we keep on top of
these changes by registering callbacks to update our latency estimation.
2017-03-18 14:15:34 +01:00
wm4 94e82bcdb8 ao_alsa: fix device filtering, add another exception
The "return false;" was debugging code.

In addition, filter a plain "default", because it's not going to do
anything interesting and just looks ugly.
2017-03-14 18:06:17 +01:00
wm4 2827a615dc ao_alsa: filter fewer devices
It appears some device can be missing if we filter too many. In
particular, I've seen devices starting with "front" and "sysdefault"
being mapped to different hardware. I conclude that it's not sane trying
to present a nice device list to users in ALSA. It's fucked. (Although
kodi appears to attempt some intense "beautification" of the device
list, which includes parsing parameters from the device name and such.
Well, let's not.)

No other audio API requires such ridiculous acrobatics.
2017-03-14 15:50:24 +01:00
wm4 bc04acf3a7 ao_alsa: POLLERR can be set even if the device is not lost
Apparently POLLERR can be set if poll is called while the device is in
the SND_PCM_STATE_PREPARED state. So assume that we can simply call
snd_pcm_status() to check whether the error is because the device went
away (i.e. we expect it to return ENODEV if this happened).

This avoids sporadic device lost warnings and AO reloads. The actual
device lost case is untested.
2017-03-14 15:50:18 +01:00
Philip Sequeira a2a5fa4545 options: add M_OPT_FILE to some more file options
(Helps shell completion.)
2017-03-06 15:41:06 +01:00
wm4 6028244160 ao_alsa: close audio device if polling returns POLLERR
This is apparently what happens in this situation:

    Turn off display with DPMS, turn back on with DPMS. MPV is hung.

See #4189.
2017-02-27 19:09:42 +01:00
wm4 6ace32100a ao_alsa: fix an error check
Fixes #4188 as pointed out in the issue.
2017-02-27 16:25:47 +01:00
Kevin Mitchell df30b217d9 ao: never set ao->device = ""
For example, previously, --audio-device='alsa/' would provide ao->device="" to
the alsa driver in spite of the fact that this is an already parsed option. To
avoid requiring a check of ao->device[0] in every driver, make sure this never
happens.
2017-02-20 22:56:30 -08:00
wm4 e50e9b6120 dec_video, dec_audio: remove redundant NULL-checks
OK, they're redundant. Now stop wasting my time, coverity.
2017-02-20 13:58:18 +01:00
wm4 06619f53a8 ao: fix potential NULL deref in ao_device_list_add()
Probably didn't happen in practice, but anyway.

Found by coverity.
2017-02-20 13:50:37 +01:00
Kevin Mitchell cc3eb531eb ao_oss: fix mixer channel message 2017-02-08 21:03:40 -08:00
Kevin Mitchell f4d75376fe ao_oss: use --audio-device if --oss-device isn't set.
Fall back on PATH_DEV_DSP if nothing is set.

This mirrors the behaviour of --audio-device / --alsa-device.

There doesn't appear to be a general way to list devices with oss, so
--audio-device=help doesn't list oss devices except for the default one if the
file exists.

Previously --audio-device was ignored entirely by ao_oss.

fixes #4122
2017-02-08 21:03:40 -08:00
wm4 96a45a16af player: add experimental stream recording feature
This is basically a WIP, but it can't remain in a branch forever. A
warning is print when using it as it's still a bit "shaky".
2017-02-07 17:05:17 +01:00
James Ross-Gowan 9692814502 win32: add COM-specific SAFE_RELEASE to windows_utils.h
See: https://msdn.microsoft.com/en-us/library/windows/desktop/dd743946.aspx

Microsoft example code often uses a SAFE_RELEASE macro like the one in
the above link. This makes it easier to avoid errors when releasing COM
interfaces. It also reduces noise in COM-heavy code.

ao_wasapi.h also had a macro called SAFE_RELEASE, though unlike the
version above, its SAFE_RELEASE macro accepted a second parameter which
allowed it to destroy arbitrary objects other than just COM interfaces.
This renames ao_wasapi's SAFE_RELEASE to SAFE_DESTROY, which should more
accurately reflect what it does and prevent confusion with the Microsoft
version.
2017-01-30 00:22:30 +11:00
wm4 cfda696580 build: explicitly check for FFmpeg vs. Libav, and their exact versions
In a first pass, we check whether libavcodec is present.

Then we try to compile a snippet and check for FFmpeg vs. Libav. (This
could probably also be done by somehow checking the pkgconfig version.
But pkg-config can't deal with that idiotic FFmpeg idea that a micro
version number >= 100 identifies FFmpeg vs. Libav.)

After that we check the project-specific version numbers. This means it
can no longer happen that we accidentally allow older, unsupported
versions of FFmpeg, just because the Libav version numbers are somehow
this way.

Also drop the resampler checks. We hardcode which resampler to each with
each project. A user can no longer force use of libavresample with
FFmpeg.
2017-01-27 09:57:01 +01:00
wm4 801fa486b0 ad_lavc, vd_lavc: move mpv->lavc decoder parameter setup to common code
This can be useful in other contexts.

Note that we end up setting AVCodecContext.width/height instead of
coded_width/coded_height now. AVCodecParameters can't set coded_width,
but this is probably more correct anyway.
2017-01-25 08:24:19 +01:00
wm4 b14fac9afa build: replace some FFmpeg API checks with version checks
The FFmpeg versions we support all have the APIs we were checking for.
Only Libav missed them. Simplify this by explicitly checking for FFmpeg
in the code, instead of trying to detect the presence of the API.
2017-01-24 08:11:42 +01:00
wm4 6be58df8d1 ad_lavc: respect AV_FRAME_FLAG_DISCARD
Since we set "skip_manual", we can actually get frames with this set.
Currently, only AV_PKT_FLAG_DISCARD will trigger this flag, and only
mov.c sets the latter flags, so this is related to FFmpeg's half-broken
mp4 edit list support.
2017-01-24 08:04:53 +01:00
wm4 8cbb2b5e9a ad_spdif: log avformat errors 2017-01-19 12:44:28 +01:00
wm4 c522d0dfbd ad_spdif: fix obscure cases of AC3 passthrough
Apparently you set the native sample rate when passing through AC3.
This fixes passthrough with 44100 Hz AC3.

Avoid opening a decoder for this and only open the parser. (Hopefully
DTS will also support this some time in the future or so - having to
open a decoder just to get the profile is dumb.)
2017-01-18 10:22:28 +01:00
wm4 cbd8abcbff audio: restructure decode loop
Same deal as with video. Including the EOF handling.

(It would be nice if this code were not duplicated, but right now we're
not even close to unifying the audio and video code paths.)
2017-01-11 11:58:32 +01:00
wm4 5d7f881bdc audio/out/push: merge if branches with same condition
Cosmetic change.
2017-01-09 13:32:04 +01:00
wm4 43386a7c92 af_lavfi, vf_lavfi: work around recent libavfilter EOF bug
Looks quite like a bug. If you have a filter chain with only the
dynaudnorm filter, and send call av_buffersrc_add_frame(s, NULL), then
subsequent av_buffersink_get_frame() calls will return EAGAIN instead of
EOF.

This was apparently caused by a recent change in FFmpeg.

Some other circumstances (which I didn't fully analyze and which is due
to the playloop's absurd temporary-EOF behavior on seeks) then led the
decoder loop to send data again, but since libavfilter was stuck in the
EOF state now, it could never recover. It kept sending new input (due to
missing output), until the demuxer refused to return more audio packets.
Each time a filter error was printed.

Fortunately, it's pretty easy to workaround. We just mark the p->eof
flag as we send an EOF frame to libavfilter. The p->eof flag is used
only to recover from temporary EOF: it resets the filter if new data is
available again. We don't care much about av_buffersink_get_frame()
returning a broken EAGAIN state in this situation and essentially ignore
it, meaning if we get EAGAIN after sending EOF, we assume effectively
that EOF was fully reached.
2017-01-02 18:13:08 +01:00
wm4 9d21f2503f options: deprecate codec family selection in --vd/--ad
Useless now, so get rid of it. Also affects some user-visible display
things (like reported codec in use).
2016-12-23 18:12:29 +01:00
wm4 c560f6ff0a audio: change how spdif codecs are selected
Remove ad_spdif from the normal codec list, and select it explicitly.

One goal was to decouple this from the normal codec selection, so
they're less entangled and the decoder selection code can be simplified
in the far future. This means spdif codec selection is now done
explicitly via select_spdif_codec(). We can also remove the weird
requirements on "dts" and "dts-hd" for the --audio-spdif option, and it
can just do the right thing.

Now both video and audio codecs consist of a single codec family each,
vd_lavc and ad_lavc.
2016-12-23 18:10:07 +01:00
wm4 e57037dc95 ad_lavc, vd_lavc: don't set AVCodecContext.refcounted_frames
This field is (or should be) deprecated, and there's no need to set it
with the new API.
2016-12-18 12:28:09 +01:00
Michael Forney 2d9b6ff7cd ad_spdif: Fix crash when spdif muxer is not available
Currently, if init_filter fails after lavf_ctx is allocated, uninit is called
which frees lavf_ctx, but doesn't clear the pointer in spdif_ctx. So, on the
next call of decode_packet, it thinks it is already initialized and uses it,
resulting in a crash on my system.
2016-12-11 14:20:58 +01:00
wm4 3eceac2eab Remove compatibility things
Possible with bumped FFmpeg/Libav.

These are just the simple cases.
2016-12-07 19:53:11 +01:00
wm4 42799005dc ao_alsa: print certain ALSA errors as string instead as number 2016-12-07 12:51:17 +01:00
wm4 ec74a79e12 ao_wasapi: log return code when probing audio formats
We log a large number of formats, but we rarely log the result of the
probing. Change this.

The logic in try_format_exclusive() changes slightly, but should be
equivalent. EXIT_ON_ERROR() checks for FAILED(), which should be
exclusive to SUCCEEDED().
2016-11-30 17:56:33 +01:00
pavelxdd 3203d6003c ao_wasapi_utils: remove unused variable
Introduced in 1a2319f3e4
Produced a warning during compilation on Windows.
2016-11-27 20:32:33 +01:00
wm4 1a2319f3e4 options: remove deprecated sub-option handling for --vo and --ao
Long planned. Leads to some sanity.

There still are some rather gross things. Especially g_groups is ugly,
and a hack that can hopefully be removed. (There is a plan for it, but
whether it's implemented depends on how much energy is left.)
2016-11-25 21:17:25 +01:00
wm4 c03a67c37c audio/out/push: play silence on --audio-stream-silence
Until now, this was only implemented for ao_alsa and AOs not using
push.c. ao_alsa.c relied on enabling funny underrun semantics for
avoiding resets on lower levels, while other AOs using push.c didn't do
anything.

Change this and at least make push.c copy silent data to the AO. This
still isn't perfect as keeping track of how much silence was played when
seems complex, so we don't do it. The consequence is that frame-stepping
will essentially randomize the A/V offset (it'll recover immediately
when unpausing, but still ugly). Also, in order to empty the currently
buffered audio on seeks etc., we still call ao_driver->reset and so on,
so the AO driver will still need to handle this specially.

The intent is to make behavior with ALSA less weird (for one we can
remove the code in ao_alsa.c that tries to trigger an initial
underflow). Also might help with #3754.
2016-11-24 20:52:15 +01:00
wm4 de37c5b1cb audio: fix --audio-stream-silence with ao_wasapi
Seems like wasapi will restart the HDMI stream if resume is called
during playback.
2016-11-21 19:35:06 +01:00
wm4 fcba41e2e4 audio: fix --audio-stream-silence with ao_alsa
ao_alsa.c calls this before the common code sets ao->sstride.

Other than this, I'm still not sure whether this works. Seems like no,
or depends.
2016-11-21 19:35:06 +01:00
wm4 c1ae1def85 ao_alsa: explicitly add default device manually
The "default" entry (which is and always was mpv/mplayer's default) does
not have a description set in the ALSA API. (While "sysdefault"
strangely has.)

Instead of an empty description, this should show something nice, so
reuse the ao.c code for naming default devices (see previous commit).

It's still a bit ugly that audio-device-list will have a default entry
for "Autoselect device" and "Default (alsa)", but then again we probably
want to allow the user to force ALSA (i.e. prevent fallbacks to other
AOs) just because ALSA is so flaky and makes this a legitimate feature.
2016-11-14 13:42:49 +01:00
wm4 a2b93e0c27 audio: make empty device ID mean default device
This will make it easier for AOs to add explicit default device entries.
(See next commit.)

Hopefully this change doesn't lead accidentally to bogus "Default"
entries to appear, but then it can only happen if the device ID is
empty, which would mean the underlying audio API returned bogus entries.
2016-11-14 13:42:41 +01:00
wm4 84513ba58b audio: avoid returning audio-device-list entries without description
Use the device name as fallback. This is ugly, but still better than
skipping the description entirely. This can be an issue on ALSA, where
the API can return entries without proper description.
2016-11-14 13:33:53 +01:00
wm4 67467103e8 dec_video, dec_audio: avoid full reinit on switches to the same segment
Same deal as with the previous commit.

(Unfortunately, this code is still duplicated.)
2016-11-09 16:44:06 +01:00
wm4 33012b4141 ao_alsa: fill unused ALSA channels with silence
This happens when ALSA gives us more channels than we asked for, for
whatever reasons. It looks like this wasn't handled correctly. The mpv
and ALSA channel counts could mismatch, which would lead to UB.

I couldn't actually trigger this case, though. I'm fairly sure that
drivers or plugins exist that do it anyway. (Inofficial ALSA motto: if
it can be broken, then why not break it?)
2016-11-08 17:49:40 +01:00
wm4 1d51dc20ea ao_alsa: strictly disable chmap use for mono/stereo
If the input is already mono or stereo, or if channel map selection
results in mono or stereo, then disable further use of the champ ALSA
API (or rather, stop trusting its results). Then we behave like a simple
application that only wants to output mono or stereo.

See #3045 and #2905. I couldn't actually test these cases, but this
commit is supposed to fix them.
2016-11-08 17:49:13 +01:00
wm4 2e113a7391 ao_alsa: _really_ disable chmap API use in cases where we should
set_chmap() skipped _setting_ the ALSA chmap if chmap use was requested
to be disabled by setting dev_chmap.num=0 by the caller, but it still
queried the current ALSA channel map. We don't trust it that much, so
disable that as well.

But we still query and log it, because that could be helpful for
debugging. Otherwise we could skip the entire set_chmap() call in these
cases.
2016-11-08 17:48:40 +01:00
wm4 2b71bef2ba ao_alsa: slightly better debug logging
Try to make it more compact, and also always list the reordered layout,
but only if it's actually different.

Should be the same functionally.
2016-11-08 16:59:12 +01:00
Aman Gupta 3f5b41dfa3 audio/out: add AudioUnit output driver for iOS 2016-11-01 16:25:40 +01:00
wm4 139f6b5de7 ad_lavc, vd_lavc: fix a recent libavcodec deprecation warning
Both AVFrame.pts and AVFrame.pkt_pts have existed for a long time. Until
now, decoders always returned the pts via the pkt_pts field, while the
pts field was used for encoding and libavfilter only. Recently, pkt_pts
was deprecated, and pts was switched to always carry the pts.

This means we have to be careful not to accidentally use the wrong
field, depending on the libavcodec version. We have to explicitly check
the version numbers. Of course the version numbers are completely
idiotic, because idiotically the pkg-config and library names are the
same for FFmpeg and Libav, so we have to deal with this explicitly as
well.
2016-10-17 19:18:03 +02:00
wm4 b5357e8ba7 ao_alsa: try to fallback to "hdmi" before "iec958" for spdif
If the "default" device refuses to be opened as spdif device (i.e. it
errors due to the AES0 etc. parameters), we were falling back to the
iec958 device. This is needed on some systems for smooth operation with
PCM vs. spdif.

Now change it to try "hdmi" before "iec958", which supposedly helps in
other situations.

Better suggestions welcome. Apparently kodi does this too, although I
didn't check directly.
2016-10-07 17:21:08 +02:00
wm4 39f515cb6a audio/out: prevent underruns with spdif under certain conditions
The player tries to avoid splitting frames with spdif (sample alignment
stuff). This can in certain corner cases with certain drivers lead to
the situation that ao_get_space() returns a number higher than 0 and
lower than the audio frame size. The playloop will round this down to 0
bytes and do nothing, leading to a missed wakeup. This can lead to
underruns or playback completely getting stuck.

It can be reproduced by playing AC3 passthrough with no video and:

    --ao=null --ao-null-buffer=0.256 --ao-null-outburst=6100

This commit attempts to fix it by allowing the playloop to write some
additional data (to get a complete frame), that will be buffered within
the AO ringbuffer even if the audio device doesn't want it.
2016-10-04 19:31:17 +02:00
wm4 6f4d918cb7 audio: dump timestamp difference
Can help to analyze timestamp jitter or seeing completely bogus
timestamps.
2016-10-02 12:55:22 +02:00
James Ross-Gowan 3751065f97 win32: build with -DINITGUID
We always want to use __declspec(selectany) to declare GUIDs, but
manually including <initguid.h> in every file that used GUIDs was
error-prone. Since all <initguid.h> does is define INITGUID and include
<guiddef.h>, we can remove all references to <initguid.h> and just
compile with -DINITGUID to get the same effect.

Also, this partially reverts 622bcb0 by re-adding libuuid.a to the
build, since apparently some GUIDs (such as GUID_NULL) are not declared
in the source file, even when INITGUID is set.
2016-09-28 21:38:52 +10:00
Josh de Kock af6126adbe ao_openal: enable building on OSX
Signed-off-by: Josh de Kock <josh@itanimul.li>
2016-09-21 12:43:14 +02:00
Hector Martin 297f9f1bec af_pan: fix typo
This was in the parser code all along. As far as I can tell, *cp was
intended. There is no need to check cp for NULL (nor does it make any
sense to do so every time around the loop) for AF_CONTROL_COMMAND.

However, s->matrixstr can be NULL, so checking for that separately is in
order.
2016-09-19 19:01:52 +02:00
Hector Martin f504661852 af_rubberband: default to channels=together
For stereo and typical L/R-first channel arrangements, this avoids
undesirable phasing artifacts, especially obvious when speed is changed
and then reset. Without this, there is a very audible change in the
stereo field even when librubberband is no longer actually making any
speed changes.
2016-09-19 18:59:42 +02:00
Hector Martin 57eca14a45 af_rubberband: add af-command and option to change the pitch
This allows both fixed and dynamic control over the audio pitch using
librubberband, which was previously not exposed to the user.
2016-09-19 18:56:14 +02:00
Hector Martin ed8540c38e af_pan: add af-command support to change the matrix
This allows for seamless changes in the downmixing matrix without having
to reinitialize the filter chain.
2016-09-19 14:55:58 +02:00
Hector Martin 0525f5fa93 af_pan: coding style fixes 2016-09-19 14:55:55 +02:00
wm4 dc48893630 options: simplify M_OPT_EXIT
There were multiple values under M_OPT_EXIT (M_OPT_EXIT-n for n>=0).
Somehow M_OPT_EXIT-n either meant error code n (with n==0 no error?), or
the number of option valus consumed (0 or 1). The latter is MPlayer
legacy, which left it to the option type parsers to determine whether an
option took a value or not. All of this was changed in mpv, by requiring
the user to use explicit syntax ("--opt=val" instead of "-opt val").

In any case, the n value wasn't even used (anymore), so rip this all
out. Now M_OPT_EXIT-1 doesn't mean anything, and could be used by a new
error code.
2016-09-17 18:07:40 +02:00
wm4 b8ade7c99b player, ao, vo: don't call mp_input_wakeup() directly
Currently, calling mp_input_wakeup() will wake up the core thread (also
called the playloop). This seems odd, but currently the core indeed
calls mp_input_wait() when it has nothing more to do. It's done this way
because MPlayer used input_ctx as central "mainloop".

This is probably going to change. Remove direct calls to this function,
and replace it with mp_wakeup_core() calls. ao and vo are changed to use
opaque callbacks and not use input_ctx for this purpose. Other code
already uses opaque callbacks, or has legitimate reasons to use
input_ctx directly (such as sending actual user input).
2016-09-16 14:37:48 +02:00
wm4 062423381d ao_rsound: fix compilation
Probably fixes #3501.
2016-09-07 18:10:12 +02:00
wm4 5a7b1ff4c0 ao_pcm: remove some useless messages
The first one is printed even if the user disabled video (or there's no
video), so just remove it. The second one uses deprecated sub-option
syntax, so remove that as well.
2016-09-07 12:54:33 +02:00
wm4 591e21a2eb osdep: rename atomics.h to atomic.h
The standard header is stdatomic.h, so the extra "s" freaks me out every
time I look at it.
2016-09-07 11:26:25 +02:00
wm4 1d9032f011 audio/out: deprecate "exclusive" sub-options
And introduce a global option which does this. Or more precisely, this
deprecates the global wasapi and coreaudio options, and adds a new one
that merges their functionality. (Due to the way the sub-option
deprecation mechanism works, this is simpler.)
2016-09-05 21:26:39 +02:00
wm4 13786dc643 audio/out: deprecate device sub-options
We have --audio-device, which can force the device. Also add something
describing to this extent to the manpage.
2016-09-05 21:26:39 +02:00
wm4 69283bc0f8 options: deprecate suboptions for the remaining AO/VOs 2016-09-05 21:26:39 +02:00
wm4 633eb30cbe options: add automagic hack for handling sub-option deprecations
I decided that it's too much work to convert all the VO/AOs to the new
option system manually at once. So here's a shitty hack instead, which
achieves almost the same thing. (The only user-visible difference is
that e.g. --vo=name:help will list the sub-options normally, instead of
showing them as deprecation placeholders. Also, the sub-option parser
will verify each option normally, instead of deferring to the global
option parser.)

Another advantage is that once we drop the deprecated options,
converting the remaining things will be easier, because we obviously
don't need to add the compatibility hacks.

Using this mechanism is separate in the next commit to keep the diff
noise down.
2016-09-05 21:26:39 +02:00
wm4 726ef35aa8 ao_jack: move to global options 2016-09-05 21:04:41 +02:00
wm4 4ab860cddc options: add a mechanism to make sub-option replacement slightly easier
Instead of requiring each VO or AO to manually add members to MPOpts and
the global option table, make it possible to register them automatically
via vo_driver/ao_driver.global_opts members. This avoids modifying
options.c/options.h every time, including having to duplicate the exact
ifdeffery used to enable a driver.
2016-09-05 21:04:17 +02:00
wm4 a85eecfe40 ao_alsa: change sub-options to global options
Same deal as with vo_opengl.

Also edit the outdated information about multichannel output a little.
2016-09-02 21:21:47 +02:00
wm4 4fa6bcbb90 m_config: add helper function for initializing af/ao/vf/vo suboptions
Normally I'd prefer a bunch of smaller functions with fewer parameters
over a single function with a lot of parameters. But future changes will
require messing with the parameters in a slightly more complex way, so a
combined function will be needed anyway. The now-unused "global"
parameter is required for later as well.
2016-09-02 14:49:34 +02:00
wm4 6b4f560f3c vo, ao: disable positional parameter suboptions
Positional parameters cause problems because they can be ambiguous with
flag options. If a flag option is removed or turned into a non-flag
option, it'll usually be interpreted as value for the first sub-option
(as positional parameter), resulting in very confusing error messages.
This changes it into a simple "option not found" error.

I don't expect that anyone really used positional parameters with --vo
or --ao. Although the docs for --ao=pulse seem to encourage positional
parameters for the host/sink options, which means it could possibly
annoy some PulseAudio users.

--vf and --af are still mostly used with positional parameters, so this
must be a configurable option in the option parser.
2016-09-01 14:21:32 +02:00
wm4 0110b738d5 vd_lavc, ad_lavc: set pkt_timebase, not time_base
These are different AVCodecContext fields. pkt_timebase is the correct
one for identifying the unit of packet/frame timestamps when decoding,
while time_base is for encoding. Some decoders also overwrite the
time_base field with some unrelated codec metadata.

pkt_timebase does not exist in Libav, so an #if is required.
2016-08-29 12:46:12 +02:00
wm4 a47d849df7 ad_lavc: actually tell decoder about the timebase
Essentially forgotten in commit 05e4df3f.
2016-08-23 12:06:47 +02:00
wm4 6980575e15 ao_alsa: log if retrieving supported channel maps fails
It's a sign that the driver doesn't implement the channel map API.
2016-08-22 20:05:34 +02:00
Paul B Mahol e057629493 af_lavrresample: better swr reinitialization 2016-08-20 11:37:06 +02:00
wm4 23993e91f3 af_lavrresample: fix error if resampler could not be recreated
There are situations where the resampler is destroyed and recreated
during playback. If recreating the resampler unexpectedly fails, the
filter function is supposed to return an error. This wasn't done
correctly, because get_out_samples() accessed the resampler before the
check. Move the check up to fix this.
2016-08-19 22:27:15 +02:00
wm4 05e4df3f0c video/audio: always provide "proper" timestamps to libavcodec
Instead of passing through double float timestamps opaquely, pass real
timestamps. Do so by always setting a valid timebase on the
AVCodecContext for audio and video decoding.

Specifically try not to round timestamps to a too coarse timebase, which
could round off small adjustments to timestamps (such as for start time
rebasing or demux_timeline). If the timebase is considered too coarse,
make it finer.

This gets rid of the need to do this specifically for some hardware
decoding wrapper. The old method of passing through double timestamps
was also a bit questionable. While libavcodec is not supposed to
interpret timestamps at all if no timebase is provided, it was
needlessly tricky. Also, it actually does compare them with
AV_NOPTS_VALUE. This change will probably also reduce confusion in the
future.
2016-08-19 14:59:30 +02:00
wm4 bbcd0b6a03 audio: improve aspects of EOF handling
The code actually kept going out of EOF mode into resync mode back into
EOF mode when the playloop had to wait after an audio EOF caused by the
endpts. This would break seamless looping (as added by the next commit).

Apply endpts earlier, to ensure the filter_audio() function always
returns AD_EOF in this case.

The idiotic ao_buffer makes this an amazing pain in the ass.
2016-08-18 20:38:09 +02:00
wm4 814dacdd7d af_lavrresample: work around libswresample misbehavior
The touched code is for seek resets and such - we simply want to reset
the entire resample state. But I noticed after a seek a tiny bit of
audio is missing (mpv's audio sync code inserted silence to compensate).

It turns out swr_drop_output() either does not reset some internal state
as we expect, or it's designed to drop not only buffered samples, but
also future samples.

On the other hand, libavresample's avresample_read(), does not have this
problem. (It is also pretty explicit in what it does - return/skip
buffered data, nothing else.)

Is the libswresample behavior a bug? Or a feature? Does nobody even
know? Who cares - use the hammer to unfuck the situation. Destroy and
deallocate the libswresample context and recreate it. On every seek.
2016-08-16 00:05:34 +02:00
wm4 78d808c5bd audio: log replaygain values in af_volume instead demuxer
The demuxer layer usually doesn't log per-stream information, and even
the replaygain information was logged only if it came from tags.

So log it in af_volume instead.
2016-08-13 15:06:07 +02:00
Paul B Mahol e2a54bb1ca audio/filter: remove delay audio filter
Similar filter is available in libavfilter.
2016-08-12 19:45:39 +02:00
wm4 367e9fb7f1 ao_alsa: make pause state more robust, reduce minor code duplication
With the previous commit, ao_alsa.c now has 3 possible ways to pause
playback. Actually all 3 of them need get_delay() to fake its return
value, so don't duplicate that code.

Also much of the code looks a bit questionable when considering
inconsistent pause/resume calls from outside, so ignore redundant calls.
2016-08-09 17:09:29 +02:00
wm4 2ded41d2be ao_alsa: handle --audio-stream-silence
push.c does not handle this automatically, and AOs using push.c have to
handle it themselves. Also, ALSA is low-level enough that it needs
explicit support in user code. At least I haven't found any option that
does this.

We still can get away relatively cheaply by abusing underflow-handling
for this. ao_alsa.c already configures ALSA to handle underflows by
playing silence. So we purposely induce an underflow when opening the
device, as well as when pausing or resetting the device.

This introduces minor misbehavior: it doesn't account for the additional
delay the initial silence adds, unless the device has fully played the
fragment of silence when the player starts sending data to it. But
nobody cares.
2016-08-09 17:09:29 +02:00
wm4 eab92cec60 player: add --audio-stream-silence
Completely insane that this has to be done. Crap for compensating HDMI
crap.
2016-08-09 17:09:29 +02:00
wm4 3759a3f40b ao_coreaudio: actually use stop callback
The .pause callback is never used for pull.c-based AOs.

This means this always streamed silence instead of deactivating audio.
2016-08-09 17:09:29 +02:00
wm4 d81b5690df af_lavcac3enc: allow passing options to libavcodec 2016-08-09 17:09:29 +02:00
wm4 b2e5eb13bc ao_wasapi: in exclusive mode do not output multichannel by default
Exactly the same situation as with ao_alsa in commit 0b144eac (except
that we can detect the situation better under wasapi).

Essentially, wasapi will allow us to output any sample format, and not
just the one configured by the user in the audio system settings.
2016-08-05 16:11:42 +02:00
wm4 9f70117233 ao_null: use channel list option type for channel-layouts suboption 2016-08-05 12:23:42 +02:00
wm4 0b144eac39 audio: use --audio-channels=auto behavior, except on ALSA
This commit adds an --audio-channel=auto-safe mode, and makes it the
default. This mode behaves like "auto" with most AOs, except with
ao_alsa. The intention is to allow multichannel output by default on
sane APIs. ALSA is not sane as in it's so low level that it will e.g.
configure any layout over HDMI, even if the connected A/V receiver does
not support it. The HDMI fuckup is of course not ALSA's fault, but other
audio APIs normally isolate applications from dealing with this and
require the user to globally configure the correct output layout.

This will help with other AOs too. ao_lavc (encoding) is changed to the
new semantics as well, because it used to force stereo (perhaps because
encoding mode is supposed to produce safe files for crap devices?).
Exclusive mode output on Windows might need to be adjusted accordingly,
as it grants the same kind of low level access as ALSA (requires more
research).

In addition to the things mentioned above, the --audio-channels option
is extended to accept a set of channel layouts. This is supposed to be
the correct way to configure mpv ALSA multichannel output. You need to
put a list of channel layouts that your A/V receiver supports.
2016-08-04 20:49:20 +02:00
wm4 c30aa23401 player: remove special-case for DL/DR speakers
Pointless anyway. With superficial checking I couldn't find any decoder
which actually outputs this, and AO chmap negotiation would properly
ignore them anyway in most cases.
2016-08-04 19:14:35 +02:00
wm4 f3c35d8108 af_lavcac3enc: skip output if there was no input frame
Unrealistic corner case: drainning was initiated right after a seek.
2016-08-02 22:06:22 +02:00
wm4 251299da4f af_lavcac3enc: fix buffering timestamps calculations
In theory, an encoder could buffer some data.
2016-08-01 19:59:59 +02:00
wm4 2e3db648b5 af_lavcac3enc: fix memory leak
A major one. Oops.
2016-08-01 17:59:37 +02:00
wm4 0432ab8f09 af_lavcac3enc: fix a debug message 2016-07-31 18:51:10 +02:00
wm4 0a1c87464b af_lavcac3enc: error out properly if encoding fails 2016-07-31 18:51:08 +02:00
wm4 48f60e182a af_lavcac3enc: fix aspects of AVFrame handling
We send a refcounted frame to the encoder, but then disrespect
refcounting rules and write to the frame data without making sure the
buffer is really writeable.

In theory this can lead to reallocation on every frame is the encoder
really keeps a reference. If we really cared, we could fix this by
providing a buffer pool. But then again, we don't care.
2016-07-31 18:51:05 +02:00
wm4 98af572484 audio: make mp_audio_realloc[_min] ensure frame is writeable
This is logical: the function makes sense only in situations where you
are going to write to the audio data. To make it worse,
av_buffer_realloc() also handles this situation, but only if the buffer
size changes (simply because it can't realloc memory in use), so we have
to explicitly force reallocation by unreffing the buffers first.
2016-07-31 18:51:02 +02:00
Rostislav Pehlivanov c3e11f7b7c osdep/io: introduce mp_flush_wakeup_pipe()
Makes a fairly common occurence with wakeup_pipes easier to handle.
2016-07-30 00:02:39 +02:00
wm4 dcfde2934d audio: use idiotic FFmpeg ABI rules for public-except-not-public fields
The FFmpeg API is incredibly weird and inconsistent about this. This is
also a FFmpeg-only issue and nothing like this is in Libav - which
doesn't really show FFmpeg in a very positive light.

(To make it even worse: this is a full-blown Libav API incompatibility,
even though this crap was added for Libav ABI-compatibility. It's
absurd.)

Quoting the FFmpeg header for the AVFrame.channels field:

    /**
     * number of audio channels, only used for audio.
     * Code outside libavutil should access this field using:
     * av_frame_get_channels(frame)
     * - encoding: unused
     * - decoding: Read by user.
     */
    int channels;

It says "should" not must, and it doesn't even mention
av_frame_set_channels(). It's also in the section for public fields (not
below a marker that indicates private fields in a public struct, like
it's done e.g. in AVCodecContext).

But not using the accessor will cause silent failures on ABI changes.
The failure that happened due to this code didn't even make it apparent
what was wrong. So just use the idiotic accessor.

Also harmonize the FFmpeg-cursing in the code. (It's fully justified.)

Fixes #3295.

Note that mpv will still check the exact library version numbers, and
reject mismatches - to protect itself from such issues in the future.
2016-07-24 19:33:20 +02:00
wm4 3623cec7d2 af_lavcac3enc: use common code for AVFrame setup 2016-07-24 19:06:00 +02:00
wm4 77e1e8e38e audio: refactor mixer code and delete mixer.c
mixer.c didn't really deserve to be separate anymore, as half of its
contents were unnecessary glue code after recent changes. It also
created a weird split between audio.c and af.c due to the fact that
mixer.c could insert audio filters. With the code being in audio.c
directly, together with other code that unserts filters during runtime,
it will be possible to cleanup this code a bit and make it work like the
video filter code.

As part of this change, make the balance code work like the volume code,
and add an option to back the current balance value. Also, since the
balance semantics are unexpected for most users (panning between the
audio channels, instead of just changing the relative volume), and there
are some other volumes, formally deprecate both the old property and the
new option.
2016-07-17 19:21:28 +02:00
wm4 79974e7ad9 audio: fix crashes due to broken uninit check
Since mixer->ao is always NULL now (it was really just forgotten to be
removed), the uninit call never actually cleared the af field, leaving
a dangling pointer that could be accessed by volume control.
2016-07-15 23:11:25 +02:00
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