2012-12-11 18:27:34 +01:00
|
|
|
#ifndef MPV_LAVC_H
|
|
|
|
#define MPV_LAVC_H
|
|
|
|
|
2012-12-12 00:43:50 +01:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
2012-12-11 18:27:34 +01:00
|
|
|
#include <libavcodec/avcodec.h>
|
|
|
|
|
|
|
|
#include "demux/stheader.h"
|
|
|
|
#include "video/mp_image.h"
|
2013-11-23 21:26:31 +01:00
|
|
|
#include "video/hwdec.h"
|
2012-12-11 18:27:34 +01:00
|
|
|
|
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-28 01:49:45 +02:00
|
|
|
typedef struct lavc_ctx {
|
2013-12-21 17:47:38 +01:00
|
|
|
struct mp_log *log;
|
2013-11-01 17:14:05 +01:00
|
|
|
struct MPOpts *opts;
|
2012-12-11 18:27:34 +01:00
|
|
|
AVCodecContext *avctx;
|
|
|
|
AVFrame *pic;
|
2013-08-11 23:23:12 +02:00
|
|
|
struct vd_lavc_hwdec *hwdec;
|
2013-11-29 17:39:57 +01:00
|
|
|
enum AVPixelFormat pix_fmt;
|
2012-12-11 18:27:34 +01:00
|
|
|
int best_csp;
|
|
|
|
enum AVDiscard skip_frame;
|
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 15:15:19 +01:00
|
|
|
const char *software_fallback_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 21:52:04 +02:00
|
|
|
bool hwdec_failed;
|
2013-03-09 20:50:06 +01:00
|
|
|
|
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-28 01:49:45 +02:00
|
|
|
// From VO
|
|
|
|
struct mp_hwdec_info *hwdec_info;
|
|
|
|
|
|
|
|
// For free use by hwdec implementation
|
|
|
|
void *hwdec_priv;
|
|
|
|
|
2014-03-10 22:36:23 +01:00
|
|
|
int hwdec_fmt;
|
|
|
|
int hwdec_w;
|
|
|
|
int hwdec_h;
|
2014-03-17 18:19:03 +01:00
|
|
|
int hwdec_profile;
|
2015-05-28 21:56:13 +02:00
|
|
|
|
|
|
|
bool hwdec_request_reinit;
|
2012-12-11 18:27:34 +01:00
|
|
|
} vd_ffmpeg_ctx;
|
|
|
|
|
2013-08-11 23:23:12 +02:00
|
|
|
struct vd_lavc_hwdec {
|
|
|
|
enum hwdec_type type;
|
2014-03-16 09:21:21 +01:00
|
|
|
// If not-0: the IMGFMT_ format that should be accepted in the libavcodec
|
|
|
|
// get_format callback.
|
|
|
|
int image_format;
|
2013-08-11 23:23:12 +02:00
|
|
|
int (*probe)(struct vd_lavc_hwdec *hwdec, struct mp_hwdec_info *info,
|
|
|
|
const char *decoder);
|
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-28 01:49:45 +02:00
|
|
|
int (*init)(struct lavc_ctx *ctx);
|
2015-08-19 21:33:18 +02: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-28 01:49:45 +02:00
|
|
|
void (*uninit)(struct lavc_ctx *ctx);
|
2014-03-10 22:36:23 +01: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 21:33:18 +02:00
|
|
|
struct mp_image *(*allocate_image)(struct lavc_ctx *ctx, int w, int h);
|
2013-08-15 18:21:54 +02: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 22:04:25 +02:00
|
|
|
// For horrible Intel shit-drivers only
|
|
|
|
void (*lock)(struct lavc_ctx *ctx);
|
|
|
|
void (*unlock)(struct lavc_ctx *ctx);
|
2015-03-29 15:12:11 +02:00
|
|
|
// Optional; if a special hardware decoder is needed (instead of "hwaccel").
|
|
|
|
const char *(*get_codec)(struct lavc_ctx *ctx);
|
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-28 01:49:45 +02:00
|
|
|
};
|
|
|
|
|
2013-08-11 23:23:12 +02:00
|
|
|
enum {
|
|
|
|
HWDEC_ERR_NO_CTX = -2,
|
|
|
|
HWDEC_ERR_NO_CODEC = -3,
|
2014-05-28 01:37:53 +02:00
|
|
|
HWDEC_ERR_EMULATED = -4, // probing successful, but emulated API detected
|
2013-08-11 23:23:12 +02:00
|
|
|
};
|
|
|
|
|
2013-11-01 17:14:05 +01: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);
|
|
|
|
bool hwdec_check_codec_support(const char *decoder,
|
|
|
|
const struct hwdec_profile_entry *table);
|
|
|
|
int hwdec_get_max_refs(struct lavc_ctx *ctx);
|
|
|
|
|
2012-12-11 18:27:34 +01:00
|
|
|
#endif
|