dxva2: Directly use AVFrames
The assumption of (MPEG) Picture and H264Picture layout matching might not hold true in the future. Signed-off-by: Hendrik Leppkes <h.leppkes@gmail.com>
This commit is contained in:
		
							parent
							
								
									f94371b1db
								
							
						
					
					
						commit
						678e455f1d
					
				@ -30,15 +30,15 @@
 | 
				
			|||||||
#include "mpegvideo.h"
 | 
					#include "mpegvideo.h"
 | 
				
			||||||
#include "dxva2_internal.h"
 | 
					#include "dxva2_internal.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void *ff_dxva2_get_surface(const Picture *picture)
 | 
					void *ff_dxva2_get_surface(const AVFrame *frame)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return picture->f.data[3];
 | 
					    return frame->data[3];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
unsigned ff_dxva2_get_surface_index(const struct dxva_context *ctx,
 | 
					unsigned ff_dxva2_get_surface_index(const struct dxva_context *ctx,
 | 
				
			||||||
                                    const Picture *picture)
 | 
					                                    const AVFrame *frame)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    void *surface = ff_dxva2_get_surface(picture);
 | 
					    void *surface = ff_dxva2_get_surface(frame);
 | 
				
			||||||
    unsigned i;
 | 
					    unsigned i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (i = 0; i < ctx->surface_count; i++)
 | 
					    for (i = 0; i < ctx->surface_count; i++)
 | 
				
			||||||
