Commit Graph

374 Commits

Author SHA1 Message Date
wm4 2556f45f2e af_lavrresample: set cutoff as double, not int
Regression introduced with commit a89549e8.
2013-11-17 16:22:35 +01:00
wm4 e403140201 ao_null: properly simulate final chunk, add buffer options
Simulate proper handling of AOPLAY_FINAL_CHUNK. Print when underruns
occur (i.e. running out of data). Add some options that control
simulated buffer and outburst sizes.

All this is useful for debugging and self-documentation. (Note that
ao_null always was supposed to simulate an ideal AO, which is the reason
why it fools people who try to use it for benchmarking video.)
2013-11-17 16:22:25 +01:00
wm4 ca455e65a3 ao_lavc: use af_format_conversion_score()
This should allow it to select better fallback formats, instead of
picking the first encoder sample format if ao->format is not equal to
any of the encoder sample formats.

Not sure what is supposed to happen if the encoder provides no
compatible sample format (or no sample format list at all), but in this
case ao_lavc.c still fails gracefully.
2013-11-16 21:46:17 +01:00
wm4 3f7e1f0492 audio/format: add heuristic to estimate loss on format conversion
The added function af_format_conversion_score() can be used to select
the best sample format to convert to in order to reduce loss and extra
conversion work.

It calculates a "loss" score when going from one format to another, and
for each conversion that needs to be done a certain score is subtracted.
Thus, if you have to convert from one format to a set of other formats,
you can calculate the score for each conversion, and pick the one with
the highest score.

Conversion between int and float is considered the worst case. One odd
consequence is that when converting from s32 to u8 or float, u8 will be
picked.

Test program used to develop this follows:

#define MAX_FMT 200
struct entry {
    const char *name;
    int score;
};

static int compentry(const void *px1, const void *px2)
{
    const struct entry *x1 = px1;
    const struct entry *x2 = px2;
    if (x1->score > x2->score)
        return 1;
    if (x1->score < x2->score)
        return -1;
    return 0;
}

int main(int argc, char *argv[])
{
    for (int n = 0; af_fmtstr_table[n].name; n++) {
        struct entry entry[MAX_FMT];
        int entries = 0;
        for (int i = 0; af_fmtstr_table[i].name; i++) {
            assert(i < MAX_FMT);
            entry[entries].name = af_fmtstr_table[i].name;
            entry[entries].score =
                af_format_conversion_score(af_fmtstr_table[i].format,
                                           af_fmtstr_table[n].format);
            entries++;
        }
        qsort(&entry[0], entries, sizeof(entry[0]), compentry);
        for (int i = 0; i < entries; i++) {
            printf("%s -> %s: %d \n", af_fmtstr_table[n].name,
                   entry[i].name, entry[i].score);
        }
    }
}
2013-11-16 21:46:17 +01:00
wm4 0ed0f4d33a audio/format: fix doublep sample format
This was accidentally equivalent to floatp.
2013-11-16 21:46:16 +01:00
Rudolf Polzer 6391453fab ao_lavc: write the final audio chunks from uninit()
These must be written even if there was no "final frame", e.g. due to
the player being exited with "q".

Although the issue is mostly of theoretical nature, as most audio codecs
don't need the final encoding calls with NULL data. Maybe will be more
relevant in the future.
2013-11-16 18:50:07 +01:00
Rudolf Polzer 0d4628a7fd ao_lavc: fix crash with interleaved audio outputs. 2013-11-16 14:10:00 +01:00
wm4 514c454770 audio: drop "_NE"/"ne" suffix from audio formats
You get the native format by not appending any suffix to the format.

This change includes user-facing names, e.g. for the --format option.
2013-11-15 21:25:05 +01:00
wm4 3ded03b1f9 dec_audio: adjust "large" decoding amount
This used to be in bytes, now it's in samples. Divide the value by 8
(assuming a typical audio format, float samples with 2 channels).

Fix some editing mistake or non-sense about the extra buffering added
(1<<x instead of x<<5).

Also sneak in a s/MPlayer/mpv/.
2013-11-15 21:12:01 +01:00
wm4 7f7e9a9fff af_lavcac3enc: use option parser
This changes option parsing as well as filter defaults slightly. The
default is now to encode to spdif (this is way more useful than writing
raw AC3 - what was this even useful for, other than writing broken ac3
-in-wav files?). The bitrate parameter is now always in kbps.
2013-11-15 00:24:03 +01:00
wm4 8512a08046 ad_spdif: fix regressions
Apparently this was completely broken after commit 22b3f522. Basically,
this locked up immediately completely while decoding the first packet.
The reason was that the buffer calculations confused bytes and number of
samples. Also, EOF reporting was broken (wrong return code).

