Revision 5e5c247a

View differences:

libavcodec/avcodec.h
291 291
   used */
292 292
#define CODEC_CAP_PARSE_ONLY      0x0004
293 293
#define CODEC_CAP_TRUNCATED       0x0008
294
/* codec can export data for HW decoding (XvMC) */
295
#define CODEC_CAP_HWACCEL         0x0010
294 296

  
295 297
//the following defines might change, so dont expect compatibility if u use them
296 298
#define MB_TYPE_INTRA4x4   0x0001
libavcodec/mpeg12.c
1010 1010
#define MT_DMV   3
1011 1011

  
1012 1012
static int mpeg_decode_mb(MpegEncContext *s,
1013
                          DCTELEM block[6][64])
1013
                          DCTELEM block[12][64])
1014 1014
{
1015 1015
    int i, j, k, cbp, val, mb_type, motion_type;
1016 1016
    
......
1026 1026
    
1027 1027
        /* skip mb */
1028 1028
        s->mb_intra = 0;
1029
        for(i=0;i<6;i++)
1029
        for(i=0;i<12;i++)
1030 1030
            s->block_last_index[i] = -1;
1031 1031
        if(s->picture_structure == PICT_FRAME)
1032 1032
            s->mv_type = MV_TYPE_16X16;
......
1126 1126
#endif
1127 1127

  
1128 1128
        if (s->codec_id == CODEC_ID_MPEG2VIDEO) {
1129
            for(i=0;i<6;i++) {
1129
            for(i=0;i<4+(1<<s->chroma_format);i++) {
1130 1130
                if (mpeg2_decode_block_intra(s, s->pblocks[i], i) < 0)
1131 1131
                    return -1;
1132 1132
            }
......
1311 1311
                return -1;
1312 1312
            }
1313 1313
            cbp++;
1314
            if(s->chroma_format == 2){//CHROMA422
1315
                 cbp|= ( get_bits(&s->gb,2) ) << 6;
1316
            }else
1317
            if(s->chroma_format >  2){//CHROMA444
1318
                 cbp|= ( get_bits(&s->gb,6) ) << 6;
1319
            }
1314 1320

  
1315 1321
#ifdef HAVE_XVMC
1316 1322
            //on 1 we memcpy blocks in xvmcvideo
......
1324 1330

  
1325 1331
            if (s->codec_id == CODEC_ID_MPEG2VIDEO) {
1326 1332
                for(i=0;i<6;i++) {
1327
                    if (cbp & 32) {
1333
                    if (cbp & (1<<(5-i)) ) {
1328 1334
                        if (mpeg2_decode_block_non_intra(s, s->pblocks[i], i) < 0)
1329 1335
                            return -1;
1330 1336
                    } else {
1331 1337
                        s->block_last_index[i] = -1;
1332 1338
                    }
1333
                    cbp+=cbp;
1339
                }
1340
                if (s->chroma_format >= 2) {
1341
                    if (s->chroma_format == 2) {//CHROMA_422)
1342
                        for(i=6;i<8;i++) {
1343
                            if (cbp & (1<<(6+7-i)) ) {
1344
                                if (mpeg2_decode_block_non_intra(s, s->pblocks[i], i) < 0)
1345
                                    return -1;
1346
                            } else {
1347
                                s->block_last_index[i] = -1;
1348
                            }
1349
                        }
1350
                    }else{ /*CHROMA_444*/
1351
                        for(i=6;i<12;i++) {
1352
                            if (cbp & (1<<(6+11-i)) ) {
1353
                                if (mpeg2_decode_block_non_intra(s, s->pblocks[i], i) < 0)
1354
                                    return -1;
1355
                            } else {
1356
                                s->block_last_index[i] = -1;
1357
                            }
1358
                        }
1359
                    }
1334 1360
                }
1335 1361
            } else {
1336 1362
                for(i=0;i<6;i++) {
......
1654 1680
        component = 0; 
1655 1681
    }else{
1656 1682
        quant_matrix = s->chroma_intra_matrix;
1657
        component = n - 3;
1683
        component = (n&1) + 1;
1658 1684
    }
1659 1685
    diff = decode_dc(&s->gb, component);
1660 1686
    if (diff >= 0xffff)
......
1817 1843
    profile= get_bits(&s->gb, 3);
1818 1844
    level= get_bits(&s->gb, 4);
1819 1845
    s->progressive_sequence = get_bits1(&s->gb); /* progressive_sequence */
1820
    skip_bits(&s->gb, 2); /* chroma_format */
1846
    s->chroma_format = get_bits(&s->gb, 2); /* chroma_format 1=420, 2=422, 3=444 */
1821 1847
    horiz_size_ext = get_bits(&s->gb, 2);
1822 1848
    vert_size_ext = get_bits(&s->gb, 2);
1823 1849
    s->width |= (horiz_size_ext << 12);
1824 1850
    s->height |= (vert_size_ext << 12);
1825 1851
    bit_rate_ext = get_bits(&s->gb, 12);  /* XXX: handle it */
1826
    s->bit_rate = ((s->bit_rate / 400) | (bit_rate_ext << 12)) * 400;
1852
    s->bit_rate += (bit_rate_ext << 12) * 400;
1827 1853
    skip_bits1(&s->gb); /* marker */
1828 1854
    s->avctx->rc_buffer_size += get_bits(&s->gb, 8)*1024*16<<10;
1829 1855

  
......
2556 2582
    }
2557 2583
}
2558 2584

  
2585
static void mpeg_decode_gop(AVCodecContext *avctx, 
2586
                            uint8_t *buf, int buf_size){
2587
    Mpeg1Context *s1 = avctx->priv_data;
2588
    MpegEncContext *s = &s1->mpeg_enc_ctx;
2589

  
2590
    int drop_frame_flag;
2591
    int time_code_hours, time_code_minutes;
2592
    int time_code_seconds, time_code_pictures;
2593
    int broken_link;
2594

  
2595
    s->first_field = 0;
2596

  
2597
    init_get_bits(&s->gb, buf, buf_size*8);
2598

  
2599
    drop_frame_flag = get_bits1(&s->gb);
2600
    
2601
    time_code_hours=get_bits(&s->gb,5);
2602
    time_code_minutes = get_bits(&s->gb,6);
2603
    skip_bits1(&s->gb);//marker bit
2604
    time_code_seconds = get_bits(&s->gb,6);
2605
    time_code_pictures = get_bits(&s->gb,6);
2606
    /*broken_link indicate that after editing the
2607
      reference frames of the first B-Frames after GOP I-Frame
2608
      are missing (open gop)*/
2609
    broken_link = get_bits1(&s->gb);
2610
    if(broken_link == 1){
2611
//        avcodec_flush_buffers(avctx);
2612
        ff_mpeg_flush(avctx);
2613
    }
2614
}
2615

  
2559 2616
/**
2560 2617
 * finds the end of the current frame in the bitstream.
2561 2618
 * @return the position of the first byte of the next frame, or -1
......
2692 2749
                                          buf_ptr, input_size);
2693 2750
                    break;
2694 2751
                case GOP_START_CODE:
2695
                    s2->first_field=0;
2752
    	            mpeg_decode_gop(avctx, buf_ptr, input_size);
2696 2753
                    break;
2697 2754
                default:
2698 2755
                    if (start_code >= SLICE_MIN_START_CODE &&
......
2850 2907
    NULL,
2851 2908
    mpeg_decode_end,
2852 2909
    mpeg_decode_frame,
2853
    CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED,
2910
    CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED| CODEC_CAP_HWACCEL,
2911
    .flush= ff_mpeg_flush,
2854 2912
};
2855 2913

  
2856 2914
#endif
libavcodec/mpegvideo.c
267 267
    ff_init_scantable(s->dsp.idct_permutation, &s->intra_h_scantable, ff_alternate_horizontal_scan);
268 268
    ff_init_scantable(s->dsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan);
269 269

  
270
    s->picture_structure= PICT_FRAME;
271
    
272 270
    return 0;
273 271
}
274 272

  
......
424 422
            CHECKED_ALLOCZ(s->dct_error_sum, 2 * 64 * sizeof(int))
425 423
        }
426 424
    }   
427
    CHECKED_ALLOCZ(s->blocks, 64*6*2 * sizeof(DCTELEM))
425
    CHECKED_ALLOCZ(s->blocks, 64*12*2 * sizeof(DCTELEM))
428 426
    s->block= s->blocks[0];
429 427

  
430 428
    for(i=0;i<12;i++){
......
539 537
    s->y_dc_scale_table=
540 538
    s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
541 539
    s->chroma_qscale_table= ff_default_chroma_qscale_table;
542
    if (!s->encoding)
543
        s->progressive_sequence= 1;
544
    s->progressive_frame= 1;
540
    if( s->codec_id != CODEC_ID_MPEG1VIDEO && 
541
        s->codec_id != CODEC_ID_MPEG2VIDEO) 
542
    {
543
        /* default structure is frame */
544
        s->progressive_frame= 1;
545
        s->picture_structure= PICT_FRAME;
546

  
547
        s->y_dc_scale_table=
548
        s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
549
        if (!s->encoding)
550
            s->progressive_sequence= 1;
551
    }
545 552
    s->coded_picture_number = 0;
546 553

  
547 554
    y_size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2);
libavcodec/mpegvideo.h
355 355
    int last_pict_type;
356 356
    int last_non_b_pict_type;   ///< used for mpeg4 gmc b-frames & ratecontrol 
357 357
    int frame_rate_index;
358
    int frame_rate_ext_n;       ///< MPEG-2 specific framerate modificators (numerator)
359
    int frame_rate_ext_d;       ///< MPEG-2 specific framerate modificators (denominator)
360

  
358 361
    /* motion compensation */
359 362
    int unrestricted_mv;        ///< mv can point outside of the coded picture 
360 363
    int h263_long_vectors;      ///< use horrible h263v1 long vector mode 
......
465 468
    /** identical to the above but for MMX & these are not permutated, second 64 entries are bias*/
466 469
    uint16_t (*q_intra_matrix16)[2][64];
467 470
    uint16_t (*q_inter_matrix16)[2][64];
468
    int block_last_index[6];  ///< last non zero coefficient in block
471
    int block_last_index[12];  ///< last non zero coefficient in block
469 472
    /* scantables */
470 473
    ScanTable __align8 intra_scantable;
471 474
    ScanTable intra_h_scantable;
......
653 656
    int alternate_scan;
654 657
    int repeat_first_field;
655 658
    int chroma_420_type;
659
    int chroma_format;
660
#define CHROMA_420 1
661
#define CHROMA_422 2
662
#define CHROMA_444 3
663

  
656 664
    int progressive_frame;
657 665
    int full_pel[2];
658 666
    int interlaced_dct;
libavcodec/xvmcvideo.c
55 55

  
56 56
void XVMC_pack_pblocks(MpegEncContext *s, int cbp){
57 57
int i,j;
58
#define numblocks 6
59 58

  
60 59
    j=0;
61
    for(i=0;i<numblocks;i++){
62
        if(cbp & (1<<(numblocks-1-i)) ){
60
    for(i=0;i<6;i++){
61
        if(cbp & (1<<(5-i)) ){
63 62
           s->pblocks[i] = (short *)(&s->block[(j++)]);
64 63
        }else{
65 64
           s->pblocks[i] = NULL;
66 65
        }
67 66
//        printf("s->pblocks[%d]=%p ,s->block=%p cbp=%d\n",i,s->pblocks[i],s->block,cbp);
68 67
    }
68
    if (s->chroma_format >= 2){
69
        if (s->chroma_format == 2){//CHROMA_422
70
            for(i=6;i<8;i++){
71
                if(cbp & (1<<(6+7-i)) ){
72
                    s->pblocks[i] = (short *)(&s->block[(j++)]);
73
                }else{
74
                    s->pblocks[i] = NULL;
75
                }
76
            }
77
        }else{//CHROMA_444
78
            for(i=6; i<12; i++){
79
                if(cbp & (1<<(6+11-i)) ){
80
                    s->pblocks[i] = (short *)(&s->block[(j++)]);
81
                }else{
82
                    s->pblocks[i] = NULL;
83
                }
84
            }
85
	}
86
    }
69 87
}
70 88

  
71
static int calc_cbp(MpegEncContext *s, int blocknum){
89
static int calc_cbp(MpegEncContext *s){
72 90
/* compute cbp */
73
// for I420 bit_offset=5
74 91
int  i,cbp = 0;
75
    for(i=0; i<blocknum; i++) {
92
    for(i=0; i<4; i++) {
76 93
        if(s->block_last_index[i] >= 0)
77 94
            cbp |= 1 << (5 - i);
78 95
    }
96
    if(s->flags & CODEC_FLAG_GRAY)
97
         return cbp; //4 block for grayscale one done
98

  
99

  
100
    for(i=4; i<6; i++) {
101
        if(s->block_last_index[i] >= 0)
102
            cbp |= 1 << (5 - i);
103
    }
104
    if(s->chroma_format <  2) return cbp;
105

  
106

  
107
    if(s->chroma_format == 2){/*CHROMA_422*/
108
        for(i=6; i<8; i++) {
109
            if(s->block_last_index[i] >= 0)
110
                cbp |= 1 << (6+7 - i);
111
        }
112
    }else{/*CHROMA_444*/
113
        for(i=6; i<12; i++) {
114
            if(s->block_last_index[i] >= 0)
115
                cbp |= 1 << (6+11 - i);
116
        }
117
    }
79 118
    return cbp;
80 119
}
81 120

  
......
121 160
            assert(last->state & MP_XVMC_STATE_PREDICTION);
122 161
            render->p_past_surface = last->p_surface;
123 162
            return 0;
124
     }
163
    }
125 164

  
126 165
return -1;
127 166
}
......
256 295
    }//!intra
257 296
//time to handle data blocks;
258 297
    mv_block->index = render->next_free_data_block_num;
298

  
259 299
    blocks_per_mb = 6;
260
/*
261
    switch( s->chroma_format){
262
        case CHROMA_422:
263
            blocks_per_mb = 8;
264
            break;
265
        case CHROMA_444:
266
            blocks_per_mb = 12;
267
            break;
300
    if( s->chroma_format >= 2){
301
        block_per_mb = 4 + (1 << (s->chroma_format));
268 302
    }
269
*/
303

  
270 304
    if(s->flags & CODEC_FLAG_GRAY){
271 305
        if(s->mb_intra){//intra frames are alwasy full chroma block
272 306
            for(i=4; i<blocks_per_mb; i++){
......
277 311
        }else
278 312
            blocks_per_mb = 4;//Luminance blocks only
279 313
    }
280
    cbp = calc_cbp(s,blocks_per_mb);
314
    cbp = calc_cbp(s);
281 315
    mv_block->coded_block_pattern = cbp;
282 316
    if(cbp == 0)
283 317
        mv_block->macroblock_type &= ~XVMC_MB_TYPE_PATTERN;

Also available in: Unified diff