2012-12-11 17:27:34 +00:00
|
|
|
#ifndef MPV_LAVC_H
|
|
|
|
#define MPV_LAVC_H
|
|
|
|
|
2012-12-11 23:43:50 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
2012-12-11 17:27:34 +00:00
|
|
|
#include <libavcodec/avcodec.h>
|
|
|
|
|
|
|
|
#include "demux/stheader.h"
|
|
|
|
#include "video/mp_image.h"
|
2013-11-23 20:26:31 +00:00
|
|
|
#include "video/hwdec.h"
|
2012-12-11 17:27:34 +00:00
|
|
|
|
2016-01-25 20:00:53 +00:00
|
|
|
#define HWDEC_DELAY_QUEUE_COUNT 2
|
|
|
|
|
vdpau: split off decoder parts, use "new" libavcodec vdpau hwaccel API
Move the decoder parts from vo_vdpau.c to a new file vdpau_old.c. This
file is named so because because it's written against the "old"
libavcodec vdpau pseudo-decoder (e.g. "h264_vdpau").
Add support for the "new" libavcodec vdpau support. This was recently
added and replaces the "old" vdpau parts. (In fact, Libav is about to
deprecate and remove the "old" API without deprecation grace period,
so we have to support it now. Moreover, there will probably be no Libav
release which supports both, so the transition is even less smooth than
we could hope, and we have to support both the old and new API.)
Whether the old or new API is used is checked by a configure test: if
the new API is found, it is used, otherwise the old API is assumed.
Some details might be handled differently. Especially display preemption
is a bit problematic with the "new" libavcodec vdpau support: it wants
to keep a pointer to a specific vdpau API function (which can be driver
specific, because preemption might switch drivers). Also, surface IDs
are now directly stored in AVFrames (and mp_images), so they can't be
forced to VDP_INVALID_HANDLE on preemption. (This changes even with
older libavcodec versions, because mp_image always uses the newer
representation to make vo_vdpau.c simpler.)
Decoder initialization in the new code tries to deal with codec
profiles, while the old code always uses the highest profile per codec.
Surface allocation changes. Since the decoder won't call config() in
vo_vdpau.c on video size change anymore, we allow allocating surfaces
of arbitrary size instead of locking it to what the VO was configured.
The non-hwdec code also has slightly different allocation behavior now.
Enabling the old vdpau special decoders via e.g. --vd=lavc:h264_vdpau
doesn't work anymore (a warning suggesting the --hwdec option is
printed instead).
2013-07-27 23:49:45 +00:00
|
|
|
typedef struct lavc_ctx {
|
2013-12-21 16:47:38 +00:00
|
|
|
struct mp_log *log;
|
2013-11-01 16:14:05 +00:00
|
|
|
struct MPOpts *opts;
|
2012-12-11 17:27:34 +00:00
|
|
|
AVCodecContext *avctx;
|
|
|
|
AVFrame *pic;
|
2013-08-11 21:23:12 +00:00
|
|
|
struct vd_lavc_hwdec *hwdec;
|
2016-02-03 20:29:56 +00:00
|
|
|
AVRational codec_timebase;
|
2013-11-29 16:39:57 +00:00
|
|
|
enum AVPixelFormat pix_fmt;
|
2012-12-11 17:27:34 +00:00
|
|
|
enum AVDiscard skip_frame;
|
2015-11-10 15:06:42 +00:00
|
|
|
bool flushing;
|
2016-01-29 21:46:46 +00:00
|
|
|
const char *decoder;
|
vd_lavc: make hardware decoding fallback less violent
Most of hardware decoding is initialized lazily. When the first packet
is parsed, libavcodec will call get_format() to check whether hw or sw
decoding is wanted. Until now, we've returned AV_PIX_FMT_NONE from
get_format() if hw decoder initialization failed. This caused the
avcodec_decode_video2() call to fail, which in turn let us trigger the
fallback. We didn't return a sw format from get_format(), because we
didn't want to continue decoding at all. (The reason being that full
reinitialization is more robust when continuing sw decoding.)
This has some disadvantages. libavcodec vomited some unwanted error
messages. Sometimes the failures are more severe, like it happened with
HEVC. In this case, the error code path simply acted up in a way that
was extremely inconvenient (and had to be fixed by myself). In general,
libavcodec is not designed to fallback this way.
Make it a bit less violent from the API usage point of view. Return a sw
format if hw decoder initialization fails. In this case, we let
get_buffer2() call avcodec_default_get_buffer2() as well. libavcodec is
allowed to perform its own sw fallback. But once the decode function
returns, we do the full reinitialization we wanted to do.
The result is that the fallback is more robust, and doesn't trigger any
decoder error codepaths or messages either. Change our own fallback
message to a warning, since there are no other messages with error
severity anymore.
2015-05-28 19:52:04 +00:00
|
|
|
bool hwdec_failed;
|
2015-09-02 21:31:01 +00:00
|
|
|
bool hwdec_notified;
|
2013-03-09 19:50:06 +00:00
|
|
|
|
2016-01-25 20:00:53 +00:00
|
|
|
struct mp_image **delay_queue;
|
|
|
|
int num_delay_queue;
|
|
|
|
int max_delay_queue;
|
|
|
|
|
vdpau: split off decoder parts, use "new" libavcodec vdpau hwaccel API
Move the decoder parts from vo_vdpau.c to a new file vdpau_old.c. This
file is named so because because it's written against the "old"
libavcodec vdpau pseudo-decoder (e.g. "h264_vdpau").
Add support for the "new" libavcodec vdpau support. This was recently
added and replaces the "old" vdpau parts. (In fact, Libav is about to
deprecate and remove the "old" API without deprecation grace period,
so we have to support it now. Moreover, there will probably be no Libav
release which supports both, so the transition is even less smooth than
we could hope, and we have to support both the old and new API.)
Whether the old or new API is used is checked by a configure test: if
the new API is found, it is used, otherwise the old API is assumed.
Some details might be handled differently. Especially display preemption
is a bit problematic with the "new" libavcodec vdpau support: it wants
to keep a pointer to a specific vdpau API function (which can be driver
specific, because preemption might switch drivers). Also, surface IDs
are now directly stored in AVFrames (and mp_images), so they can't be
forced to VDP_INVALID_HANDLE on preemption. (This changes even with
older libavcodec versions, because mp_image always uses the newer
representation to make vo_vdpau.c simpler.)
Decoder initialization in the new code tries to deal with codec
profiles, while the old code always uses the highest profile per codec.
Surface allocation changes. Since the decoder won't call config() in
vo_vdpau.c on video size change anymore, we allow allocating surfaces
of arbitrary size instead of locking it to what the VO was configured.
The non-hwdec code also has slightly different allocation behavior now.
Enabling the old vdpau special decoders via e.g. --vd=lavc:h264_vdpau
doesn't work anymore (a warning suggesting the --hwdec option is
printed instead).
2013-07-27 23:49:45 +00:00
|
|
|
// From VO
|
2016-05-09 17:42:03 +00:00
|
|
|
struct mp_hwdec_devices *hwdec_devs;
|
vdpau: split off decoder parts, use "new" libavcodec vdpau hwaccel API
Move the decoder parts from vo_vdpau.c to a new file vdpau_old.c. This
file is named so because because it's written against the "old"
libavcodec vdpau pseudo-decoder (e.g. "h264_vdpau").
Add support for the "new" libavcodec vdpau support. This was recently
added and replaces the "old" vdpau parts. (In fact, Libav is about to
deprecate and remove the "old" API without deprecation grace period,
so we have to support it now. Moreover, there will probably be no Libav
release which supports both, so the transition is even less smooth than
we could hope, and we have to support both the old and new API.)
Whether the old or new API is used is checked by a configure test: if
the new API is found, it is used, otherwise the old API is assumed.
Some details might be handled differently. Especially display preemption
is a bit problematic with the "new" libavcodec vdpau support: it wants
to keep a pointer to a specific vdpau API function (which can be driver
specific, because preemption might switch drivers). Also, surface IDs
are now directly stored in AVFrames (and mp_images), so they can't be
forced to VDP_INVALID_HANDLE on preemption. (This changes even with
older libavcodec versions, because mp_image always uses the newer
representation to make vo_vdpau.c simpler.)
Decoder initialization in the new code tries to deal with codec
profiles, while the old code always uses the highest profile per codec.
Surface allocation changes. Since the decoder won't call config() in
vo_vdpau.c on video size change anymore, we allow allocating surfaces
of arbitrary size instead of locking it to what the VO was configured.
The non-hwdec code also has slightly different allocation behavior now.
Enabling the old vdpau special decoders via e.g. --vd=lavc:h264_vdpau
doesn't work anymore (a warning suggesting the --hwdec option is
printed instead).
2013-07-27 23:49:45 +00:00
|
|
|
|
|
|
|
// For free use by hwdec implementation
|
|
|
|
void *hwdec_priv;
|
|
|
|
|
2014-03-10 21:36:23 +00:00
|
|
|
int hwdec_fmt;
|
|
|
|
int hwdec_w;
|
|
|
|
int hwdec_h;
|
2014-03-17 17:19:03 +00:00
|
|
|
int hwdec_profile;
|
2015-05-28 19:56:13 +00:00
|
|
|
|
|
|
|
bool hwdec_request_reinit;
|
2015-11-03 13:03:02 +00:00
|
|
|
int hwdec_fail_count;
|
2012-12-11 17:27:34 +00:00
|
|
|
} vd_ffmpeg_ctx;
|
|
|
|
|
2013-08-11 21:23:12 +00:00
|
|
|
struct vd_lavc_hwdec {
|
|
|
|
enum hwdec_type type;
|
2014-03-16 08:21:21 +00:00
|
|
|
// If not-0: the IMGFMT_ format that should be accepted in the libavcodec
|
|
|
|
// get_format callback.
|
|
|
|
int image_format;
|
2016-05-11 14:18:58 +00:00
|
|
|
// Always returns a non-hwaccel image format.
|
|
|
|
bool copying;
|
2016-04-07 16:26:58 +00:00
|
|
|
// Setting this will queue the given number of frames before calling
|
|
|
|
// process_image() or returning them to the renderer. This can increase
|
|
|
|
// efficiency by not blocking on the hardware pipeline by reading back
|
|
|
|
// immediately after decoding.
|
|
|
|
int delay_queue;
|
2016-05-09 17:42:03 +00:00
|
|
|
int (*probe)(struct lavc_ctx *ctx, struct vd_lavc_hwdec *hwdec,
|
2016-04-07 15:48:00 +00:00
|
|
|
const char *codec);
|
vdpau: split off decoder parts, use "new" libavcodec vdpau hwaccel API
Move the decoder parts from vo_vdpau.c to a new file vdpau_old.c. This
file is named so because because it's written against the "old"
libavcodec vdpau pseudo-decoder (e.g. "h264_vdpau").
Add support for the "new" libavcodec vdpau support. This was recently
added and replaces the "old" vdpau parts. (In fact, Libav is about to
deprecate and remove the "old" API without deprecation grace period,
so we have to support it now. Moreover, there will probably be no Libav
release which supports both, so the transition is even less smooth than
we could hope, and we have to support both the old and new API.)
Whether the old or new API is used is checked by a configure test: if
the new API is found, it is used, otherwise the old API is assumed.
Some details might be handled differently. Especially display preemption
is a bit problematic with the "new" libavcodec vdpau support: it wants
to keep a pointer to a specific vdpau API function (which can be driver
specific, because preemption might switch drivers). Also, surface IDs
are now directly stored in AVFrames (and mp_images), so they can't be
forced to VDP_INVALID_HANDLE on preemption. (This changes even with
older libavcodec versions, because mp_image always uses the newer
representation to make vo_vdpau.c simpler.)
Decoder initialization in the new code tries to deal with codec
profiles, while the old code always uses the highest profile per codec.
Surface allocation changes. Since the decoder won't call config() in
vo_vdpau.c on video size change anymore, we allow allocating surfaces
of arbitrary size instead of locking it to what the VO was configured.
The non-hwdec code also has slightly different allocation behavior now.
Enabling the old vdpau special decoders via e.g. --vd=lavc:h264_vdpau
doesn't work anymore (a warning suggesting the --hwdec option is
printed instead).
2013-07-27 23:49:45 +00:00
|
|
|
int (*init)(struct lavc_ctx *ctx);
|
2015-08-19 19:33:18 +00:00
|
|
|
int (*init_decoder)(struct lavc_ctx *ctx, int w, int h);
|
vdpau: split off decoder parts, use "new" libavcodec vdpau hwaccel API
Move the decoder parts from vo_vdpau.c to a new file vdpau_old.c. This
file is named so because because it's written against the "old"
libavcodec vdpau pseudo-decoder (e.g. "h264_vdpau").
Add support for the "new" libavcodec vdpau support. This was recently
added and replaces the "old" vdpau parts. (In fact, Libav is about to
deprecate and remove the "old" API without deprecation grace period,
so we have to support it now. Moreover, there will probably be no Libav
release which supports both, so the transition is even less smooth than
we could hope, and we have to support both the old and new API.)
Whether the old or new API is used is checked by a configure test: if
the new API is found, it is used, otherwise the old API is assumed.
Some details might be handled differently. Especially display preemption
is a bit problematic with the "new" libavcodec vdpau support: it wants
to keep a pointer to a specific vdpau API function (which can be driver
specific, because preemption might switch drivers). Also, surface IDs
are now directly stored in AVFrames (and mp_images), so they can't be
forced to VDP_INVALID_HANDLE on preemption. (This changes even with
older libavcodec versions, because mp_image always uses the newer
representation to make vo_vdpau.c simpler.)
Decoder initialization in the new code tries to deal with codec
profiles, while the old code always uses the highest profile per codec.
Surface allocation changes. Since the decoder won't call config() in
vo_vdpau.c on video size change anymore, we allow allocating surfaces
of arbitrary size instead of locking it to what the VO was configured.
The non-hwdec code also has slightly different allocation behavior now.
Enabling the old vdpau special decoders via e.g. --vd=lavc:h264_vdpau
doesn't work anymore (a warning suggesting the --hwdec option is
printed instead).
2013-07-27 23:49:45 +00:00
|
|
|
void (*uninit)(struct lavc_ctx *ctx);
|
2014-03-10 21:36:23 +00:00
|
|
|
// Note: if init_decoder is set, this will always use the values from the
|
|
|
|
// last successful init_decoder call. Otherwise, it's up to you.
|
2015-08-19 19:33:18 +00:00
|
|
|
struct mp_image *(*allocate_image)(struct lavc_ctx *ctx, int w, int h);
|
2013-08-15 16:21:54 +00:00
|
|
|
// Process the image returned by the libavcodec decoder.
|
|
|
|
struct mp_image *(*process_image)(struct lavc_ctx *ctx, struct mp_image *img);
|
2014-08-21 20:04:25 +00:00
|
|
|
// For horrible Intel shit-drivers only
|
|
|
|
void (*lock)(struct lavc_ctx *ctx);
|
|
|
|
void (*unlock)(struct lavc_ctx *ctx);
|
2015-03-29 13:12:11 +00:00
|
|
|
// Optional; if a special hardware decoder is needed (instead of "hwaccel").
|
2015-11-05 16:24:35 +00:00
|
|
|
const char *(*get_codec)(struct lavc_ctx *ctx, const char *codec);
|
2016-04-25 09:28:25 +00:00
|
|
|
// Suffix for libavcodec decoder. If non-NULL, get_codec() is overridden
|
|
|
|
// with hwdec_find_decoder.
|
|
|
|
// Intuitively, this will force the corresponding wrapper decoder.
|
|
|
|
const char *lavc_suffix;
|
vdpau: split off decoder parts, use "new" libavcodec vdpau hwaccel API
Move the decoder parts from vo_vdpau.c to a new file vdpau_old.c. This
file is named so because because it's written against the "old"
libavcodec vdpau pseudo-decoder (e.g. "h264_vdpau").
Add support for the "new" libavcodec vdpau support. This was recently
added and replaces the "old" vdpau parts. (In fact, Libav is about to
deprecate and remove the "old" API without deprecation grace period,
so we have to support it now. Moreover, there will probably be no Libav
release which supports both, so the transition is even less smooth than
we could hope, and we have to support both the old and new API.)
Whether the old or new API is used is checked by a configure test: if
the new API is found, it is used, otherwise the old API is assumed.
Some details might be handled differently. Especially display preemption
is a bit problematic with the "new" libavcodec vdpau support: it wants
to keep a pointer to a specific vdpau API function (which can be driver
specific, because preemption might switch drivers). Also, surface IDs
are now directly stored in AVFrames (and mp_images), so they can't be
forced to VDP_INVALID_HANDLE on preemption. (This changes even with
older libavcodec versions, because mp_image always uses the newer
representation to make vo_vdpau.c simpler.)
Decoder initialization in the new code tries to deal with codec
profiles, while the old code always uses the highest profile per codec.
Surface allocation changes. Since the decoder won't call config() in
vo_vdpau.c on video size change anymore, we allow allocating surfaces
of arbitrary size instead of locking it to what the VO was configured.
The non-hwdec code also has slightly different allocation behavior now.
Enabling the old vdpau special decoders via e.g. --vd=lavc:h264_vdpau
doesn't work anymore (a warning suggesting the --hwdec option is
printed instead).
2013-07-27 23:49:45 +00:00
|
|
|
};
|
|
|
|
|
2013-08-11 21:23:12 +00:00
|
|
|
enum {
|
|
|
|
HWDEC_ERR_NO_CTX = -2,
|
|
|
|
HWDEC_ERR_NO_CODEC = -3,
|
2014-05-27 23:37:53 +00:00
|
|
|
HWDEC_ERR_EMULATED = -4, // probing successful, but emulated API detected
|
2013-08-11 21:23:12 +00:00
|
|
|
};
|
|
|
|
|
2013-11-01 16:14:05 +00:00
|
|
|
struct hwdec_profile_entry {
|
|
|
|
enum AVCodecID av_codec;
|
|
|
|
int ff_profile;
|
|
|
|
uint64_t hw_profile;
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct hwdec_profile_entry *hwdec_find_profile(
|
|
|
|
struct lavc_ctx *ctx, const struct hwdec_profile_entry *table);
|
2016-04-07 15:48:00 +00:00
|
|
|
bool hwdec_check_codec_support(const char *codec,
|
2013-11-01 16:14:05 +00:00
|
|
|
const struct hwdec_profile_entry *table);
|
|
|
|
int hwdec_get_max_refs(struct lavc_ctx *ctx);
|
|
|
|
|
2016-04-25 09:28:25 +00:00
|
|
|
const char *hwdec_find_decoder(const char *codec, const char *suffix);
|
|
|
|
|
2012-12-11 17:27:34 +00:00
|
|
|
#endif
|