The special-casing of ad_mpg123 and ad_spdif (with DECODE_MAX_UNIT) is a
bit annoying, but will eventually be solved in a better way.
2013-11-14 23:54:06 +01:00
wm4 53c6d97873 ao_alsa: non-interleaved access is not always available
I thought this would always work... how disappointing.

Revert to interleaved format if requesting non-interleaved fails.
2013-11-14 21:19:04 +01:00
wm4 d0346e087a audio: fix audio data memory leak
Practically all audio decoding and filtering code leaked sample data
memory after uninitialization due to a simple logic bug (or typo).
2013-11-14 19:51:42 +01:00
wm4 e5fec0ad07 ao_null: add untimed sub-option 2013-11-13 20:10:17 +01:00
wm4 621cff80df ao_null: support pausing properly
ao_null should simulate a "perfect" AO, but framestepping behaved quite
badly with it. Framstepping usually exposes problems with AOs dropping
their buffers on pause, and that's what happened here.
2013-11-13 20:10:17 +01:00
wm4 933fbf7333 ao_lavc: support non-interleaved audio 2013-11-13 20:10:17 +01:00
wm4 e4bbb1d348 Merge branch 'planar_audio'
Conflicts:
	audio/out/ao_lavc.c
2013-11-12 23:42:04 +01:00
wm4 22b3f522ca audio: add support for using non-interleaved audio from decoders directly
Most libavcodec decoders output non-interleaved audio. Add direct
support for this, and remove the hack that repacked non-interleaved
audio back to packed audio.

Remove the minlen argument from the decoder callback. Instead of
forcing every decoder to have its own decode loop to fill the buffer
until minlen is reached, leave this to the caller. So if a decoder
doesn't return enough data, it's simply called again. (In future, I
even want to change it so that decoders don't read packets directly,
but instead the caller has to pass packets to the decoders. This fits
well with this change, because now the decoder callback typically
decodes at most one packet.)

ad_mpg123.c receives some heavy refactoring. The main problem is that
it wanted to handle format changes when there was no data in the decode
output buffer yet. This sounds reasonable, but actually it would write
data into a buffer prepared for old data, since the caller doesn't know
about the format change yet. (I.e. the best place for a format change
would be _after_ writing the last sample to the output buffer.) It's
possible that this code was not perfectly sane before this commit,
and perhaps lost one frame of data after a format change, but I didn't
confirm this. Trying to fix this, I ended up rewriting the decoding
and also the probing.
2013-11-12 23:39:09 +01:00
wm4 5388a0cd40 ad_mpg123: reduce ifdeffery
Drop support for anything before 1.14.0.
2013-11-12 23:38:52 +01:00
wm4 9127aad2fd dec_audio: fix behavior on format changes
Decoder overwrites parameters in sh_audio, but we still have old audio
in the old format to filter.
2013-11-12 23:38:36 +01:00
wm4 cc5083cfe0 mp_audio: use av_malloc (cargo cult for libav*)
libav* is generally freaking horrible, and might do bad things if the
data pointer passed to it are not aligned. One way to be sure that the
alignment is correct is allocating all pointers using av_malloc().

It's possible that this is not needed at all, though. For now it might
be better to keep this, since the mp_audio code is intended to replace
another buffer in dec_audio.c, which is currently av_malloc() allocated.
The original reason why this uses av_malloc() is apparently because
libavcodec used to directly encode into mplayer buffers, which is not
the case anymore, and thus (probably) doesn't make sense anymore.

(The commit subject uses the word "cargo cult", after all.)
2013-11-12 23:35:33 +01:00
William Light e1656d369a ao_jack: switch from interleaved to planar audio 2013-11-12 23:35:12 +01:00
William Light 4bd690c998 ao_jack: refactoring, also fix "no-connect" option 2013-11-12 23:35:04 +01:00
wm4 6f557aef42 af_lavcac3enc: use planar formats
Remove the awkward planarization. It had to be done because the AC3
encoder requires planar formats, but now we support them natively.

Try to simplify buffer management with mp_audio_buffer.

Improve checking for buffer overflows and out of bound writes. In
theory, these shouldn't happen due to AC3 fixed frame sizes, but being
paranoid is better.
2013-11-12 23:34:49 +01:00
wm4 a72072c605 af_lavcac3enc: simplify format negotiation
The format negotiation is the same, except don't confusingly copy the
input format into af->data, just to overwrite it later. af->data should
alwass contain the output format, and the existing code was just a very
misguided use of the af_test_output() helper function.

