summaryrefslogtreecommitdiffstats
path: root/audio/audio.c
Commit message (Collapse)AuthorAgeFilesLines
* audio: rewrite filtering glue codewm42018-01-301-625/+0
| | | | Use the new filtering code for audio too.
* Get rid of deprecated AVFrame accessorswm42017-10-301-3/+3
| | | | | | 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.
* audio: move libswresample wrapper out of audio filter codewm42017-09-211-0/+31
| | | | | | | | | 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.
* audio: fix uninitialized data accesswm42017-08-181-0/+1
| | | | | | 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.
* audio: introduce a new type to hold audio frameswm42017-08-161-0/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* audio: make mp_audio_realloc[_min] ensure frame is writeablewm42016-07-311-1/+10
| | | | | | | | 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.
* audio: use idiotic FFmpeg ABI rules for public-except-not-public fieldswm42016-07-241-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* af_lavcac3enc: use common code for AVFrame setupwm42016-07-241-5/+19
|
* audio: add a helper for getting frame end PTSwm42016-06-271-2/+10
| | | | Although I don't see any use for it yet, why not.
* audio: make mp_audio_skip_samples() adjust the PTSwm42016-02-221-1/+3
| | | | Slight simplification/cleanup.
* audio: move frame clipping to a generic functionwm42016-02-211-0/+33
|
* Fix build on Libavwm42016-01-301-0/+1
| | | | I hope.
* audio: move mp_audio->AVFrame conversion to a functionwm42016-01-291-0/+72
| | | | | | | | | This also makes it refcounted, i.e. the new AVFrame will reference the mp_audio buffers, instead of potentially forcing the consumer of the AVFrame to copy the data. All the extra code is for handling the >8 channels case, which requires very messy dealing with the extended_ fields (not our fault).
* mpv_talloc.h: rename from talloc.hDmitrij D. Czarkoff2016-01-111-1/+1
| | | | This change helps avoiding conflict with talloc.h from libtalloc.
* audio: use AVFrames with more than 8 channels correctlywm42015-10-261-5/+7
| | | | | | | Requires messy dealing with the extended_ fields. Don't bother with af_lavfi and ao_lavc for now. There are probably no valid use-cases for these.
* audio/filter: remove some useless filterswm42015-09-031-7/+0
| | | | | | | | | | | | | | | | | | | | | | | | All of these filters are considered not useful anymore by us. Some have replacements in libavfilter (useable through af_lavfi). af_center, af_extrastereo, af_karaoke, af_sinesuppress, af_sub, af_surround, af_sweep: pretty simple and useless filters which probably nobody ever wants. af_ladspa: has a replacement in libavfilter. af_hrtf: the algorithm doesn't work properly on most sources, and the implementation was buggy and complicated. (The filter was inherited from MPlayer; but even in mpv times we had to apply fixes that fixed major issues with added noise.) There is a ladspa filter if you still want to use it. af_export: I'm not even sure what this is supposed to do. Possibly it was meant for GUIs rendering audio visualizations, but it couldn't really work well. For example, the size of the audio depended on the samplerate (fixed number of samples only), and it couldn't retrieve the complete audio, only fragments. If this is really needed for GUIs, mpv should add native visualization, or a proper API for it.
* audio: fix format function consistency issueswm42015-06-261-3/+3
| | | | | | | | | | | Replace all the check macros with function calls. Give them all the same case and naming schema. Drop af_fmt2bits(). Only af_fmt2bps() survives as af_fmt_to_bytes(). Introduce af_fmt_is_pcm(), and use it in situations that used !AF_FORMAT_IS_SPECIAL. Nobody really knew what a "special" format was. It simply meant "not PCM".
* audio: output human-readable channel layouts toowm42015-06-251-2/+6
| | | | | This gets you the "logical" channel layout, instead of the exact thing we're sending to the AO. (Tired of the cryptic shit ALSA gives me.)
* audio: remove unused readonly fieldwm42015-06-151-2/+1
| | | | Its last use was removed in 433402b5.
* audio: deal with AVFrame-style buffer assignmentswm42015-06-121-3/+13
| | | | | | | | | | | | | | | | In the AVFrame-style system (which we inreasingly map our internal data stuctures on), buffers and plane pointers don't necessarily have a 1:1 correspondence. For example, a single buffer could cover 2 or more planes, all while other planes are covered by a second buffer, and so on. They don't need to be ordered in the same way. Change mp_audio_get_allocated_size() to retrieve the maximum size all planes provide. This also considers the case of planes not pointing to buffer start. Change mp_audio_realloc() to reset all planes, even if corresponding buffers are not reallocated. (The caller has to be careful anyway if it wants to be sure the contents are preserved on realloc calls.)
* audio: introduce mp_audio readonly bitwm42015-05-041-1/+2
| | | | Convenience for the following commit.
* audio: make all format query shortcuts macrosKevin Mitchell2015-04-031-2/+2
| | | | | af_fmt_is_float and af_fmt_is_planar were previously inconsistent with AF_FORAMT_IS_SPECIAL/AF_FORMAT_IS_IEC61937
* audio: fix pool allocationwm42015-02-111-1/+2
| | | | | It reallocated the pool on every request, making the pool completely useless. Oops.
* audio: add some utility functions for refcounted frameswm42015-01-131-10/+58
| | | | Used in the following commits.
* audio: make mp_audio_config_to_str return a stack-allocated stringwm42014-11-251-10/+5
| | | | Simpler overall.
* audio: make mp_chmap_to_str() return a stack-allocated stringwm42014-11-241-4/+3
| | | | Simplifies memory management.
* audio: make sure AVFrame is actually refcountedwm42014-11-111-0/+12
| | | | | | | | | | | The mp_audio_from_avframe() function requires the AVFrame to be refcounted, and merely increases its refcount while referencing the same data. For non-refcounted frames, it simply did nothing and potentially would make the caller pass around a frame with dangling pointers. (libavcodec should always return refcounted frames, but it's not clear what other code does; and also the function should simply work, instead of having weird requirements on its arguments.)
* audio: refuse to allocate frames in invalid formatwm42014-11-111-1/+1
|
* audio: add mp_audio_make_writeable()wm42014-11-101-0/+26
|
* audio: clear buffer array too with mp_audio_set_null_data()wm42014-11-101-1/+3
|
* audio: add function to convert AVFrame to mp_audio referenceswm42014-11-101-0/+48
| | | | | This is somewhat duplicated from ad_lavc.c and af_lavfi.c, but will eventually be used by both.
* audio: add mp_audio_poolwm42014-11-101-4/+62
| | | | | | A helper to allocate refcounted audio frames from a pool. This will replace the static buffer many audio filters use (af->data), because such static buffers are incompatible with refcounting.
* audio: use AVBufferRef to allocate audio frameswm42014-11-101-19/+9
| | | | | | | A first step towards refcounted audio frames. Amazingly, the API just does what we want, and the code becomes simpler. We will need to NIH allocation from a pool, though.
* 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: preallocate audio buffers on resizewm42014-04-181-2/+7
| | | | | | This avoids too many realloc() calls if the caller is appending to an audo buffer. This case is actually quite noticeable when using something that buffers a large amount of audio.
* audio: check for overflowswm42014-01-031-0/+5
|
* Split mpvcore/ into common/, misc/, bstr/wm42013-12-171-1/+1
|
* Merge mp_talloc.h into ta/ta_talloc.hwm42013-12-171-1/+1
|
* audio: better rejection of invalid formatswm42013-11-271-0/+6
| | | | | | | | | 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: fix audio data memory leakwm42013-11-141-1/+1
| | | | | Practically all audio decoding and filtering code leaked sample data memory after uninitialization due to a simple logic bug (or typo).
* mp_audio: use av_malloc (cargo cult for libav*)wm42013-11-121-3/+27
| | | | | | | | | | | | | | | 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.)
* audio/filter: prepare filter chain for non-interleaved audiowm42013-11-121-11/+137
| | | | | | | | | | | | | | | | | | 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.
* audio: replace af_fmt2str_short -> af_fmt_to_strwm42013-11-071-1/+1
| | | | Also, remove all af_fmt2str usages.
* core: move contents to mpvcore (2/2)Stefano Pigozzi2013-08-061-1/+1
| | | | Followup commit. Fixes all the files references.
* audio: add channel map selection functionwm42013-05-121-2/+1
| | | | | | | | | | | | | | | | | | | | The point is selecting a minimal fallback. The AOs will call this through the AO API, so it will be possible to add options affecting the general channel layout selection. It provides the following mechanism to AOs: - forcing the correct channel order - downmixing to stereo if no layout is available - allow 5.1 <-> 5.1(side) fallback - handling "unknown" channel layouts This is quite weak and lots of code/complexity for little gain. All AOs already made sure the channel order was correct, and the fallback is of little value, and could perhaps be done in the frontend instead, like stereo downmixing with --channels=2 is handled. But I'm not really sure how this stuff should _really_ work, and the new code will hopefully provides enough flexibility to make radical changes to channel layout negotiation easier.
* audio/filters: add af_forcewm42013-05-121-0/+6
| | | | | Its main purpose is for testing in case channel layout stuff breaks, in particular in connection with old audio filters.
* audio: print channel map additionally to channel count on terminalwm42013-05-121-0/+15
|
* af: use mp_chmap for mp_audio, include channel map in format negotiationwm42013-05-121-2/+20
| | | | | Now af_lavrresample pretends to reorder the channels, although it doesn't yet, and nothing sets non-standard layouts either.
* audio: add some setters for mp_audio, and require filters to use themwm42013-05-121-0/+38
mp_audio has some redundant fields. Setters like mp_audio_set_format() initialize these properly. Also move the mp_audio struct to a the file audio.c. We can remove a mysterious line of code from af.c: in.format |= af_bits2fmt(in.bps * 8); I'm not sure if this was ever actually needed, or if it was some kind of "make it work" quick-fix that works against the way things were supposed to work. All filters etc. now set the format correctly, so if there ever was a need for this code, it's definitely gone.