vdpau: don't assume Picture and H264Picture are the same
[ffmpeg.git] / libavcodec / vdpau_h264.c
index e787762..c71d6b8 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "avcodec.h"
 #include "h264.h"
+#include "mpegutils.h"
 #include "vdpau.h"
 #include "vdpau_internal.h"
 
@@ -46,7 +47,7 @@ static void vdpau_h264_clear_rf(VdpReferenceFrameH264 *rf)
     rf->frame_idx           = 0;
 }
 
-static void vdpau_h264_set_rf(VdpReferenceFrameH264 *rf, Picture *pic,
+static void vdpau_h264_set_rf(VdpReferenceFrameH264 *rf, H264Picture *pic,
                               int pic_structure)
 {
     VdpVideoSurface surface = ff_vdpau_get_surface_id(pic);
@@ -66,19 +67,19 @@ static void vdpau_h264_set_rf(VdpReferenceFrameH264 *rf, Picture *pic,
 static void vdpau_h264_set_reference_frames(AVCodecContext *avctx)
 {
     H264Context * const h = avctx->priv_data;
-    AVVDPAUContext *hwctx = avctx->hwaccel_context;
-    VdpPictureInfoH264 *info = &hwctx->info.h264;
+    struct vdpau_picture_context *pic_ctx = h->cur_pic_ptr->hwaccel_picture_private;
+    VdpPictureInfoH264 *info = &pic_ctx->info.h264;
     int list;
 
     VdpReferenceFrameH264 *rf = &info->referenceFrames[0];
 #define H264_RF_COUNT FF_ARRAY_ELEMS(info->referenceFrames)
 
     for (list = 0; list < 2; ++list) {
-        Picture **lp = list ? h->long_ref : h->short_ref;
+        H264Picture **lp = list ? h->long_ref : h->short_ref;
         int i, ls    = list ? 16          : h->short_ref_count;
 
         for (i = 0; i < ls; ++i) {
-            Picture *pic = lp[i];
+            H264Picture *pic = lp[i];
             VdpReferenceFrameH264 *rf2;
             VdpVideoSurface surface_ref;
             int pic_frame_idx;
@@ -118,9 +119,9 @@ static int vdpau_h264_start_frame(AVCodecContext *avctx,
                                   const uint8_t *buffer, uint32_t size)
 {
     H264Context * const h = avctx->priv_data;
-    AVVDPAUContext *hwctx = avctx->hwaccel_context;
-    VdpPictureInfoH264 *info = &hwctx->info.h264;
-    Picture *pic = h->cur_pic_ptr;
+    H264Picture *pic = h->cur_pic_ptr;
+    struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
+    VdpPictureInfoH264 *info = &pic_ctx->info.h264;
 
     /* init VdpPictureInfoH264 */
     info->slice_count                            = 0;
@@ -161,7 +162,7 @@ static int vdpau_h264_start_frame(AVCodecContext *avctx,
 
     vdpau_h264_set_reference_frames(avctx);
 
-    return ff_vdpau_common_start_frame(avctx, buffer, size);
+    return ff_vdpau_common_start_frame(pic_ctx, buffer, size);
 }
 
 static const uint8_t start_code_prefix[3] = { 0x00, 0x00, 0x01 };
@@ -169,18 +170,20 @@ static const uint8_t start_code_prefix[3] = { 0x00, 0x00, 0x01 };
 static int vdpau_h264_decode_slice(AVCodecContext *avctx,
                                    const uint8_t *buffer, uint32_t size)
 {
-    AVVDPAUContext *hwctx = avctx->hwaccel_context;
+    H264Context *h = avctx->priv_data;
+    H264Picture *pic = h->cur_pic_ptr;
+    struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
     int val;
 
-    val = ff_vdpau_add_buffer(avctx, start_code_prefix, 3);
+    val = ff_vdpau_add_buffer(pic_ctx, start_code_prefix, 3);
     if (val)
         return val;
 
-    val = ff_vdpau_add_buffer(avctx, buffer, size);
+    val = ff_vdpau_add_buffer(pic_ctx, buffer, size);
     if (val)
         return val;
 
-    hwctx->info.h264.slice_count++;
+    pic_ctx->info.h264.slice_count++;
     return 0;
 }
 
@@ -188,13 +191,15 @@ static int vdpau_h264_end_frame(AVCodecContext *avctx)
 {
     AVVDPAUContext *hwctx = avctx->hwaccel_context;
     H264Context *h = avctx->priv_data;
-    VdpVideoSurface surf = ff_vdpau_get_surface_id(h->cur_pic_ptr);
+    H264Picture *pic = h->cur_pic_ptr;
+    struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
+    VdpVideoSurface surf = ff_vdpau_get_surface_id(pic);
 
-    hwctx->render(hwctx->decoder, surf, (void *)&hwctx->info,
-                  hwctx->bitstream_buffers_used, hwctx->bitstream_buffers);
+    hwctx->render(hwctx->decoder, surf, (void *)&pic_ctx->info,
+                  pic_ctx->bitstream_buffers_used, pic_ctx->bitstream_buffers);
 
     ff_h264_draw_horiz_band(h, 0, h->avctx->height);
-    hwctx->bitstream_buffers_used = 0;
+    av_freep(&pic_ctx->bitstream_buffers);
 
     return 0;
 }
@@ -207,4 +212,5 @@ AVHWAccel ff_h264_vdpau_hwaccel = {
     .start_frame    = vdpau_h264_start_frame,
     .end_frame      = vdpau_h264_end_frame,
     .decode_slice   = vdpau_h264_decode_slice,
+    .priv_data_size = sizeof(struct vdpau_picture_context),
 };