From dd428691ecefe6523a1c8cf63cbe581ce38cfd1b Mon Sep 17 00:00:00 2001 From: "Xiang, Haihao" Date: Thu, 27 Dec 2012 15:23:53 +0800 Subject: [PATCH] vaapi: VC-1 multi slices decoding Signed-off-by: Xiang, Haihao --- libavcodec/vaapi_vc1.c | 2 +- libavcodec/vc1dec.c | 49 +++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/libavcodec/vaapi_vc1.c b/libavcodec/vaapi_vc1.c index e5d5626..a279c82 100644 --- a/libavcodec/vaapi_vc1.c +++ b/libavcodec/vaapi_vc1.c @@ -336,7 +336,7 @@ static int vaapi_vc1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, if (!slice_param) return -1; slice_param->macroblock_offset = get_bits_count(&s->gb); - slice_param->slice_vertical_position = s->mb_y; + slice_param->slice_vertical_position = s->start_mb_y; return 0; } diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index 2fc4913..c202d1e 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -5313,6 +5313,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data, uint8_t *buf; GetBitContext gb; int mby_start; + uint8_t *slice_buf_start; } *slices = NULL, *tmp; if(s->flags & CODEC_FLAG_LOW_DELAY) @@ -5396,6 +5397,10 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data, init_get_bits(&slices[n_slices].gb, slices[n_slices].buf, buf_size3 << 3); slices[n_slices].mby_start = get_bits(&slices[n_slices].gb, 9); + + if (avctx->hwaccel) + slices[n_slices].slice_buf_start = start; + n_slices++; break; } @@ -5542,16 +5547,14 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data, s->me.qpel_avg = s->dsp.avg_qpel_pixels_tab; if ((CONFIG_VC1_VDPAU_DECODER) - &&s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) + &&s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) { ff_vdpau_vc1_decode_picture(s, buf_start, (buf + buf_size) - buf_start); - else if (avctx->hwaccel) { - if (avctx->hwaccel->start_frame(avctx, buf, buf_size) < 0) - goto err; - if (avctx->hwaccel->decode_slice(avctx, buf_start, (buf + buf_size) - buf_start) < 0) - goto err; - if (avctx->hwaccel->end_frame(avctx) < 0) - goto err; } else { + if (avctx->hwaccel) { + if (avctx->hwaccel->start_frame(avctx, buf, buf_size) < 0) + goto err; + } + ff_er_frame_start(s); v->bits = buf_size * 8; @@ -5612,7 +5615,29 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data, av_log(v->s.avctx, AV_LOG_ERROR, "end mb y %d %d invalid\n", s->end_mb_y, s->start_mb_y); continue; } - vc1_decode_blocks(v); + + if (avctx->hwaccel) { + if (i == 0) { + if (n_slices == 0) { + if (avctx->hwaccel->decode_slice(avctx, buf_start, (buf + buf_size) - buf_start) < 0) + goto err; + } else { + if (avctx->hwaccel->decode_slice(avctx, buf_start, slices[0].slice_buf_start - buf_start) < 0) + goto err; + } + } else { + if (i < n_slices) { + if (avctx->hwaccel->decode_slice(avctx, slices[i - 1].slice_buf_start, slices[i].slice_buf_start - slices[i - 1].slice_buf_start) < 0) + goto err; + } else { + if (avctx->hwaccel->decode_slice(avctx, slices[i - 1].slice_buf_start, (buf + buf_size) - slices[i - 1].slice_buf_start) < 0) + goto err; + } + } + } else { + vc1_decode_blocks(v); + } + if (i != n_slices) s->gb = slices[i].gb; } @@ -5633,8 +5658,14 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data, // return -1; if(s->error_occurred && s->pict_type == AV_PICTURE_TYPE_B) goto err; + if(!v->field_mode) ff_er_frame_end(s); + + if (avctx->hwaccel) { + if (avctx->hwaccel->end_frame(avctx) < 0) + goto err; + } } ff_MPV_frame_end(s); -- 1.7.9.5