[FFmpeg-cvslog] vdpau: store picture data in picture's rather than codec's context
Rémi Denis-Courmont
git at videolan.org
Tue Aug 6 14:30:08 CEST 2013
ffmpeg | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Jul 25 22:30:20 2013 +0300| [2852740e23f91d6775714d7cc29b9a73e1111ce0] | committer: Anton Khirnov
vdpau: store picture data in picture's rather than codec's context
Signed-off-by: Anton Khirnov <anton at khirnov.net>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2852740e23f91d6775714d7cc29b9a73e1111ce0
---
libavcodec/Makefile | 2 +-
libavcodec/vdpau.c | 33 ++++++++++++++++++---------------
libavcodec/vdpau_h264.c | 31 ++++++++++++++++++-------------
libavcodec/vdpau_internal.h | 28 +++++++++++++++++++++++++---
libavcodec/vdpau_mpeg12.c | 21 +++++++++++++--------
libavcodec/vdpau_mpeg4.c | 11 +++++++----
libavcodec/vdpau_vc1.c | 18 ++++++++++++------
7 files changed, 94 insertions(+), 50 deletions(-)
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index d9c6e33..c58d18a 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -680,7 +680,7 @@ SKIPHEADERS-$(CONFIG_LIBSCHROEDINGER) += libschroedinger.h
SKIPHEADERS-$(CONFIG_MPEG_XVMC_DECODER) += xvmc.h
SKIPHEADERS-$(CONFIG_VAAPI) += vaapi_internal.h
SKIPHEADERS-$(CONFIG_VDA) += vda.h
-SKIPHEADERS-$(CONFIG_VDPAU) += vdpau.h
+SKIPHEADERS-$(CONFIG_VDPAU) += vdpau.h vdpau_internal.h
EXAMPLES = api
diff --git a/libavcodec/vdpau.c b/libavcodec/vdpau.c
index b6bb7ba..9bcbc2e 100644
--- a/libavcodec/vdpau.c
+++ b/libavcodec/vdpau.c
@@ -38,13 +38,15 @@
* @{
*/
-int ff_vdpau_common_start_frame(AVCodecContext *avctx,
+int ff_vdpau_common_start_frame(Picture *pic,
av_unused const uint8_t *buffer,
av_unused uint32_t size)
{
- AVVDPAUContext *hwctx = avctx->hwaccel_context;
+ struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
- hwctx->bitstream_buffers_used = 0;
+ pic_ctx->bitstream_buffers_allocated = 0;
+ pic_ctx->bitstream_buffers_used = 0;
+ pic_ctx->bitstream_buffers = NULL;
return 0;
}
@@ -55,31 +57,32 @@ int ff_vdpau_mpeg_end_frame(AVCodecContext *avctx)
{
AVVDPAUContext *hwctx = avctx->hwaccel_context;
MpegEncContext *s = avctx->priv_data;
- VdpVideoSurface surf = ff_vdpau_get_surface_id(s->current_picture_ptr);
+ Picture *pic = s->current_picture_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_mpeg_draw_horiz_band(s, 0, s->avctx->height);
- hwctx->bitstream_buffers_used = 0;
+ av_freep(&pic_ctx->bitstream_buffers);
return 0;
}
#endif
-int ff_vdpau_add_buffer(AVCodecContext *avctx,
- const uint8_t *buf, uint32_t size)
+int ff_vdpau_add_buffer(Picture *pic, const uint8_t *buf, uint32_t size)
{
- AVVDPAUContext *hwctx = avctx->hwaccel_context;
- VdpBitstreamBuffer *buffers = hwctx->bitstream_buffers;
+ struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
+ VdpBitstreamBuffer *buffers = pic_ctx->bitstream_buffers;
- buffers = av_fast_realloc(buffers, &hwctx->bitstream_buffers_allocated,
- (hwctx->bitstream_buffers_used + 1) * sizeof(*buffers));
+ buffers = av_fast_realloc(buffers, &pic_ctx->bitstream_buffers_allocated,
+ (pic_ctx->bitstream_buffers_used + 1) * sizeof(*buffers));
if (!buffers)
return AVERROR(ENOMEM);
- hwctx->bitstream_buffers = buffers;
- buffers += hwctx->bitstream_buffers_used++;
+ pic_ctx->bitstream_buffers = buffers;
+ buffers += pic_ctx->bitstream_buffers_used++;
buffers->struct_version = VDP_BITSTREAM_BUFFER_VERSION;
buffers->bitstream = buf;
diff --git a/libavcodec/vdpau_h264.c b/libavcodec/vdpau_h264.c
index e787762..3e84644 100644
--- a/libavcodec/vdpau_h264.c
+++ b/libavcodec/vdpau_h264.c
@@ -66,8 +66,8 @@ 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];
@@ -118,9 +118,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;
+ struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
+ VdpPictureInfoH264 *info = &pic_ctx->info.h264;
/* init VdpPictureInfoH264 */
info->slice_count = 0;
@@ -161,7 +161,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, buffer, size);
}
static const uint8_t start_code_prefix[3] = { 0x00, 0x00, 0x01 };
@@ -169,18 +169,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;
+ Picture *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, start_code_prefix, 3);
if (val)
return val;
- val = ff_vdpau_add_buffer(avctx, buffer, size);
+ val = ff_vdpau_add_buffer(pic, buffer, size);
if (val)
return val;
- hwctx->info.h264.slice_count++;
+ pic_ctx->info.h264.slice_count++;
return 0;
}
@@ -188,13 +190,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);
+ Picture *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 +211,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),
};
diff --git a/libavcodec/vdpau_internal.h b/libavcodec/vdpau_internal.h
index c03c1ff..e93c672 100644
--- a/libavcodec/vdpau_internal.h
+++ b/libavcodec/vdpau_internal.h
@@ -25,6 +25,7 @@
#define AVCODEC_VDPAU_INTERNAL_H
#include <stdint.h>
+#include <vdpau/vdpau.h>
#include "h264.h"
#include "mpegvideo.h"
@@ -34,10 +35,31 @@ static inline uintptr_t ff_vdpau_get_surface_id(Picture *pic)
return (uintptr_t)pic->f.data[3];
}
-int ff_vdpau_common_start_frame(AVCodecContext *avctx,
+struct vdpau_picture_context {
+ /**
+ * VDPAU picture information.
+ */
+ union AVVDPAUPictureInfo info;
+
+ /**
+ * Allocated size of the bitstream_buffers table.
+ */
+ int bitstream_buffers_allocated;
+
+ /**
+ * Useful bitstream buffers in the bitstream buffers table.
+ */
+ int bitstream_buffers_used;
+
+ /**
+ * Table of bitstream buffers.
+ */
+ VdpBitstreamBuffer *bitstream_buffers;
+};
+
+int ff_vdpau_common_start_frame(Picture *pic,
const uint8_t *buffer, uint32_t size);
int ff_vdpau_mpeg_end_frame(AVCodecContext *avctx);
-int ff_vdpau_add_buffer(AVCodecContext *avctx,
- const uint8_t *buf, uint32_t buf_size);
+int ff_vdpau_add_buffer(Picture *pic, const uint8_t *buf, uint32_t buf_size);
#endif /* AVCODEC_VDPAU_INTERNAL_H */
diff --git a/libavcodec/vdpau_mpeg12.c b/libavcodec/vdpau_mpeg12.c
index 20031ea..426d580 100644
--- a/libavcodec/vdpau_mpeg12.c
+++ b/libavcodec/vdpau_mpeg12.c
@@ -31,8 +31,9 @@ static int vdpau_mpeg_start_frame(AVCodecContext *avctx,
const uint8_t *buffer, uint32_t size)
{
MpegEncContext * const s = avctx->priv_data;
- AVVDPAUContext *hwctx = avctx->hwaccel_context;
- VdpPictureInfoMPEG1Or2 *info = &hwctx->info.mpeg;
+ Picture *pic = s->current_picture_ptr;
+ struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
+ VdpPictureInfoMPEG1Or2 *info = &pic_ctx->info.mpeg;
VdpVideoSurface ref;
int i;
@@ -44,11 +45,11 @@ static int vdpau_mpeg_start_frame(AVCodecContext *avctx,
case AV_PICTURE_TYPE_B:
ref = ff_vdpau_get_surface_id(&s->next_picture);
assert(ref != VDP_INVALID_HANDLE);
- hwctx->info.mpeg.backward_reference = ref;
+ info->backward_reference = ref;
/* fall through to forward prediction */
case AV_PICTURE_TYPE_P:
ref = ff_vdpau_get_surface_id(&s->last_picture);
- hwctx->info.mpeg.forward_reference = ref;
+ info->forward_reference = ref;
}
info->slice_count = 0;
@@ -74,20 +75,22 @@ static int vdpau_mpeg_start_frame(AVCodecContext *avctx,
info->non_intra_quantizer_matrix[i] = s->inter_matrix[i];
}
- return ff_vdpau_common_start_frame(avctx, buffer, size);
+ return ff_vdpau_common_start_frame(pic, buffer, size);
}
static int vdpau_mpeg_decode_slice(AVCodecContext *avctx,
const uint8_t *buffer, uint32_t size)
{
- AVVDPAUContext *hwctx = avctx->hwaccel_context;
+ MpegEncContext * const s = avctx->priv_data;
+ Picture *pic = s->current_picture_ptr;
+ struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
int val;
- val = ff_vdpau_add_buffer(avctx, buffer, size);
+ val = ff_vdpau_add_buffer(pic, buffer, size);
if (val < 0)
return val;
- hwctx->info.mpeg.slice_count++;
+ pic_ctx->info.mpeg.slice_count++;
return 0;
}
@@ -100,6 +103,7 @@ AVHWAccel ff_mpeg1_vdpau_hwaccel = {
.start_frame = vdpau_mpeg_start_frame,
.end_frame = ff_vdpau_mpeg_end_frame,
.decode_slice = vdpau_mpeg_decode_slice,
+ .priv_data_size = sizeof(struct vdpau_picture_context),
};
#endif
@@ -112,5 +116,6 @@ AVHWAccel ff_mpeg2_vdpau_hwaccel = {
.start_frame = vdpau_mpeg_start_frame,
.end_frame = ff_vdpau_mpeg_end_frame,
.decode_slice = vdpau_mpeg_decode_slice,
+ .priv_data_size = sizeof(struct vdpau_picture_context),
};
#endif
diff --git a/libavcodec/vdpau_mpeg4.c b/libavcodec/vdpau_mpeg4.c
index 6555872..8ccb3d6 100644
--- a/libavcodec/vdpau_mpeg4.c
+++ b/libavcodec/vdpau_mpeg4.c
@@ -31,8 +31,9 @@ static int vdpau_mpeg4_start_frame(AVCodecContext *avctx,
const uint8_t *buffer, uint32_t size)
{
MpegEncContext * const s = avctx->priv_data;
- AVVDPAUContext *hwctx = avctx->hwaccel_context;
- VdpPictureInfoMPEG4Part2 *info = &hwctx->info.mpeg4;
+ Picture *pic = s->current_picture_ptr;
+ struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
+ VdpPictureInfoMPEG4Part2 *info = &pic_ctx->info.mpeg4;
VdpVideoSurface ref;
int i;
@@ -74,8 +75,8 @@ static int vdpau_mpeg4_start_frame(AVCodecContext *avctx,
info->non_intra_quantizer_matrix[i] = s->inter_matrix[i];
}
- ff_vdpau_common_start_frame(avctx, buffer, size);
- return ff_vdpau_add_buffer(avctx, buffer, size);
+ ff_vdpau_common_start_frame(pic, buffer, size);
+ return ff_vdpau_add_buffer(pic, buffer, size);
}
static int vdpau_mpeg4_decode_slice(av_unused AVCodecContext *avctx,
@@ -94,6 +95,7 @@ AVHWAccel ff_h263_vdpau_hwaccel = {
.start_frame = vdpau_mpeg4_start_frame,
.end_frame = ff_vdpau_mpeg_end_frame,
.decode_slice = vdpau_mpeg4_decode_slice,
+ .priv_data_size = sizeof(struct vdpau_picture_context),
};
#endif
@@ -106,5 +108,6 @@ AVHWAccel ff_mpeg4_vdpau_hwaccel = {
.start_frame = vdpau_mpeg4_start_frame,
.end_frame = ff_vdpau_mpeg_end_frame,
.decode_slice = vdpau_mpeg4_decode_slice,
+ .priv_data_size = sizeof(struct vdpau_picture_context),
};
#endif
diff --git a/libavcodec/vdpau_vc1.c b/libavcodec/vdpau_vc1.c
index 57d50fb..c21a861 100644
--- a/libavcodec/vdpau_vc1.c
+++ b/libavcodec/vdpau_vc1.c
@@ -32,9 +32,10 @@ static int vdpau_vc1_start_frame(AVCodecContext *avctx,
const uint8_t *buffer, uint32_t size)
{
VC1Context * const v = avctx->priv_data;
- AVVDPAUContext *hwctx = avctx->hwaccel_context;
MpegEncContext * const s = &v->s;
- VdpPictureInfoVC1 *info = &hwctx->info.vc1;
+ Picture *pic = s->current_picture_ptr;
+ struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
+ VdpPictureInfoVC1 *info = &pic_ctx->info.vc1;
VdpVideoSurface ref;
/* fill LvPictureInfoVC1 struct */
@@ -88,20 +89,23 @@ static int vdpau_vc1_start_frame(AVCodecContext *avctx,
info->deblockEnable = v->postprocflag & 1;
info->pquant = v->pq;
- return ff_vdpau_common_start_frame(avctx, buffer, size);
+ return ff_vdpau_common_start_frame(pic, buffer, size);
}
static int vdpau_vc1_decode_slice(AVCodecContext *avctx,
const uint8_t *buffer, uint32_t size)
{
- AVVDPAUContext *hwctx = avctx->hwaccel_context;
+ VC1Context * const v = avctx->priv_data;
+ MpegEncContext * const s = &v->s;
+ Picture *pic = s->current_picture_ptr;
+ struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
int val;
- val = ff_vdpau_add_buffer(avctx, buffer, size);
+ val = ff_vdpau_add_buffer(pic, buffer, size);
if (val < 0)
return val;
- hwctx->info.vc1.slice_count++;
+ pic_ctx->info.vc1.slice_count++;
return 0;
}
@@ -114,6 +118,7 @@ AVHWAccel ff_wmv3_vdpau_hwaccel = {
.start_frame = vdpau_vc1_start_frame,
.end_frame = ff_vdpau_mpeg_end_frame,
.decode_slice = vdpau_vc1_decode_slice,
+ .priv_data_size = sizeof(struct vdpau_picture_context),
};
#endif
@@ -125,4 +130,5 @@ AVHWAccel ff_vc1_vdpau_hwaccel = {
.start_frame = vdpau_vc1_start_frame,
.end_frame = ff_vdpau_mpeg_end_frame,
.decode_slice = vdpau_vc1_decode_slice,
+ .priv_data_size = sizeof(struct vdpau_picture_context),
};
More information about the ffmpeg-cvslog
mailing list