Just set af->data to the output format immediately, and modify the input
format properly.

Also, if format negotiation fails (and needs another iteration), don't
initialize the libavcodec encoder.
2013-11-12 23:34:37 +01:00
wm4 824e6550f8 audio/filter: fix mul/delay scale and values
Before this commit, the af_instance->mul/delay values were in bytes.
Using bytes is confusing for non-interleaved audio, so switch mul to
samples, and delay to seconds. For delay, seconds are more intuitive
than bytes or samples, because it's used for the latency calculation.
We also might want to replace the delay mechanism with real PTS
tracking inside the filter chain some time in the future, and PTS
will also require time-adjustments to be done in seconds.

For most filters, we just remove the redundant mul=1 initialization.
(Setting this used to be required, but not anymore.)
2013-11-12 23:34:35 +01:00
wm4 7510caa0c5 ao_openal: support non-interleaved output
Since ao_openal simulates multi-channel audio by placing a bunch of
mono-sources in 3D space, non-interleaved audio is a perfect match for
it. We just have to remove the interleaving code.
2013-11-12 23:30:37 +01:00
wm4 dab6eaaa5e ao_alsa: support non-interleaved audio
ALSA supports non-interleaved audio natively using a separate API
function for writing audio. (Though you have to tell it about this on
initialization.) ALSA doesn't have separate sample formats for this,
so just pretend to negotiate the interleaved format, and assume that
all non-interleaved formats have an interleaved companion format.
2013-11-12 23:30:25 +01:00
wm4 fedb9229d5 ao_null: support non-interleaved audio
Simply change internals from using byte counts to sample counts.
2013-11-12 23:30:10 +01:00
wm4 347a86198b audio: switch output to mp_audio_buffer
Replace the code that used a single buffer with mp_audio_buffer. This
also enables non-interleaved output operation, although it's still
disabled, and no AO supports it yet.
2013-11-12 23:29:53 +01:00
wm4 d1ee9ea261 audio: add mp_audio_buffer
Implementation wise, this could be much improved, such as using a
ringbuffer that doesn't require copying data all the time. This is
why we don't use mp_audio directly instead of mp_audio_buffer.
2013-11-12 23:28:21 +01:00
wm4 380fc765e4 audio/out: prepare for non-interleaved audio
This comes with two internal AO API changes:

1. ao_driver.play now can take non-interleaved audio. For this purpose,
the data pointer is changed to void **data, where data[0] corresponds to
the pointer in the old API. Also, the len argument as well as the return
value are now in samples, not bytes. "Sample" in this context means the
unit of the smallest possible audio frame, i.e. sample_size * channels.

2. ao_driver.get_space now returns samples instead of bytes. (Similar to
the play function.)

Change all AOs to use the new API.

The AO API as exposed to the rest of the player still uses the old API.
It's emulated in ao.c. This is purely to split the commits changing all
AOs and the commits adding actual support for outputting N-I audio.
2013-11-12 23:27:51 +01:00
wm4 d115fb3b0e af: don't require filters to allocate af_instance->data, redo buffers
Allocate af_instance->data in generic code before filter initialization.
Every filter needs af->data (since it contains the output
configuration), so there's no reason why every filter should allocate
and free it.

Remove RESIZE_LOCAL_BUFFER(), and replace it with mp_audio_realloc_min().
Interestingly, most code becomes simpler, because the new function takes
the size in samples, and not in bytes. There are larger change in
af_scaletempo.c and af_lavcac3enc.c, because these had copied and
modified versions of the RESIZE_LOCAL_BUFFER macro/function.
2013-11-12 23:27:03 +01:00
wm4 e763d528e2 af_lavfi: add support for non-interleaved audio 2013-11-12 23:16:31 +01:00
wm4 4f31d56eb1 af_volume: add support for non-interleaved audio 2013-11-12 23:16:31 +01:00
wm4 45d1510e4e af_lavrresample: add support for non-interleaved audio 2013-11-12 23:16:31 +01:00
wm4 bf60281ffb audio/out: reject non-interleaved formats
No AO can handle these, so it would be a problem if they get added
later, and non-interleaved formats get accepted erroneously. Let them
gracefully fall back to other formats.

Most AOs actually would fall back, but to an unrelated formats. This is
covered by this commit too, and if possible they should pick the
interleaved variant if a non-interleaved format is requested.
2013-11-12 23:16:31 +01:00
wm4 d2e7467eb2 audio/filter: prepare filter chain for non-interleaved audio
Based on earlier work by Stefano Pigozzi.

