summaryrefslogtreecommitdiffstats
path: root/video/decode/dec_video.h
Commit message (Collapse)AuthorAgeFilesLines
* video: make decoder wrapper a filterwm42018-01-301-101/+0
| | | | | | | | | | | | | | | | | | | | | | | | | Move dec_video.c to filters/f_decoder_wrapper.c. It essentially becomes a source filter. vd.h mostly disappears, because mp_filter takes care of the dataflow, but its remains are in struct mp_decoder_fns. One goal is to simplify dataflow by letting the filter framework handle it (or more accurately, using its conventions). One result is that the decode calls disappear from video.c, because we simply connect the decoder wrapper and the filter chain with mp_pin_connect(). Another goal is to eventually remove the code duplication between the audio and video paths for this. This commit prepares for this by trying to make f_decoder_wrapper.c extensible, so it can be used for audio as well later. Decoder framedropping changes a bit. It doesn't seem to be worse than before, and it's an obscure feature, so I'm content with its new state. Some special code that was apparently meant to avoid dropping too many frames in a row is removed, though. I'm not sure how the source code tree should be organized. For one, video/decode/vd_lavc.c is the only file in its directory, which is a bit annoying.
* video, audio: always read all frames before getting next packetwm42018-01-011-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The old code tried to make sure at all times to try to read a new packet. Only once that was read, it tried to retrieve new video or audio frames the decoder might already have decoded. Change this to strictly read frames from the decoder until it signals that it wants a new packet, and only then read and feed a new packet. This is in theory nicer, follows the libavcodec recommended data flow, and and reduces the minimum latency by 1 frame. This merely requires switching the order in which those calls are done. Normally, the decoder will return only 1 frame until a new packet is required. If we would just feed it 1 packet, return DATA_AGAIN, and wait until the next frame is decoded, we would run the playloop 1 time too often for no reason (which is fine but might have some overhead). To avoid this, try to read a frame again after possibly feeding a packet. For this reason, move the feed/read code to its own functions each, instead of merely moving the code. The audio and video code for this particular thing is basically duplicated. The idea is to unify them one day, so make the change to both. (Doing this for video is the real motivation for this change, see below.) The video code change is slightly more complicated, because we have to care about the framedrop counting (which is just a heuristic, but for now considered better than nothing, and possibly considered required to warn the user of framedrops happening - maybe). Apparently this change helps with stalling streams on Android with the mediacodec wrapper and mpeg2 decoder implementations which deinterlace on decoding (and return 2 frames per packet). Based on an idea and observations by tmm1.
* build: add preliminary LGPL modewm42017-09-211-9/+7
| | | | | | | See "Copyright" file for caveats. This changes the remaining "almost LGPL" files to LGPL, because we think that the conditions the author set for these was finally fulfilled.
* vo_opengl: add direct rendering supportwm42017-07-241-0/+1
| | | | | | | | | | | | | | | | | | | | Can be enabled via --vd-lavc-dr=yes. See manpage additions for what it does. This reminds of the MPlayer -dr flag, but the implementation is completely different. It's the same basic concept: letting the decoder render into a GPU buffer to avoid a copy. Unlike MPlayer, this doesn't try to go through filters (libavfilter doesn't support this anyway). Unless a filter can work in-place, DR will be silently disabled. MPlayer had very complex semantics about buffer types and management (which apparently nobody ever understood) and weird restrictions that mostly limited it to mpeg2 style codecs. The mpv code does not do any of this, and just lets the decoder allocate an arbitrary number of untyped images. (No MPlayer code was used.) Parts of the code based on work by atomnuker (starting point for the generic code) and haasn (some GL definitions, some basic PBO code, and correct fencing).
* options: drop --video-aspect-method=hybridwm42017-07-211-1/+0
| | | | | | | | | Remove this code because it could be argued that it contains GPL-only code (see commit 642e963c860 for details). The remaining aspect methods appear to work just as well, are potentially more compatible to other players, and the code becomes much simpler.
* dec_video: change license to LGPL (almost)wm42017-06-181-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | "Almost" because this might contain copyright by michael, who agreed with LGPL, but only once the core is LGPL. This is preparation for that to happen. Apart from that, the usual remarks apply. In particular, dec_video.c started out quite chaotic with no modularization, but was later basically gutted, and in general rewritten a bunch of times. Not going to give a history lesson. Special attention needs to be given to 3 patches by cehosos, who did not agree to the relicensing: 240b743ebdf: --field-dominance e32cbbf7dc3: reinit VO if aspect ratio changes 306f6243fdf: use container aspect if codec aspect unset (?) The first patch is pretty clearly still in the current code, and needs to be disabled for LGPL. The functionality of the second patch is still active, but implemented completely different, and as part of general frame parameter changes (at the time of the patch, MPlayer already reinitialized the VO on frame size and pixel format changes - all this was merged into a single check for changing image parameters). The third patch makes me a bit more uncomfortable. It appears the code was moved to dec_video.c in de68b8f23c8c, and further changed in 82f0d373, 0a0bb905, and bf13bd0d. You could claim that cehoyos' copyright still sticks. Fortunately, we implement alternative aspect detection, which is simpler and probably preferable, and which arguably contains none of the original code and logic, and thus should be fully safe. While I don't know if cehoyos' copyright actually still applies, I'm more comfortable with making the code GPL-only for now. Also change the default to use the (in future) plain LGPL code, and deprecate the one associated with the GPL code, so we can eventually remove the GPL code. But it's also possible we decide that the copyright doesn't apply, and undo the deprecation and GPL guards. I expect that users won't notice anything. If you ask me, the old aspect method was probably an accidental bug instead of intentional behavior. Although, the new aspect method was broken too, so I had to fix it.
* player: add experimental stream recording featurewm42017-02-071-0/+2
| | | | | This is basically a WIP, but it can't remain in a branch forever. A warning is print when using it as it's still a bit "shaky".
* player: change aspects of cover art handlingwm42017-01-101-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | Cover art handling is a disgusting hack that causes a mess in all components. And this will stay this way. This is the Xth time I've changed cover art handling, and that will probably also continue. But change the code such that cover art is injected into the demux packet stream, instead of having an explicit special case it in the decoder glue code. (This is somewhat more similar to the cover art hack in libavformat.) To avoid that the over art picture is decoded again on each seek, we need some additional "caching" in player/video.c. Decoding it after each seek would work as well, but since cover art pictures can be pretty huge, it's probably ok to invest some lines of code into caching it. One weird thing is that the cover art packet will remain queued after seeks, but that is probably not an issue. In exchange, we can drop the dec_video.c code, which is pretty convenient for one of the following commits. This code duplicates a bunch of lower-level decode calls and does icky messing with this weird state stuff, so I'm glad it goes away.
* dec_video: don't spam missing PTS warningswm42016-11-091-0/+2
| | | | | Only print at most 2. Just because with some decoders, we will always hit this code path, such as playing avi of vfw-muxed mkv on RPI.
* command: add a video-dec-params propertywm42016-09-201-1/+2
| | | | | | This is the actual decoder output, with no overrides applied. (Maybe video-params shouldn't contain the overrides in the first place, but damage done.)
* command: change update handling of some video-related propertieswm42016-09-201-1/+1
| | | | | | | | Use the new mechanism, instead of wrapped properties. As usual, extend the update handling to some options that were forgotten/neglected before. Rename video_reset_aspect() to video_reset_params() to make it more "general" (and we can amazingly include write access to video-aspect as well in this).
* video: refactor how VO exports hwdec device handleswm42016-05-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | The main change is with video/hwdec.h. mp_hwdec_info is made opaque (and renamed to mp_hwdec_devices). Its accessors are mainly thread-safe (or documented where not), which makes the whole thing saner and cleaner. In particular, thread-safety rules become less subtle and more obvious. The new internal API makes it easier to support multiple OpenGL interop backends. (Although this is not done yet, and it's not clear whether it ever will.) This also removes all the API-specific fields from mp_hwdec_ctx and replaces them with a "ctx" field. For d3d in particular, we drop the mp_d3d_ctx struct completely, and pass the interfaces directly. Remove the emulation checks from vaapi.c and vdpau.c; they are pointless, and the checks that matter are done on the VO layer. The d3d hardware decoders might slightly change behavior: dxva2-copy will not use the VO device anymore if the VO supports proper interop. This pretty much assumes that any in such cases the VO will not use any form of exclusive mode, which makes using the VO device in copy mode unnecessary. This is a big refactor. Some things may be untested and could be broken.
* Rewrite ordered chapters and timeline stuffwm42016-02-151-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This uses a different method to piece segments together. The old approach basically changes to a new file (with a new start offset) any time a segment ends. This meant waiting for audio/video end on segment end, and then changing to the new segment all at once. It had a very weird impact on the playback core, and some things (like truly gapless segment transitions, or frame backstepping) just didn't work. The new approach adds the demux_timeline pseudo-demuxer, which presents an uniform packet stream from the many segments. This is pretty similar to how ordered chapters are implemented everywhere else. It also reminds of the FFmpeg concat pseudo-demuxer. The "pure" version of this approach doesn't work though. Segments can actually have different codec configurations (different extradata), and subtitles are most likely broken too. (Subtitles have multiple corner cases which break the pure stream-concatenation approach completely.) To counter this, we do two things: - Reinit the decoder with each segment. We go as far as allowing concatenating files with completely different codecs for the sake of EDL (which also uses the timeline infrastructure). A "lighter" approach would try to make use of decoder mechanism to update e.g. the extradata, but that seems fragile. - Clip decoded data to segment boundaries. This is equivalent to normal playback core mechanisms like hr-seek, but now the playback core doesn't need to care about these things. These two mechanisms are equivalent to what happened in the old implementation, except they don't happen in the playback core anymore. In other words, the playback core is completely relieved from timeline implementation details. (Which honestly is exactly what I'm trying to do here. I don't think ordered chapter behavior deserves improvement, even if it's bad - but I want to get it out from the playback core.) There is code duplication between audio and video decoder common code. This is awful and could be shareable - but this will happen later. Note that the audio path has some code to clip audio frames for the purpose of codec preroll/gapless handling, but it's not shared as sharing it would cause more pain than it would help.
* 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.
* video: remove pointless parameter indirectionwm42016-02-151-1/+1
| | | | This is always the same value.
* video: approximate AVI timestamps via DTS handlingwm42016-02-111-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Until now (and in mplayer traditionally), avi timestamps were handled with a timestamp FIFO. AVI timestamps are essentially just strictly increasing frame numbers and are not reordered like normal timestamps. Limiting the FIFO is required because frames can be dropped. To make it worse, frame dropping can't be distinguished from the decoder not returning output due to increasing the buffering required for B-frames. ("Measuring" the buffering at playback start seems like an interesting idea, but won't work as the buffering could be increased mid-playback.) Another problem are skipped frames (packets with data, but which do not contain a video frame). Besides dropped and skipped frames, there is the problem that we can't always know the delay. External decoders like MMAL are not going to tell us. (And later perhaps others, like direct VideoToolbox usage.) In general, this works not-well enough that I prefer the solution of passing through AVI timestamps as DTS. This is slightly incorrect, because most decoders treat DTS as mpeg-style timestamps, which already include a b-frame delay, and thus will be shifted by a few frames. This means there will be a problem with A/V sync in some situations. Note that the FFmpeg AVI demuxer shifts timestamps by an additional amount (which increases after the first seek!?!?), which makes the situation worse. It works well with VfW-muxed Matroska files, though. On RPI, the first X timestamps are broken until the MMAL decoder "locks on".
* audio/video: merge decoder return valueswm42016-02-011-6/+1
| | | | | | 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.
* video: cleanup pts/dts passing between decoder componentswm42016-01-251-2/+2
| | | | | Instead of using semi-public codec_pts/codec_dts fields in struct dec_video, pass them via mp_image fields.
* player: fix some oversights in video refactoringwm42016-01-221-5/+0
| | | | | | | | | | vo_chain_uninit() isn't supposed to care much about the decoder (although decoders and outputs still go strictly together, so there is not much of an actual difference now). Also unset track.d_video correctly. Remove a stale declaration from dec_video.h as well.
* video: refactor: disentangle decoding/filtering some morewm42016-01-161-9/+23
| | | | | | | | | | | This moves some code related to decoding from video.c to dec_video.c, and also removes some accesses to dec_video.c from the filtering code. dec_video.ch is starting to make sense, and simply returns video frames from a demuxer stream. The API exposed is also somewhat intended to be easily changeable to move decoding to a separate thread, if we ever want this (due to libavcodec already being threaded, I don't see much of a reason, but it might still be helpful).
* video: fix interactively changing aspect ratiowm42016-01-141-0/+1
| | | | | | | | | The aspect ratio calculations are cached (mainly so that aspect ratio related messages are not logged on every frame). The cache is not clared anymore when video filters are reconfigured, but changing the video-aspect-ratio property relied on it. Make it explicit. Fixes #2714.
* video: decouple filtering/decoding slightly morewm42016-01-141-2/+0
| | | | | | | | | | | | | | | | | | | Lots of noise to remove the vfilter/vo fields from dec_video. From now on, video filtering and output will still be done together, summarized under struct vo_chain. There is the question where exactly the vf_chain should go in such a decoupled architecture. The end goal is being able to place a "complex" filter between video decoders and output (which will culminate in natural integration of A->V filters for natural integration of libavfilter audio visualizations). The vf_chain is still useful for "final" processing, such as format conversions and deinterlacing. Also, there's only 1 VO and 1 --vf option. So having 1 vf_chain for a VO seems ideal, since otherwise there would be no natural way to handle all these existing options and mechanisms. There is still some work required to truly decouple decoding.
* video: refactor: shuffle code aroundwm42016-01-141-5/+1
| | | | | | struct dec_video should have nothing to do with video filters or outputs, and this huge chunk of code was somehow stuck directly in dec_video.c.
* video: refactor: handle video format fixups closer to decoderwm42016-01-141-3/+2
| | | | | | | | | | Instead of handling this on filter chain reinit, do it directly after the decoder. This makes the code less entangled. In particular, this gets rid of the really weird "override params" concept in the video filter code. The last_format/fixed_formats have some redundance with decoder_output, but unfortunately the latter has a slightly different use.
* video: increase avi pts buffer sizewm42015-11-061-1/+1
| | | | | When decoding on RPI/MMAL, the buffering between decoder input and output can be quite excessive.
* video: fix base for --no-correct-ptswm42015-10-061-2/+2
| | | | | | | | | | Use the first encountered packet PTS/DTS as base, instead of the last one. This does not add the amount of frames buffered in the codec to the PTS offset, and thus is better. Also, don't add the frame time if there was no decoded frame yet. The first frame should obviously have the timestamp of the first packet (going by this heuristic).
* video: increase maximum number of buffered AVI pts sampleswm42015-10-061-1/+1
| | | | | | | While b-frame reordering limits the maximum required number to around 16, the number of additionally buffered frames can be much higher. Guess when this actually matters? (For the libavcodec MMAL wrapper.)
* video: remove user-controllable PTS sorting (--pts-association-mode)wm42015-10-061-6/+1
| | | | | | | | | Useless. Sometimes it might be useful to make some extremely broken files work, but on the other hand --no-correct-pts is sufficient for these cases. While we still need some of the code for AVI, the "auto" mode in particular inflated the size of the code.
* player: make decoding cover art more robustwm42015-06-181-0/+2
| | | | | | | | | | | | | | When showing cover art, the decoding logic pretends that the source has an infinite number of frames. This slightly simplifies dealing with filter data flow. It was done by feeding the same packet repeatedly to the decoder (each decode run produces new output). Change this by decoding once at the video initialization. This is easier to follow, and increases robustness in case of broken images. Usually, we try to tolerate decoding errors, so decoding normally continues, but in this case it would just burn the CPU for no reason. Fixes #2056.
* player: change video-bitrate and audio-bitrate propertieswm42015-04-201-1/+0
| | | | | | | | | | | | | | Remove the old implementation for these properties. It was never very good, often returned very innaccurate values or just 0, and was static even if the source was variable bitrate. Replace it with the implementation of "packet-video-bitrate". Mark the "packet-..." properties as deprecated. (The effective difference is different formatting, and returning the raw value in bits instead of kilobits.) Also extend the documentation a little. It appears at least some decoders (sipr?) need the AVCodecContext.bit_rate field set, so this one is still passed through.
* Update license headersMarcin Kurczewski2015-04-131-5/+4
| | | | Signed-off-by: wm4 <wm4@nowhere>
* video: don't keep multiple pointers to hwdec info structwm42014-08-111-1/+1
| | | | This makes a certain corner case simpler at a later point.
* dvd, bluray, cdda: add demux_disc containing all related hackswm42014-07-051-1/+0
| | | | | | | | | | | | DVD and Bluray (and to some extent cdda) require awful hacks all over the codebase to make them work. The main reason is that they act like container, but are entirely implemented on the stream layer. The raw mpeg data resulting from these streams must be "extended" with the container-like metadata transported via STREAM_CTRLs. The result were hacks all over demux.c and some higher-level parts. Add a "disc" pseudo-demuxer, and move all these hacks and special-cases to it.
* audio: rename i_bps to 'bitrate' to avoid confusionMarcoen Hirschberg2014-05-281-1/+1
| | | | 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-1/+1
| | | | | | | 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.
* video: change everythingwm42014-05-021-4/+2
| | | | | | | Change how the video decoding loop works. The structure should now be a bit easier to follow. The interactions on format changes are (probably) simpler. This also aligns the decoding loop with future planned changes, such as moving various things to separate threads.
* video/decode: mp_msg conversionswm42013-12-211-0/+2
| | | | Doesn't cover vdpau/vaapi parts yet, because these are a bit messier.
* video: display last frame, drain frames on video reconfigwm42013-12-101-0/+3
| | | | | | | | | | | | | | | | | | | | | | Until now, the player didn't care to drain frames on video reconfig. Instead, the VO was reconfigured (i.e. resized) before the queued frames finished displaying. This can for example be observed by passing multiple images with different size as mf:// filename. Then the window would resize one frame before image with the new size is displayed. With --vo=vdpau, the effect is worse, because this VO queues more than 1 frame internally. Fix this by explicitly draining buffered frames before video reconfig. Raise the display time of the last frame. Otherwise, the last frame would be shown for a very short time only. This usually doesn't matter, but helps when playing image files. This is a byproduct of frame draining, because normally, video timing is based on the frames queued to the VO, and we can't do that with frames of different size or format. So we pretend that the frame before the change is the last frame in order to time it. This code is incorrect though: it tries to use the framerate, which often doesn't make sense. But it's good enough to test this code with mf://.
* video: move handling of brightness and deinterlacing controlwm42013-12-101-1/+4
| | | | | Handling of brightness/gamma/saturation/etc. and deinterlacing is moved from vf_vo.c to dec_video.c.
* video: move video filter chain initialization from decoder to playerwm42013-12-101-3/+6
| | | | | | | | | | | | | This should help fixing some issues (like not draining video frames correctly on reinit), as well as decoupling the decoder, filter chain, and VO code. I also wanted to make the hardware video decoding fallback work properly if software-only video filters are inserted. This currently has the issue that the fallback is too violent, and throws away a bunch of demuxer packets needed to restart software decoding properly. But keeping "backup" packets turned out as too hacky, so I'm not doing this, at least not yet.
* video: create a separate context for video filter chainwm42013-12-071-2/+1
| | | | | | This adds vf_chain, which unlike vf_instance refers to the filter chain as a whole. This makes the filter API less awkward, and will allow handling format negotiation better.
* video: add heuristic to prevent framedrop during hrseek if pts brokenwm42013-11-281-0/+3
| | | | | | | | | | | | | | | | | | | | | | | Using --start with files that use DTS only, or which simply have broken PTS timestamps, would incorrectly drop frames and possibly not execute the seek correctly. Add yet another heuristic to detect this. The intent is that --start and hr-seeks in general should work correctly, but in order to keep things fast, we still want to allow frame dropping during hr-seek if there are no problems doing so. Do this by disabling frame dropping by default, but re-enabling it if there are no problems found for a while. As a consequence, --start might be somewhat slower, but normal user interaction should remain as fast as before. Note that there's something subtle about the added code: the has_broken_packet_pts field is checked even before the first packet is fed to dec_video.c, so the field must not be set to 0 right on start. It's not initially set to 0 anyway, because the heuristic requires decoding some images before enabling frame drop anyway. Note 2: it's not clear whether frame dropping during hr-seek really helps; I didn't benchmark it.
* video: replace d_video->pts field, change PTS jump checkswm42013-11-271-3/+0
|