Mercurial > libavcodec.hg
comparison dnxhdenc.c @ 8129:a9734fe0811e libavcodec
Making it easier to send arbitrary structures as work orders to MT workers
author | romansh |
---|---|
date | Wed, 12 Nov 2008 17:47:23 +0000 |
parents | e943e1409077 |
children | d77ee820a5f1 |
comparison
equal
deleted
inserted
replaced
8128:e2241dd85c65 | 8129:a9734fe0811e |
---|---|
447 } | 447 } |
448 } | 448 } |
449 | 449 |
450 static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg) | 450 static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg) |
451 { | 451 { |
452 DNXHDEncContext *ctx = arg; | 452 DNXHDEncContext *ctx = *(void**)arg; |
453 int mb_y, mb_x; | 453 int mb_y, mb_x; |
454 int qscale = ctx->thread[0]->qscale; | 454 int qscale = ctx->thread[0]->qscale; |
455 | 455 |
456 for (mb_y = ctx->m.start_mb_y; mb_y < ctx->m.end_mb_y; mb_y++) { | 456 for (mb_y = ctx->m.start_mb_y; mb_y < ctx->m.end_mb_y; mb_y++) { |
457 ctx->m.last_dc[0] = | 457 ctx->m.last_dc[0] = |
497 return 0; | 497 return 0; |
498 } | 498 } |
499 | 499 |
500 static int dnxhd_encode_thread(AVCodecContext *avctx, void *arg) | 500 static int dnxhd_encode_thread(AVCodecContext *avctx, void *arg) |
501 { | 501 { |
502 DNXHDEncContext *ctx = arg; | 502 DNXHDEncContext *ctx = *(void**)arg; |
503 int mb_y, mb_x; | 503 int mb_y, mb_x; |
504 | 504 |
505 for (mb_y = ctx->m.start_mb_y; mb_y < ctx->m.end_mb_y; mb_y++) { | 505 for (mb_y = ctx->m.start_mb_y; mb_y < ctx->m.end_mb_y; mb_y++) { |
506 ctx->m.last_dc[0] = | 506 ctx->m.last_dc[0] = |
507 ctx->m.last_dc[1] = | 507 ctx->m.last_dc[1] = |
553 } | 553 } |
554 } | 554 } |
555 | 555 |
556 static int dnxhd_mb_var_thread(AVCodecContext *avctx, void *arg) | 556 static int dnxhd_mb_var_thread(AVCodecContext *avctx, void *arg) |
557 { | 557 { |
558 DNXHDEncContext *ctx = arg; | 558 DNXHDEncContext *ctx = *(void**)arg; |
559 int mb_y, mb_x; | 559 int mb_y, mb_x; |
560 for (mb_y = ctx->m.start_mb_y; mb_y < ctx->m.end_mb_y; mb_y++) { | 560 for (mb_y = ctx->m.start_mb_y; mb_y < ctx->m.end_mb_y; mb_y++) { |
561 for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) { | 561 for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) { |
562 unsigned mb = mb_y * ctx->m.mb_width + mb_x; | 562 unsigned mb = mb_y * ctx->m.mb_width + mb_x; |
563 uint8_t *pix = ctx->thread[0]->src[0] + ((mb_y<<4) * ctx->m.linesize) + (mb_x<<4); | 563 uint8_t *pix = ctx->thread[0]->src[0] + ((mb_y<<4) * ctx->m.linesize) + (mb_x<<4); |
576 int last_lower = INT_MAX, last_higher = 0; | 576 int last_lower = INT_MAX, last_higher = 0; |
577 int x, y, q; | 577 int x, y, q; |
578 | 578 |
579 for (q = 1; q < avctx->qmax; q++) { | 579 for (q = 1; q < avctx->qmax; q++) { |
580 ctx->qscale = q; | 580 ctx->qscale = q; |
581 avctx->execute(avctx, dnxhd_calc_bits_thread, (void**)&ctx->thread[0], NULL, avctx->thread_count); | 581 avctx->execute(avctx, dnxhd_calc_bits_thread, (void**)&ctx->thread[0], NULL, avctx->thread_count, sizeof(void*)); |
582 } | 582 } |
583 up_step = down_step = 2<<LAMBDA_FRAC_BITS; | 583 up_step = down_step = 2<<LAMBDA_FRAC_BITS; |
584 lambda = ctx->lambda; | 584 lambda = ctx->lambda; |
585 | 585 |
586 for (;;) { | 586 for (;;) { |
656 qscale = ctx->qscale; | 656 qscale = ctx->qscale; |
657 for (;;) { | 657 for (;;) { |
658 bits = 0; | 658 bits = 0; |
659 ctx->qscale = qscale; | 659 ctx->qscale = qscale; |
660 // XXX avoid recalculating bits | 660 // XXX avoid recalculating bits |
661 ctx->m.avctx->execute(ctx->m.avctx, dnxhd_calc_bits_thread, (void**)&ctx->thread[0], NULL, ctx->m.avctx->thread_count); | 661 ctx->m.avctx->execute(ctx->m.avctx, dnxhd_calc_bits_thread, (void**)&ctx->thread[0], NULL, ctx->m.avctx->thread_count, sizeof(void*)); |
662 for (y = 0; y < ctx->m.mb_height; y++) { | 662 for (y = 0; y < ctx->m.mb_height; y++) { |
663 for (x = 0; x < ctx->m.mb_width; x++) | 663 for (x = 0; x < ctx->m.mb_width; x++) |
664 bits += ctx->mb_rc[qscale][y*ctx->m.mb_width+x].bits; | 664 bits += ctx->mb_rc[qscale][y*ctx->m.mb_width+x].bits; |
665 bits = (bits+31)&~31; // padding | 665 bits = (bits+31)&~31; // padding |
666 if (bits > ctx->frame_bits) | 666 if (bits > ctx->frame_bits) |
729 } | 729 } |
730 max_bits += 31; //worst padding | 730 max_bits += 31; //worst padding |
731 } | 731 } |
732 if (!ret) { | 732 if (!ret) { |
733 if (RC_VARIANCE) | 733 if (RC_VARIANCE) |
734 avctx->execute(avctx, dnxhd_mb_var_thread, (void**)&ctx->thread[0], NULL, avctx->thread_count); | 734 avctx->execute(avctx, dnxhd_mb_var_thread, (void**)&ctx->thread[0], NULL, avctx->thread_count, sizeof(void*)); |
735 qsort(ctx->mb_cmp, ctx->m.mb_num, sizeof(RCEntry), dnxhd_rc_cmp); | 735 qsort(ctx->mb_cmp, ctx->m.mb_num, sizeof(RCEntry), dnxhd_rc_cmp); |
736 for (x = 0; x < ctx->m.mb_num && max_bits > ctx->frame_bits; x++) { | 736 for (x = 0; x < ctx->m.mb_num && max_bits > ctx->frame_bits; x++) { |
737 int mb = ctx->mb_cmp[x].mb; | 737 int mb = ctx->mb_cmp[x].mb; |
738 max_bits -= ctx->mb_rc[ctx->qscale][mb].bits - ctx->mb_rc[ctx->qscale+1][mb].bits; | 738 max_bits -= ctx->mb_rc[ctx->qscale][mb].bits - ctx->mb_rc[ctx->qscale+1][mb].bits; |
739 ctx->mb_qscale[mb] = ctx->qscale+1; | 739 ctx->mb_qscale[mb] = ctx->qscale+1; |
801 AV_WB32(ctx->msip + i * 4, offset); | 801 AV_WB32(ctx->msip + i * 4, offset); |
802 offset += ctx->slice_size[i]; | 802 offset += ctx->slice_size[i]; |
803 assert(!(ctx->slice_size[i] & 3)); | 803 assert(!(ctx->slice_size[i] & 3)); |
804 } | 804 } |
805 | 805 |
806 avctx->execute(avctx, dnxhd_encode_thread, (void**)&ctx->thread[0], NULL, avctx->thread_count); | 806 avctx->execute(avctx, dnxhd_encode_thread, (void**)&ctx->thread[0], NULL, avctx->thread_count, sizeof(void*)); |
807 | 807 |
808 AV_WB32(buf + ctx->cid_table->coding_unit_size - 4, 0x600DC0DE); // EOF | 808 AV_WB32(buf + ctx->cid_table->coding_unit_size - 4, 0x600DC0DE); // EOF |
809 | 809 |
810 if (ctx->interlaced && first_field) { | 810 if (ctx->interlaced && first_field) { |
811 first_field = 0; | 811 first_field = 0; |