There are 2 changes:

1. Instead of mp_audio.audio, mp_audio.planes[0] must be used.

2. mp_audio.len used to contain the size of the audio in bytes. Now
   mp_audio.samples must be used. (Where 1 sample is the smallest unit
   of audio that covers all channels.)

Also, some filters need changes to reject non-interleaved formats
properly.

Nothing uses the non-interleaved features yet, but this is needed so
that things don't just break when doing so.
2013-11-12 23:16:31 +01:00
wm4 b2d4b5ee43 audio/format: add non-interleaved audio formats 2013-11-12 23:16:27 +01:00
wm4 d8882bbfb7 demux_mkv: support some raw PCM variants
This affects 64 bit floats and big endian integer PCM variants
(basically crap nobody uses). Possibly not all MS-muxed files work, but
I couldn't get or produce any samples.

Remove a bunch of format tags that are not needed anymore. Most of these
were used by demux_mov, which is long gone. Repurpose/abuse 'twos' as
mpv-internal tag for dealing with the PCM variants mentioned above.
2013-11-11 18:40:59 +01:00
Rudolf Polzer 149ab3afa2 ao_lavc: remove audio offset hack to ease supporting planar audio.
Now to shift audio pts when outputting to e.g. avi, you need an explicit
facility to insert/remove initial samples, to avoid initial regions of
the video to be sped up/slowed down.

One such facility is the delay filter in libavfilter.
2013-11-11 13:04:13 +01:00
wm4 3cb4116243 ao: add ao_play_silence, use for ao_alsa and ao_oss
Also add a corresponding function to audio/format.c, which fills an
audio block with silence.
2013-11-10 23:05:59 +01:00
wm4 6ec1f31765 af: don't skip filtering if there's no more audio
My main problem with this is that the output format will be incorrect.
(This doesn't matter right, because there are no samples output.)

This assumes all audio filters can deal with len==0 passed in for
filtering (though I wouldn't see why not).

A filter can still signal an error by returning NULL.

af_lavrresample has to be fixed, since resampling 0 samples makes
libavresample fail and return a negative error code. (Even though it's
not documented to return an error code!)
2013-11-10 22:49:39 +01:00
wm4 9e40d7155c ad_spdif: change API usage so that it works on Libav
Apparently we were using FFmpeg-specific APIs. I have no idea whether
this code is correct on both FFmpeg and Libav (no examples, bad
doxygen... why do they even complaint aht people are using their APIs
incorrectly?), but it appears to work on FFmpeg. That was also the case
before commit ebc4ccb though, where it used internal libavformat
symbols.

Untested on Libav, Travis will tell us.
2013-11-10 00:52:55 +01:00
wm4 1a5c863a32 player: set PulseAudio stream title to window title
Set the PulseAudio stream title, just like the VO window title is set.
Refactor update_vo_window_title() so that we can use it for AOs too.

The ao_pulse.c bit is stolen from MPlayer.
2013-11-10 00:49:13 +01:00
wm4 d6abfcd578 af_volume: use only one volume setting for all channels
In theory, af_volume could use separate volume levels for each channel.
But this was never used anywhere.

MPlayer implemented something similar before (svn r36498), but kept the
old path for some reason.
2013-11-09 23:32:58 +01:00
wm4 0f82107535 ao_alsa: use correct magic spdif flags
I accidentally copied the AES4/ORIGFS constants from the ALSA headers,
instead of the AES3/FS ones. The difference is probably important.
2013-11-09 23:32:58 +01:00
wm4 53d3827843 Remove sh_audio->samplesize
This member was redundant. sh_audio->sample_format indicates the sample
size already.

The TV code is a bit strange: the redundant sample size was part of the
internal TV interface. Assume it's really redundant and not something
else. The PCM decoder ignores the sample size anyway.
2013-11-09 23:32:58 +01:00
wm4 0ff863c179 af_scaletempo: uncrustify
Also do some cosmetic changes, like merging definition and
initialization of local variables.

Remove an annoying debug mp_msg() from af_open(). It just printed the
command line parameters; if this is really needed, it could be added
to af.c instead (similar as to what vf.c does).
2013-11-09 23:32:58 +01:00
wm4 142d5c985e af_lavrresample: reconfigure libavresample only on successful init
If filter initialization fails anyway, we don't need to reconfigure
libavresample.
2013-11-09 23:32:58 +01:00