Revision 029911d1

View differences:

libavcodec/allcodecs.c
52 52
    register_avcodec(&mpeg1video_encoder);
53 53
//    register_avcodec(&h264_encoder);
54 54
#ifdef CONFIG_RISKY
55
    register_avcodec(&mpeg2video_encoder);
55 56
    register_avcodec(&h263_encoder);
56 57
    register_avcodec(&h263p_encoder);
57 58
    register_avcodec(&flv_encoder);
libavcodec/avcodec.h
15 15

  
16 16
#define LIBAVCODEC_VERSION_INT 0x000406
17 17
#define LIBAVCODEC_VERSION     "0.4.6"
18
#define LIBAVCODEC_BUILD       4675
19
#define LIBAVCODEC_BUILD_STR   "4675"
18
#define LIBAVCODEC_BUILD       4676
19
#define LIBAVCODEC_BUILD_STR   "4676"
20 20

  
21 21
#define LIBAVCODEC_IDENT	"FFmpeg" LIBAVCODEC_VERSION "b" LIBAVCODEC_BUILD_STR
22 22

  
23 23
enum CodecID {
24 24
    CODEC_ID_NONE, 
25 25
    CODEC_ID_MPEG1VIDEO,
26
    CODEC_ID_MPEG2VIDEO,
26 27
    CODEC_ID_MPEG2VIDEO_XVMC,
27 28
    CODEC_ID_H263,
28 29
    CODEC_ID_RV10,
......
219 220
#define CODEC_CAP_PARSE_ONLY      0x0004
220 221
#define CODEC_CAP_TRUNCATED       0x0008
221 222

  
223

  
222 224
#define FF_COMMON_FRAME \
223 225
    /**\
224 226
     * pointer to the picture planes.\
......
462 464
     *                    do something for a generic case as well.
463 465
     * - decoding: set by lavc.
464 466
     */
465
    enum PixelFormat pix_fmt;
467
    enum PixelFormat pix_fmt; //FIXME move to AVFrme
466 468
 
467 469
    /**
468 470
     * Frame rate emulation. If not zero lower layer (i.e. format handler) 
......
710 712
                       data is returned. Only MPEG codecs support this now. */
711 713
    
712 714
    /**
713
     * 0-> h263 quant 1-> mpeg quant.
715
     * 0-> default, 1-> mpeg quant.
714 716
     * - encoding: set by user.
715 717
     * - decoding: unused
716 718
     */
......
1281 1283
extern AVCodec mp3lame_encoder;
1282 1284
extern AVCodec oggvorbis_encoder;
1283 1285
extern AVCodec mpeg1video_encoder;
1286
extern AVCodec mpeg2video_encoder;
1284 1287
extern AVCodec h263_encoder;
1285 1288
extern AVCodec h263p_encoder;
1286 1289
extern AVCodec flv_encoder;
......
1587 1590
int avcodec(void* handle, avc_cmd_t cmd, void* pin, void* pout);
1588 1591

  
1589 1592
/* memory */
1590
void *av_malloc(unsigned int size);
1593
void *av_malloc(unsigned int size); //FIXME unsigned could be bad, dunno, need thinking
1591 1594
void *av_mallocz(unsigned int size);
1592 1595
void *av_realloc(void *ptr, unsigned int size);
1593 1596
void av_free(void *ptr);
libavcodec/motion_est.c
32 32
#include "dsputil.h"
33 33
#include "mpegvideo.h"
34 34

  
35
//#undef NDEBUG
36
//#include <assert.h>
35
#undef NDEBUG
36
#include <assert.h>
37 37

  
38 38
#define SQ(a) ((a)*(a))
39 39

  
......
1507 1507
        type = MB_TYPE_FORWARD;
1508 1508
        
1509 1509
        // RAL: No MB_TYPE_DIRECT in MPEG-1 video (only MPEG-4)
1510
        if (s->codec_id != CODEC_ID_MPEG1VIDEO && dmin <= score){
1510
        if (s->codec_id == CODEC_ID_MPEG4 && dmin <= score){
1511 1511
            score = dmin;
1512 1512
            type = MB_TYPE_DIRECT;
1513 1513
        }
......
1586 1586
{
1587 1587
    const int f_code= s->f_code;
1588 1588
    int y, range;
1589
    assert(s->pict_type==P_TYPE);
1589 1590

  
1590
    range = (((s->codec_id == CODEC_ID_MPEG1VIDEO) ? 8 : 16) << f_code);
1591
    range = (((s->out_format == FMT_MPEG1) ? 8 : 16) << f_code);
1591 1592
    
1592 1593
    if(s->msmpeg4_version) range= 16;
1593 1594
    
......
1647 1648
    int y;
1648 1649

  
1649 1650
    // RAL: 8 in MPEG-1, 16 in MPEG-4
1650
    int range = (((s->codec_id == CODEC_ID_MPEG1VIDEO) ? 8 : 16) << f_code);
1651
    int range = (((s->out_format == FMT_MPEG1) ? 8 : 16) << f_code);
1651 1652
    
1652 1653
    if(s->avctx->me_range && range > s->avctx->me_range) range= s->avctx->me_range;
1653 1654

  
......
1673 1674
        }
1674 1675
    }
1675 1676
}
1677
#if 0
1678
/**
1679
 * estimates global motion and inits sprite_ref
1680
 */
