Revision 029911d1 libavcodec/mpegvideo.c

View differences:

libavcodec/mpegvideo.c
34 34
#include "fastmemcpy.h"
35 35
#endif
36 36

  
37
//#undef NDEBUG
38
//#include <assert.h>
37
#undef NDEBUG
38
#include <assert.h>
39 39

  
40 40
#ifdef CONFIG_ENCODERS
41 41
static void encode_picture(MpegEncContext *s, int picture_number);
......
191 191
#endif
192 192
        
193 193
#ifdef HAVE_MMX
194
    MPV_common_init_mmx(s);
194
    MPV_common_init_mmx(s); //FIXME dont pass mpegenccontext to these, rather use dspcontext
195 195
#endif
196 196
#ifdef ARCH_ALPHA
197 197
    MPV_common_init_axp(s);
......
279 279
        }
280 280

  
281 281
        CHECKED_ALLOCZ(pic->mbskip_table , mb_array_size * sizeof(uint8_t)+2) //the +2 is for the slice end check
282
        CHECKED_ALLOCZ(pic->qscale_table , mb_array_size * sizeof(uint8_t))
282
        CHECKED_ALLOCZ(pic->qscale_table , mb_array_size * sizeof(uint8_t)+3) //+3 for mpeg2 SIMD >>1
283 283
        CHECKED_ALLOCZ(pic->mb_type_base , big_mb_num    * sizeof(int))
284 284
        pic->mb_type= pic->mb_type_base + s->mb_stride+1;
285 285
        if(s->out_format == FMT_H264){
......
424 424
        
425 425
    CHECKED_ALLOCZ(s->error_status_table, mb_array_size*sizeof(uint8_t))
426 426
    
427
    if (s->out_format == FMT_H263 || s->encoding) {
427
    if (s->out_format == FMT_H263 || s->encoding || 1) {
428 428
        int size;
429 429

  
430 430
        /* MV prediction */
......
581 581
    s->data_partitioning= avctx->flags & CODEC_FLAG_PART;
582 582
    s->quarter_sample= (avctx->flags & CODEC_FLAG_QPEL)!=0;
583 583
    s->mpeg_quant= avctx->mpeg_quant;
584

  
584
    
585 585
    if (s->gop_size <= 1) {
586 586
        s->intra_only = 1;
587 587
        s->gop_size = 12;
......
618 618
        return -1;
619 619
    }
620 620
    
621
    if(s->max_b_frames && s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG1VIDEO){
621
    if(s->max_b_frames && s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO){
622 622
        fprintf(stderr, "b frames not supporetd by codec\n");
623 623
        return -1;
624 624
    }
625
    
625
/*    
626 626
    if(s->mpeg_quant && s->codec_id != CODEC_ID_MPEG4){ //FIXME mpeg2 uses that too
627 627
        fprintf(stderr, "mpeg2 style quantization not supporetd by codec\n");
628 628
        return -1;
629 629
    }
630
        
630
  */      
631 631
    if(s->codec_id==CODEC_ID_MJPEG){
632 632
        s->intra_quant_bias= 1<<(QUANT_BIAS_SHIFT-1); //(a + x/2)/x
633 633
        s->inter_quant_bias= 0;
634
    }else if(s->mpeg_quant || s->codec_id==CODEC_ID_MPEG1VIDEO){
634
    }else if(s->mpeg_quant || s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO){
635 635
        s->intra_quant_bias= 3<<(QUANT_BIAS_SHIFT-3); //(a + x*3/8)/x
636 636
        s->inter_quant_bias= 0;
637 637
    }else{
......
652 652
        s->low_delay= 0; //s->max_b_frames ? 0 : 1;
653 653
        avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1);
654 654
        break;
655
    case CODEC_ID_MPEG2VIDEO:
656
        s->out_format = FMT_MPEG1;
657
        s->low_delay= 0; //s->max_b_frames ? 0 : 1;
658
        avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1);
659
        s->rtp_mode= 1; // mpeg2 must have slices
660
        if(s->rtp_payload_size == 0) s->rtp_payload_size= 256*256*256;
661
        break;
655 662
    case CODEC_ID_LJPEG:
656 663
    case CODEC_ID_MJPEG:
657 664
        s->out_format = FMT_MJPEG;
......
820 827
            s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i];
821 828
        }else
822 829
#endif
823
        { /* mpeg1 */
830
        { /* mpeg1/2 */
824 831
            s->intra_matrix[j] = ff_mpeg1_default_intra_matrix[i];
825 832
            s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i];
826 833
        }
......
1002 1009
        
1003 1010
        if( alloc_picture(s, (Picture*)pic, 0) < 0)
1004 1011
            return -1;
1012
        assert(pic->data[0]);
1005 1013

  
1006 1014
        s->current_picture_ptr= &s->picture[i];
1007 1015
    }
