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
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or modify
|
2010-01-30 16:57:40 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
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
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
2015-04-13 07:36:54 +00:00
|
|
|
* 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;
|
2013-12-07 18:32:44 +00:00
|
|
|
struct vf_chain *vfilter; // video filter chain
|
2013-12-10 18:08:56 +00:00
|
|
|
struct vo *vo; // (still) needed by video_set/get_colors
|
2013-11-23 20:36:20 +00:00
|
|
|
const struct vd_functions *vd_driver;
|
2014-08-11 21:08:35 +00:00
|
|
|
struct mp_hwdec_info *hwdec_info; // video output hwdec handles
|
2013-11-23 20:36:20 +00:00
|
|
|
struct sh_stream *header;
|
2002-08-31 13:09:23 +00:00
|
|
|
|
2013-11-23 20:36:20 +00:00
|
|
|
char *decoder_desc;
|
|
|
|
|
2014-05-01 21:53:18 +00:00
|
|
|
// Used temporarily during decoding (important for format changes)
|
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
|
|
|
struct mp_image *waiting_decoded_mpi;
|
2014-05-01 21:53:18 +00:00
|
|
|
struct mp_image_params decoder_output; // last output of the decoder
|
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
|
|
|
|
2015-06-18 16:39:46 +00:00
|
|
|
struct mp_image *cover_art_mpi;
|
|
|
|
|
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
|
|
|
|
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 15:55:15 +00:00
|
|
|
// PTS sorting (needed for AVI-style timestamps)
|
2015-10-06 16:00:28 +00:00
|
|
|
double buffered_pts[64];
|
2013-11-23 20:36:20 +00:00
|
|
|
int num_buffered_pts;
|
2013-11-25 22:16:22 +00:00
|
|
|
|
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
|
|
|
|
|
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;
|
|
|
|
|
2013-11-23 20:41:40 +00:00
|
|
|
float fps; // FPS from demuxer or from user override
|
2013-11-23 20:40:51 +00:00
|
|
|
float initial_decoder_aspect;
|
2013-11-25 22:08:29 +00:00
|
|
|
|
|
|
|
// State used only by player/video.c
|
|
|
|
double last_pts;
|
2013-11-23 20:36:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct mp_decoder_list *video_decoder_list(void);
|
|
|
|
|
2013-11-23 20:38:39 +00:00
|
|
|
bool video_init_best_codec(struct dec_video *d_video, char* video_decoders);
|
2013-11-23 20:36:20 +00:00
|
|
|
void video_uninit(struct dec_video *d_video);
|
2001-10-30 17:04:59 +00:00
|
|
|
|
2011-08-20 17:25:43 +00:00
|
|
|
struct demux_packet;
|
2013-11-25 22:09:40 +00:00
|
|
|
struct mp_image *video_decode(struct dec_video *d_video,
|
|
|
|
struct demux_packet *packet,
|
|
|
|
int drop_frame);
|
2001-10-30 17:04:59 +00:00
|
|
|
|
2013-11-23 20:36:20 +00:00
|
|
|
int video_get_colors(struct dec_video *d_video, const char *item, int *value);
|
|
|
|
int video_set_colors(struct dec_video *d_video, const char *item, int value);
|
2013-11-27 19:54:07 +00:00
|
|
|
void video_reset_decoding(struct dec_video *d_video);
|
2013-11-23 20:36:20 +00:00
|
|
|
int video_vd_control(struct dec_video *d_video, int cmd, void *arg);
|
2001-10-30 17:38:09 +00:00
|
|
|
|
2013-12-10 18:07:29 +00:00
|
|
|
int video_reconfig_filters(struct dec_video *d_video,
|
|
|
|
const struct mp_image_params *params);
|
|
|
|
|
2013-12-10 18:08:56 +00:00
|
|
|
int video_vf_vo_control(struct dec_video *d_video, int vf_cmd, void *data);
|
|
|
|
|
2008-02-22 09:09:46 +00:00
|
|
|
#endif /* MPLAYER_DEC_VIDEO_H */
|