Mercurial > libavcodec.hg
comparison mpegvideo.c @ 766:8d36b35a7e6e libavcodec
slice encoding cleanup
author | michaelni |
---|---|
date | Fri, 25 Oct 2002 00:08:32 +0000 |
parents | d4726182dfd2 |
children | c75c3f1bef4b |
comparison
equal
deleted
inserted
replaced
765:7f0d502a42c5 | 766:8d36b35a7e6e |
---|---|
574 s->out_format = FMT_H263; | 574 s->out_format = FMT_H263; |
575 avctx->delay=0; | 575 avctx->delay=0; |
576 break; | 576 break; |
577 case CODEC_ID_H263P: | 577 case CODEC_ID_H263P: |
578 s->out_format = FMT_H263; | 578 s->out_format = FMT_H263; |
579 s->rtp_mode = 1; | |
580 s->rtp_payload_size = 1200; | |
581 s->h263_plus = 1; | 579 s->h263_plus = 1; |
582 s->unrestricted_mv = 1; | 580 s->unrestricted_mv = 1; |
583 s->h263_aic = 1; | 581 s->h263_aic = 1; |
584 | 582 |
585 /* These are just to be sure */ | 583 /* These are just to be sure */ |
2473 } | 2471 } |
2474 } | 2472 } |
2475 | 2473 |
2476 static void encode_picture(MpegEncContext *s, int picture_number) | 2474 static void encode_picture(MpegEncContext *s, int picture_number) |
2477 { | 2475 { |
2478 int mb_x, mb_y, last_gob, pdif = 0; | 2476 int mb_x, mb_y, pdif = 0; |
2479 int i; | 2477 int i; |
2480 int bits; | 2478 int bits; |
2481 MpegEncContext best_s, backup_s; | 2479 MpegEncContext best_s, backup_s; |
2482 UINT8 bit_buf[2][3000]; | 2480 UINT8 bit_buf[2][3000]; |
2483 UINT8 bit_buf2[2][3000]; | 2481 UINT8 bit_buf2[2][3000]; |
2655 s->last_dc[2] = 128; | 2653 s->last_dc[2] = 128; |
2656 s->mb_incr = 1; | 2654 s->mb_incr = 1; |
2657 s->last_mv[0][0][0] = 0; | 2655 s->last_mv[0][0][0] = 0; |
2658 s->last_mv[0][0][1] = 0; | 2656 s->last_mv[0][0][1] = 0; |
2659 | 2657 |
2660 if (s->codec_id==CODEC_ID_H263 && s->codec_id==CODEC_ID_H263) | 2658 if (s->codec_id==CODEC_ID_H263 || s->codec_id==CODEC_ID_H263P) |
2661 s->gob_index = ff_h263_get_gob_height(s); | 2659 s->gob_index = ff_h263_get_gob_height(s); |
2662 else | |
2663 s->gob_index = 1; //FIXME remove | |
2664 | 2660 |
2665 if(s->codec_id==CODEC_ID_MPEG4 && s->partitioned_frame) | 2661 if(s->codec_id==CODEC_ID_MPEG4 && s->partitioned_frame) |
2666 ff_mpeg4_init_partitions(s); | 2662 ff_mpeg4_init_partitions(s); |
2667 | 2663 |
2668 s->resync_mb_x=0; | 2664 s->resync_mb_x=0; |
2669 s->resync_mb_y=0; | 2665 s->resync_mb_y=0; |
2670 s->first_slice_line = 1; | 2666 s->first_slice_line = 1; |
2667 s->ptr_lastgob = s->pb.buf; | |
2668 s->ptr_last_mb_line = s->pb.buf; | |
2671 for(mb_y=0; mb_y < s->mb_height; mb_y++) { | 2669 for(mb_y=0; mb_y < s->mb_height; mb_y++) { |
2672 /* Put GOB header based on RTP MTU for formats which support it per line (H263*)*/ | |
2673 /* TODO: Put all this stuff in a separate generic function */ | |
2674 if (s->rtp_mode) { | |
2675 if (!mb_y) { | |
2676 s->ptr_lastgob = s->pb.buf; | |
2677 s->ptr_last_mb_line = s->pb.buf; | |
2678 } else if (s->out_format == FMT_H263 && !s->h263_pred && !s->h263_msmpeg4 && !(mb_y % s->gob_index)) { | |
2679 // MN: we could move the space check from h263 -> here, as its not h263 specific | |
2680 last_gob = h263_encode_gob_header(s, mb_y); | |
2681 if (last_gob) { | |
2682 s->first_slice_line = 1; | |
2683 }else{ | |
2684 /*MN: we reset it here instead at the end of each line cuz mpeg4 can have | |
2685 slice lines starting & ending in the middle*/ | |
2686 s->first_slice_line = 0; | |
2687 } | |
2688 } | |
2689 } | |
2690 | |
2691 s->y_dc_scale= s->y_dc_scale_table[ s->qscale ]; | 2670 s->y_dc_scale= s->y_dc_scale_table[ s->qscale ]; |
2692 s->c_dc_scale= s->c_dc_scale_table[ s->qscale ]; | 2671 s->c_dc_scale= s->c_dc_scale_table[ s->qscale ]; |
2693 | 2672 |
2694 s->block_index[0]= s->block_wrap[0]*(mb_y*2 + 1) - 1; | 2673 s->block_index[0]= s->block_wrap[0]*(mb_y*2 + 1) - 1; |
2695 s->block_index[1]= s->block_wrap[0]*(mb_y*2 + 1); | 2674 s->block_index[1]= s->block_wrap[0]*(mb_y*2 + 1); |
2709 s->block_index[1]+=2; | 2688 s->block_index[1]+=2; |
2710 s->block_index[2]+=2; | 2689 s->block_index[2]+=2; |
2711 s->block_index[3]+=2; | 2690 s->block_index[3]+=2; |
2712 s->block_index[4]++; | 2691 s->block_index[4]++; |
2713 s->block_index[5]++; | 2692 s->block_index[5]++; |
2714 //printf("%d %d %d %d %d\n", s->mb_x, s->mb_y, s->resync_mb_x, s->resync_mb_y, s->first_slice_line); | 2693 |
2715 /* write gob / video packet header for formats which support it at any MB (MPEG4) */ | 2694 /* write gob / video packet header */ |
2716 if(s->rtp_mode && s->mb_y>0 && s->codec_id==CODEC_ID_MPEG4){ | 2695 if(s->rtp_mode){ |
2717 int pdif= pbBufPtr(&s->pb) - s->ptr_lastgob; | 2696 int current_packet_size, is_gob_start; |
2718 | 2697 |
2719 //the *2 is there so we stay below the requested size | 2698 current_packet_size= pbBufPtr(&s->pb) - s->ptr_lastgob; |
2720 if(pdif + s->mb_line_avgsize/s->mb_width >= s->rtp_payload_size){ | 2699 is_gob_start=0; |
2721 if(s->codec_id==CODEC_ID_MPEG4){ | 2700 |
2701 if(s->codec_id==CODEC_ID_MPEG4){ | |
2702 if(current_packet_size + s->mb_line_avgsize/s->mb_width >= s->rtp_payload_size | |
2703 && s->mb_y + s->mb_x>0){ | |
2704 | |
2722 if(s->partitioned_frame){ | 2705 if(s->partitioned_frame){ |
2723 ff_mpeg4_merge_partitions(s); | 2706 ff_mpeg4_merge_partitions(s); |
2724 ff_mpeg4_init_partitions(s); | 2707 ff_mpeg4_init_partitions(s); |
2725 } | 2708 } |
2726 ff_mpeg4_encode_video_packet_header(s); | 2709 ff_mpeg4_encode_video_packet_header(s); |
2729 int bits= get_bit_count(&s->pb); | 2712 int bits= get_bit_count(&s->pb); |
2730 s->misc_bits+= bits - s->last_bits; | 2713 s->misc_bits+= bits - s->last_bits; |
2731 s->last_bits= bits; | 2714 s->last_bits= bits; |
2732 } | 2715 } |
2733 ff_mpeg4_clean_buffers(s); | 2716 ff_mpeg4_clean_buffers(s); |
2717 is_gob_start=1; | |
2734 } | 2718 } |
2719 }else{ | |
2720 if(current_packet_size + s->mb_line_avgsize*s->gob_index >= s->rtp_payload_size | |
2721 && s->mb_x==0 && s->mb_y>0 && s->mb_y%s->gob_index==0){ | |
2722 | |
2723 h263_encode_gob_header(s, mb_y); | |
2724 is_gob_start=1; | |
2725 } | |
2726 } | |
2727 | |
2728 if(is_gob_start){ | |
2735 s->ptr_lastgob = pbBufPtr(&s->pb); | 2729 s->ptr_lastgob = pbBufPtr(&s->pb); |
2736 s->first_slice_line=1; | 2730 s->first_slice_line=1; |
2737 s->resync_mb_x=mb_x; | 2731 s->resync_mb_x=mb_x; |
2738 s->resync_mb_y=mb_y; | 2732 s->resync_mb_y=mb_y; |
2739 } | 2733 } |
2923 MPV_decode_mb(s, s->block); | 2917 MPV_decode_mb(s, s->block); |
2924 //printf("MB %d %d bits\n", s->mb_x+s->mb_y*s->mb_width, get_bit_count(&s->pb)); | 2918 //printf("MB %d %d bits\n", s->mb_x+s->mb_y*s->mb_width, get_bit_count(&s->pb)); |
2925 } | 2919 } |
2926 | 2920 |
2927 | 2921 |
2928 /* Obtain average GOB size for RTP */ | 2922 /* Obtain average mb_row size for RTP */ |
2929 if (s->rtp_mode) { | 2923 if (s->rtp_mode) { |
2930 if (!mb_y) | 2924 if (mb_y==0) |
2931 s->mb_line_avgsize = pbBufPtr(&s->pb) - s->ptr_last_mb_line; | 2925 s->mb_line_avgsize = pbBufPtr(&s->pb) - s->ptr_last_mb_line; |
2932 else if (!(mb_y % s->gob_index)) { | 2926 else { |
2933 s->mb_line_avgsize = (s->mb_line_avgsize + pbBufPtr(&s->pb) - s->ptr_last_mb_line) >> 1; | 2927 s->mb_line_avgsize = (s->mb_line_avgsize + pbBufPtr(&s->pb) - s->ptr_last_mb_line) >> 1; |
2934 s->ptr_last_mb_line = pbBufPtr(&s->pb); | 2928 } |
2935 } | 2929 s->ptr_last_mb_line = pbBufPtr(&s->pb); |
2936 //fprintf(stderr, "\nMB line: %d\tSize: %u\tAvg. Size: %u", s->mb_y, | |
2937 // (s->pb.buf_ptr - s->ptr_last_mb_line), s->mb_line_avgsize); | |
2938 if(s->codec_id!=CODEC_ID_MPEG4) s->first_slice_line = 0; //FIXME clean | |
2939 } | 2930 } |
2940 } | 2931 } |
2941 emms_c(); | 2932 emms_c(); |
2942 | 2933 |
2943 if(s->codec_id==CODEC_ID_MPEG4 && s->partitioned_frame) | 2934 if(s->codec_id==CODEC_ID_MPEG4 && s->partitioned_frame) |