aboutsummaryrefslogtreecommitdiff
path: root/lib/ffmpeg/libavcodec
diff options
context:
space:
mode:
authorCrystalP <CrystalP@xbmc.org>2011-10-10 19:42:50 -0400
committerCrystalP <CrystalP@xbmc.org>2011-10-15 17:19:05 -0400
commit3274326600051dd9978a8ba889824b9fa94e4baa (patch)
tree5e68c7d7898fc01e5ec452665f757a4d594cc89b /lib/ffmpeg/libavcodec
parentdb66c987e276a74a9e210d28fb3e0e67d277e99a (diff)
dxva-mpeg2 speed up slice allocation
The number of slices is not very likely to change from frame to frame, so at the beginning of a new frame, allocate memory for the amount of slices of the previous frame. Saves a lot of reallocation, for some TV capture samples there are over 200 slices. There wasn't anywhere really appropriate to store last_slice_count (needs to live from first frame to last frame), so this is likely to cause discussion to merge upstream. Adding members to dxva_context breaks ABI, which we don't care too much about since on Windows we don't support external ffmpeg. dxva mpeg2 code also has access to MpegEncContext, but adding there would likely break ABI as well.
Diffstat (limited to 'lib/ffmpeg/libavcodec')
-rw-r--r--lib/ffmpeg/libavcodec/dxva2.h1
-rw-r--r--lib/ffmpeg/libavcodec/dxva2_mpeg2.c12
2 files changed, 13 insertions, 0 deletions
diff --git a/lib/ffmpeg/libavcodec/dxva2.h b/lib/ffmpeg/libavcodec/dxva2.h
index 6eb494b9fe..12dce4704b 100644
--- a/lib/ffmpeg/libavcodec/dxva2.h
+++ b/lib/ffmpeg/libavcodec/dxva2.h
@@ -65,6 +65,7 @@ struct dxva_context {
* Private to the FFmpeg AVHWAccel implementation
*/
unsigned report_id;
+ unsigned last_slice_count;
};
#endif /* AVCODEC_DXVA_H */
diff --git a/lib/ffmpeg/libavcodec/dxva2_mpeg2.c b/lib/ffmpeg/libavcodec/dxva2_mpeg2.c
index 9ac2d170b5..2482c2fa10 100644
--- a/lib/ffmpeg/libavcodec/dxva2_mpeg2.c
+++ b/lib/ffmpeg/libavcodec/dxva2_mpeg2.c
@@ -224,6 +224,16 @@ static int start_frame(AVCodecContext *avctx,
ctx_pic->slice_alloc = 0;
ctx_pic->bitstream_size = 0;
ctx_pic->bitstream = NULL;
+
+ if (ctx->last_slice_count > 0)
+ {
+ ctx_pic->slice = av_fast_realloc(NULL,
+ &ctx_pic->slice_alloc,
+ ctx->last_slice_count * sizeof(DXVA_SliceInfo));
+ if (!ctx_pic->slice)
+ return -1;
+ }
+
return 0;
}
@@ -258,6 +268,7 @@ static int end_frame(AVCodecContext *avctx)
struct MpegEncContext *s = avctx->priv_data;
struct dxva2_picture_context *ctx_pic =
s->current_picture_ptr->hwaccel_picture_private;
+ struct dxva_context *ctx = avctx->hwaccel_context;
if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0)
return -1;
@@ -266,6 +277,7 @@ static int end_frame(AVCodecContext *avctx)
&ctx_pic->qm, sizeof(ctx_pic->qm),
commit_bitstream_and_slice_buffer);
av_freep(ctx_pic->slice);
+ ctx->last_slice_count = ctx_pic->slice_count;
}
AVHWAccel ff_mpeg2_dxva2_hwaccel = {