1681
void ff_estimate_global_motion(MpegEncContext *s, int sprite_ref[3][2]){
1682
    int y;
1683
    int num= 16<<s->f_code;
1684
    int score[2][num];
1685
    int best_i[2]={0,0};
1686
    int best_score[2]={0,0};
1687
    
1688
    memset(score, 0, 2*num*sizeof(int));
1689
    
1690
    for(y=0; y<s->mb_height; y++){
1691
        int x;
1692
        int xy= (y+1)* (s->mb_width+2)+1;
1693
        int i= y*s->mb_width;
1694
        for(x=0; x<s->mb_width; x++){
1695
            int mv[2];
1696
           
1697
            if(!(s->mb_type[i]&MB_TYPE_INTER))
1698
                continue;
1699
            
1700
            mv[0]= s->p_mv_table[xy][0];
1701
            mv[1]= s->p_mv_table[xy][1];
1702

  
1703
            if(mv[0]==0 && mv[1]==0) continue;
1704
            
1705
            score[0][mv[0] + num/2]++;
1706
            score[1][mv[1] + num/2]++;
1707
        }
1708
    }
1709

  
1710
    for(n=0; n<2; n++){
1711
        for(i=1; i<num-1; i++){
1712
            int s= score[n][i-1] + score[n][i]*2 + score[n][i+1];
1713
    
1714
            if(s > best_score[n]){
1715
                best_score[n]= s;
1716
                best_i[n]= i;
1717
            }
1718
        }
1719
    }
1720
    
1721
    sprite_ref[0][0]= best_i[0] - num/2;
1722
    sprite_ref[0][1]= best_i[1] - num/2;
1723
    
1724
    // decide block type
1725
}
1726
#endif
libavcodec/mpeg12.c
19 19
 
20 20
/**
21 21
 * @file mpeg12.c
22
 * MPEG1 codec / MPEG2 decoder.
22
 * MPEG1/2 codec
23 23
 */
24 24
 
25 25
//#define DEBUG
......
228 228
            put_bits(&s->pb, 4, s->aspect_ratio_info);
229 229
            put_bits(&s->pb, 4, s->frame_rate_index);
230 230
            v = (s->bit_rate + 399) / 400;
231
            if (v > 0x3ffff)
231
            if (v > 0x3ffff && s->codec_id == CODEC_ID_MPEG1VIDEO)
232 232
                v = 0x3ffff;
233
            put_bits(&s->pb, 18, v);
233
            put_bits(&s->pb, 18, v & 0x3FFFF);
