summaryrefslogtreecommitdiffstats
path: root/audio/decode/ad_lavc.c
Commit message (Collapse)AuthorAgeFilesLines
* audio: make decoders output refcounted frameswm42014-11-101-55/+37
| | | | | | | | | | | | | | 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.
* 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: 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: 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.
* Move compat/ and bstr/ directory contents somewhere elsewm42014-08-291-2/+0
| | | | | | | | | 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: change playback restart and resyncingwm42014-07-281-3/+5
| | | | | | | | | | | | | | | | | | | | | 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: move initial decode to generic codewm42014-07-211-55/+14
| | | | | | | | | | | | 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: use symbolic constants instead of magic integerswm42014-07-201-1/+1
| | | | Similar to commit 26468743.
* ad_lavc: make option struct localwm42014-06-111-9/+23
| | | | Similar to previous commit.
* 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.
* audio: rename i_bps to 'bitrate' to avoid confusionMarcoen Hirschberg2014-05-281-3/+3
| | | | 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-281-3/+3
| | | | | | | 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.
* 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.
* Factor out setting AVCodecContext extradatawm42014-01-111-10/+4
|
* 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-211-14/+10
|
* 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-171-4/+4
|
* Move options/config related files from mpvcore/ to options/wm42013-12-171-1/+1
| | | | | | | | | 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-161-5/+5
| | | | | | | | | 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.
* 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-041-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* cosmetics: rename video/audio reset functionswm42013-11-271-1/+1
| | | | | | | | | | These used the suffix _resync_stream, which is a bit misleading. Nothing gets "resynchronized", they really just reset state. (Some audio decoders actually used to "resync" by reading packets for resuming playback, but that's not the case anymore.) Also move the function in dec_video.c to the top of the file.
* audio: better rejection of invalid formatswm42013-11-271-9/+7
| | | | | | | | | This includes the case when lavc decodes audio with more than 8 channels, which our audio chain currently does not support. the changes in ad_lavc.c are just simplifications. The code tried to avoid overriding global parameters if it found something invalid, but that is not needed anymore.
* ad_lavc: increase number of packets for initial decodewm42013-11-261-2/+5
| | | | | | | | | | | Apparently just 5 packets is not enough for the initial audio decode (which is needed to find the format). The old code (before the recent refactor) appeared to use 5 packets, but there were apparently other code paths which in the end amounted to more than 5 packets being read. The sample that failed (see github issue #368) needed 9 packets. Fixes #368.
* demux: remove gsh field from sh_audio/sh_video/sh_subwm42013-11-231-6/+7
| | | | | | | | | This used to be needed to access the generic stream header from the specific headers, which in turn was needed because the decoders had access only to the specific headers. This is not the case anymore, so this can finally be removed again. Also move the "format" field from the specific headers to sh_stream.
* audio: remove ad_driver.preinitwm42013-11-231-6/+0
| | | | | This never had any real use. Get rid of dec_audio.initialized too, as it's redundant.
* audio: don't write decoded audio format to sh_audiowm42013-11-231-6/+4
| | | | | | | | sh_audio is supposed to contain file headers, not whatever was decoded. Fix this, and write the decoded format to separate fields in the decoder context, the dec_audio.decoded field. (Note that this field is really only needed to communicate the audio format from decoder driver to the generic code, so no other code accesses it.)
* audio: move decoder context from sh_audio into new structwm42013-11-231-34/+34
| | | | | | | | | Move all state that basically changes during decoding or is needed in order to manage decoding itself into a new struct (dec_audio). sh_audio (defined in stheader.h) is supposed to be the audio stream header. This should reflect the file headers for the stream. Putting the decoder context there is strange design, to say the least.
* Merge branch 'planar_audio'wm42013-11-121-108/+53
|\ | | | | | | | | Conflicts: audio/out/ao_lavc.c
| * audio: add support for using non-interleaved audio from decoders directlywm42013-11-121-108/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | demux_mkv: support some raw PCM variantswm42013-11-111-23/+11
|/ | | | | | | | | | 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.
* Remove sh_audio->samplesizewm42013-11-091-1/+0
| | | | | | | | | 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.
* demux: rename Windows symbolswm42013-11-021-1/+1
| | | | | | | | | | | | | | | | | | | | There are some Microsoft Windows symbols which are traditionally used by the mplayer core, because it used to be convenient (avi was the big format, using binary windows decoders made sense...). So these symbols have the exact same definition as the Windows one, and if mplayer is compiled on Windows, the symbols from windows.h are used. This broke recently just because some files were shuffled around, and the symbols defined in ms_hdr.h collided with windows.h ones. Since we don't have windows binary decoders anymore, there's not the slightest reason our symbols should have the same names. Rename them to reduce the risk for collision, and to fix the recent regression. Drop WAVEFORMATEXTENSIBLE, because it's mostly unused. ao_dsound defines its own version if the windows headers don't define it, and ao_wasapi is not available on systems where this symbol is missing. Also reindent ms_hdr.h.
* audio: fix playback of Musepack SV8 fileswm42013-09-011-2/+4
| | | | | | | | | | | | | | This is basically a libavcodec API oddity: it can happen that avcodec_decode_audio4() returns 0 (meaning 0 bytes were consumed). It requires you to feed the complete packet again to decode the full packet, and to successfully decode the following packets. We ignored this case with the argument that there's the danger of an endless decode loop (because nothing of that packet is apparently decoded, so it would retry forever), but change it in order to decode mpc8 files correctly. Also add some comments to explain the mess.
* core: move contents to mpvcore (2/2)Stefano Pigozzi2013-08-061-5/+5
| | | | Followup commit. Fixes all the files references.
* audio/decode: remove macro crapwm42013-07-221-3/+14
| | | | | Declare decoders directly, instead of using the LIBAD_EXTERN macro. This is simpler (no weird magic) and more extensible.
* demux_mkv: never force output sample ratewm42013-07-161-12/+5
| | | | | | | | | | | | | | Matroska has an output sample rate (OutputSamplingFrequency), which in theory should be forced instead of whatever the decoder outputs. But it appears no software (other than mplayer2 and mpv until now) actually respects this. Even worse, there were broken files around, which played correctly with (in theory) broken software, but not mplayer2/mpv. Hacks were added to our code to play these files correctly, but they didn't catch all cases. Simplify this by doing what everyone else does, and always use the decoder's sample rate instead. In particular, we try to handle all sample rate issues like libavformat's Matroska demuxer does.
* ad_lavc: re-unsimplify, fix libavcodec API usagewm42013-07-111-2/+19
| | | | | | | | | | | | | | | | | | | | | | It turns out that some code that was removed earlier was still needed. avcodec_decode_audio4() can decode packets "partially". In that case, you have to "slice" the packet and call the decode function again. Codecs which need this are obscure and in low numbers. One sample that needs it is here: rsync://fate-suite.ffmpeg.org/fate-suite/lossless-audio/luckynight-partial.shn (This one decodes in rather small increments.) The new code is much simpler than what has been removed earlier, though. The fact that we own the packet returned by the demuxer helps a lot. Not sure what should happen if avcodec_decode_audio4() returns 0. Currently, we throw away the packet in this case. We don't want to be stuck in an endless loop (could happen if the decoder produces no output either).
* demux: remove facility for partial packet readswm42013-07-111-2/+5
| | | | | | | | | | | | | | | | | | Partial packet reads were needed because the video/audio parsers were working on top of them. So it could happen that a parser read a part of a packet, and returned that to the decoder. With libavformat/libavcodec, packets are already parsed, and everything is much simpler. Most of the simplifications in ad_spdif could have been done earlier. Remove some other stuff as well, like the questionable slave mode start time reporting (could be replaced by proper code, but we don't bother). Remove the unused skip_audio_frame() functionality as well (it was used by old demuxers). Some functions become private to demux.c, like demux_fill_buffer(). Introduce new packet read functions, which have simpler semantics. Packets returned from them are owned by the caller, and all packets in the demux.c packet queue are considered unread. Remove special code that dropped subtitle packets with size 0. This used to be needed because it caused special cases in the old code.
* ad_lavc: simplifywm42013-07-101-30/+5
| | | | | | | | | We don't need to deal with partial packet reads, manually using an audio parser, or having to call the libavcodec decoder multiple times per packet. Actually, I'm not sure about the last point. ffplay still does this, but the ffmpeg demuxing.c example doesn't.
* demux: remove audio parserwm42013-07-081-8/+3