Also constify lots of pointers.
---
Not very well tested because *someone* broke hwaccel decode with multiple
slices per frame. I think it passes FATE for the files with single-slice
frames.
I've only converted H.264 so far - the other codecs should be straightforward,
but I wanted to get some feedback on the first patch before doing them.
libavcodec/vaapi_h264.c | 85 ++++++++++++++++++++++++++-----------------------
1 file changed, 45 insertions(+), 40 deletions(-)
diff --git a/libavcodec/vaapi_h264.c b/libavcodec/vaapi_h264.c
index 931357a..8e30dcd 100644
--- a/libavcodec/vaapi_h264.c
+++ b/libavcodec/vaapi_h264.c
@@ -20,7 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "vaapi_internal.h"
+#include "vaapi_decode.h"
#include "h264dec.h"
#include "h264_ps.h"
#include "mpegutils.h"
@@ -52,9 +52,9 @@ static void init_vaapi_pic(VAPictureH264 *va_pic)
* @param[in] pic_structure The picture field type (as defined in
mpegvideo.h),
* supersedes pic's field type if nonzero.
*/
-static void fill_vaapi_pic(VAPictureH264 *va_pic,
- H264Picture *pic,
- int pic_structure)
+static void fill_vaapi_pic(VAPictureH264 *va_pic,
+ const H264Picture *pic,
+ int pic_structure)
{
if (pic_structure == 0)
pic_structure = pic->reference;
@@ -123,7 +123,7 @@ static int dpb_add(DPB *dpb, H264Picture *pic)
/** Fill in VA API reference frames array. */
static int fill_vaapi_ReferenceFrames(VAPictureParameterBufferH264 *pic_param,
- H264Context *h)
+ const H264Context *h)
{
DPB dpb;
int i;
@@ -156,9 +156,9 @@ static int
fill_vaapi_ReferenceFrames(VAPictureParameterBufferH264 *pic_param,
* @param[in] ref_list A pointer to the Libav reference list
* @param[in] ref_count The number of reference pictures in ref_list
*/
-static void fill_vaapi_RefPicList(VAPictureH264 RefPicList[32],
- H264Ref *ref_list,
- unsigned int ref_count)
+static void fill_vaapi_RefPicList(VAPictureH264 RefPicList[32],
+ const H264Ref *ref_list,
+ unsigned int ref_count)
{
unsigned int i, n = 0;
for (i = 0; i < ref_count; i++)
@@ -184,7 +184,7 @@ static void fill_vaapi_RefPicList(VAPictureH264
RefPicList[32],
* @param[out] chroma_weight VA API plain chroma weight table
* @param[out] chroma_offset VA API plain chroma offset table
*/
-static void fill_vaapi_plain_pred_weight_table(H264Context *h,
+static void fill_vaapi_plain_pred_weight_table(const H264Context *h,
int list,
unsigned char *luma_weight_flag,
short luma_weight[32],
@@ -226,19 +226,21 @@ static int vaapi_h264_start_frame(AVCodecContext
*avctx,
av_unused const uint8_t *buffer,
av_unused uint32_t size)
{
- H264Context * const h = avctx->priv_data;
- struct vaapi_context * const vactx = avctx->hwaccel_context;
- const PPS *pps = h->ps.pps;
- const SPS *sps = h->ps.sps;
+ const H264Context *h = avctx->priv_data;
+ VAAPIDecodePicture *pic = h->cur_pic_ptr->hwaccel_picture_private;
+ const PPS *pps = h->ps.pps;
+ const SPS *sps = h->ps.sps;
VAPictureParameterBufferH264 *pic_param;
- VAIQMatrixBufferH264 *iq_matrix;
+ VAIQMatrixBufferH264 *iq_matrix;
- vactx->slice_param_size = sizeof(VASliceParameterBufferH264);
+ pic->output_surface = ff_vaapi_get_surface_id(h->cur_pic_ptr->f);
- /* Fill in VAPictureParameterBufferH264. */
- pic_param = ff_vaapi_alloc_pic_param(vactx,
sizeof(VAPictureParameterBufferH264));
+ pic_param = ff_vaapi_decode_alloc_param_buffer(avctx, pic,
+
VAPictureParameterBufferType,
+ sizeof(*pic_param));
if (!pic_param)
return -1;
+
fill_vaapi_pic(&pic_param->CurrPic, h->cur_pic_ptr, h->picture_structure);
if (fill_vaapi_ReferenceFrames(pic_param, h) < 0)
return -1;
@@ -280,7 +282,9 @@ static int vaapi_h264_start_frame(AVCodecContext
*avctx,
pic_param->frame_num =
h->poc.frame_num;
/* Fill in VAIQMatrixBufferH264. */
- iq_matrix = ff_vaapi_alloc_iq_matrix(vactx, sizeof(VAIQMatrixBufferH264));
+ iq_matrix = ff_vaapi_decode_alloc_param_buffer(avctx, pic,
+ VAIQMatrixBufferType,
+ sizeof(*iq_matrix));
if (!iq_matrix)
return -1;
memcpy(iq_matrix->ScalingList4x4, pps->scaling_matrix4,
sizeof(iq_matrix->ScalingList4x4));
@@ -292,23 +296,18 @@ static int vaapi_h264_start_frame(AVCodecContext
*avctx,
/** End a hardware decoding based frame. */
static int vaapi_h264_end_frame(AVCodecContext *avctx)
{
- struct vaapi_context * const vactx = avctx->hwaccel_context;
- H264Context * const h = avctx->priv_data;
- H264SliceContext *sl = &h->slice_ctx[0];
+ const H264Context *h = avctx->priv_data;
+ VAAPIDecodePicture *pic = h->cur_pic_ptr->hwaccel_picture_private;
+ H264SliceContext *sl = &h->slice_ctx[0];
int ret;
- ret = ff_vaapi_commit_slices(vactx);
- if (ret < 0)
- goto finish;
-
- ret = ff_vaapi_render_picture(vactx,
ff_vaapi_get_surface_id(h->cur_pic_ptr->f));
+ ret = ff_vaapi_decode_issue(avctx, pic);
if (ret < 0)
- goto finish;
+ goto fail;
ff_h264_draw_horiz_band(h, sl, 0, h->avctx->height);
-finish:
- ff_vaapi_common_end_frame(avctx);
+fail:
return ret;
}
@@ -317,12 +316,14 @@ static int vaapi_h264_decode_slice(AVCodecContext *avctx,
const uint8_t *buffer,
uint32_t size)
{
- H264Context * const h = avctx->priv_data;
- H264SliceContext *sl = &h->slice_ctx[0];
+ const H264Context *h = avctx->priv_data;
+ VAAPIDecodePicture *pic = h->cur_pic_ptr->hwaccel_picture_private;
+ const H264SliceContext *sl = &h->slice_ctx[0];
VASliceParameterBufferH264 *slice_param;
- /* Fill in VASliceParameterBufferH264. */
- slice_param = (VASliceParameterBufferH264
*)ff_vaapi_alloc_slice(avctx->hwaccel_context, buffer, size);
+ slice_param = ff_vaapi_decode_alloc_slice_buffer(avctx, pic,
+ sizeof(*slice_param),
+ buffer, size);
if (!slice_param)
return -1;
slice_param->slice_data_bit_offset = get_bits_count(&sl->gb);
@@ -352,11 +353,15 @@ static int vaapi_h264_decode_slice(AVCodecContext *avctx,
}
AVHWAccel ff_h264_vaapi_hwaccel = {
- .name = "h264_vaapi",
- .type = AVMEDIA_TYPE_VIDEO,
- .id = AV_CODEC_ID_H264,
- .pix_fmt = AV_PIX_FMT_VAAPI,
- .start_frame = vaapi_h264_start_frame,
- .end_frame = vaapi_h264_end_frame,
- .decode_slice = vaapi_h264_decode_slice,
+ .name = "h264_vaapi",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = AV_CODEC_ID_H264,
+ .pix_fmt = AV_PIX_FMT_VAAPI,
+ .start_frame = &vaapi_h264_start_frame,
+ .end_frame = &vaapi_h264_end_frame,
+ .decode_slice = &vaapi_h264_decode_slice,
+ .frame_priv_data_size = sizeof(VAAPIDecodePicture),
+ .init = &ff_vaapi_decode_init,
+ .uninit = &ff_vaapi_decode_uninit,
+ .priv_data_size = sizeof(VAAPIDecodeContext),
};
--
2.8.1
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel