summaryrefslogtreecommitdiffstats
path: root/audio/decode/dec_audio.c
Commit message (Collapse)AuthorAgeFilesLines
* audio: make decoders output refcounted frameswm42014-11-101-119/+45
| | | | | | | | | | | | | | 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().
* audio: refactor some aspects of filter chain setupwm42014-10-021-49/+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: 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-291-1/+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.
* audio: change playback restart and resyncingwm42014-07-281-23/+24
| | | | | | | | | | | | | | | | | | | | | 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-241-0/+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-241-2/+2
| | | | | | | | | | 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-211-22/+31
| | | | | | | | | | | | 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.
* audio: remove unused metadata fieldwm42014-07-211-2/+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-201-5/+5
| | | | Similar to commit 26468743.
* 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".
* 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-041-0/+2
| | | | Closes #664
* af: add metadata field to af_stream and af_instanceAlessandro Ghedini2014-03-131-0/+2
| | | | | | This allows to propagate metadata information to audio filters. Closes #632
* codecs: mp_msg conversionwm42013-12-211-1/+1
|
* audio: mp_msg conversionswm42013-12-211-22/+18
|
* Split mpvcore/ into common/, misc/, bstr/wm42013-12-171-3/+3
|
* 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.
* 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.
* Move some code from player to audio/video reset functionswm42013-11-271-2/+6
|
* cosmetics: rename video/audio reset functionswm42013-11-271-3/+3
| | | | | | | | | | 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-11/+14
| | | | | | | | | 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.
* audio: remove ad_driver.preinitwm42013-11-231-18/+9
| | | | | 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-15/+8
| | | | | | | | 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-75/+86
| | | | | | | | | 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.
* audio: use the decoder buffer's format, not sh_audiowm42013-11-181-2/+2
| | | | | | | | | | | | | | | | | | When the decoder detects a format change, it overwrites the values stored in sh_audio (this affects the members sample_format, samplerate, channels). In the case when the old audio data still needs to be played/filtered, the audio format as identified by sh_audio and the format used for the decoder buffer can mismatch. In particular, they will mismatch in the very unlikely but possible case the audio chain is reinitialized while old data is draining during a format change. Or in other words, sh_audio might contain the new format, while the audio chain is still configured to use the old format. Currently, the audio code (player/audio.c and init_audio_filters) access sh_audio to get the current format. This is in theory incorrect for the reasons mentioned above. Use the decoder buffer's format instead, which should be correct at any point.
* audio: fix mid-stream audio reconfigurationwm42013-11-181-1/+5
| | | | | | | | | | | | | | | | | | | | | Commit 22b3f522 not only redid major aspects of audio decoding, but also attempted to fix audio format change handling. Before that commit, data that was already decoded but not yet filtered was thrown away on a format change. After that commit, data was supposed to finish playing before rebuilding filters and so on. It was still buggy, though: the decoder buffer was initialized to the new format too early, triggering an assertion failure. Move the reinit call below filtering to fix this. ad_mpg123.c needs to be adjusted so that it doesn't decode new data before the format change is actually executed. Add some more assertions to af_play() (audio filtering) to make sure input data and configured format don't mismatch. This will also catch filters which don't set the format on their output data correctly. Regression due to planar_audio branch.
* dec_audio: adjust "large" decoding amountwm42013-11-151-5/+5
| | | | | | | | | | 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/.
* ad_spdif: fix regressionswm42013-11-141-3/+4
| | | | | | | | | | 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.
* audio: add support for using non-interleaved audio from decoders directlywm42013-11-121-72/+77
| | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* dec_audio: fix behavior on format changeswm42013-11-121-3/+1
| | | | | Decoder overwrites parameters in sh_audio, but we still have old audio in the old format to filter.
* audio/filter: fix mul/delay scale and valueswm42013-11-121-4/+3
| | | | | | | | | | | | | 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.)
* audio: switch output to mp_audio_bufferwm42013-11-121-35/+19
| | | | | | 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.
* audio/filter: prepare filter chain for non-interleaved audiowm42013-11-121-6/+6
| | | | | | | | | | | | | | | | | | 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.
* Remove sh_audio->samplesizewm42013-11-091-2/+2
| | | | | | | | | 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.
* audio: replace af_fmt2str_short -> af_fmt_to_strwm42013-11-071-1/+1
| | | | Also, remove all af_fmt2str usages.
* configure: uniform the defines to #define HAVE_xxx (0|1)Stefano Pigozzi2013-11-031-1/+1
| | | | | | | | | | | | | | | | | | | | | The configure followed 5 different convetions of defines because the next guy always wanted to introduce a new better way to uniform it[1]. For an hypothetic feature 'hurr' you could have had: * #define HAVE_HURR 1 / #undef HAVE_DURR * #define HAVE_HURR / #undef HAVE_DURR * #define CONFIG_HURR 1 / #undef CONFIG_DURR * #define HAVE_HURR 1 / #define HAVE_DURR 0 * #define CONFIG_HURR 1 / #define CONFIG_DURR 0 All is now uniform and uses: * #define HAVE_HURR 1 * #define HAVE_DURR 0 We like definining to 0 as opposed to `undef` bcause it can help spot typos and is very helpful when doing big reorganizations in the code. [1]: http://xkcd.com/927/ related
* core: move contents to mpvcore (2/2)Stefano Pigozzi2013-08-061-3/+3
| | | | Followup commit. Fixes all the files references.
* audio/filter: use new option APIwm42013-07-221-12/+5
| | | | | | | | | | | | | Make the VF/VO/AO option parser available to audio filters. No audio filter uses this yet, but it's still a quite intrusive change. In particular, the commands for manipulating filters at runtime completely change. We delete the old code, and use the same infrastructure as for video filters. (This forces complete reinitialization of the filter chain, which hopefully isn't a problem for any use cases. The old code forced reinitialization too, but it could potentially allow a filter to cache things; e.g. consider loaded ladspa plugins and such.)
* audio/decode: remove macro crapwm42013-07-221-5/+18
| | | | | Declare decoders directly, instead of using the LIBAD_EXTERN macro. This is simpler (no weird magic) and more extensible.
* mplayer: fix incorrect audio sync after format changeswm42013-07-111-8/+2
| | | | | | | | | | | This is not directly related to the handling of format changes itself, but playing audio normally after the change. This was broken: the output byte rate was not recalculated, so audio-video sync was simply broken. Fix this by calculating the byte rate on the fly, instead of storing it in sh_audio. Format changes are relatively common (switches between stereo and 5.1 in TV recordings), so this fixes a somewhat critical bug.
* demux: remove facility for partial packet readswm42013-07-111-11/+0
| | | | | | | | | | | | | | | | | | 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.
* audio: remove decoder input bufferwm42013-07-101-11/+0
| | | | This was unused.
* Remove old demuxerswm42013-07-071-0/+2
| | | | | | | | | | Delete demux_avi, demux_asf, demux_mpg, demux_ts. libavformat does better than them (except in rare corner cases), and the demuxers have a bad influence on the rest of the code. Often they don't output proper packets, and require additional audio and video parsing. Most work only in --no-correct-pts mode. Remove them to facilitate further cleanups.
* options: remove --stereowm42013-06-131-2/+0
| | | | | | | Whatever this was supposed to be originally, it doesn't have much value anymore. It just forced ad_mpg123 to upmix mono to stereo by default (the audio chain can do that). As an option, it was mostly useless and misleading, so get rid of it.
* audio: print channel map additionally to channel count on terminalwm42013-05-121-4/+5