frame = CONTEXT(s, ctx_id)->frame;
pctx = CONTEXT(s, ctx_id)->parser_ctx;
- if(!avctx || !avctx->codec || !frame) {
+ if (!avctx || !avctx->codec || !frame) {
ERR("critical error !!!\n");
assert(0);
}
return NULL;
}
+#if LIBAVUTIL_VERSION_CHECK
resample_frame = avcodec_alloc_frame();
+#else
+ resample_frame = av_frame_alloc();
+#endif
TRACE("resample audio. nb_samples %d sample_fmt %d\n", resample_nb_samples, resample_sample_fmt);
*resample_buffer_size = av_samples_get_buffer_size(NULL, avctx->channels, resample_nb_samples, resample_sample_fmt, 0);
return avcodec_default_get_format(avctx, pi_fmt);
}
-static int get_buffer(struct AVCodecContext *avctx, AVFrame *frame) {
+#if LIBAVCODEC_VERSION_CHECK
+static int get_buffer(struct AVCodecContext *avctx, AVFrame *frame)
+#else
+static int get_buffer(struct AVCodecContext *avctx, AVFrame *frame, int flags)
+#endif
+{
CodecContext *context = (CodecContext *)avctx->opaque;
if (context->is_hwaccel) {
return context->state->hwaccel_plugin->get_buffer(avctx, frame);
}
+#if LIBAVCODEC_VERSION_CHECK
return avcodec_default_get_buffer(avctx, frame);
+#else
+ return avcodec_default_get_buffer2(avctx, frame, flags);
+#endif
}
-static void release_buffer(struct AVCodecContext *avctx, AVFrame *frame) {
+#if LIBAVCODEC_VERSION_CHECK
+static void release_buffer(struct AVCodecContext *avctx, AVFrame *frame)
+{
CodecContext *context = (CodecContext *)avctx->opaque;
if (context->is_hwaccel) {
return avcodec_default_release_buffer(avctx, frame);
}
+#endif
// allocate avcontext and avframe struct.
static AVCodecContext *maru_brill_codec_alloc_context(MaruBrillCodecState *s, int ctx_id)
AVCodecContext *avctx = CONTEXT(s, ctx_id)->avctx;
avctx->get_format = get_format;
+#if LIBAVCODEC_VERSION_CHECK
avctx->get_buffer = get_buffer;
avctx->reget_buffer = avcodec_default_reget_buffer;
avctx->release_buffer = release_buffer;
- avctx->opaque = CONTEXT(s, ctx_id);
+#else
+ avctx->get_buffer2 = get_buffer;
+#endif
+#if LIBAVUTIL_VERSION_CHECK
CONTEXT(s, ctx_id)->frame = avcodec_alloc_frame();
+#else
+ CONTEXT(s, ctx_id)->frame = av_frame_alloc();
+#endif
+ avctx->opaque = CONTEXT(s, ctx_id);
+
CONTEXT(s, ctx_id)->opened_context = false;
CONTEXT(s, ctx_id)->state = s;
}
switch (avctx->codec_id) {
- case CODEC_ID_MPEG4:
- case CODEC_ID_VC1:
+ case AV_CODEC_ID_MPEG4:
+ case AV_CODEC_ID_VC1:
TRACE("not using parser\n");
break;
- case CODEC_ID_H264:
+ case AV_CODEC_ID_H264:
if (avctx->extradata_size == 0) {
TRACE("H.264 with no extradata, creating parser.\n");
parser = av_parser_init (avctx->codec_id);
if (frame) {
TRACE("free frame\n");
+#if LIBAVUTIL_VERSION_CHECK
avcodec_free_frame(&frame);
+#else
+ av_frame_free(&frame);
+#endif
}
if (avctx) {
#include "stdbool.h"
+#ifndef LIBAVCODEC_VERSION_CHECK
+#define LIBAVCODEC_VERSION_CHECK (LIBAVCODEC_VERSION_MAJOR < 55)
+#endif
+
+#ifndef LIBAVUTIL_VERSION_CHECK
+#define LIBAVUTIL_VERSION_CHECK (LIBAVUTIL_VERSION_MAJOR < 53)
+#endif
+
extern void *get_plugin_context(AVCodecContext *avctx);
extern void set_plugin_context(AVCodecContext *avctx, void *plugin_context);
void *(*setup)(AVCodecContext *, int , int);
void (*cleanup)(void *);
int (*get_buffer)(struct AVCodecContext *, AVFrame *);
+#if LIBAVCODEC_VERSION_CHECK
void (*release_buffer)(struct AVCodecContext *, AVFrame *);
+#endif
void (*get_picture)(void *dst, void *src);
} CodecPlugin;
#define DEFAULT_SURFACE_COUNT 4
+#include "debug_ch.h"
+
+/* define debug channel */
+MULTI_DEBUG_CHANNEL(qemu, vaapi);
+
struct SurfaceState;
typedef struct SurfaceState SurfaceState;
Display *display = XOpenDisplay(NULL);
if (!display)
{
- printf("Could not connect to x server\n");
+ ERR("Could not connect to x server\n");
return false;
}
va_display = _vaGetDisplay(display);
if (!va_display)
{
- printf("Could not get a VAAPI device\n");
+ ERR("Could not get a VAAPI device\n");
return false;
}
if (_vaInitialize(va_display, &va_major_version, &va_minor_version))
{
va_display = NULL;
- printf("Failed to initialize the VAAPI device\n");
+ ERR("Failed to initialize the VAAPI device\n");
return false;
}
}
// we initialize vaapi now for sure...
if (!initialize()) {
- printf("Can not initialize VA-API\n");
+ ERR("Can not initialize VA-API\n");
return false;
}
return true;
error:
- printf("plugin load failed : %s\n", dlerror());
+ ERR("plugin load failed : %s\n", dlerror());
return false;
}
goto error;
}
#else
- printf("Can not run with VA-API version (%d, %d)\n", va_major_version, va_minor_version);
+ ERR("Can not run with VA-API version (%d, %d)\n", va_major_version, va_minor_version);
goto error;
#endif
} else {
if (((_vaCreateSurfaces6)_vaCreateSurfaces)(va_ctx->display, width, height, VA_RT_FORMAT_YUV420,
va_ctx->surface_count, va_ctx->surface_id)) {
+ ERR("Can not run with VA-API version (%d, %d)\n", va_major_version, va_minor_version);
goto error;
}
}
for (i = 0; i < fmt_count; ++i) {
if (p_fmt[i].fourcc == VA_FOURCC_YV12) { // we support only VA_FOURCC_YV12 for now...
- if (_vaCreateImage(va_ctx->display, &p_fmt[i], width, height, &va_ctx->image )) {
+ if (_vaCreateImage(va_ctx->display, &p_fmt[i], width, height, &va_ctx->image)) {
goto error;
}
}
}
g_free(p_fmt);
-
return 0;
error:
}
-static void *setup(AVCodecContext *ctx, int width, int height) {
+static void *setup(AVCodecContext *ctx, int width, int height)
+{
VAPluginContext *va_ctx = g_malloc0(sizeof(VAPluginContext));
va_ctx->display = va_display;
VAProfile profile;
int codec_id = ctx->codec_id;
+
switch(codec_id)
{
case AV_CODEC_ID_MPEG1VIDEO:
}
}
g_free(profiles_list);
- if (!is_supported_profile)
- {
- printf("Codec and profile not supported by the VAAPI device");
+
+ if (!is_supported_profile) {
+ ERR("Codec and profile not supported by the VAAPI device");
goto error;
}
- if(create_surfaces(va_ctx, width, height, profile)) {
- printf("Failed to initialize the VAAPI device\n");
+ if (create_surfaces(va_ctx, width, height, profile)) {
+ ERR("Failed to initialize the VAAPI device\n");
goto error;
}
return;
}
+#if LIBAVCODEC_VERSION_CHECK
+static void release_surface(AVCodecContext *ctx, AVFrame *frame)
+{
+ int i;
+
+ for (i = 0; i < 4; ++i) {
+ frame->data[i] = NULL;
+ }
+
+ ((SurfaceState *)frame->opaque)->is_occupied = false;
+}
+#else
+static void release_surface(void *opaque, uint8_t *data)
+{
+ ((SurfaceState *)opaque)->is_occupied = false;
+}
+#endif
+
static int get_surface(AVCodecContext *ctx,
AVFrame *frame)
{
frame->data[0] = (void *)(uintptr_t)va_ctx->surface_id[i];
frame->data[3] = frame->data[0];
- frame->type = FF_BUFFER_TYPE_USER;
frame->opaque = (void *)&(va_ctx->surface_state[i]);
- return 0;
-}
-
-static void release_surface(AVCodecContext *ctx,
- AVFrame *frame)
-{
- int i;
-
- for (i = 0; i < 4; ++i) {
- frame->data[i] = NULL;
+#if LIBAVCODEC_VERSION_CHECK
+ frame->type = FF_BUFFER_TYPE_USER;
+#else
+ frame->buf[0] = av_buffer_create(frame->data[0], 0, release_surface, frame->opaque, 0);
+ if (!frame->buf[0]) {
+ ERR("failed to create AVBufferRef\n");
}
+#endif
- ((SurfaceState *)frame->opaque)->is_occupied = false;
+ return 0;
}
CodecPlugin vaapi_plugin = {
.setup = setup,
.cleanup = cleanup,
.get_buffer = get_surface,
+#if LIBAVCODEC_VERSION_CHECK
.release_buffer = release_surface,
+#endif
.get_picture = extract,
};
*
*/
+#if 0
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x600
#else
# define _WIN32_WINNT 0x600
# endif
#endif
+#endif
#define DXVA2API_USE_BITFIELDS
#define COBJMACROS
#include "debug_ch.h"
/* define debug channel */
-MULTI_DEBUG_CHANNEL(qemu, dxva2_plugin);
+MULTI_DEBUG_CHANNEL(qemu, dxva2);
MS_GUID(IID_IDirectXVideoDecoderService, 0xfc51a551, 0xd5e7, 0x11d9, 0xaf,0x55,0x00,0x05,0x4e,0x43,0xff,0x02);
return dxva_ctx;
}
+#if LIBAVCODEC_VERSION_CHECK
+static void dxva_release_surface(AVCodecContext *dec_ctx, AVFrame *frame)
+{
+ DXVAPluginSurface *surface = NULL;
+ unsigned int i;
+
+ for (i = 0; i < 4; ++i) {
+ frame->data[i] = NULL;
+ }
+
+ surface = frame->opaque;
+ surface->is_occupied = false;
+}
+#else
+static void dxva_release_surface(void *opaque, uint8_t *data)
+{
+ ((DXVAPluginSurface *)opaque)->is_occupied = false;
+}
+#endif
+
static int dxva_get_surface(AVCodecContext *dec_ctx, AVFrame *frame)
{
unsigned i = 0;
frame->data[0] = (void *)surface->d3d;
frame->data[3] = frame->data[0];
- frame->type = FF_BUFFER_TYPE_USER;
- frame->opaque = surface;
-
- return 0;
-}
-static void dxva_release_surface(AVCodecContext *dec_ctx, AVFrame *frame)
-{
- DXVAPluginSurface *surface = NULL;
- unsigned int i;
+ frame->opaque = surface;
- for (i = 0; i < 4; ++i) {
- frame->data[i] = NULL;
+#if LIBAVCODEC_VERSION_CHECK
+ frame->type = FF_BUFFER_TYPE_USER;
+#else
+ frame->buf[0] = av_buffer_create(frame->data[0], 0, dxva_release_surface, frame->opaque, 0);
+ if (!frame->buf[0]) {
+ ERR("failed to create AVBufferRef\n");
}
+#endif
- surface = frame->opaque;
- surface->is_occupied = false;
+ return 0;
}
static void extract(void *dst, void *src)
.setup = dxva_setup,
.cleanup = cleanup,
.get_buffer = dxva_get_surface,
+#if LIBAVCODEC_VERSION_CHECK
.release_buffer = dxva_release_surface,
+#endif
.get_picture = extract,
};