brillcodec: remove deprecated libav APIs and use new functions. 31/32131/2
authorKitae Kim <kt920.kim@samsung.com>
Tue, 16 Dec 2014 04:42:02 +0000 (13:42 +0900)
committerKitae Kim <kt920.kim@samsung.com>
Tue, 16 Dec 2014 04:56:08 +0000 (13:56 +0900)
Change-Id: I5fcaa5ebb83500a295fe3269a6da2f04f1b7974d
Signed-off-by: Kitae Kim <kt920.kim@samsung.com>
tizen/src/hw/pci/maru_brillcodec.c
tizen/src/hw/pci/maru_brillcodec_plugin.h
tizen/src/hw/pci/maru_brillcodec_vaapi.c
tizen/src/hw/pci/maru_dxva2_plugin.c

index 5b0d1e97d33beb747c6c3fa55f4ebb5acdc67be0..331e3c8e744f65dcd9edd190402bd6e5570ac3e8 100644 (file)
@@ -1010,7 +1010,7 @@ static bool decode_video_common(MaruBrillCodecState *s, int ctx_id,
     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);
     }
@@ -1284,7 +1284,11 @@ static AVFrame *resample_audio(AVCodecContext *avctx, AVFrame *sample_frame,
         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);
@@ -1644,17 +1648,28 @@ end:
     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) {
@@ -1663,6 +1678,7 @@ static void release_buffer(struct AVCodecContext *avctx, AVFrame *frame) {
 
     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)
@@ -1675,12 +1691,21 @@ static AVCodecContext *maru_brill_codec_alloc_context(MaruBrillCodecState *s, in
 
     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;
 
@@ -1791,11 +1816,11 @@ static AVCodecParserContext *maru_brill_codec_parser_init(AVCodecContext *avctx)
     }
 
     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);
@@ -1940,7 +1965,11 @@ static bool deinit(MaruBrillCodecState *s, int ctx_id, void *data_buf)
 
     if (frame) {
         TRACE("free frame\n");
+#if LIBAVUTIL_VERSION_CHECK
         avcodec_free_frame(&frame);
+#else
+        av_frame_free(&frame);
+#endif
     }
 
     if (avctx) {
index cc3a485f1eef4f514376b1ad0a6addc07be88000..e82a7fb080aa37ce9d5292119710308f2c6cb0d7 100644 (file)
 
 #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);
 
@@ -44,7 +52,9 @@ typedef struct CodecPlugin {
     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;
 
index 62227d549f65138f9552f307372142c8ad3a03bc..460982bd6a9780d2c4fe513a92847407450b462b 100644 (file)
 
 #define DEFAULT_SURFACE_COUNT   4
 
+#include "debug_ch.h"
+
+/* define debug channel */
+MULTI_DEBUG_CHANNEL(qemu, vaapi);
+
 struct SurfaceState;
 typedef struct SurfaceState SurfaceState;
 
@@ -127,21 +132,21 @@ static bool initialize(void)
         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;
         }
     }
@@ -192,14 +197,14 @@ static bool probe(void)
 
     // 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;
 }
@@ -248,12 +253,13 @@ static int create_surfaces(VAPluginContext *va_ctx,
             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;
         }
     }
@@ -284,7 +290,7 @@ static int create_surfaces(VAPluginContext *va_ctx,
 
     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;
             }
         }
@@ -296,7 +302,6 @@ static int create_surfaces(VAPluginContext *va_ctx,
     }
 
     g_free(p_fmt);
-
     return 0;
 
 error:
@@ -329,13 +334,15 @@ static void cleanup(void *opaque)
 }
 
 
-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:
@@ -377,15 +384,15 @@ static void *setup(AVCodecContext *ctx, int width, int height) {
         }
     }
     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;
     }
 
@@ -502,6 +509,24 @@ static void extract(void* dst, void *src)
     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)
 {
@@ -520,23 +545,19 @@ static int get_surface(AVCodecContext *ctx,
 
     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 = {
@@ -547,6 +568,8 @@ CodecPlugin vaapi_plugin = {
     .setup = setup,
     .cleanup = cleanup,
     .get_buffer = get_surface,
+#if LIBAVCODEC_VERSION_CHECK
     .release_buffer = release_surface,
+#endif
     .get_picture = extract,
 };
index fca00646aee4a199981744e9306d65217fe7772b..3c3836908eb07d76b6a6aa47ce5b13469aff9d93 100644 (file)
@@ -27,6 +27,7 @@
  *
  */
 
+#if 0
 #ifndef _WIN32_WINNT
 #define _WIN32_WINNT 0x600
 #else
@@ -36,6 +37,7 @@
 #  define _WIN32_WINNT 0x600
 # endif
 #endif
+#endif
 
 #define DXVA2API_USE_BITFIELDS
 #define COBJMACROS
@@ -82,7 +84,7 @@
 #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);
@@ -880,6 +882,26 @@ static void *dxva_setup(AVCodecContext *dec_ctx, int width, int height)
     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;
@@ -909,23 +931,19 @@ static int dxva_get_surface(AVCodecContext *dec_ctx, AVFrame *frame)
 
     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)
@@ -1004,6 +1022,8 @@ CodecPlugin dxva_plugin = {
     .setup = dxva_setup,
     .cleanup = cleanup,
     .get_buffer = dxva_get_surface,
+#if LIBAVCODEC_VERSION_CHECK
     .release_buffer = dxva_release_surface,
+#endif
     .get_picture = extract,
 };