2010-01-30 16:57:40 +00:00
|
|
|
/*
|
2015-04-13 07:36:54 +00:00
|
|
|
* This file is part of mpv.
|
2010-01-30 16:57:40 +00:00
|
|
|
*
|
2017-09-21 11:50:18 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2010-01-30 16:57:40 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2010-01-30 16:57:40 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2017-09-21 11:50:18 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2010-01-30 16:57:40 +00:00
|
|
|
*
|
2017-09-21 11:50:18 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2010-01-30 16:57:40 +00:00
|
|
|
*/
|
|
|
|
|
2008-02-22 09:09:46 +00:00
|
|
|
#ifndef MPLAYER_DEC_VIDEO_H
|
|
|
|
#define MPLAYER_DEC_VIDEO_H
|
2001-10-30 17:04:59 +00:00
|
|
|
|
2013-11-23 20:38:39 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "demux/stheader.h"
|
2013-11-23 20:36:20 +00:00
|
|
|
#include "video/hwdec.h"
|
|
|
|
#include "video/mp_image.h"
|
2008-03-06 08:34:50 +00:00
|
|
|
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
struct mp_decoder_list;
|
2013-12-10 18:08:56 +00:00
|
|
|
struct vo;
|
2008-06-23 22:53:58 +00:00
|
|
|
|
2013-11-23 20:36:20 +00:00
|
|
|
struct dec_video {
|
2013-12-21 16:47:38 +00:00
|
|
|
struct mp_log *log;
|
|
|
|
struct mpv_global *global;
|
2013-11-23 20:36:20 +00:00
|
|
|
struct MPOpts *opts;
|
|
|
|
const struct vd_functions *vd_driver;
|
2016-05-09 17:42:03 +00:00
|
|
|
struct mp_hwdec_devices *hwdec_devs; // video output hwdec handles
|
2013-11-23 20:36:20 +00:00
|
|
|
struct sh_stream *header;
|
2016-02-15 19:34:45 +00:00
|
|
|
struct mp_codec_params *codec;
|
2017-07-23 07:41:51 +00:00
|
|
|
struct vo *vo; // required for direct rendering into video memory
|
2002-08-31 13:09:23 +00:00
|
|
|
|
2013-11-23 20:36:20 +00:00
|
|
|
char *decoder_desc;
|
|
|
|
|
2016-01-16 20:19:52 +00:00
|
|
|
float fps; // FPS from demuxer or from user override
|
video: display last frame, drain frames on video reconfig
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://.
2013-12-10 18:33:11 +00:00
|
|
|
|
2016-01-16 20:19:52 +00:00
|
|
|
int dropped_frames;
|
|
|
|
|
2017-02-07 16:05:17 +00:00
|
|
|
struct mp_recorder_sink *recorder_sink;
|
|
|
|
|
2016-01-16 20:19:52 +00:00
|
|
|
// Internal (shared with vd_lavc.c).
|
2015-06-18 16:39:46 +00:00
|
|
|
|
video: refactor PTS code, add fall back heuristic to DTS
Refactor the PTS handling code to make it cleaner, and to separate the
bits that use PTS sorting.
Add a heuristic to fall back to DTS if the PTS us non-monotonic. This
code is based on what FFmpeg/Libav use for ffplay/avplay and also
best_effort_timestamp (which is only in FFmpeg). Basically, this 1. just
uses the DTS if PTS is unset, and 2. ignores PTS entirely if PTS is non-
monotonic, but DTS is sorted.
The code is pretty much the same as in Libav [1]. I'm not sure if all of
it is really needed, or if it does more than what the paragraph above
mentions. But maybe it's fine to cargo-cult this.
This heuristic fixes playback of mpeg4 in ogm, which returns packets
with PTS==DTS, even though the PTS timestamps should follow codec
reordering. This is probably a libavformat demuxer bug, but good luck
trying to fix it.
The way vd_lavc.c returns the frame PTS and DTS to dec_video.c is a bit
inelegant, but maybe better than trying to mess the PTS back into the
decoder callback again.
[1] https://git.libav.org/?p=libav.git;a=blob;f=cmdutils.c;h=3f1c667075724c5cde69d840ed5ed7d992898334;hb=fa515c2088e1d082d45741bbd5c05e13b0500804#l1431
2013-11-27 19:54:56 +00:00
|
|
|
void *priv; // for free use by vd_driver
|
2013-11-23 20:36:20 +00:00
|
|
|
|
2016-01-25 19:47:13 +00:00
|
|
|
// Strictly internal (dec_video.c).
|
|
|
|
|
video: refactor PTS code, add fall back heuristic to DTS
Refactor the PTS handling code to make it cleaner, and to separate the
bits that use PTS sorting.
Add a heuristic to fall back to DTS if the PTS us non-monotonic. This
code is based on what FFmpeg/Libav use for ffplay/avplay and also
best_effort_timestamp (which is only in FFmpeg). Basically, this 1. just
uses the DTS if PTS is unset, and 2. ignores PTS entirely if PTS is non-
monotonic, but DTS is sorted.
The code is pretty much the same as in Libav [1]. I'm not sure if all of
it is really needed, or if it does more than what the paragraph above
mentions. But maybe it's fine to cargo-cult this.
This heuristic fixes playback of mpeg4 in ogm, which returns packets
with PTS==DTS, even though the PTS timestamps should follow codec
reordering. This is probably a libavformat demuxer bug, but good luck
trying to fix it.
The way vd_lavc.c returns the frame PTS and DTS to dec_video.c is a bit
inelegant, but maybe better than trying to mess the PTS back into the
decoder callback again.
[1] https://git.libav.org/?p=libav.git;a=blob;f=cmdutils.c;h=3f1c667075724c5cde69d840ed5ed7d992898334;hb=fa515c2088e1d082d45741bbd5c05e13b0500804#l1431
2013-11-27 19:54:56 +00:00
|
|
|
// Last PTS from decoder (set with each vd_driver->decode() call)
|
|
|
|
double codec_pts;
|
|
|
|
int num_codec_pts_problems;
|
|
|
|
|
|
|
|
// Last packet DTS from decoder (passed through from source packets)
|
|
|
|
double codec_dts;
|
|
|
|
int num_codec_dts_problems;
|
|
|
|
|
2015-10-06 16:13:23 +00:00
|
|
|
// PTS or DTS of packet first read
|
|
|
|
double first_packet_pdts;
|
video: refactor PTS code, add fall back heuristic to DTS
Refactor the PTS handling code to make it cleaner, and to separate the
bits that use PTS sorting.
Add a heuristic to fall back to DTS if the PTS us non-monotonic. This
code is based on what FFmpeg/Libav use for ffplay/avplay and also
best_effort_timestamp (which is only in FFmpeg). Basically, this 1. just
uses the DTS if PTS is unset, and 2. ignores PTS entirely if PTS is non-
monotonic, but DTS is sorted.
The code is pretty much the same as in Libav [1]. I'm not sure if all of
it is really needed, or if it does more than what the paragraph above
mentions. But maybe it's fine to cargo-cult this.
This heuristic fixes playback of mpeg4 in ogm, which returns packets
with PTS==DTS, even though the PTS timestamps should follow codec
reordering. This is probably a libavformat demuxer bug, but good luck
trying to fix it.
The way vd_lavc.c returns the frame PTS and DTS to dec_video.c is a bit
inelegant, but maybe better than trying to mess the PTS back into the
decoder callback again.
[1] https://git.libav.org/?p=libav.git;a=blob;f=cmdutils.c;h=3f1c667075724c5cde69d840ed5ed7d992898334;hb=fa515c2088e1d082d45741bbd5c05e13b0500804#l1431
2013-11-27 19:54:56 +00:00
|
|
|
|
2013-11-28 12:34:56 +00:00
|
|
|
// There was at least one packet with non-sense timestamps.
|
|
|
|
int has_broken_packet_pts; // <0: uninitialized, 0: no problems, 1: broken
|
|
|
|
|
2016-11-09 16:51:19 +00:00
|
|
|
int has_broken_decoded_pts;
|
|
|
|
|
video: refactor PTS code, add fall back heuristic to DTS
Refactor the PTS handling code to make it cleaner, and to separate the
bits that use PTS sorting.
Add a heuristic to fall back to DTS if the PTS us non-monotonic. This
code is based on what FFmpeg/Libav use for ffplay/avplay and also
best_effort_timestamp (which is only in FFmpeg). Basically, this 1. just
uses the DTS if PTS is unset, and 2. ignores PTS entirely if PTS is non-
monotonic, but DTS is sorted.
The code is pretty much the same as in Libav [1]. I'm not sure if all of
it is really needed, or if it does more than what the paragraph above
mentions. But maybe it's fine to cargo-cult this.
This heuristic fixes playback of mpeg4 in ogm, which returns packets
with PTS==DTS, even though the PTS timestamps should follow codec
reordering. This is probably a libavformat demuxer bug, but good luck
trying to fix it.
The way vd_lavc.c returns the frame PTS and DTS to dec_video.c is a bit
inelegant, but maybe better than trying to mess the PTS back into the
decoder callback again.
[1] https://git.libav.org/?p=libav.git;a=blob;f=cmdutils.c;h=3f1c667075724c5cde69d840ed5ed7d992898334;hb=fa515c2088e1d082d45741bbd5c05e13b0500804#l1431
2013-11-27 19:54:56 +00:00
|
|
|
// Final PTS of previously decoded image
|
|
|
|
double decoded_pts;
|
|
|
|
|
2016-09-20 13:40:44 +00:00
|
|
|
struct mp_image_params dec_format, last_format, fixed_format;
|
2013-11-25 22:08:29 +00:00
|
|
|
|
2016-01-16 20:19:52 +00:00
|
|
|
double start_pts;
|
Rewrite ordered chapters and timeline stuff
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.
2016-02-15 20:04:07 +00:00
|
|
|
double start, end;
|
|
|
|
struct demux_packet *new_segment;
|
|
|
|
struct demux_packet *packet;
|
2016-01-16 20:19:52 +00:00
|
|
|
bool framedrop_enabled;
|
video, audio: always read all frames before getting next packet
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.
2017-12-30 12:14:15 +00:00
|
|
|
bool may_decoder_framedrop;
|
2016-01-16 20:19:52 +00:00
|
|
|
struct mp_image *current_mpi;
|
|
|
|
int current_state;
|
2013-11-23 20:36:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct mp_decoder_list *video_decoder_list(void);
|
|
|
|
|
2016-02-15 19:28:36 +00:00
|
|
|
bool video_init_best_codec(struct dec_video *d_video);
|
2013-11-23 20:36:20 +00:00
|
|
|
void video_uninit(struct dec_video *d_video);
|
2001-10-30 17:04:59 +00:00
|
|
|
|
2016-01-16 20:19:52 +00:00
|
|
|
void video_work(struct dec_video *d_video);
|
2016-02-01 20:32:01 +00:00
|
|
|
int video_get_frame(struct dec_video *d_video, struct mp_image **out_mpi);
|
2016-01-16 20:19:52 +00:00
|
|
|
|
|
|
|
void video_set_framedrop(struct dec_video *d_video, bool enabled);
|
|
|
|
void video_set_start(struct dec_video *d_video, double start_pts);
|
|
|
|
|
2013-11-23 20:36:20 +00:00
|
|
|
int video_vd_control(struct dec_video *d_video, int cmd, void *arg);
|
2016-01-16 20:19:52 +00:00
|
|
|
void video_reset(struct dec_video *d_video);
|
2016-09-20 13:34:31 +00:00
|
|
|
void video_reset_params(struct dec_video *d_video);
|
2016-09-20 13:40:44 +00:00
|
|
|
void video_get_dec_params(struct dec_video *d_video, struct mp_image_params *p);
|
2013-12-10 18:08:56 +00:00
|
|
|
|
2008-02-22 09:09:46 +00:00
|
|
|
#endif /* MPLAYER_DEC_VIDEO_H */
|