234 234
            put_bits(&s->pb, 1, 1); /* marker */
235 235

  
236 236
            if(s->avctx->rc_buffer_size)
......
238 238
            else
239 239
                /* VBV calculation: Scaled so that a VCD has the proper VBV size of 40 kilobytes */
240 240
                vbv_buffer_size = (( 20 * s->bit_rate) / (1151929 / 2)) * 8 * 1024;	 
241
            put_bits(&s->pb, 10, (vbv_buffer_size + 16383) / 16384); 
241
            put_bits(&s->pb, 10, ((vbv_buffer_size + 16383) / 16384) & 0x3FF); 
242 242
            put_bits(&s->pb, 1, 1); /* constrained parameter flag */
243 243
            
244 244
            ff_write_quant_matrix(&s->pb, s->avctx->intra_matrix);
245 245
            ff_write_quant_matrix(&s->pb, s->avctx->inter_matrix);
246 246

  
247
            if(s->codec_id == CODEC_ID_MPEG2VIDEO){
248
                put_header(s, EXT_START_CODE);
249
                put_bits(&s->pb, 4, 1); //seq ext
250
                put_bits(&s->pb, 1, 0); //esc
251
                put_bits(&s->pb, 3, 4); //profile
252
                put_bits(&s->pb, 4, 8); //level
253
                put_bits(&s->pb, 1, s->progressive_sequence=1);
254
                put_bits(&s->pb, 2, 1); //chroma format 4:2:0
255
                put_bits(&s->pb, 2, 0); //horizontal size ext
256
                put_bits(&s->pb, 2, 0); //vertical size ext
257
                put_bits(&s->pb, 12, v>>18); //bitrate ext
258
                put_bits(&s->pb, 1, 1); //marker
259
                put_bits(&s->pb, 8, vbv_buffer_size >>10); //vbv buffer ext
260
                put_bits(&s->pb, 1, s->low_delay);
261
                put_bits(&s->pb, 2, 0); // frame_rate_ext_n
262
                put_bits(&s->pb, 5, 0); // frame_rate_ext_d
263
            }
264
            
247 265
            put_header(s, GOP_START_CODE);
248 266
            put_bits(&s->pb, 1, 0); /* do drop frame */
249 267
            /* time code : we must convert from the real frame rate to a
......
286 304
/* insert a fake P picture */
287 305
static void mpeg1_skip_picture(MpegEncContext *s, int pict_num)
288 306
{
307
    assert(s->codec_id == CODEC_ID_MPEG1VIDEO); // mpeg2 can do these repeat things
308

  
289 309
    /* mpeg1 picture header */
290 310
    put_header(s, PICTURE_START_CODE);
291 311
    /* temporal reference */
......
372 392
    if (s->pict_type == B_TYPE) {
373 393
        put_bits(&s->pb, 1, 0); /* half pel coordinates */
374 394
        put_bits(&s->pb, 3, s->b_code); /* backward_f_code */
375
        }
395
    }
376 396

  
377 397
    put_bits(&s->pb, 1, 0); /* extra bit picture */
378 398
    
399
    if(s->codec_id == CODEC_ID_MPEG2VIDEO){
400
        put_header(s, EXT_START_CODE);
401
        put_bits(&s->pb, 4, 8); //pic ext
402
        put_bits(&s->pb, 4, s->f_code);
403
        put_bits(&s->pb, 4, s->f_code);
404
        put_bits(&s->pb, 4, s->b_code);
405
        put_bits(&s->pb, 4, s->b_code);
406
        put_bits(&s->pb, 2, s->intra_dc_precision);
407
        put_bits(&s->pb, 2, s->picture_structure= PICT_FRAME);
408
        put_bits(&s->pb, 1, s->top_field_first);
409
        put_bits(&s->pb, 1, s->frame_pred_frame_dct= 1);
410
        put_bits(&s->pb, 1, s->concealment_motion_vectors);
411
        put_bits(&s->pb, 1, s->q_scale_type);
412
        put_bits(&s->pb, 1, s->intra_vlc_format);
413
        put_bits(&s->pb, 1, s->alternate_scan);
414
        put_bits(&s->pb, 1, s->repeat_first_field);
415
        put_bits(&s->pb, 1, s->chroma_420_type=1);
416
        put_bits(&s->pb, 1, s->progressive_frame=1);
417
        put_bits(&s->pb, 1, 0); //composite_display_flag
418
    }
