command: add property returning detected hwdec API

This is somewhat imperfect, because detection of hw decoding APIs is
mostly done on demand, and often avoided if not necessary. (For example,
we know very well that there are no hw decoders for certain codecs.)

This also requires every hwdec backend to identify itself (see hwdec.h
changes).
This commit is contained in:
wm4 2015-02-02 22:43:05 +01:00
parent c07e046bfa
commit 2a9534871d
8 changed files with 59 additions and 15 deletions

View File

@ -1119,6 +1119,17 @@ Property list
Note that you don't know the success of the operation immediately after
writing this property. It happens with a delay as video is reinitialized.
``detected-hwdec``
Return the current hardware decoder that was detected and opened. Returns
the same values as ``hwdec``.
This is known only once the VO has opened (and possibly later). With some
VOs (like ``opengl``), this is never known in advance, but only when the
decoder attempted to create the hw decoder successfully. Also, hw decoders
with ``-copy`` suffix are returned only while hw decoding is active (and
unset afterwards). All this reflects how detecting hw decoders are
detected and used internally in mpv.
``panscan`` (RW)
See ``--panscan``.

View File

@ -2014,6 +2014,35 @@ static int mp_property_hwdec(void *ctx, struct m_property *prop,
return mp_property_generic_option(mpctx, prop, action, arg);
}
static int mp_property_detected_hwdec(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
struct dec_video *vd = mpctx->d_video;
if (!vd || !vd->hwdec_info)
return M_PROPERTY_UNAVAILABLE;
switch (action) {
case M_PROPERTY_GET_TYPE: {
// Abuse another hwdec option to resolve the value names
struct m_property dummy = {.name = "hwdec"};
return mp_property_generic_option(mpctx, &dummy, action, arg);
}
case M_PROPERTY_GET: {
int d = vd->hwdec_info->hwctx ? vd->hwdec_info->hwctx->type : HWDEC_NONE;
if (d) {
*(int *)arg = d;
} else {
// Maybe one of the "-copy" ones. These are "detected" every time
// the decoder is opened, so we don't know much about them otherwise.
return mp_property_hwdec(ctx, prop, action, arg);
}
return M_PROPERTY_OK;
}
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
#define VF_DEINTERLACE_LABEL "deinterlace"
static bool probe_deint_filter(struct MPContext *mpctx, const char *filt)
@ -3389,6 +3418,7 @@ static const struct m_property mp_properties[] = {
{"vid", mp_property_video},
{"program", mp_property_program},
{"hwdec", mp_property_hwdec},
{"detected-hwdec", mp_property_detected_hwdec},
{"estimated-frame-count", mp_property_frame_count},
{"estimated-frame-number", mp_property_frame_number},
@ -3482,7 +3512,8 @@ static const char *const *const mp_event_property_change[] = {
"estimated-vf-fps"),
E(MPV_EVENT_VIDEO_RECONFIG, "video-out-params", "video-params",
"video-format", "video-codec", "video-bitrate", "dwidth", "dheight",
"width", "height", "fps", "aspect", "vo-configured", "current-vo"),
"width", "height", "fps", "aspect", "vo-configured", "current-vo",
"detected-hwdec"),
E(MPV_EVENT_AUDIO_RECONFIG, "audio-format", "audio-codec", "audio-bitrate",
"samplerate", "channels", "audio", "volume", "mute", "balance",
"volume-restore-data", "current-ao"),

View File

@ -9,18 +9,6 @@
#include "video/mp_image.h"
#include "video/hwdec.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,
HWDEC_VAAPI_COPY = 5,
HWDEC_DXVA2_COPY = 6,
};
typedef struct lavc_ctx {
struct mp_log *log;
struct MPOpts *opts;

View File

@ -3,7 +3,20 @@
struct mp_image_pool;
// keep in sync with --hwdec option
enum hwdec_type {
HWDEC_AUTO = -1,
HWDEC_NONE = 0,
HWDEC_VDPAU = 1,
HWDEC_VDA = 2,
HWDEC_VAAPI = 4,
HWDEC_VAAPI_COPY = 5,
HWDEC_DXVA2_COPY = 6,
};
struct mp_hwdec_ctx {
enum hwdec_type type;
void *priv; // for free use by hwdec implementation
// API-specific, not needed by all backends.

View File

@ -89,6 +89,7 @@ static int create(struct gl_hwdec *hw)
return -1;
hw->hwctx = &p->hwctx;
hw->hwctx->type = HWDEC_VDA;
hw->hwctx->download_image = download_image;
GL *gl = hw->gl;

View File

@ -27,8 +27,6 @@
#include "gl_video.h"
#include "gl_hwdec.h"
#include "video/decode/lavc.h" // HWDEC_* values
#include "libmpv/opengl_cb.h"
/*

View File

@ -130,6 +130,7 @@ struct mp_vaapi_ctx *va_initialize(VADisplay *display, struct mp_log *plog)
.log = talloc_steal(res, log),
.display = display,
.hwctx = {
.type = HWDEC_VAAPI,
.priv = res,
.vaapi_ctx = res,
.download_image = ctx_download_image,

View File

@ -371,6 +371,7 @@ struct mp_vdpau_ctx *mp_vdpau_create_device_x11(struct mp_log *log, Display *x11
.x11 = x11,
.preemption_counter = 1,
.hwctx = {
.type = HWDEC_VDPAU,
.priv = ctx,
.vdpau_ctx = ctx,
.download_image = download_image,