comparison dxva2_h264.c @ 10974:b1ccfdc1b409 libavcodec

Moved reusable code from dxva2_h264.c:end_frame to ff_dxva2_common_end_frame.
author fenrir
date Sat, 23 Jan 2010 17:59:08 +0000
parents ea8f891d997d
children cec4a174365c
comparison
equal deleted inserted replaced
10973:214adf5e303b 10974:b1ccfdc1b409
311 } 311 }
312 return result; 312 return result;
313 } 313 }
314 314
315 static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, 315 static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
316 struct dxva_context *ctx,
317 struct dxva2_picture_context *ctx_pic,
318 DXVA2_DecodeBufferDesc *bs, 316 DXVA2_DecodeBufferDesc *bs,
319 DXVA2_DecodeBufferDesc *sc, 317 DXVA2_DecodeBufferDesc *sc)
320 unsigned mb_count) 318 {
321 { 319 H264Context *h = avctx->priv_data;
320 MpegEncContext *s = &h->s;
321 const unsigned mb_count = s->mb_width * s->mb_height;
322 struct dxva_context *ctx = avctx->hwaccel_context;
323 const Picture *current_picture = h->s.current_picture_ptr;
324 struct dxva2_picture_context *ctx_pic = current_picture->hwaccel_picture_private;
322 DXVA_Slice_H264_Short *slice = NULL; 325 DXVA_Slice_H264_Short *slice = NULL;
323 uint8_t *dxva_data, *current, *end; 326 uint8_t *dxva_data, *current, *end;
324 unsigned dxva_size; 327 unsigned dxva_size;
325 void *slice_data; 328 void *slice_data;
326 unsigned slice_size; 329 unsigned slice_size;
459 if (h->slice_type != FF_I_TYPE && h->slice_type != FF_SI_TYPE) 462 if (h->slice_type != FF_I_TYPE && h->slice_type != FF_SI_TYPE)
460 ctx_pic->pp.wBitFields &= ~(1 << 15); /* Set IntraPicFlag to 0 */ 463 ctx_pic->pp.wBitFields &= ~(1 << 15); /* Set IntraPicFlag to 0 */
461 return 0; 464 return 0;
462 } 465 }
463 466
464 static int end_frame(AVCodecContext *avctx) 467 static int ff_dxva2_common_end_frame(AVCodecContext *avctx, MpegEncContext *s,
465 { 468 const void *pp, unsigned pp_size,
466 H264Context *h = avctx->priv_data; 469 const void *qm, unsigned qm_size,
467 MpegEncContext *s = &h->s; 470 int (*commit_bs_si)(AVCodecContext *,
468 const unsigned mb_count = s->mb_width * s->mb_height; 471 DXVA2_DecodeBufferDesc *bs,
472 DXVA2_DecodeBufferDesc *slice))
473 {
469 struct dxva_context *ctx = avctx->hwaccel_context; 474 struct dxva_context *ctx = avctx->hwaccel_context;
470 const Picture *current_picture = h->s.current_picture_ptr;
471 struct dxva2_picture_context *ctx_pic = current_picture->hwaccel_picture_private;
472 unsigned buffer_count = 0; 475 unsigned buffer_count = 0;
473 DXVA2_DecodeBufferDesc buffer[4]; 476 DXVA2_DecodeBufferDesc buffer[4];
474 DXVA2_DecodeExecuteParams exec; 477 DXVA2_DecodeExecuteParams exec;
475 int result; 478 int result;
476 479
477 if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0)
478 return -1;
479
480 if (FAILED(IDirectXVideoDecoder_BeginFrame(ctx->decoder, 480 if (FAILED(IDirectXVideoDecoder_BeginFrame(ctx->decoder,
481 get_surface(current_picture), 481 get_surface(s->current_picture_ptr),
482 NULL))) { 482 NULL))) {
483 av_log(avctx, AV_LOG_ERROR, "Failed to begin frame\n"); 483 av_log(avctx, AV_LOG_ERROR, "Failed to begin frame\n");
484 return -1; 484 return -1;
485 } 485 }
486 486
487 result = commit_buffer(avctx, ctx, &buffer[buffer_count], 487 result = commit_buffer(avctx, ctx, &buffer[buffer_count],
488 DXVA2_PictureParametersBufferType, 488 DXVA2_PictureParametersBufferType,
489 &ctx_pic->pp, sizeof(ctx_pic->pp), 0); 489 pp, pp_size, 0);
490 if (result) { 490 if (result) {
491 av_log(avctx, AV_LOG_ERROR, 491 av_log(avctx, AV_LOG_ERROR,
492 "Failed to add picture parameter buffer\n"); 492 "Failed to add picture parameter buffer\n");
493 goto end; 493 goto end;
494 } 494 }
495 buffer_count++; 495 buffer_count++;
496 496
497 if (qm_size > 0) {
497 result = commit_buffer(avctx, ctx, &buffer[buffer_count], 498 result = commit_buffer(avctx, ctx, &buffer[buffer_count],
498 DXVA2_InverseQuantizationMatrixBufferType, 499 DXVA2_InverseQuantizationMatrixBufferType,
499 &ctx_pic->qm, sizeof(ctx_pic->qm), 0); 500 qm, qm_size, 0);
500 if (result) { 501 if (result) {
501 av_log(avctx, AV_LOG_ERROR, 502 av_log(avctx, AV_LOG_ERROR,
502 "Failed to add inverse quantization matrix buffer\n"); 503 "Failed to add inverse quantization matrix buffer\n");
503 goto end; 504 goto end;
504 } 505 }
505 buffer_count++; 506 buffer_count++;
506 507 }
507 result = commit_bitstream_and_slice_buffer(avctx, ctx, ctx_pic, 508
508 &buffer[buffer_count + 0], 509 result = commit_bs_si(avctx,
509 &buffer[buffer_count + 1], 510 &buffer[buffer_count + 0],
510 mb_count); 511 &buffer[buffer_count + 1]);
511 if (result) { 512 if (result) {
512 av_log(avctx, AV_LOG_ERROR, 513 av_log(avctx, AV_LOG_ERROR,
513 "Failed to add bitstream or slice control buffer\n"); 514 "Failed to add bitstream or slice control buffer\n");
514 goto end; 515 goto end;
515 } 516 }
516 buffer_count += 2; 517 buffer_count += 2;
517 518
518 /* TODO Film Grain when possible */ 519 /* TODO Film Grain when possible */
519 520
520 assert(buffer_count == 4); 521 assert(buffer_count == 1 + (qm_size > 0) + 2);
521 522
522 memset(&exec, 0, sizeof(exec)); 523 memset(&exec, 0, sizeof(exec));
523 exec.NumCompBuffers = buffer_count; 524 exec.NumCompBuffers = buffer_count;
524 exec.pCompressedBuffers = buffer; 525 exec.pCompressedBuffers = buffer;
525 exec.pExtensionData = NULL; 526 exec.pExtensionData = NULL;
535 } 536 }
536 537
537 if (!result) 538 if (!result)
538 ff_draw_horiz_band(s, 0, s->avctx->height); 539 ff_draw_horiz_band(s, 0, s->avctx->height);
539 return result; 540 return result;
541 }
542
543 static int end_frame(AVCodecContext *avctx)
544 {
545 H264Context *h = avctx->priv_data;
546 MpegEncContext *s = &h->s;
547 struct dxva2_picture_context *ctx_pic =
548 h->s.current_picture_ptr->hwaccel_picture_private;
549
550 if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0)
551 return -1;
552 return ff_dxva2_common_end_frame(avctx, s,
553 &ctx_pic->pp, sizeof(ctx_pic->pp),
554 &ctx_pic->qm, sizeof(ctx_pic->qm),
555 commit_bitstream_and_slice_buffer);
540 } 556 }
541 557
542 AVHWAccel h264_dxva2_hwaccel = { 558 AVHWAccel h264_dxva2_hwaccel = {
543 .name = "h264_dxva2", 559 .name = "h264_dxva2",
544 .type = CODEC_TYPE_VIDEO, 560 .type = CODEC_TYPE_VIDEO,