419
    
379 420
    s->mb_y=0;
380 421
    ff_mpeg1_encode_slice_header(s);
381 422
}
......
396 437
            cbp |= 1 << (5 - i);
397 438
    }
398 439

  
399
    if (cbp == 0 && !first_mb && (mb_x != s->mb_width - 1 || mb_y != s->mb_height - 1) && 
440
    if (cbp == 0 && !first_mb && (mb_x != s->mb_width - 1 || (mb_y != s->mb_height - 1 && s->codec_id == CODEC_ID_MPEG1VIDEO)) && 
400 441
        ((s->pict_type == P_TYPE && (motion_x | motion_y) == 0) ||
401 442
        (s->pict_type == B_TYPE && s->mv_dir == s->last_mv_dir && (((s->mv_dir & MV_DIR_FORWARD) ? ((s->mv[0][0][0] - s->last_mv[0][0][0])|(s->mv[0][0][1] - s->last_mv[0][0][1])) : 0) |
402 443
        ((s->mv_dir & MV_DIR_BACKWARD) ? ((s->mv[1][0][0] - s->last_mv[1][0][0])|(s->mv[1][0][1] - s->last_mv[1][0][1])) : 0)) == 0))) {
......
708 749
    }
709 750
    s->me.mv_penalty= mv_penalty;
710 751
    s->fcode_tab= fcode_tab;
711
    s->min_qcoeff=-255;
712
    s->max_qcoeff= 255;
752
    if(s->codec_id == CODEC_ID_MPEG1VIDEO){
753
        s->min_qcoeff=-255;
754
        s->max_qcoeff= 255;
755
    }else{
756
        s->min_qcoeff=-2047;
757
        s->max_qcoeff= 2047;
758
    }
713 759
    s->intra_ac_vlc_length=
714 760
    s->inter_ac_vlc_length= uni_mpeg1_ac_vlc_len;
715 761
}
......
747 793
        encode_dc(s, diff, component);
748 794
        s->last_dc[component] = dc;
749 795
        i = 1;