......
1048 1056

  
1049 1057
    /* set dequantizer, we cant do it during init as it might change for mpeg4
1050 1058
       and we cant do it in the header decode as init isnt called for mpeg4 there yet */
1051
    if(s->out_format == FMT_H263){
1052
        if(s->mpeg_quant)
1053
            s->dct_unquantize = s->dct_unquantize_mpeg2;
1054
        else
1055
            s->dct_unquantize = s->dct_unquantize_h263;
1056
    }else 
1059
    if(s->mpeg_quant || s->codec_id == CODEC_ID_MPEG2VIDEO) 
1060
        s->dct_unquantize = s->dct_unquantize_mpeg2;
1061
    else if(s->out_format == FMT_H263)
1062
        s->dct_unquantize = s->dct_unquantize_h263;
1063
    else 
1057 1064
        s->dct_unquantize = s->dct_unquantize_mpeg1;
1058 1065

  
1059 1066
#ifdef HAVE_XVMC
......
1074 1081
        XVMC_field_end(s);
1075 1082
    }else
1076 1083
#endif
1077
    if(s->codec_id!=CODEC_ID_SVQ1 && s->codec_id != CODEC_ID_MPEG1VIDEO){
1084
    if(s->codec_id!=CODEC_ID_SVQ1 && s->out_format != FMT_MPEG1){
1078 1085
        if (s->pict_type != B_TYPE && !s->intra_only && !(s->flags&CODEC_FLAG_EMU_EDGE)) {
1079 1086
            draw_edges(s->current_picture.data[0], s->linesize  , s->h_edge_pos   , s->v_edge_pos   , EDGE_WIDTH  );
1080 1087
            draw_edges(s->current_picture.data[1], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2);
......
2345 2352
        }
2346 2353
    }
2347 2354
    break;
2348

  
2355
    default:
2356
        printf("X");
2349 2357
    }
2350 2358
}
2351 2359

  
......
2523 2531
            if(s->hurry_up>1) return;
2524 2532

  
2525 2533
            /* add dct residue */
