summaryrefslogtreecommitdiffstats
path: root/player/audio.c
Commit message (Collapse)AuthorAgeFilesLines
* audio/video: expose codec info as separate fieldwm42016-02-151-0/+1
| | | | | Preparation for the timeline rewrite. The codec will be able to change, the stream header not.
* player: remove dead codewm42016-02-121-1/+1
| | | | Fixes CID 1350055 and CID 1350054.
* player: remove double assignment in declarationwm42016-02-121-1/+1
| | | | | | Fixes CID 1350058. (Still looks like this might be valid C, in some fucked up way.)
* player: force refresh seek when changing audio filterswm42016-02-091-1/+16
| | | | | | | | | | | | | Unfortunately I see no better solution. The refresh seek is skipped if the amount of buffered audio is not overly huge. Unfortunately softvol af_volume insertion still can cause this issue, because it's outside of the normal dynamic filter chain changing code. Move the video refresh call to reinit_video_filters() to make it more uniform along with the audio code.
* audio: fix EOF handling if nothing could be decoded at allwm42016-02-061-0/+4
| | | | The code for decoding the initial frame has to handle this explicitly.
* player: remove some further current_track dependencieswm42016-02-051-6/+4
| | | | Now it's used for initialization only for audio and video.
* player: add complex filter graph supportwm42016-02-051-22/+54
| | | | | | | | | | | | | | | | See --lavfi-complex option. This is still quite rough. There's no support for dynamic configuration of any kind. There are probably corner cases where playback might freeze or burn 100% CPU (due to dataflow problems when interaction with libavfilter). Future possible plans might include: - freely switch tracks by providing some sort of default track graph label - automatically enabling audio visualization - automatically mix audio or stack video when multiple tracks are selected at once (similar to how multiple sub tracks can be selected)
* player: move audio and video decoder init to separate functionswm42016-02-051-11/+31
| | | | Preparation.
* player: use different variable to indicate coverartwm42016-02-011-3/+3
| | | | Slightly better.
* audio/video: merge decoder return valueswm42016-02-011-5/+5
| | | | | | Will be helpful for the coming filter support. I planned on merging audio/video decoding, but this will have to wait a bit longer, so only remove the duplicate status codes.
* audio: use brutal resync only on larger PTS discontinuitieswm42016-01-311-2/+4
| | | | | | | | | Let's fix broken samples with questionable heuristic without real reasoning. Until this gets fixed properly, this is a good compromise, though. A proper fix would properly resync audio and video without brutally resetting the decoders, but on the other hand not doing the brutal reset would cause issues in other obscure corner cases such resyncing might cause.
* audio: fix a case of going to sleep before playback startwm42016-01-311-0/+1
| | | | | | | | | | | | | | | This code is tricky because it has to wakeup the mainloop to make progressing during syncing audio, but also has to avoid waking it up when it's not needed. Failure to do so either burns CPU by not ever going to sleep, or causes apparent "freezes" by going to sleep (and it will continue if the mainloop is woken up e.g. due to user input). In this case, simply starting A/V playback with --start=5 and removing an unrelated wakeup in osd.c can trigger such a "freeze". The unrelated wakeup did hide this bug, nonetheless it's a bug. (Can't wait to rewrite this shitty audio resync code. And it's all my fault.)
* player: refactor: some more minor decoder/output decouplingwm42016-01-291-7/+8
| | | | | | These changes don't make too much sense without context, but are preparation for later. Then the audio_src/video_src fields will be actually be NULL under circumstances.
* audio: refactor: separate audio init and filter/output initwm42016-01-291-47/+62
| | | | | | | | | | | | Before this commit, reinit_audio_chain() did 2 things: create all the management data structures and initialize the decoder, and handling lazy filter/output init (as well as dealing with format changes). For the second purpose, it could be called multiple times (even though it wasn't really idempotent). This was pretty weird, so make them separate functions. The new function is actually idempotent too. It also turns out the reinit functions don't have to call themselves recursively for the spdif PCM fallback.
* audio: move pts reset checkwm42016-01-291-2/+15
| | | | Reduces the dependency of the filter/output code on the decoder.
* player: fix initial audio sync in certain caseswm42016-01-291-2/+2
| | | | | | | | | | | | | | | | | Regression caused by commit 3b95dd47. Also see commit 4c25b000. We can either use video_next_pts and add "delay", or we just use video_pts. Any other combination breaks. The reason why the assumption that delay==0 at this point was wrong exactly because after displaying the first video frame (usually done before audio resync) a new frame might be "added" immediately, resulting in a new video_next_pts and "delay", which will still amount to video_pts. Fixes #2770. (The reason why display-sync was blamed in this issue is because enabling display-sync in the options forces a prefetch by 2 instead of 1 frames for seeks/playback restart, which triggers the issue, even if display-sync is not actually enabled. In this case, display-sync is never enabled because the frames have a unusually high frame duration. This is also what exposed the initial desync issue.)
* audio: fix spdif PCM fallbackwm42016-01-251-0/+2
| | | | | | | | | With the format left untouched, this would just try to reinit with a spdif format again. We're not clearing the format in reset_audio_state() so the audio chain can be recreated any time without having to wait for a frame to be decoded.
* audio: release pending audio frame on seekingwm42016-01-251-0/+2
|
* player: free queued audio frame on uninitwm42016-01-231-0/+1
|
* audio: refactor: move MPContext.ao_buffer fieldwm42016-01-221-24/+21
| | | | | | | | | | | | It doesn't need to be part of the big context, but is strictly part of shuffling data from the audio filters to audio output, and thus belongs into ao_chain. It also turns out that clearing it in clear_audio_output_buffers() is completely redundant. (Of course ao_buffer is an abomination in the first place and shouldn't exist at all.)
* player: refactor: eliminate MPContext.d_audiowm42016-01-221-23/+42
|
* audio: refactor: work towards unentangling audio decoding and filteringwm42016-01-221-47/+148
| | | | | | | | | Similar to the video path. dec_audio.c now handles decoding only. It also looks very similar to dec_video.c, and actually contains some of the rewritten code from it. (A further goal might be unifying the decoders, I guess.) High potential for regressions.
* audio: remove initial decoding retry limitationwm42016-01-191-8/+0
| | | | | | | | | | | | | | | Seems useless. This only helped in one case: one audio stream in the sample av_find_best_stream_fails.ts had a AC3 packets which couldn't be decoded, and for which avcodec_decode_audio4() returned 0 forever. In this specific case, playback will now not start, and you have to deselect audio manually. (If someone complains, the old behavior might be restored, but differently.) Also remove the stale "bitrate" field.
* audio: move dec_audio.pool to ad_spdifwm42016-01-191-1/+0
| | | | That's where its only use is.
* player: refactor: eliminate MPContext.d_videowm42016-01-171-2/+2
| | | | | | | | | | | | | | Eventually we want the VO be driven by a A->V filter, so a decoder doesn't even have to exist. Some features definitely require a decoder though (like reporting the decoder in use, hardware decoding, etc.), so for each thing which accessed d_video, it has to be redecided if and how it can access decoder state. At least the "framedrop" property slightly changes semantics: you can now always set this property, even if no video is active. Some untested changes in this commit, but our bio-based distributed test suite has to take care of this.
* demux: merge sh_video/sh_audio/sh_subwm42016-01-121-1/+1
| | | | | | | | | | This is mainly a refactor. I'm hoping it will make some things easier in the future due to cleanly separating codec metadata and stream metadata. Also, declare that the "codec" field can not be NULL anymore. demux.c will set it to "" if it's NULL when added. This gets rid of a corner case everything had to handle, but which rarely happened.
* mpv_talloc.h: rename from talloc.hDmitrij D. Czarkoff2016-01-111-1/+1
| | | | This change helps avoiding conflict with talloc.h from libtalloc.
* player: detect audio PTS jumps, make video PTS heuristic less aggressivewm42016-01-091-1/+9
| | | | | | | | | | | | | | | | | | | | | | This is another attempt at making files with sparse video frames work better. The problem is that you generally can't know whether a jump in video timestamps is just a (very) long video frame, or a timestamp reset. Due to the existence of files with sparse video frames (new frame only every few seconds or longer), every heuristic will be arbitrary (in general, at least). But we can use the fact that if video is continuous, audio should also be continuous. Audio discontinuities can be easily detected, and if that happens, reset some of the playback state. The way the playback state is reset is rather radical (resets decoders as well), but it's just better not to cause too much obscure stuff to happen here. If the A/V sync code were to be rewritten, it should probably strictly use PTS values (not this strange time_frame/delay stuff), which would make it much easier to detect such situations and to react to them.
* audio: update outdated commentwm42016-01-051-3/+4
|
* player: use demuxer ts offset to simplify timeline ts handlingwm42015-11-161-2/+1
| | | | | | | | | Use the demux_set_ts_offset() added in the previous commit to base each timeline segment to use timestamps according to its relative position within the overall timeline. As a consequence we don't need to care about these timestamps anymore, and everything becomes simpler. (Another minor but delicious nugget of sanity.)
* player: silence sporadic error messages on audio initwm42015-11-101-1/+1
| | | | | | | | | | | | When the audio format is not known yet and the audio chain is still initializing, filter reinit will fail. Normally, attempts to reinitialize filters at this stage should be rare (e.g. user commands editing the filter chain). But it sometimes happened with track switching in combination with the video code calling update_playback_speed() at arbitrary times. Get rid of the message by not trying to change the filters for the sake of playback speed update while decoding is still being initialized.
* audio: do not require full audio chain reinit for speed changeswm42015-11-041-57/+66
| | | | | | | | | | | | | | | Actually, it didn't really require that before (most work was avoided), but some bits had to be run anyway. Separate the speed change into a light-weight function, which merely updates already created filters, and a heavy-weight one which messes with filter insertion. This also happens to fix the case where the filters would "forget" the current speed (force resampling, change speed, hit a volume control to force af_volume insertion - it will reset speed and desync). Since we now always run the light-weight function, remove the af_scaletempo verbose message that is printed on speed setting. Other than that, all setters are cheap.
* audio: strictly align audio on spdif frameswm42015-11-041-3/+7
| | | | | | We still have a sample-based buffer between filters and audio outputs. In order to avoid cutting frames into half (which can upset receivers), we strictly need to align the boundaries on which we cut the audio.
* player: fix display-sync adrop speed limitingwm42015-11-041-1/+2
| | | | Commit 49d94853 worked only at the start of playback.
* player: limit speed change in display-sync adrop modewm42015-11-031-0/+8
| | | | | | | | | | Discontinuities (like toggling fullscreen) can cause multiple frames to be dropped in succession, which sounds very weird. It's better to drop some video frames instead to compensate for larger desyncs. We roughly base it on the maximum allowed speed changes (audio change is "additional" to the video change to account for deviations when playing at max. video speed change).
* player: reset AO stats on pause and other discontinuitieswm42015-10-281-1/+3
| | | | It's annoying.
* player: simplify display-adrop mode safeguardwm42015-10-281-8/+1
| | | | | | It's not needed, because the additional data is not appended, but is the total size of the audio buffer. The maximum size is the static audio drop size (or twice, if the audio is duplicated).
* player: add audio drop/duplicate modewm42015-10-271-0/+36
| | | | Not very robust in the moment.
* player: simplify audio sync pts calculationwm42015-10-271-1/+1
| | | | | This was done for symmetry with adjust_sync(). But mpctx->delay is always 0 at this point, so prefer slightly simpler code.
* audio: add AO deviation loggingwm42015-10-081-0/+24
| | | | | Pretty dumb (and doesn't handle pausing or other discontinuities), but at least somewhat idiot-proof.
* audio: make spdif re-probe from normal decoding workwm42015-10-061-1/+10
| | | | | | | | The previous commit handled not falling back to normal decoding if the AO was reloaded (I think...), and this tries to re-engage spdif pass- through if it was previously falling back to normal decoding (e.g. because it temporarily switched to an audio device incapable of passthrough).
* audio: re-probe spdif if AO is reloadedwm42015-10-061-1/+3
| | | | Makes the spdif automagic work better on audio hotplugging.
* audio: add option for falling back to ao_nullwm42015-10-051-4/+6
| | | | | | | | | The manpage entry explains this. (Maybe this option could be always enabled and removed. I don't quite remember what valid use-cases there are for just disabling audio entirely, other than that this is also needed for audio decoder init failure.)
* audio: don't sleep when finishing audio resyncwm42015-08-231-1/+1
| | | | | | | This should avoid unnecessary sleeping when audio playback start resync has finished and goes into the normal playback state. This is tricky; see e.g. commit 402fe381.
* player: separate controls for user and video controlled speedwm42015-08-101-11/+27
| | | | | | | | | | For video sync, we want separate playback speed controls for user- requested speed and the "correction" speed for video timing. Further, we use this separation to make sure only a resampler is inserted if playback speed is only changed for video sync correction. As of this commit, this is basically inactive code. It's just preparation for the video sync code (the following commit).
* audio: fix --end handling (again)wm42015-08-031-5/+2
| | | | | | | | | | Commit c5818046 fixed one case of audio EOF handling, and caused a new one. This time, the ao_buffer doesn't actually contain everyting that should be played - because if --end is used, only a part of it is played. Of course this is stupid, and it will be changed later. For now, this smaller change fixes the bug. Fixes #2189.
* audio: remove questionable speed change adjustmentwm42015-08-011-3/+0
| | | | | | | | | time_frame is when the next video frame should be shown. It's normally overwritten by the video timing code. This also says something about "nosound mode" (--no-audio today), but at least these days we don't use it at all if video is disabled. Remove it; it likely has no function at all.
* audio: remove an unused parameterwm42015-07-241-3/+2
|
* audio: fix EOF state with --keep-openwm42015-07-241-1/+1
| | | | | | | | | | In paused mode, we never entered the audio EOF state. This shows e.g. in --keep-open mode, which will not set the eof-reached property correctly. Regression since commit c06cd1b9. This commit was the wrong fix. We need to respect the buffer state, and pausing has nothing to do with this. Fixes #2167.
* 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: add some change notificationswm42015-06-091-0/+4
| | | | | We must be sure that every change comes with a notification. Otherwise, some property changes could possibly be missed.
* audio: add --audio-spdif as new method for enabling passthroughwm42015-06-051-1/+14
| | | | | | | | | | | | | This provides a new method for enabling spdif passthrough. The old method via --ad (--ad=spdif:ac3 etc.) is deprecated. The deprecated method will probably stop working at some point. This also supports PCM fallback. One caveat is that it will lose at least 1 audio packet in doing so. (I don't care enough to prevent this.) (This is named after the old S/PDIF connector, because it uses the same underlying technology as far as the higher level protoco is concerned. Also, the user should be renamed that passthrough is backwards.)
* audio: do not allow AO to change passthrough formatswm42015-06-051-7/+17
| | | | | | | This makes no sense, because the format can't be converted anyway. It just sets up the filter chain init code, which will vomit a bunch of useless and confusing messages. So uninit and fail explicitly when this happens.
* audio: do not exit when loading small files in paused modewm42015-06-041-1/+1
| | | | | | | | When starting in paused mode, no audio is written to the device at all, because writing audio implicitly unpauses the AO. If the file is very small, and all audio fits within the AO buffer, this accidentally triggered the EOF condition. (In unpaused mode, it would write all audio, end playback, and then wait until the AO has everything played.)
* audio: remove an old hackwm42015-05-301-10/+1
| | | | | | | This was a cosmetic issue. It's handled differently now (clamping the display time to known duration range). This reverts commit 33b57f55573e658b3af6c6e8ff3188c8f959e82e.
* audio: fix resync issue differentwm42015-05-191-1/+3
| | | | | | | | | | | Commit 10915000 attempted to fix wasting CPU when resyncing and no new data was actually coming from the demuxer. The fix assumed that at this point it would have reached the sync point, but since the code attempts weird incremental decoding, this wasn't actually true. So it broke seeking in addition to removing the CPU waste. Try something else. This time, we essentially only wakeup again if data was read (i.e. audio_decode() returned successfully).
* audio: avoid wasting CPU due to continuous wakeupwm42015-05-191-1/+2
| | | | | | | | | Thsi code path happens during seeking. If video is still being decoded to get to the first video frame, audio has nothing to do, as it is synchronized against the first video frame. We only want to wake up if there's an actual state change. Fixes #1958.
* Update license headersMarcin Kurczewski2015-04-131-5/+4
| | | | Signed-off-by: wm4 <wm4@nowhere>
* audio: change a detail about filter insertionwm42015-04-071-18/+1
| | | | | | | | | | The af_add() function has a problem: if the inserted filter returns AF_DETACH during init, the function will have a dangling pointer. Until now this was avoided by making sure none of the used filters actually return AF_DETACH, but it's getting infeasible. Solve this by requiring passing an unique label to af_add(), which is then used instead of the pointer.
* audio: avoid one more redundant audio filter reinitwm42015-04-071-2/+2
| | | | | | Only reinit filters if it's actually needed. This is also slightly easier to understand: if you look at the code, it should now be more obvious why a reinit is needed (hopefully).
* audio: increase maximum amount of audio skipped for seekingwm42015-03-241-1/+1
| | | | | | | | | | | Precise seeking requires skipping audio, since the demuxer usually doesn't seek precisely enough. There is a sanity check that prevents skipping more than 300 seconds of audio. This still fails with very large mp3s. For example, with a 1GB sized mp3 with Xing headers, entries will be 4 MB apart on aver