796
/*
797
        if (s->intra_vlc_format)
798
            rl = &rl_mpeg2;
799
        else
800
            rl = &rl_mpeg1;
801
*/
750 802
    } else {
751 803
        /* encode the first coefficient : needs to be done here because
752 804
           it is handled slightly differently */
......
791 843
                put_bits(&s->pb, mpeg1_vlc[111/*rl->n*/][1], mpeg1_vlc[111/*rl->n*/][0]);
792 844
                /* escape: only clip in this case */
793 845
                put_bits(&s->pb, 6, run);
794
                if (alevel < 128) {
795
                    put_bits(&s->pb, 8, level & 0xff);
796
                } else {
797
                    if (level < 0) {
798
                        put_bits(&s->pb, 16, 0x8001 + level + 255);
846
                if(s->codec_id == CODEC_ID_MPEG1VIDEO){
847
                    if (alevel < 128) {
848
                        put_bits(&s->pb, 8, level & 0xff);
799 849
                    } else {
800
                        put_bits(&s->pb, 16, level & 0xffff);
850
                        if (level < 0) {
851
                            put_bits(&s->pb, 16, 0x8001 + level + 255);
852
                        } else {
853
                            put_bits(&s->pb, 16, level & 0xffff);
854
                        }
801 855
                    }
856
                }else{
857
                    put_bits(&s->pb, 12, level & 0xfff);
802 858
                }
803 859
            }
804 860
            last_non_zero = i;
......
868 924
static inline int get_qscale(MpegEncContext *s)
869 925
{
870 926
    int qscale = get_bits(&s->gb, 5);
871
    if (s->mpeg2) {
927
    if (s->codec_id == CODEC_ID_MPEG2VIDEO) {
872 928
        if (s->q_scale_type) {
873 929
            return non_linear_qscale[qscale];
874 930
        } else {
......
987 1043
            memset(s->last_mv, 0, sizeof(s->last_mv)); /* reset mv prediction */
988 1044
        s->mb_intra = 1;
989 1045

  
990
        if (s->mpeg2) {
1046
        if (s->codec_id == CODEC_ID_MPEG2VIDEO) {
991 1047
            for(i=0;i<6;i++) {
992 1048
                if (mpeg2_decode_block_intra(s, block[i], i) < 0)
993 1049
                    return -1;
......
1165 1221
            }
1166 1222
            cbp++;
1167 1223

  
1168
            if (s->mpeg2) {
1224
            if (s->codec_id == CODEC_ID_MPEG2VIDEO) {
1169 1225
                for(i=0;i<6;i++) {
1170 1226
                    if (cbp & 32) {
1171 1227
                        if (mpeg2_decode_block_non_intra(s, block[i], i) < 0)
......
1648 1704
    int horiz_size_ext, vert_size_ext;
1649 1705
    int bit_rate_ext, vbv_buf_ext;
1650 1706
    int frame_rate_ext_n, frame_rate_ext_d;
1707
    int level, profile;
1651 1708
    float aspect;
1652 1709

  
1653
    skip_bits(&s->gb, 8); /* profil and level */
1710
    skip_bits(&s->gb, 1); /* profil and level esc*/
1711
    profile= get_bits(&s->gb, 3);
1712
    level= get_bits(&s->gb, 4);
1654 1713
    s->progressive_sequence = get_bits1(&s->gb); /* progressive_sequence */
1655 1714
    skip_bits(&s->gb, 2); /* chroma_format */
1656 1715
    horiz_size_ext = get_bits(&s->gb, 2);
......
1675 1734
        1<<30);
1676 1735

  
1677 1736
    dprintf("sequence extension\n");
1678
    s->mpeg2 = 1;
1737
    s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO;
1679 1738
    s->avctx->sub_id = 2; /* indicates mpeg2 found */
1680 1739

  
1681 1740
    aspect= mpeg2_aspect[s->aspect_ratio_info];
1682 1741
    if(aspect>0.0)      s->avctx->aspect_ratio= s->width/(aspect*s->height);
1683 1742
    else if(aspect<0.0) s->avctx->aspect_ratio= -1.0/aspect;
1743
    
1744
    if(s->avctx->debug & FF_DEBUG_PICT_INFO)
1745
        printf("profile: %d, level: %d \n", profile, level);
1684 1746
}
1685 1747

  
1686 1748
static void mpeg_decode_quant_matrix_extension(MpegEncContext *s)
......
2046 2108
    if (/*s->mb_y<<field_pic == s->mb_height &&*/ !s->first_field) {
2047 2109
        /* end of image */
2048 2110

  
2049
        if(s->mpeg2){
2111
        if(s->codec_id == CODEC_ID_MPEG2VIDEO){
2050 2112
            s->current_picture_ptr->qscale_type= FF_QSCALE_TYPE_MPEG2;
2051 2113
        }else
2052 2114
            s->current_picture_ptr->qscale_type= FF_QSCALE_TYPE_MPEG1;
......
2089 2151
    width = get_bits(&s->gb, 12);
2090 2152
    height = get_bits(&s->gb, 12);
2091 2153
    s->aspect_ratio_info= get_bits(&s->gb, 4);
2092
    if(!s->mpeg2){
2154
    if(s->codec_id == CODEC_ID_MPEG1VIDEO){
2093 2155
        aspect= mpeg1_aspect[s->aspect_ratio_info];
2094 2156
        if(aspect!=0.0) avctx->aspect_ratio= width/(aspect*height);
2095 2157
    }
......
2187 2249
    s->progressive_frame = 1;
2188 2250
    s->picture_structure = PICT_FRAME;
2189 2251
    s->frame_pred_frame_dct = 1;
2190
    s->mpeg2 = 0;
2252
    s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG1VIDEO;
2191 2253
    avctx->sub_id = 1; /* indicates mpeg1 */
2192 2254
    return 0;
2193 2255
}
......
2233 2295
    s->progressive_frame = 1;
2234 2296
    s->picture_structure = PICT_FRAME;
2235 2297
    s->frame_pred_frame_dct = 1;
2236
    s->mpeg2 = 1;
2298
    s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO;
2237 2299
    avctx->sub_id = 2; /* indicates mpeg2 */
2238 2300
    return 0;
2239 2301
}
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,
libavcodec/mpegvideo.h
48 48

  
49 49
#define MAX_PICTURE_COUNT 15
50 50

  
51
#if 1
52
#define ME_MAP_SIZE 4096
53
#define ME_MAP_SHIFT 6
54
#else
51 55
#define ME_MAP_SIZE 64
52 56
#define ME_MAP_SHIFT 3
57
#endif
53 58
#define ME_MAP_MV_BITS 11
54 59

  
55 60
/* run length table */
......
385 390
    int me_method;                       ///< ME algorithm 
386 391
    int scene_change_score;
387 392
    int mv_dir;
388
#define MV_DIR_BACKWARD  1
389
#define MV_DIR_FORWARD   2
393
#define MV_DIR_L1        1
394
#define MV_DIR_L0        2
395
#define MV_DIR_BACKWARD  MV_DIR_L1
396
#define MV_DIR_FORWARD   MV_DIR_L0
390 397
#define MV_DIRECT        4 ///< bidirectional mode where the difference equals the MV of the last P/S/I-Frame (mpeg4)
391 398
    int mv_type;
392 399
#define MV_TYPE_16X16       0   ///< 1 vector for the whole mb 
......
568 575
    uint8_t *tex_pb_buffer;          
569 576
    uint8_t *pb2_buffer;
570 577
    int mpeg_quant;
578
#define FF_QUANT_DEFAULT 0
579
#define FF_QUANT_MPEG2   1
580
#define FF_QUANT_MPEG1   2
581
#define FF_QUANT_H263    3
582

  
571 583
    int16_t (*field_mv_table)[2][2];   ///< used for interlaced b frame decoding 
572 584
    int8_t (*field_select_table)[2];   ///< wtf, no really another table for interlaced b frames 
573 585
    int t_frame;                       ///< time distance of first I -> B, used for interlaced b frames 
......
644 656
    int repeat_first_field;
645 657
    int chroma_420_type;
646 658
    int progressive_frame;
647
    int mpeg2;
648 659
    int full_pel[2];
649 660
    int interlaced_dct;
650 661
    int first_slice;
......
652 663
    
653 664
    /* RTP specific */
654 665
    /* These are explained on avcodec.h */
655
    int rtp_mode;
666
    int rtp_mode; //FIXME simplify this mess (remove callback, merge mode + payload)
656 667
    int rtp_payload_size;
657 668
    void (*rtp_callback)(void *data, int size, int packet_number);
658 669
    uint8_t *ptr_lastgob;
......
870 881
int ff_msmpeg4_decode_init(MpegEncContext *s);
871 882
void ff_msmpeg4_encode_init(MpegEncContext *s);
872 883
int ff_wmv2_decode_picture_header(MpegEncContext * s);
884
int ff_wmv2_decode_secondary_picture_header(MpegEncContext * s);
873 885
void ff_wmv2_add_mb(MpegEncContext *s, DCTELEM block[6][64], uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr);
874 886
void ff_mspel_motion(MpegEncContext *s,
875 887
                               uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,

Also available in: Unified diff