mirror of
https://github.com/mpv-player/mpv
synced 2025-02-27 10:50:53 +00:00
This is based on the MPlayer VA API patches. To be exact it's based on a very stripped down version of commit f1ad459a263f8537f6c from git://gitorious.org/vaapi/mplayer.git. This doesn't contain useless things like benchmarking hacks and the demo code for GLX interop. Also, unlike in the original patch, decoding and video output are split into separate source files (the separation between decoding and display also makes pixel format hacks unnecessary). On the other hand, some features not present in the original patch were added, like screenshot support. VA API is rather bad for actual video output. Dealing with older libva versions or the completely broken vdpau backend doesn't help. OSD is low quality and should be rather slow. In some cases, only either OSD or subtitles can be shown at the same time (because OSD is drawn first, OSD is prefered). Also, libva can't decide whether it accepts straight or premultiplied alpha for OSD sub-pictures: the vdpau backend seems to assume premultiplied, while a native vaapi driver uses straight. So I picked straight alpha. It doesn't matter much, because the blending code for straight alpha I added to img_convert.c is probably buggy, and ASS subtitles might be blended incorrectly. Really good video output with VA API would probably use OpenGL and the GL interop features, but at this point you might just use vo_opengl. (Patches for making HW decoding with vo_opengl have a chance of being accepted.) Despite these issues, decoding seems to work ok. I still got tearing on the Intel system I tested (Intel(R) Core(TM) i3-2350M). It was also tested with the vdpau vaapi wrapper on a nvidia system; however this was rather broken. (Fortunately, there is no reason to use mpv's VAAPI support over native VDPAU.)
83 lines
2.3 KiB
C
83 lines
2.3 KiB
C
#ifndef MPV_LAVC_H
|
|
#define MPV_LAVC_H
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <libavcodec/avcodec.h>
|
|
|
|
#include "config.h"
|
|
|
|
#include "demux/stheader.h"
|
|
#include "video/mp_image.h"
|
|
|
|
// keep in sync with --hwdec option
|
|
enum hwdec_type {
|
|
HWDEC_AUTO = -1,
|
|
HWDEC_NONE = 0,
|
|
HWDEC_VDPAU = 1,
|
|
HWDEC_VDA = 2,
|
|
HWDEC_CRYSTALHD = 3,
|
|
HWDEC_VAAPI = 4,
|
|
};
|
|
|
|
typedef struct lavc_ctx {
|
|
AVCodecContext *avctx;
|
|
AVFrame *pic;
|
|
struct vd_lavc_hwdec *hwdec;
|
|
enum PixelFormat pix_fmt;
|
|
int do_hw_dr1;
|
|
int vo_initialized;
|
|
int best_csp;
|
|
struct mp_image_params image_params;
|
|
AVRational last_sample_aspect_ratio;
|
|
enum AVDiscard skip_frame;
|
|
const char *software_fallback_decoder;
|
|
|
|
// From VO
|
|
struct mp_hwdec_info *hwdec_info;
|
|
|
|
// For free use by hwdec implementation
|
|
void *hwdec_priv;
|
|
|
|
// Legacy
|
|
bool do_dr1;
|
|
struct FramePool *dr1_buffer_pool;
|
|
struct mp_image_pool *non_dr1_pool;
|
|
} vd_ffmpeg_ctx;
|
|
|
|
struct vd_lavc_hwdec {
|
|
enum hwdec_type type;
|
|
// If non-NULL: lists pairs software and hardware decoders. If the current
|
|
// codec is not one of the listed software decoders, probing fails.
|
|
// Otherwise, the AVCodecContext is initialized with the associated
|
|
// hardware decoder.
|
|
// Useful only if hw decoding requires a special codec, instead of using
|
|
// the libavcodec hwaccel infrastructure.
|
|
const char **codec_pairs;
|
|
// If not-NULL: a 0 terminated list of IMGFMT_ formats, and only one of
|
|
// these formats is accepted in the libavcodec get_format callback.
|
|
const int *image_formats;
|
|
int (*probe)(struct vd_lavc_hwdec *hwdec, struct mp_hwdec_info *info,
|
|
const char *decoder);
|
|
int (*init)(struct lavc_ctx *ctx);
|
|
void (*uninit)(struct lavc_ctx *ctx);
|
|
struct mp_image *(*allocate_image)(struct lavc_ctx *ctx, AVFrame *frame);
|
|
void (*fix_image)(struct lavc_ctx *ctx, struct mp_image *img);
|
|
};
|
|
|
|
enum {
|
|
HWDEC_ERR_NO_CTX = -2,
|
|
HWDEC_ERR_NO_CODEC = -3,
|
|
};
|
|
|
|
// lavc_dr1.c
|
|
int mp_codec_get_buffer(AVCodecContext *s, AVFrame *frame);
|
|
void mp_codec_release_buffer(AVCodecContext *s, AVFrame *frame);
|
|
struct FrameBuffer;
|
|
void mp_buffer_ref(struct FrameBuffer *buffer);
|
|
void mp_buffer_unref(struct FrameBuffer *buffer);
|
|
bool mp_buffer_is_unique(struct FrameBuffer *buffer);
|
|
void mp_buffer_pool_free(struct FramePool **pool);
|
|
|
|
#endif
|