@ -91,7 +91,7 @@ int ff_dxva2_commit_buffer(AVCodecContext *avctx,
 | 
				
			|||||||
    return result;
 | 
					    return result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int ff_dxva2_common_end_frame(AVCodecContext *avctx, Picture *pic,
 | 
					int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame,
 | 
				
			||||||
                              const void *pp, unsigned pp_size,
 | 
					                              const void *pp, unsigned pp_size,
 | 
				
			||||||
                              const void *qm, unsigned qm_size,
 | 
					                              const void *qm, unsigned qm_size,
 | 
				
			||||||
                              int (*commit_bs_si)(AVCodecContext *,
 | 
					                              int (*commit_bs_si)(AVCodecContext *,
 | 
				
			||||||
@ -107,7 +107,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, Picture *pic,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    do {
 | 
					    do {
 | 
				
			||||||
        hr = IDirectXVideoDecoder_BeginFrame(ctx->decoder,
 | 
					        hr = IDirectXVideoDecoder_BeginFrame(ctx->decoder,
 | 
				
			||||||
                                             ff_dxva2_get_surface(pic),
 | 
					                                             ff_dxva2_get_surface(frame),
 | 
				
			||||||
                                             NULL);
 | 
					                                             NULL);
 | 
				
			||||||
        if (hr == E_PENDING)
 | 
					        if (hr == E_PENDING)
 | 
				
			||||||
            av_usleep(2000);
 | 
					            av_usleep(2000);
 | 
				
			||||||
 | 
				
			|||||||
@ -51,7 +51,7 @@ static void fill_picture_parameters(struct dxva_context *ctx, const H264Context
 | 
				
			|||||||
    memset(pp, 0, sizeof(*pp));
 | 
					    memset(pp, 0, sizeof(*pp));
 | 
				
			||||||
    /* Configure current picture */
 | 
					    /* Configure current picture */
 | 
				
			||||||
    fill_picture_entry(&pp->CurrPic,
 | 
					    fill_picture_entry(&pp->CurrPic,
 | 
				
			||||||
                       ff_dxva2_get_surface_index(ctx, current_picture),
 | 
					                       ff_dxva2_get_surface_index(ctx, ¤t_picture->f),
 | 
				
			||||||
                       h->picture_structure == PICT_BOTTOM_FIELD);
 | 
					                       h->picture_structure == PICT_BOTTOM_FIELD);
 | 
				
			||||||
    /* Configure the set of references */
 | 
					    /* Configure the set of references */
 | 
				
			||||||
    pp->UsedForReferenceFlags  = 0;
 | 
					    pp->UsedForReferenceFlags  = 0;
 | 
				
			||||||
@ -67,7 +67,7 @@ static void fill_picture_parameters(struct dxva_context *ctx, const H264Context
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        if (r) {
 | 
					        if (r) {
 | 
				
			||||||
            fill_picture_entry(&pp->RefFrameList[i],
 | 
					            fill_picture_entry(&pp->RefFrameList[i],
 | 
				
			||||||
                               ff_dxva2_get_surface_index(ctx, r),
 | 
					                               ff_dxva2_get_surface_index(ctx, &r->f),
 | 
				
			||||||
                               r->long_ref != 0);
 | 
					                               r->long_ref != 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if ((r->reference & PICT_TOP_FIELD) && r->field_poc[0] != INT_MAX)
 | 
					            if ((r->reference & PICT_TOP_FIELD) && r->field_poc[0] != INT_MAX)
 | 
				
			||||||
@ -230,7 +230,7 @@ static void fill_slice_long(AVCodecContext *avctx, DXVA_Slice_H264_Long *slice,
 | 
				
			|||||||
                const H264Picture *r = &h->ref_list[list][i];
 | 
					                const H264Picture *r = &h->ref_list[list][i];
 | 
				
			||||||
                unsigned plane;
 | 
					                unsigned plane;
 | 
				
			||||||
                fill_picture_entry(&slice->RefPicList[list][i],
 | 
					                fill_picture_entry(&slice->RefPicList[list][i],
 | 
				
			||||||
                                   ff_dxva2_get_surface_index(ctx, r),
 | 
					                                   ff_dxva2_get_surface_index(ctx, &r->f),
 | 
				
			||||||
                                   r->reference == PICT_BOTTOM_FIELD);
 | 
					                                   r->reference == PICT_BOTTOM_FIELD);
 | 
				
			||||||
                for (plane = 0; plane < 3; plane++) {
 | 
					                for (plane = 0; plane < 3; plane++) {
 | 
				
			||||||
                    int w, o;
 | 
					                    int w, o;
 | 
				
			||||||
@ -432,7 +432,7 @@ static int dxva2_h264_end_frame(AVCodecContext *avctx)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0)
 | 
					    if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0)
 | 
				
			||||||
        return -1;
 | 
					        return -1;
 | 
				
			||||||
    ret = ff_dxva2_common_end_frame(avctx, h->cur_pic_ptr,
 | 
					    ret = ff_dxva2_common_end_frame(avctx, &h->cur_pic_ptr->f,
 | 
				
			||||||
                                    &ctx_pic->pp, sizeof(ctx_pic->pp),
 | 
					                                    &ctx_pic->pp, sizeof(ctx_pic->pp),
 | 
				
			||||||
                                    &ctx_pic->qm, sizeof(ctx_pic->qm),
 | 
					                                    &ctx_pic->qm, sizeof(ctx_pic->qm),
 | 
				
			||||||
                                    commit_bitstream_and_slice_buffer);
 | 
					                                    commit_bitstream_and_slice_buffer);
 | 
				
			||||||
 | 
				
			|||||||
@ -36,10 +36,10 @@
 | 
				
			|||||||
#include "avcodec.h"
 | 
					#include "avcodec.h"
 | 
				
			||||||
#include "mpegvideo.h"
 | 
					#include "mpegvideo.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void *ff_dxva2_get_surface(const Picture *picture);
 | 
					void *ff_dxva2_get_surface(const AVFrame *frame);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
unsigned ff_dxva2_get_surface_index(const struct dxva_context *,
 | 
					unsigned ff_dxva2_get_surface_index(const struct dxva_context *,
 | 
				
			||||||
                                    const Picture *picture);
 | 
					                                    const AVFrame *frame);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int ff_dxva2_commit_buffer(AVCodecContext *, struct dxva_context *,
 | 
					int ff_dxva2_commit_buffer(AVCodecContext *, struct dxva_context *,
 | 
				
			||||||
                           DXVA2_DecodeBufferDesc *,
 | 
					                           DXVA2_DecodeBufferDesc *,
 | 
				
			||||||
@ -47,7 +47,7 @@ int ff_dxva2_commit_buffer(AVCodecContext *, struct dxva_context *,
 | 
				
			|||||||
                           unsigned mb_count);
 | 
					                           unsigned mb_count);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int ff_dxva2_common_end_frame(AVCodecContext *, Picture *,
 | 
					int ff_dxva2_common_end_frame(AVCodecContext *, AVFrame *,
 | 
				
			||||||
                              const void *pp, unsigned pp_size,
 | 
					                              const void *pp, unsigned pp_size,
 | 
				
			||||||
                              const void *qm, unsigned qm_size,
 | 
					                              const void *qm, unsigned qm_size,
 | 
				
			||||||
                              int (*commit_bs_si)(AVCodecContext *,
 | 
					                              int (*commit_bs_si)(AVCodecContext *,
 | 
				
			||||||
 | 
				
			|||||||
@ -44,14 +44,14 @@ static void fill_picture_parameters(AVCodecContext *avctx,
 | 
				
			|||||||
    int is_field = s->picture_structure != PICT_FRAME;
 | 
					    int is_field = s->picture_structure != PICT_FRAME;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    memset(pp, 0, sizeof(*pp));
 | 
					    memset(pp, 0, sizeof(*pp));
 | 
				
			||||||
    pp->wDecodedPictureIndex         = ff_dxva2_get_surface_index(ctx, current_picture);
 | 
					    pp->wDecodedPictureIndex         = ff_dxva2_get_surface_index(ctx, ¤t_picture->f);
 | 
				
			||||||
    pp->wDeblockedPictureIndex       = 0;
 | 
					    pp->wDeblockedPictureIndex       = 0;
 | 
				
			||||||
    if (s->pict_type != AV_PICTURE_TYPE_I)
 | 
					    if (s->pict_type != AV_PICTURE_TYPE_I)
 | 
				
			||||||
        pp->wForwardRefPictureIndex  = ff_dxva2_get_surface_index(ctx, &s->last_picture);
 | 
					        pp->wForwardRefPictureIndex  = ff_dxva2_get_surface_index(ctx, &s->last_picture.f);
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        pp->wForwardRefPictureIndex  = 0xffff;
 | 
					        pp->wForwardRefPictureIndex  = 0xffff;
 | 
				
			||||||
    if (s->pict_type == AV_PICTURE_TYPE_B)
 | 
					    if (s->pict_type == AV_PICTURE_TYPE_B)
 | 
				
			||||||
        pp->wBackwardRefPictureIndex = ff_dxva2_get_surface_index(ctx, &s->next_picture);
 | 
					        pp->wBackwardRefPictureIndex = ff_dxva2_get_surface_index(ctx, &s->next_picture.f);
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        pp->wBackwardRefPictureIndex = 0xffff;
 | 
					        pp->wBackwardRefPictureIndex = 0xffff;
 | 
				
			||||||
    pp->wPicWidthInMBminus1          = s->mb_width  - 1;
 | 
					    pp->wPicWidthInMBminus1          = s->mb_width  - 1;
 | 
				
			||||||
@ -259,7 +259,7 @@ static int dxva2_mpeg2_end_frame(AVCodecContext *avctx)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0)
 | 
					    if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0)
 | 
				
			||||||
        return -1;
 | 
					        return -1;
 | 
				
			||||||
    ret = ff_dxva2_common_end_frame(avctx, s->current_picture_ptr,
 | 
					    ret = ff_dxva2_common_end_frame(avctx, &s->current_picture_ptr->f,
 | 
				
			||||||
                                    &ctx_pic->pp, sizeof(ctx_pic->pp),
 | 
					                                    &ctx_pic->pp, sizeof(ctx_pic->pp),
 | 
				
			||||||
                                    &ctx_pic->qm, sizeof(ctx_pic->qm),
 | 
					                                    &ctx_pic->qm, sizeof(ctx_pic->qm),
 | 
				
			||||||
                                    commit_bitstream_and_slice_buffer);
 | 
					                                    commit_bitstream_and_slice_buffer);
 | 
				
			||||||
 | 
				
			|||||||
@ -42,13 +42,13 @@ static void fill_picture_parameters(AVCodecContext *avctx,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    memset(pp, 0, sizeof(*pp));
 | 
					    memset(pp, 0, sizeof(*pp));
 | 
				
			||||||
    pp->wDecodedPictureIndex    =
 | 
					    pp->wDecodedPictureIndex    =
 | 
				
			||||||
    pp->wDeblockedPictureIndex  = ff_dxva2_get_surface_index(ctx, current_picture);
 | 
					    pp->wDeblockedPictureIndex  = ff_dxva2_get_surface_index(ctx, ¤t_picture->f);
 | 
				
			||||||
    if (s->pict_type != AV_PICTURE_TYPE_I && !v->bi_type)
 | 
					    if (s->pict_type != AV_PICTURE_TYPE_I && !v->bi_type)
 | 
				
			||||||
        pp->wForwardRefPictureIndex = ff_dxva2_get_surface_index(ctx, &s->last_picture);
 | 
					        pp->wForwardRefPictureIndex = ff_dxva2_get_surface_index(ctx, &s->last_picture.f);
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        pp->wForwardRefPictureIndex = 0xffff;
 | 
					        pp->wForwardRefPictureIndex = 0xffff;
 | 
				
			||||||
    if (s->pict_type == AV_PICTURE_TYPE_B && !v->bi_type)
 | 
					    if (s->pict_type == AV_PICTURE_TYPE_B && !v->bi_type)
 | 
				
			||||||
        pp->wBackwardRefPictureIndex = ff_dxva2_get_surface_index(ctx, &s->next_picture);
 | 
					        pp->wBackwardRefPictureIndex = ff_dxva2_get_surface_index(ctx, &s->next_picture.f);
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        pp->wBackwardRefPictureIndex = 0xffff;
 | 
					        pp->wBackwardRefPictureIndex = 0xffff;
 | 
				
			||||||
    if (v->profile == PROFILE_ADVANCED) {
 | 
					    if (v->profile == PROFILE_ADVANCED) {
 | 
				
			||||||
@ -261,7 +261,7 @@ static int dxva2_vc1_end_frame(AVCodecContext *avctx)
 | 
				
			|||||||
    if (ctx_pic->bitstream_size <= 0)
 | 
					    if (ctx_pic->bitstream_size <= 0)
 | 
				
			||||||
        return -1;
 | 
					        return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ret = ff_dxva2_common_end_frame(avctx, v->s.current_picture_ptr,
 | 
					    ret = ff_dxva2_common_end_frame(avctx, &v->s.current_picture_ptr->f,
 | 
				
			||||||
                                    &ctx_pic->pp, sizeof(ctx_pic->pp),
 | 
					                                    &ctx_pic->pp, sizeof(ctx_pic->pp),
 | 
				
			||||||
                                    NULL, 0,
 | 
					                                    NULL, 0,
 | 
				
			||||||
                                    commit_bitstream_and_slice_buffer);
 | 
					                                    commit_bitstream_and_slice_buffer);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user