summaryrefslogtreecommitdiffstats
path: root/audio/decode
Commit message (Collapse)AuthorAgeFilesLines
* audio: make decoders output refcounted frameswm42014-11-106-194/+107
| | | | | | | | | | | | | | This rewrites the audio decode loop to some degree. Audio filters don't do refcounted frames yet, so af.c contains a hacky "emulation". Remove some of the weird heuristic-heavy code in dec_audio.c. Instead of estimating how much audio we need to filter, we always filter full frames. Maybe this should be adjusted later: in case filtering increases the volume of the audio data, we should try not to buffer too much filter output by reducing the input that is fed at once. For ad_spdif.c and ad_mpg123.c, we don't avoid extra copying yet - it doesn't seem worth the trouble.
* audio: change how filters are inserted on playback speed changeswm42014-11-101-1/+0
| | | | | | | | | | Use a pseudo-filter when changing speed with resampling, instead of somehow changing a samplerate somewhere. This uses the same underlying mechanism, but is a bit more structured and cleaner. It also makes some of the following changes easier. Since we now always use filters to change audio speed, move most of the work set_playback_speed() does to recreate_audio_filters().
* ad_lavc: allow skip samples amount to be larger than 1 packetwm42014-11-031-2/+6
| | | | | Apparently we actually need this. At least the following commit would break without this.
* ad_lavc: avoid warning messages on older FFmpeg or Libavwm42014-10-041-0/+2
| | | | | If the flag doesn't exist, the av_opt_set() API will print warning messages.
* audio: skip samples and adjust timestamps ourselveswm42014-10-031-2/+22
| | | | | | | | | | This gets rid of this warning: Could not update timestamps for skipped samples. This required an API addition to FFmpeg (otherwise it would instead doing arithmetic on the timestamps itself), so whether it works depends on the FFmpeg version.
* audio: refactor some aspects of filter chain setupwm42014-10-022-54/+4
| | | | | | | | | | | There's no real reason why audio_init_filter() should exist. Just use af_init or af_reinit directly. (We lose a useless message; the same information is printed in a quite close place with more details.) Requires less code, and the way the filter chain is marked as having failed to initialize allows just switching off audio instead of crashing if trying to insert a volume filter in mixer.c fails, and recreating the old filter chain fails too.
* audio: remove WAVEFORMATEX from internal demuxer APIwm42014-09-251-19/+5
| | | | | Same as with the previous commit. A bit more involved due to how the code is written.
* audio: confine demux_mkv audio PCM hackwm42014-09-241-50/+0
| | | | | | | | Let codec_tags.c do the messy mapping. In theory we could simplify further by makign demux_mkv.c directly use codec names instead of the MPlayer-inherited "internal FourCC" business, but I'd rather not touch this - it would just break things.
* audio: decouple demux and audio decoder/filter sample formatswm42014-09-241-34/+3
| | | | | | | | | | | | | | | | | | | | For a while, we used this to transfer PCM from demuxer to the filter chain. We had a special "codec" that mapped what MPlayer used to do (MPlayer passes the AF sample format over an extra field to ad_pcm, which specially interprets it). Do this by providing a mp_set_pcm_codec() function, which describes a sample format in a generic way, and sets the appropriate demuxer header fields so that libavcodec interprets it correctly. We use the fact that libavcodec has separate PCM decoders for each format. These are systematically named, so we can easily map them. This has the advantage that we can change the audio filter chain as we like, without losing features from the "rawaudio" demuxer. In fact, this commit also gets rid of the audio filter chain formats completely. Instead have an explicit list of PCM formats. (We could even just have the user pass libavcodec PCM decoder names directly, but that would be annoying in other ways.)
* audio: cleanup spdif format definitionswm42014-09-231-7/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before this commit, there was AF_FORMAT_AC3 (the original spdif format, used for AC3 and DTS core), and AF_FORMAT_IEC61937 (used for AC3, DTS and DTS-HD), which was handled as some sort of superset for AF_FORMAT_AC3. There also was AF_FORMAT_MPEG2, which used IEC61937-framing, but still was handled as something "separate". Technically, all of them are pretty similar, but may use different bitrates. Since digital passthrough pretends to be PCM (just with special headers that wrap digital packets), this is easily detectable by the higher samplerate or higher number of channels, so I don't know why you'd need a separate "class" of sample formats (AF_FORMAT_AC3 vs. AF_FORMAT_IEC61937) to distinguish them. Actually, this whole thing is just a mess. Simplify this by handling all these formats the same way. AF_FORMAT_IS_IEC61937() now returns 1 for all spdif formats (even MP3). All AOs just accept all spdif formats now - whether that works or not is not really clear (seems inconsistent due to earlier attempts to make DTS-HD work). But on the other hand, enabling spdif requires manual user interaction, so it doesn't matter much if initialization fails in slightly less graceful ways if it can't work at all. At a later point, we will support passthrough with ao_pulse. It seems the PulseAudio API wants to know the codec type (or maybe not - feeding it DTS while telling it it's AC3 works), add separate formats for each codecs. While this reminds of the earlier chaos, it's stricter, and most code just uses AF_FORMAT_IS_IEC61937(). Also, modify AF_FORMAT_TYPE_MASK (renamed from AF_FORMAT_POINT_MASK) to include special formats, so that it always describes the fundamental sample format type. This also ensures valid AF formats are never 0 (this was probably broken in one of the earlier commits from today).
* audio: drop swapped-endian audio formatswm42014-09-231-18/+24
| | | | | | | | | | | | | | | | | | | | Until now, the audio chain could handle both little endian and big endian formats. This actually doesn't make much sense, since the audio API and the HW will most likely prefer native formats. Or at the very least, it should be trivial for audio drivers to do the byte swapping themselves. From now on, the audio chain contains native-endian formats only. All AOs and some filters are adjusted. af_convertsignendian.c is now wrongly named, but the filter name is adjusted. In some cases, the audio infrastructure was reused on the demuxer side, but that is relatively easy to rectify. This is a quite intrusive and radical change. It's possible that it will break some things (especially if they're obscure or not Linux), so watch out for regressions. It's probably still better to do it the bulldozer way, since slow transition and researching foreign platforms would take a lot of time and effort.
* audio: remove swapped-endian spdif formatswm42014-09-231-6/+6
| | | | | | | | | | | | | | | | | | | | | | IEC 61937 frames should always be little endian (little endian 16 bit words). I don't see any apparent need why the audio chain should handle swapped-endian formats. It could be that some audio outputs might want them (especially on big endian architectures). On the other hand, it's not clear how that works on these architectures, and it's not even known whether the current code works on big endian at all. If something should break, and it should turn out that swapped-endian spdif is needed on any platform/AO, swapping still could be done in-place within the affected AO, and there's no need for the additional complexity in the rest of the player. Note that af_lavcac3enc outputs big endian spdif frames for unknown reasons. Normally, the resulting data is just pulled through an auto- inserted conversion filter and turned into little endian. Maybe this was done as a trick so that the code didn't have to byte-swap the actual audio frame. In any case, just make it output little endian frames. All of this is untested, because I have no receiver hardware.
* audio: prefer libavcodec over libmpg123wm42014-09-221-1/+1
| | | | | | | | | | | | | | | | | libavcodec/libavformat now handles gapless audio better. In theory, this could be implemented with ad_mpg123 too, but since libavformat strips metadata from mp3 files and passes pure mp3 packets to the decoders only, this can't work by itself. Instead, the player must pass this metadata separately. libav* do this relatively transparently over packet "side data" (attached to AVPacket). It might also be possible to let libmpg123 handles all this by implementing it as demuxer that outputs PCM, but that would have other problems, and I think it's better to make libavformat work correctly. libmpg123 can still be used with '--ad=mpg123:mp3'. Also see issue #1101.
* Move compat/ and bstr/ directory contents somewhere elsewm42014-08-292-3/+1
| | | | | | | | | bstr.c doesn't really deserve its own directory, and compat had just a few files, most of which may as well be in osdep. There isn't really any justification for these extra directories, so get rid of them. The compat/libav.h was empty - just delete it. We changed our approach to API compatibility, and will likely not need it anymore.
* Improve setting AVOptionswm42014-08-021-10/+3
| | | | | | | | Use OPT_KEYVALUELIST() for all places where AVOptions are directly set from mpv command line options. This allows escaping values, better diagnostics (also no more "pal"), and somehow reduces code size. Remove the old crappy option parser (av_opts.c).
* audio: ignore (some) decoding errors on initializationwm42014-07-291-0/+1
| | | | | | | | | | | | It probably happens relatively often that the first packet (or even the first N packets) of a stream will fail to decode, but decoding will eventually succeed at a later point. Before commit 261506e3, this was handled by an explicit retry loop (although this was also for other purposes), but with then was changed to abort on the first error. This makes it impossible to decode some audio streams. Change this so that errors are ignored for the first 50 packets, which should make it equivalent to the old code.
* audio: change playback restart and resyncingwm42014-07-285-31/+40
| | | | | | | | | | | | | | | | | | | | | This commit makes audio decoding non-blocking. If e.g. the network is too slow the playloop will just go to sleep, instead of blocking until enough data is available. For video, this was already done with commit 7083f88c. For audio, it's unfortunately much more complicated, because the audio decoder was used in a blocking manner. Large changes are required to get around this. The whole playback restart mechanism must be turned into a statemachine, especially since it has close interactions with video restart. Lots of video code is thus also changed. (For the record, I don't think switching this code to threads would make this conceptually easier: the code would still have to deal with external input while blocked, so these in-between states do get visible [and thus need to be handled] anyway. On the other hand, it certainly should be possible to modularize this code a bit better.) This will probably cause a bunch of regressions.
* audio: fix timestampswm42014-07-243-2/+1
| | | | | | | | | Accidentally broken in b6af44d3. For ad_lavc (and in general), the PTS was not updated correctly when filtering only parts of audio frames, and for ad_mpg123 and ad_spdif the PTS was additionally offset by the frame size. This could lead to incorrect time display, and possibly broken A/V sync.
* audio: adjust format change codewm42014-07-241-8/+9
| | | | | | Execute the format change based on whether we logically detected EOF (after filters), instead of when the decode buffer was drained. It's slightly cleaner. (The requirement of len>0 existed before.)
* audio: fix race condition in EOF codewm42014-07-242-3/+3
| | | | | | | | | | Don't return an EOF code if there's still buffered data. Also, don't call demux_stream_eof() in the playloop. There's probably nothing wrong with it, but it's cleaner not to use it. Also give AD_EOF its own value, so that a decoding error doesn't drain audio by causing an EOF condition.
* audio: cosmeticswm42014-07-241-9/+5
| | | | | | | Move a function call, which does not change semantics. Write the extra buffer sample count in a more straight-forward way; the old code was not meaningful in any way (anymore).
* audio: remove unnecessary codewm42014-07-241-3/+0
| | | | | | | | It's true that the decoder can successfully decode, but return no data (for various reasons). We don't need to handle this specially, though. We just let the decoder decode some more data. This doesn't increase the danger of an endless loop either, because audio_decode() already calls this function until enough is decoded.
* audio: move initial decode to generic codewm42014-07-216-239/+127
| | | | | | | | | | | | This commit mainly moves the initial decoding of data (done to probe the audio format) to generic code. This will make it easier to make audio decoding non-blocking in a later commit. This commit also changes how decoders return data: instead of having them write the data into a prepared buffer, they return a reference to an internal buffer (by setting dec_audio.decoded). This makes it significantly easier to handle audio format changes, since the decoders don't really need to care anymore.
* ad_lavc: drop questionable fallback codewm42014-07-211-6/+0
| | | | | | | | | | | If the decoder didn't set a samplerate, it was initialized from the container samplerate. This probably didn't make much sense, because it's passed to the decoder on initialization (so it could definitely use it). It's an artifact from commit 66a9eb57 (which removed some Matroska-specific non- sense), and I've never seen it actually happen since it was made into a warning. Just get rid of it.
* audio: remove unused metadata fieldwm42014-07-212-3/+0
| | | | | This was used for replaygain at some point, until replaygain info was passed through explicitly.
* audio: use symbolic constants instead of magic integerswm42014-07-205-12/+18
| | | | Similar to commit 26468743.
* ad_lavc: make option struct localwm42014-06-111-9/+23
| | | | Similar to previous commit.
* player: hide audio/video codec and file format messageswm42014-05-311-2/+1
| | | | | None of these are very important usually. For error analysis, the plain log is useless anyway, and this information is still printed with "-v".
* ad_lavc: don't overwrite lavc bitrateMarcoen Hirschberg2014-05-281-2/+3
| | | | | If the bitrate is already known in avcodec there is no need to overwrite it again with the value from sh_audio.
* af_fmt2bits: change to af_fmt2bps (bytes/sample) where appropriateMarcoen Hirschberg2014-05-281-1/+1
| | | | | | In most places where af_fmt2bits is called to get the bits/sample, the result is immediately converted to bytes/sample. Avoid this by getting bytes/sample directly by introducing af_fmt2bps.
* audio: rename i_bps to 'bitrate' to avoid confusionMarcoen Hirschberg2014-05-283-6/+6
| | | | Since i_bps now contains bits/sec, rename it to reflect this change.
* audio: change values from bytes-per-second to bits-per-secondMarcoen Hirschberg2014-05-282-8/+10
| | | | | | | The i_bps members of the sh_audio and dev_video structs are mostly used for displaying the average audio and video bitrates. Keeping them in bits-per-second avoids truncating them to bytes-per-second and changing them back lateron.
* options: remove deprecated --identifyMartin Herkt2014-05-041-3/+0
| | | | | | | Also remove MSGL_SMODE and friends. Note: The indent in options.rst was added to work around a bug in ReportLab that causes the PDF manual build to fail.
* player: add a --dump-stats optionwm42014-04-171-5/+6
| | | | | | | | | | | | | | | | | | | | | | | This collects statistics and other things. The option dumps raw data into a file. A script to visualize this data is included too. Litter some of the player code with calls that generate these statistics. In general, this will be helpful to debug timing dependent issues, such as A/V sync problems. Normally, one could argue that this is the task of a real profiler, but then we'd have a hard time to include extra information like audio/video PTS differences. We could also just hardcode all statistics collection and processing in the player code, but then we'd end up with something like mplayer's status line, which was cluttered and required a centralized approach (i.e. getting the data to the status line; so it was all in mplayer.c). Some players can visualize such statistics on OSD, but that sounds even more complicated. So the approach added with this commit sounds sensible. The stats-conv.py script is rather primitive at the moment and its output is semi-ugly. It uses matplotlib, so it could probably be extended to do a lot, so it's not a dead-end.
* af: add replaygain_data field to af_stream and af_instanceAlessandro Ghedini2014-04-042-0/+3
| | | | Closes #664
* ad_lavc: use new AVFrame APIwm42014-03-161-2/+4
| | | | | | | Set refcounted_frames, because in some versions of libavcodec mixing the new AVFrame API and non-refcounted decoding could cause memory corruption. Likewise, it's probably still required to unref a frame before calling the decoder.
* ad_lavc: remove deprecated downmixing by channel countwm42014-03-161-4/+0
| | | | | Downmixing by channel layout now hopefully works with all supported libavcodec versions.
* af: add metadata field to af_stream and af_instanceAlessandro Ghedini2014-03-132-0/+4
| | | | | | This allows to propagate metadata information to audio filters. Closes #632
* Factor out setting AVCodecContext extradatawm42014-01-111-10/+4
|
* codecs: mp_msg conversionwm42013-12-211-1/+1
|
* audio/fmt-conversion.c: remove unknown audio format messageswm42013-12-211-1/+4
| | | | Same deal as with video/fmt-conversion.c.
* audio: mp_msg conversionswm42013-12-215-49/+42
|
* ad_lavc: work around deprecation warningwm42013-12-181-1/+4
| | | | | | | | | | request_channels has been deprecated for years (request_channel_layout is the replacement), but it appears it's still needed despite the deprecation at least on older libavcodec versions. So still set request_channels, but to it with the avoption API, which hides the deprecation warning. This should also prevent mpv getting trashed when libavcodec happens to bump its major version.
* Split mpvcore/ into common/, misc/, bstr/wm42013-12-175-11/+11
|
* Move options/config related files from mpvcore/ to options/wm42013-12-172-2/+2
| | | | | | | | | Since m_option.h and options.h are extremely often included, a lot of files have to be changed. Moving path.c/h to options/ is a bit questionable, but since this is mainly about access to config files (which are also handled in options/), it's probably ok.
* Replace mp_tmsg, mp_dbg -> mp_msg, remove mp_gtext(), remove set_osd_tmsgwm42013-12-162-10/+10
| | | | | | | | | The tmsg stuff was for the internal gettext() based translation system, which nobody ever attempted to use and thus was removed. mp_gtext() and set_osd_tmsg() were also for this. mp_dbg was once enabled in debug mode only, but since we have log level for enabling debug messages, it seems utterly useless.
* audio: flush remaining data from the filter chain on EOFwm42013-12-051-1/+5
| | | | | | | | | | | | | | | | | This can be reproduced with: mpv short.wav -af 'lavfi="aecho=0.8:0.9:5000|6800:0.3|0.25"' An audio file that is just 1-2 seconds long should play for 8-9 seconds, which audible echo towards the end. The code assumes that when playing with AF_FILTER_FLAG_EOF, the filter will either produce output, or has all remaining data flushed. I'm not really sure whether this really works if there are multiple filters with EOF handling in the chain. To handle it correctly, af_lavfi should retry filtering if 1. EOF flag is set, 2. there were input samples, and 3. no output samples were produced. But currently it seems to work well enough anyway.
* audio/filter: change filter callback signaturewm42013-12-051-9/+8
| | | | | | | | | The new signature is actually closer to how it actually works, and someone who is not familiar to the API and how it works might make fewer fatal mistakes with the new signature than the old one. Pretty weird. Do this to sneak in a flags parameter, which will later be used to flush remaining data of at least vf_lavfi.
* ad_lavc: handle decoder EAGAIN only if there was an input packetwm42013-12-041-3/+3
| | | | | Otherwise, it'd probably get stuck if the decoder still returns EAGAIN at EOF on e.g. a shortened data stream.
* ad_lavc: expose an option to enable threadingwm42013-12-041-0/+3
|
* ad_lavc: deal with arbitrary decoder delaywm42013-12-041-16/+24
| | | | | | | | | | | | | | | | | | | | Normally, audio decoder don't have a decoder delay, so the code was fine. But FFmpeg supports multithreaded decoding for some audio codecs, which introduces such a delay. The delay means that we won't get decoded audio for the first few packets, and that we need to do something to get the trailing audio still buffered in the decoder when reaching EOF. Two changes are needed to deal with the delay: - If EOF is reached, pass a "flush" packet to the decoder to return the buffered audio. Such a flush packet is automatically setup when calling mp_set_av_packet() with a NULL packet. - Use the PTS returned by the decoder, instead of the packet's. This is important to get correct timestamps for decoded audio. Ignoring this would result into offsetting the audio playback time by the decoder delay. Note that we can still use the timestamp of the first packet to get the timestamp for the start of the audio.
* av_common: add timebase parameter to mp_set_av_packet()wm42013-12-042-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | If the timebase is set, it's used for converting the packet timestamps. Otherwise, the previous method of reinterpret-casting the mpv style double timestamps to libavcodec style int64_t timestamps is used. Also replace the kind of awkward mp_get_av_frame_pkt_ts() function by mp_pts_from_av(), which simply converts timestamps in a way the old function did. (Plus it takes a timebase parameter, similar to the addition to mp_set_av_packet().) Note that this should not change anything yet. The code in ad_lavc.c and vd_lavc.c passes NULL for the timebase parameters. We could set AVCodecContext.pkt_timebase and use that if we want to give libavcodec "proper" timestamps. This could be important for ad_lavc.c: some codecs (opus, probably mp3 and aac too) have weird requirements about doing decoding preroll on the container level, and thus require adjusting the audio start timestamps in some cases. libavcodec doesn't tell us how much was skipped, so we either get shifted timestamps (by the length of the skipped data), or we give it proper timestamps. (Note: libavcodec interprets or changes timestamps only if pkt_timebase is set, which by default it is not.) This would require selecting a timebase though, so I feel uncomfortable with the idea. At least this change paves the way, and will allow some testing.
*