|
|
@ -18,11 +18,6 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include <stdint.h> |
|
|
|
#include <stdint.h> |
|
|
|
|
|
|
|
|
|
|
|
#include <vdpau/vdpau.h> |
|
|
|
|
|
|
|
#include <vdpau/vdpau_x11.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <X11/Xlib.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "avconv.h" |
|
|
|
#include "avconv.h" |
|
|
|
|
|
|
|
|
|
|
|
#include "libavcodec/vdpau.h" |
|
|
|
#include "libavcodec/vdpau.h" |
|
|
@ -38,23 +33,6 @@ typedef struct VDPAUContext { |
|
|
|
AVFrame *tmp_frame; |
|
|
|
AVFrame *tmp_frame; |
|
|
|
} VDPAUContext; |
|
|
|
} VDPAUContext; |
|
|
|
|
|
|
|
|
|
|
|
typedef struct VDPAUHWDevicePriv { |
|
|
|
|
|
|
|
VdpDeviceDestroy *device_destroy; |
|
|
|
|
|
|
|
Display *dpy; |
|
|
|
|
|
|
|
} VDPAUHWDevicePriv; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void device_free(AVHWDeviceContext *ctx) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
AVVDPAUDeviceContext *hwctx = ctx->hwctx; |
|
|
|
|
|
|
|
VDPAUHWDevicePriv *priv = ctx->user_opaque; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (priv->device_destroy) |
|
|
|
|
|
|
|
priv->device_destroy(hwctx->device); |
|
|
|
|
|
|
|
if (priv->dpy) |
|
|
|
|
|
|
|
XCloseDisplay(priv->dpy); |
|
|
|
|
|
|
|
av_freep(&priv); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void vdpau_uninit(AVCodecContext *s) |
|
|
|
static void vdpau_uninit(AVCodecContext *s) |
|
|
|
{ |
|
|
|
{ |
|
|
|
InputStream *ist = s->opaque; |
|
|
|
InputStream *ist = s->opaque; |
|
|
@ -106,15 +84,8 @@ static int vdpau_alloc(AVCodecContext *s) |
|
|
|
InputStream *ist = s->opaque; |
|
|
|
InputStream *ist = s->opaque; |
|
|
|
int loglevel = (ist->hwaccel_id == HWACCEL_AUTO) ? AV_LOG_VERBOSE : AV_LOG_ERROR; |
|
|
|
int loglevel = (ist->hwaccel_id == HWACCEL_AUTO) ? AV_LOG_VERBOSE : AV_LOG_ERROR; |
|
|
|
VDPAUContext *ctx; |
|
|
|
VDPAUContext *ctx; |
|
|
|
const char *display, *vendor; |
|
|
|
|
|
|
|
VdpStatus err; |
|
|
|
|
|
|
|
int ret; |
|
|
|
int ret; |
|
|
|
|
|
|
|
|
|
|
|
VdpDevice device; |
|
|
|
|
|
|
|
VdpGetProcAddress *get_proc_address; |
|
|
|
|
|
|
|
VdpGetInformationString *get_information_string; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VDPAUHWDevicePriv *device_priv = NULL; |
|
|
|
|
|
|
|
AVBufferRef *device_ref = NULL; |
|
|
|
AVBufferRef *device_ref = NULL; |
|
|
|
AVHWDeviceContext *device_ctx; |
|
|
|
AVHWDeviceContext *device_ctx; |
|
|
|
AVVDPAUDeviceContext *device_hwctx; |
|
|
|
AVVDPAUDeviceContext *device_hwctx; |
|
|
@ -124,10 +95,6 @@ static int vdpau_alloc(AVCodecContext *s) |
|
|
|
if (!ctx) |
|
|
|
if (!ctx) |
|
|
|
return AVERROR(ENOMEM); |
|
|
|
return AVERROR(ENOMEM); |
|
|
|
|
|
|
|
|
|
|
|
device_priv = av_mallocz(sizeof(*device_priv)); |
|
|
|
|
|
|
|
if (!device_priv) |
|
|
|
|
|
|
|
goto fail; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ist->hwaccel_ctx = ctx; |
|
|
|
ist->hwaccel_ctx = ctx; |
|
|
|
ist->hwaccel_uninit = vdpau_uninit; |
|
|
|
ist->hwaccel_uninit = vdpau_uninit; |
|
|
|
ist->hwaccel_get_buffer = vdpau_get_buffer; |
|
|
|
ist->hwaccel_get_buffer = vdpau_get_buffer; |
|
|
@ -137,51 +104,12 @@ static int vdpau_alloc(AVCodecContext *s) |
|
|
|
if (!ctx->tmp_frame) |
|
|
|
if (!ctx->tmp_frame) |
|
|
|
goto fail; |
|
|
|
goto fail; |
|
|
|
|
|
|
|
|
|
|
|
device_priv->dpy = XOpenDisplay(ist->hwaccel_device); |
|
|
|
ret = av_hwdevice_ctx_create(&device_ref, AV_HWDEVICE_TYPE_VDPAU, |
|
|
|
if (!device_priv->dpy) { |
|
|
|
ist->hwaccel_device, NULL, 0); |
|
|
|
av_log(NULL, loglevel, "Cannot open the X11 display %s.\n", |
|
|
|
if (ret < 0) |
|
|
|
XDisplayName(ist->hwaccel_device)); |
|
|
|
|
|
|
|
goto fail; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
display = XDisplayString(device_priv->dpy); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err = vdp_device_create_x11(device_priv->dpy, XDefaultScreen(device_priv->dpy), |
|
|
|
|
|
|
|
&device, &get_proc_address); |
|
|
|
|
|
|
|
if (err != VDP_STATUS_OK) { |
|
|
|
|
|
|
|
av_log(NULL, loglevel, "VDPAU device creation on X11 display %s failed.\n", |
|
|
|
|
|
|
|
display); |
|
|
|
|
|
|
|
goto fail; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define GET_CALLBACK(id, result) \ |
|
|
|
|
|
|
|
do { \
|
|
|
|
|
|
|
|
void *tmp; \
|
|
|
|
|
|
|
|
err = get_proc_address(device, id, &tmp); \
|
|
|
|
|
|
|
|
if (err != VDP_STATUS_OK) { \
|
|
|
|
|
|
|
|
av_log(NULL, loglevel, "Error getting the " #id " callback.\n"); \
|
|
|
|
|
|
|
|
goto fail; \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
result = tmp; \
|
|
|
|
|
|
|
|
} while (0) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GET_CALLBACK(VDP_FUNC_ID_GET_INFORMATION_STRING, get_information_string); |
|
|
|
|
|
|
|
GET_CALLBACK(VDP_FUNC_ID_DEVICE_DESTROY, device_priv->device_destroy); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
device_ref = av_hwdevice_ctx_alloc(AV_HWDEVICE_TYPE_VDPAU); |
|
|
|
|
|
|
|
if (!device_ref) |
|
|
|
|
|
|
|
goto fail; |
|
|
|
goto fail; |
|
|
|
device_ctx = (AVHWDeviceContext*)device_ref->data; |
|
|
|
device_ctx = (AVHWDeviceContext*)device_ref->data; |
|
|
|
device_hwctx = device_ctx->hwctx; |
|
|
|
device_hwctx = device_ctx->hwctx; |
|
|
|
device_ctx->user_opaque = device_priv; |
|
|
|
|
|
|
|
device_ctx->free = device_free; |
|
|
|
|
|
|
|
device_hwctx->device = device; |
|
|
|
|
|
|
|
device_hwctx->get_proc_address = get_proc_address; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
device_priv = NULL; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ret = av_hwdevice_ctx_init(device_ref); |
|
|
|
|
|
|
|
if (ret < 0) |
|
|
|
|
|
|
|
goto fail; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx->hw_frames_ctx = av_hwframe_ctx_alloc(device_ref); |
|
|
|
ctx->hw_frames_ctx = av_hwframe_ctx_alloc(device_ref); |
|
|
|
if (!ctx->hw_frames_ctx) |
|
|
|
if (!ctx->hw_frames_ctx) |
|
|
@ -198,26 +126,17 @@ do { |
|
|
|
if (ret < 0) |
|
|
|
if (ret < 0) |
|
|
|
goto fail; |
|
|
|
goto fail; |
|
|
|
|
|
|
|
|
|
|
|
if (av_vdpau_bind_context(s, device, get_proc_address, 0)) |
|
|
|
if (av_vdpau_bind_context(s, device_hwctx->device, device_hwctx->get_proc_address, 0)) |
|
|
|
goto fail; |
|
|
|
goto fail; |
|
|
|
|
|
|
|
|
|
|
|
get_information_string(&vendor); |
|
|
|
av_log(NULL, AV_LOG_VERBOSE, "Using VDPAU to decode input stream #%d:%d.\n", |
|
|
|
av_log(NULL, AV_LOG_VERBOSE, "Using VDPAU -- %s -- on X11 display %s, " |
|
|
|
ist->file_index, ist->st->index); |
|
|
|
"to decode input stream #%d:%d.\n", vendor, |
|
|
|
|
|
|
|
display, ist->file_index, ist->st->index); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
|
|
fail: |
|
|
|
fail: |
|
|
|
av_log(NULL, loglevel, "VDPAU init failed for stream #%d:%d.\n", |
|
|
|
av_log(NULL, loglevel, "VDPAU init failed for stream #%d:%d.\n", |
|
|
|
ist->file_index, ist->st->index); |
|
|
|
ist->file_index, ist->st->index); |
|
|
|
if (device_priv) { |
|
|
|
|
|
|
|
if (device_priv->device_destroy) |
|
|
|
|
|
|
|
device_priv->device_destroy(device); |
|
|
|
|
|
|
|
if (device_priv->dpy) |
|
|
|
|
|
|
|
XCloseDisplay(device_priv->dpy); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
av_freep(&device_priv); |
|
|
|
|
|
|
|
av_buffer_unref(&device_ref); |
|
|
|
av_buffer_unref(&device_ref); |
|
|
|
vdpau_uninit(s); |
|
|
|
vdpau_uninit(s); |
|
|
|
return AVERROR(EINVAL); |
|
|
|
return AVERROR(EINVAL); |
|
|
|