2526
            if(s->encoding || !(   s->mpeg2 || s->h263_msmpeg4 || s->codec_id==CODEC_ID_MPEG1VIDEO 
2534
            if(s->encoding || !(   s->h263_msmpeg4 || s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO
2527 2535
                                || (s->codec_id==CODEC_ID_MPEG4 && !s->mpeg_quant))){
2528 2536
                add_dequant_dct(s, block[0], 0, dest_y, dct_linesize);
2529 2537
                add_dequant_dct(s, block[1], 1, dest_y + 8, dct_linesize);
......
2552 2560
#endif
2553 2561
        } else {
2554 2562
            /* dct only in intra block */
2555
            if(s->encoding || !(s->mpeg2 || s->codec_id==CODEC_ID_MPEG1VIDEO)){
2563
            if(s->encoding || !(s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO)){
2556 2564
                put_dct(s, block[0], 0, dest_y, dct_linesize);
2557 2565
                put_dct(s, block[1], 1, dest_y + 8, dct_linesize);
2558 2566
                put_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize);
......
2997 3005
        for(i=0;i<6;i++) {
2998 3006
            if(!skip_dct[i]){
2999 3007
                int overflow;
3008
START_TIMER;
3000 3009
                s->block_last_index[i] = s->dct_quantize(s, s->block[i], i, s->qscale, &overflow);
3010
STOP_TIMER("dct_quant");
3001 3011
            // FIXME we could decide to change to quantizer instead of clipping
3002 3012
            // JS: I don't think that would be a good idea it could lower quality instead
3003 3013
            //     of improve it. Just INTRADC clipping deserves changes in quantizer
......
3023 3033
    /* huffman encode */
3024 3034
    switch(s->codec_id){ //FIXME funct ptr could be slightly faster
3025 3035
    case CODEC_ID_MPEG1VIDEO:
3036
    case CODEC_ID_MPEG2VIDEO:
3026 3037
        mpeg1_encode_mb(s, s->block, motion_x, motion_y); break;
3027 3038
#ifdef CONFIG_RISKY
3028 3039
    case CODEC_ID_MPEG4:
......
3316 3327
#ifdef CONFIG_RISKY
3317 3328
    /* we need to initialize some time vars before we can encode b-frames */
3318 3329
    // RAL: Condition added for MPEG1VIDEO
3319
    if (s->codec_id == CODEC_ID_MPEG1VIDEO || (s->h263_pred && !s->h263_msmpeg4))
3330
    //FIXME figure out why mpeg1/2 need this !!!
3331
    if (s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO || (s->h263_pred && !s->h263_msmpeg4))
3320 3332
        ff_set_mpeg4_time(s, s->picture_number); 
3321 3333
#endif
3322 3334
        
......
3562 3574

  
3563 3575
            /* write gob / video packet header  */
3564 3576
#ifdef CONFIG_RISKY
3565
            if(s->rtp_mode){
3577
            if(s->rtp_mode && mb_y + mb_x>0){
3566 3578
                int current_packet_size, is_gob_start;
3567 3579
                
3568 3580
                current_packet_size= pbBufPtr(&s->pb) - s->ptr_lastgob;
3569 3581
                is_gob_start=0;
3570 3582
                
3571 3583
                if(s->codec_id==CODEC_ID_MPEG4){
3572
                    if(current_packet_size >= s->rtp_payload_size
3573
                       && s->mb_y + s->mb_x>0){
3584
                    if(current_packet_size >= s->rtp_payload_size){
3574 3585

  
3575 3586
                        if(s->partitioned_frame){
3576 3587
                            ff_mpeg4_merge_partitions(s);
......
3588 3599
                    }
3589 3600
                }else if(s->codec_id==CODEC_ID_MPEG1VIDEO){
3590 3601
                    if(   current_packet_size >= s->rtp_payload_size 
3591
                       && s->mb_y + s->mb_x>0 && s->mb_skip_run==0){
3602
                       && s->mb_skip_run==0){
3603
                        ff_mpeg1_encode_slice_header(s);
3604
                        ff_mpeg1_clean_buffers(s);
3605
                        is_gob_start=1;
3606
                    }
3607
                }else if(s->codec_id==CODEC_ID_MPEG2VIDEO){
3608
                    if(   (   current_packet_size >= s->rtp_payload_size || mb_x==0)
3609
                       && s->mb_skip_run==0){
3592 3610
                        ff_mpeg1_encode_slice_header(s);
3593 3611
                        ff_mpeg1_clean_buffers(s);
3594 3612
                        is_gob_start=1;
3595 3613
                    }
3596 3614
                }else{
3597 3615
                    if(current_packet_size >= s->rtp_payload_size
3598
                       && s->mb_x==0 && s->mb_y>0 && s->mb_y%s->gob_index==0){
3616
                       && s->mb_x==0 && s->mb_y%s->gob_index==0){
3599 3617
                       
3600 3618
                        h263_encode_gob_header(s, mb_y);                       
3601 3619
                        is_gob_start=1;
......
4000 4018
        start_i = 1;
4001 4019
        last_non_zero = 0;
4002 4020
        qmat = s->q_intra_matrix[qscale];
4003
        if(s->mpeg_quant || s->codec_id== CODEC_ID_MPEG1VIDEO)
4021
        if(s->mpeg_quant)
4004 4022
            bias= 1<<(QMAT_SHIFT-1);
4005 4023
        length     = s->intra_ac_vlc_length;
4006 4024
        last_length= s->intra_ac_vlc_last_length;
......
4529 4547

  
4530 4548
#ifdef CONFIG_RISKY
4531 4549

  
4550
AVCodec mpeg2video_encoder = {
4551
    "mpeg2video",
4552
    CODEC_TYPE_VIDEO,
4553
    CODEC_ID_MPEG2VIDEO,
4554
    sizeof(MpegEncContext),
4555
    MPV_encode_init,
4556
    MPV_encode_picture,
4557
    MPV_encode_end,
4558
};
4559

  
4532 4560
AVCodec h263_encoder = {
4533 4561
    "h263",
4534 4562
    CODEC_TYPE_VIDEO,

Also available in: Unified diff