Revision 0da71265

View differences:

ffmpeg.c
2008 2008
            enc->debug= debug;
2009 2009
/*            if(enc->codec->capabilities & CODEC_CAP_TRUNCATED)
2010 2010
                enc->flags|= CODEC_FLAG_TRUNCATED; */
2011
            if(/*enc->codec_id==CODEC_ID_MPEG4 || */enc->codec_id==CODEC_ID_MPEG1VIDEO)
2011
            if(/*enc->codec_id==CODEC_ID_MPEG4 || */enc->codec_id==CODEC_ID_MPEG1VIDEO || enc->codec_id==CODEC_ID_H264)
2012 2012
                enc->flags|= CODEC_FLAG_TRUNCATED;
2013 2013
            
2014 2014
            if(bitexact)
libavcodec/Makefile
16 16
      motion_est.o imgconvert.o imgresample.o \
17 17
      mpeg12.o mpegaudiodec.o pcm.o simple_idct.o \
18 18
      ratecontrol.o adpcm.o eval.o dv.o error_resilience.o \
19
      fft.o mdct.o mace.o huffyuv.o cyuv.o opts.o raw.o
19
      fft.o mdct.o mace.o huffyuv.o cyuv.o opts.o raw.o h264.o golomb.o
20 20
ASM_OBJS=
21 21

  
22 22
# codecs which are patented in some non free countries like the us
libavcodec/allcodecs.c
50 50
    register_avcodec(&oggvorbis_decoder);
51 51
#endif
52 52
    register_avcodec(&mpeg1video_encoder);
53
//    register_avcodec(&h264_encoder);
53 54
#ifdef CONFIG_RISKY
54 55
    register_avcodec(&h263_encoder);
55 56
    register_avcodec(&h263p_encoder);
......
93 94
    register_avcodec(&mace6_decoder);
94 95
    register_avcodec(&huffyuv_decoder);
95 96
    register_avcodec(&cyuv_decoder);
97
    register_avcodec(&h264_decoder);
96 98
#ifdef CONFIG_AC3
97 99
    register_avcodec(&ac3_decoder);
98 100
#endif
libavcodec/avcodec.h
49 49
    CODEC_ID_MACE6,
50 50
    CODEC_ID_HUFFYUV,
51 51
    CODEC_ID_CYUV,
52
    CODEC_ID_H264,
52 53

  
53 54
    /* various pcm "codecs" */
54 55
    CODEC_ID_PCM_S16LE,
......
210 211
    int key_frame;\
211 212
\
212 213
    /**\
213
     * picture type of the frame, see ?_TYPE below\
214
     * picture type of the frame, see ?_TYPE below.\
214 215
     * - encoding: set by lavc for coded_picture (and set by user for input)\
215 216
     * - decoding: set by lavc\
216 217
     */\
......
320 321
#define FF_P_TYPE 2 // Predicted
321 322
#define FF_B_TYPE 3 // Bi-dir predicted
322 323
#define FF_S_TYPE 4 // S(GMC)-VOP MPEG4
324
#define FF_SI_TYPE 5
325
#define FF_SP_TYPE 6
323 326

  
327
/**
328
 * Audio Video Frame.
329
 */
324 330
typedef struct AVFrame {
325 331
    FF_COMMON_FRAME
326 332
} AVFrame;
......
906 912
#define FF_DEBUG_STARTCODE 0x00000100
907 913
#define FF_DEBUG_PTS       0x00000200
908 914
#define FF_DEBUG_ER        0x00000400
915
#define FF_DEBUG_MMCO      0x00000800
909 916
    
910 917
    /**
911 918
     * error.
......
1149 1156
extern AVCodec wmv1_encoder;
1150 1157
extern AVCodec wmv2_encoder;
1151 1158
extern AVCodec huffyuv_encoder;
1159
extern AVCodec h264_encoder;
1152 1160

  
1153 1161
extern AVCodec h263_decoder;
1154 1162
extern AVCodec mpeg4_decoder;
......
1174 1182
extern AVCodec huffyuv_decoder;
1175 1183
extern AVCodec oggvorbis_decoder;
1176 1184
extern AVCodec cyuv_decoder;
1185
extern AVCodec h264_decoder;
1177 1186

  
1178 1187
/* pcm codecs */
1179 1188
#define PCM_CODEC(id, name) \
libavcodec/dsputil.c
466 466
#else // 64 bit variant
467 467

  
468 468
#define PIXOP2(OPNAME, OP) \
469
static void OPNAME ## _pixels4_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
470
    int i;\
471
    for(i=0; i<h; i++){\
472
        OP(*((uint32_t*)(block  )), LD32(pixels  ));\
473
        pixels+=line_size;\
474
        block +=line_size;\
475
    }\
476
}\
469 477
static void OPNAME ## _pixels8_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
470 478
    int i;\
471 479
    for(i=0; i<h; i++){\
......
507 515
    }\
508 516
}\
509 517
\
518
static inline void OPNAME ## _pixels4_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
519
                                                int src_stride1, int src_stride2, int h){\
520
    int i;\
521
    for(i=0; i<h; i++){\
522
        uint32_t a,b;\
523
        a= LD32(&src1[i*src_stride1  ]);\
524
        b= LD32(&src2[i*src_stride2  ]);\
525
        OP(*((uint32_t*)&dst[i*dst_stride  ]), (a|b) - (((a^b)&0xFEFEFEFEUL)>>1));\
526
    }\
527
}\
528
\
510 529
static inline void OPNAME ## _pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
511 530
                                                int src_stride1, int src_stride2, int h){\
512 531
    OPNAME ## _pixels8_l2(dst  , src1  , src2  , dst_stride, src_stride1, src_stride2, h);\
......
800 819
        oy += dyy;
801 820
    }
802 821
}
822
#define H264_CHROMA_MC(OPNAME, OP)\
823
static void OPNAME ## h264_chroma_mc2_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
824
    const int A=(8-x)*(8-y);\
825
    const int B=(  x)*(8-y);\
826
    const int C=(8-x)*(  y);\
827
    const int D=(  x)*(  y);\
828
    int i;\
829
    \
830
    assert(x<8 && y<8 && x>=0 && y>=0);\
831
\
832
    for(i=0; i<h; i++)\
833
    {\
834
        OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
835
        OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
836
        dst+= stride;\
837
        src+= stride;\
838
    }\
839
}\
840
\
841
static void OPNAME ## h264_chroma_mc4_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
842
    const int A=(8-x)*(8-y);\
843
    const int B=(  x)*(8-y);\
844
    const int C=(8-x)*(  y);\
845
    const int D=(  x)*(  y);\
846
    int i;\
847
    \
848
    assert(x<8 && y<8 && x>=0 && y>=0);\
849
\
850
    for(i=0; i<h; i++)\
851
    {\
852
        OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
853
        OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
854
        OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
855
        OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
856
        dst+= stride;\
857
        src+= stride;\
858
    }\
859
}\
860
\
861
static void OPNAME ## h264_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
862
    const int A=(8-x)*(8-y);\
863
    const int B=(  x)*(8-y);\
864
    const int C=(8-x)*(  y);\
865
    const int D=(  x)*(  y);\
866
    int i;\
867
    \
868
    assert(x<8 && y<8 && x>=0 && y>=0);\
869
\
870
    for(i=0; i<h; i++)\
871
    {\
872
        OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
873
        OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
874
        OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
875
        OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
876
        OP(dst[4], (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5]));\
877
        OP(dst[5], (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6]));\
878
        OP(dst[6], (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7]));\
879
        OP(dst[7], (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8]));\
880
        dst+= stride;\
881
        src+= stride;\
882
    }\
883
}
884

  
885
#define op_avg(a, b) a = (((a)+(((b) + 32)>>6)+1)>>1)
886
#define op_put(a, b) a = (((b) + 32)>>6)
887

  
888
H264_CHROMA_MC(put_       , op_put)
889
H264_CHROMA_MC(avg_       , op_avg)
890
#undef op_avg
891
#undef op_put
892

  
893
static inline void copy_block4(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
894
{
895
    int i;
896
    for(i=0; i<h; i++)
897
    {
898
        ST32(dst   , LD32(src   ));
899
        dst+=dstStride;
900
        src+=srcStride;
901
    }
902
}
903

  
904
static inline void copy_block8(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
905
{
906
    int i;
907
    for(i=0; i<h; i++)
908
    {
909
        ST32(dst   , LD32(src   ));
910
        ST32(dst+4 , LD32(src+4 ));
911
        dst+=dstStride;
912
        src+=srcStride;
913
    }
914
}
915

  
916
static inline void copy_block16(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
917
{
918
    int i;
919
    for(i=0; i<h; i++)
920
    {
921
        ST32(dst   , LD32(src   ));
922
        ST32(dst+4 , LD32(src+4 ));
923
        ST32(dst+8 , LD32(src+8 ));
924
        ST32(dst+12, LD32(src+12));
925
        dst+=dstStride;
926
        src+=srcStride;
927
    }
928
}
803 929

  
804 930
static inline void copy_block17(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
805 931
{
......
1327 1453
#undef op_put
1328 1454
#undef op_put_no_rnd
1329 1455

  
1456
#if 1
1457
#define H264_LOWPASS(OPNAME, OP, OP2) \
1458
static void OPNAME ## h264_qpel4_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1459
    const int h=4;\
1460
    uint8_t *cm = cropTbl + MAX_NEG_CROP;\
1461
    int i;\
1462
    for(i=0; i<h; i++)\
1463
    {\
1464
        OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
1465
        OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
1466
        OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]));\
1467
        OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]));\
1468
        dst+=dstStride;\
1469
        src+=srcStride;\
1470
    }\
1471
}\
1472
\
1473
static void OPNAME ## h264_qpel4_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1474
    const int w=4;\
1475
    uint8_t *cm = cropTbl + MAX_NEG_CROP;\
1476
    int i;\
1477
    for(i=0; i<w; i++)\
1478
    {\
1479
        const int srcB= src[-2*srcStride];\
1480
        const int srcA= src[-1*srcStride];\
1481
        const int src0= src[0 *srcStride];\
1482
        const int src1= src[1 *srcStride];\
1483
        const int src2= src[2 *srcStride];\
1484
        const int src3= src[3 *srcStride];\
1485
        const int src4= src[4 *srcStride];\
1486
        const int src5= src[5 *srcStride];\
1487
        const int src6= src[6 *srcStride];\
1488
        OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
1489
        OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
1490
        OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
1491
        OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
1492
        dst++;\
1493
        src++;\
1494
    }\
1495
}\
1496
\
1497
static void OPNAME ## h264_qpel4_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
1498
    const int h=4;\
1499
    const int w=4;\
1500
    uint8_t *cm = cropTbl + MAX_NEG_CROP;\
1501
    int i;\
1502
    src -= 2*srcStride;\
1503
    for(i=0; i<h+5; i++)\
1504
    {\
1505
        tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]);\
1506
        tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]);\
1507
        tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]);\
1508
        tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]);\
1509
        tmp+=tmpStride;\
1510
        src+=srcStride;\
1511
    }\
1512
    tmp -= tmpStride*(h+5-2);\
1513
    for(i=0; i<w; i++)\
1514
    {\
1515
        const int tmpB= tmp[-2*tmpStride];\
1516
        const int tmpA= tmp[-1*tmpStride];\
1517
        const int tmp0= tmp[0 *tmpStride];\
1518
        const int tmp1= tmp[1 *tmpStride];\
1519
        const int tmp2= tmp[2 *tmpStride];\
1520
        const int tmp3= tmp[3 *tmpStride];\
1521
        const int tmp4= tmp[4 *tmpStride];\
1522
        const int tmp5= tmp[5 *tmpStride];\
1523
        const int tmp6= tmp[6 *tmpStride];\
1524
        OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
1525
        OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
1526
        OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
1527
        OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
1528
        dst++;\
1529
        tmp++;\
1530
    }\
1531
}\
1532
\
1533
static void OPNAME ## h264_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1534
    const int h=8;\
1535
    uint8_t *cm = cropTbl + MAX_NEG_CROP;\
1536
    int i;\
1537
    for(i=0; i<h; i++)\
1538
    {\
1539
        OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]));\
1540
        OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]));\
1541
        OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]));\
1542
        OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]));\
1543
        OP(dst[4], (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]));\
1544
        OP(dst[5], (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]));\
1545
        OP(dst[6], (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]));\
1546
        OP(dst[7], (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]));\
1547
        dst+=dstStride;\
1548
        src+=srcStride;\
1549
    }\
1550
}\
1551
\
1552
static void OPNAME ## h264_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1553
    const int w=8;\
1554
    uint8_t *cm = cropTbl + MAX_NEG_CROP;\
1555
    int i;\
1556
    for(i=0; i<w; i++)\
1557
    {\
1558
        const int srcB= src[-2*srcStride];\
1559
        const int srcA= src[-1*srcStride];\
1560
        const int src0= src[0 *srcStride];\
1561
        const int src1= src[1 *srcStride];\
1562
        const int src2= src[2 *srcStride];\
1563
        const int src3= src[3 *srcStride];\
1564
        const int src4= src[4 *srcStride];\
1565
        const int src5= src[5 *srcStride];\
1566
        const int src6= src[6 *srcStride];\
1567
        const int src7= src[7 *srcStride];\
1568
        const int src8= src[8 *srcStride];\
1569
        const int src9= src[9 *srcStride];\
1570
        const int src10=src[10*srcStride];\
1571
        OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
1572
        OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
1573
        OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
1574
        OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
1575
        OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*5 + (src2+src7));\
1576
        OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*5 + (src3+src8));\
1577
        OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*5 + (src4+src9));\
1578
        OP(dst[7*dstStride], (src7+src8)*20 - (src6+src9)*5 + (src5+src10));\
1579
        dst++;\
1580
        src++;\
1581
    }\
1582
}\
1583
\
1584
static void OPNAME ## h264_qpel8_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
1585
    const int h=8;\
1586
    const int w=8;\
1587
    uint8_t *cm = cropTbl + MAX_NEG_CROP;\
1588
    int i;\
1589
    src -= 2*srcStride;\
1590
    for(i=0; i<h+5; i++)\
1591
    {\
1592
        tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]);\
1593
        tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]);\
1594
        tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]);\
1595
        tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]);\
1596
        tmp[4]= (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]);\
1597
        tmp[5]= (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]);\
1598
        tmp[6]= (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]);\
1599
        tmp[7]= (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]);\
1600
        tmp+=tmpStride;\
1601
        src+=srcStride;\
1602
    }\
1603
    tmp -= tmpStride*(h+5-2);\
1604
    for(i=0; i<w; i++)\
1605
    {\
1606
        const int tmpB= tmp[-2*tmpStride];\
1607
        const int tmpA= tmp[-1*tmpStride];\
1608
        const int tmp0= tmp[0 *tmpStride];\
1609
        const int tmp1= tmp[1 *tmpStride];\
1610
        const int tmp2= tmp[2 *tmpStride];\
1611
        const int tmp3= tmp[3 *tmpStride];\
1612
        const int tmp4= tmp[4 *tmpStride];\
1613
        const int tmp5= tmp[5 *tmpStride];\
1614
        const int tmp6= tmp[6 *tmpStride];\
1615
        const int tmp7= tmp[7 *tmpStride];\
1616
        const int tmp8= tmp[8 *tmpStride];\
1617
        const int tmp9= tmp[9 *tmpStride];\
1618
        const int tmp10=tmp[10*tmpStride];\
1619
        OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
1620
        OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
1621
        OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
1622
        OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
1623
        OP2(dst[4*dstStride], (tmp4+tmp5)*20 - (tmp3+tmp6)*5 + (tmp2+tmp7));\
1624
        OP2(dst[5*dstStride], (tmp5+tmp6)*20 - (tmp4+tmp7)*5 + (tmp3+tmp8));\
1625
        OP2(dst[6*dstStride], (tmp6+tmp7)*20 - (tmp5+tmp8)*5 + (tmp4+tmp9));\
1626
        OP2(dst[7*dstStride], (tmp7+tmp8)*20 - (tmp6+tmp9)*5 + (tmp5+tmp10));\
1627
        dst++;\
1628
        tmp++;\
1629
    }\
1630
}\
1631
\
1632
static void OPNAME ## h264_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1633
    OPNAME ## h264_qpel8_v_lowpass(dst  , src  , dstStride, srcStride);\
1634
    OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\
1635
    src += 8*srcStride;\
1636
    dst += 8*dstStride;\
1637
    OPNAME ## h264_qpel8_v_lowpass(dst  , src  , dstStride, srcStride);\
1638
    OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\
1639
}\
1640
\
1641
static void OPNAME ## h264_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1642
    OPNAME ## h264_qpel8_h_lowpass(dst  , src  , dstStride, srcStride);\
1643
    OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\
1644
    src += 8*srcStride;\
1645
    dst += 8*dstStride;\
1646
    OPNAME ## h264_qpel8_h_lowpass(dst  , src  , dstStride, srcStride);\
1647
    OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\
1648
}\
1649
\
1650
static void OPNAME ## h264_qpel16_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
1651
    OPNAME ## h264_qpel8_hv_lowpass(dst  , tmp  , src  , dstStride, tmpStride, srcStride);\
1652
    OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\
1653
    src += 8*srcStride;\
1654
    tmp += 8*tmpStride;\
1655
    dst += 8*dstStride;\
1656
    OPNAME ## h264_qpel8_hv_lowpass(dst  , tmp  , src  , dstStride, tmpStride, srcStride);\
1657
    OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\
1658
}\
1659

  
1660
#define H264_MC(OPNAME, SIZE) \
1661
static void OPNAME ## h264_qpel ## SIZE ## _mc00_c (uint8_t *dst, uint8_t *src, int stride){\
1662
    OPNAME ## pixels ## SIZE ## _c(dst, src, stride, SIZE);\
1663
}\
1664
\
1665
static void OPNAME ## h264_qpel ## SIZE ## _mc10_c(uint8_t *dst, uint8_t *src, int stride){\
1666
    uint8_t half[SIZE*SIZE];\
1667
    put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
1668
    OPNAME ## pixels ## SIZE ## _l2(dst, src, half, stride, stride, SIZE, SIZE);\
1669
}\
1670
\
1671
static void OPNAME ## h264_qpel ## SIZE ## _mc20_c(uint8_t *dst, uint8_t *src, int stride){\
1672
    OPNAME ## h264_qpel ## SIZE ## _h_lowpass(dst, src, stride, stride);\
1673
}\
1674
\
1675
static void OPNAME ## h264_qpel ## SIZE ## _mc30_c(uint8_t *dst, uint8_t *src, int stride){\
1676
    uint8_t half[SIZE*SIZE];\
1677
    put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
1678
    OPNAME ## pixels ## SIZE ## _l2(dst, src+1, half, stride, stride, SIZE, SIZE);\
1679
}\
1680
\
1681
static void OPNAME ## h264_qpel ## SIZE ## _mc01_c(uint8_t *dst, uint8_t *src, int stride){\
1682
    uint8_t full[SIZE*(SIZE+5)];\
1683
    uint8_t * const full_mid= full + SIZE*2;\
1684
    uint8_t half[SIZE*SIZE];\
1685
    copy_block ## SIZE (full, src - stride*2, SIZE,  stride, SIZE + 5);\
1686
    put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
1687
    OPNAME ## pixels ## SIZE ## _l2(dst, full_mid, half, stride, SIZE, SIZE, SIZE);\
1688
}\
1689
\
1690
static void OPNAME ## h264_qpel ## SIZE ## _mc02_c(uint8_t *dst, uint8_t *src, int stride){\
1691
    uint8_t full[SIZE*(SIZE+5)];\
1692
    uint8_t * const full_mid= full + SIZE*2;\
1693
    copy_block ## SIZE (full, src - stride*2, SIZE,  stride, SIZE + 5);\
1694
    OPNAME ## h264_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE);\
1695
}\
1696
\
1697
static void OPNAME ## h264_qpel ## SIZE ## _mc03_c(uint8_t *dst, uint8_t *src, int stride){\
1698
    uint8_t full[SIZE*(SIZE+5)];\
1699
    uint8_t * const full_mid= full + SIZE*2;\
1700
    uint8_t half[SIZE*SIZE];\
1701
    copy_block ## SIZE (full, src - stride*2, SIZE,  stride, SIZE + 5);\
1702
    put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
1703
    OPNAME ## pixels ## SIZE ## _l2(dst, full_mid+SIZE, half, stride, SIZE, SIZE, SIZE);\
1704
}\
1705
\
1706
static void OPNAME ## h264_qpel ## SIZE ## _mc11_c(uint8_t *dst, uint8_t *src, int stride){\
1707
    uint8_t full[SIZE*(SIZE+5)];\
1708
    uint8_t * const full_mid= full + SIZE*2;\
1709
    uint8_t halfH[SIZE*SIZE];\
1710
    uint8_t halfV[SIZE*SIZE];\
1711
    put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
1712
    copy_block ## SIZE (full, src - stride*2, SIZE,  stride, SIZE + 5);\
1713
    put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
1714
    OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
1715
}\
1716
\
1717
static void OPNAME ## h264_qpel ## SIZE ## _mc31_c(uint8_t *dst, uint8_t *src, int stride){\
1718
    uint8_t full[SIZE*(SIZE+5)];\
1719
    uint8_t * const full_mid= full + SIZE*2;\
1720
    uint8_t halfH[SIZE*SIZE];\
1721
    uint8_t halfV[SIZE*SIZE];\
1722
    put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
1723
    copy_block ## SIZE (full, src - stride*2 + 1, SIZE,  stride, SIZE + 5);\
1724
    put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
1725
    OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
1726
}\
1727
\
1728
static void OPNAME ## h264_qpel ## SIZE ## _mc13_c(uint8_t *dst, uint8_t *src, int stride){\
1729
    uint8_t full[SIZE*(SIZE+5)];\
1730
    uint8_t * const full_mid= full + SIZE*2;\
1731
    uint8_t halfH[SIZE*SIZE];\
1732
    uint8_t halfV[SIZE*SIZE];\
1733
    put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
1734
    copy_block ## SIZE (full, src - stride*2, SIZE,  stride, SIZE + 5);\
1735
    put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
1736
    OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
1737
}\
1738
\
1739
static void OPNAME ## h264_qpel ## SIZE ## _mc33_c(uint8_t *dst, uint8_t *src, int stride){\
1740
    uint8_t full[SIZE*(SIZE+5)];\
1741
    uint8_t * const full_mid= full + SIZE*2;\
1742
    uint8_t halfH[SIZE*SIZE];\
1743
    uint8_t halfV[SIZE*SIZE];\
1744
    put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
1745
    copy_block ## SIZE (full, src - stride*2 + 1, SIZE,  stride, SIZE + 5);\
1746
    put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
1747
    OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
1748
}\
1749
\
1750
static void OPNAME ## h264_qpel ## SIZE ## _mc22_c(uint8_t *dst, uint8_t *src, int stride){\
1751
    int16_t tmp[SIZE*(SIZE+5)];\
1752
    OPNAME ## h264_qpel ## SIZE ## _hv_lowpass(dst, tmp, src, stride, SIZE, stride);\
1753
}\
1754
\
1755
static void OPNAME ## h264_qpel ## SIZE ## _mc21_c(uint8_t *dst, uint8_t *src, int stride){\
1756
    int16_t tmp[SIZE*(SIZE+5)];\
1757
    uint8_t halfH[SIZE*SIZE];\
1758
    uint8_t halfHV[SIZE*SIZE];\
1759
    put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
1760
    put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
1761
    OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
1762
}\
1763
\
1764
static void OPNAME ## h264_qpel ## SIZE ## _mc23_c(uint8_t *dst, uint8_t *src, int stride){\
1765
    int16_t tmp[SIZE*(SIZE+5)];\
1766
    uint8_t halfH[SIZE*SIZE];\
1767
    uint8_t halfHV[SIZE*SIZE];\
1768
    put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
1769
    put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
1770
    OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
1771
}\
1772
\
1773
static void OPNAME ## h264_qpel ## SIZE ## _mc12_c(uint8_t *dst, uint8_t *src, int stride){\
1774
    uint8_t full[SIZE*(SIZE+5)];\
1775
    uint8_t * const full_mid= full + SIZE*2;\
1776
    int16_t tmp[SIZE*(SIZE+5)];\
1777
    uint8_t halfV[SIZE*SIZE];\
1778
    uint8_t halfHV[SIZE*SIZE];\
1779
    copy_block ## SIZE (full, src - stride*2, SIZE,  stride, SIZE + 5);\
1780
    put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
1781
    put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
1782
    OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
1783
}\
1784
\
1785
static void OPNAME ## h264_qpel ## SIZE ## _mc32_c(uint8_t *dst, uint8_t *src, int stride){\
1786
    uint8_t full[SIZE*(SIZE+5)];\
1787
    uint8_t * const full_mid= full + SIZE*2;\
1788
    int16_t tmp[SIZE*(SIZE+5)];\
1789
    uint8_t halfV[SIZE*SIZE];\
1790
    uint8_t halfHV[SIZE*SIZE];\
1791
    copy_block ## SIZE (full, src - stride*2 + 1, SIZE,  stride, SIZE + 5);\
1792
    put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
1793
    put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
1794
    OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
1795
}\
1796

  
1797
#define op_avg(a, b)  a = (((a)+cm[((b) + 16)>>5]+1)>>1)
1798
//#define op_avg2(a, b) a = (((a)*w1+cm[((b) + 16)>>5]*w2 + o + 64)>>7)
1799
#define op_put(a, b)  a = cm[((b) + 16)>>5]
1800
#define op2_avg(a, b)  a = (((a)+cm[((b) + 512)>>10]+1)>>1)
1801
#define op2_put(a, b)  a = cm[((b) + 512)>>10]
1802

  
1803
H264_LOWPASS(put_       , op_put, op2_put)
1804
H264_LOWPASS(avg_       , op_avg, op2_avg)
1805
H264_MC(put_, 4)
1806
H264_MC(put_, 8)
1807
H264_MC(put_, 16)
1808
H264_MC(avg_, 4)
1809
H264_MC(avg_, 8)
1810
H264_MC(avg_, 16)
1811

  
1812
#undef op_avg
1813
#undef op_put
1814
#undef op2_avg
1815
#undef op2_put
1816
#endif
1817

  
1330 1818
static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){
1331 1819
    uint8_t *cm = cropTbl + MAX_NEG_CROP;
1332 1820
    int i;
......
2107 2595

  
2108 2596
    dspfunc(avg_qpel, 1, 8);
2109 2597
    /* dspfunc(avg_no_rnd_qpel, 1, 8); */
2598

  
2599
    dspfunc(put_h264_qpel, 0, 16);
2600
    dspfunc(put_h264_qpel, 1, 8);
2601
    dspfunc(put_h264_qpel, 2, 4);
2602
    dspfunc(avg_h264_qpel, 0, 16);
2603
    dspfunc(avg_h264_qpel, 1, 8);
2604
    dspfunc(avg_h264_qpel, 2, 4);
2605

  
2110 2606
#undef dspfunc
2607
    c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_c;
2608
    c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_c;
2609
    c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_c;
2610
    c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_c;
2611
    c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_c;
2612
    c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_c;
2111 2613

  
2112 2614
    c->put_mspel_pixels_tab[0]= put_mspel8_mc00_c;
2113 2615
    c->put_mspel_pixels_tab[1]= put_mspel8_mc10_c;
libavcodec/dsputil.h
76 76
// blocksizes for op_pixels_func are 8x4,8x8 16x8 16x16
77 77
typedef void (*op_pixels_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int h);
78 78
typedef void (*qpel_mc_func)(uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
79
typedef void (*h264_chroma_mc_func)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x, int y);
79 80

  
80 81
#define DEF_OLD_QPEL(name)\
81 82
void ff_put_        ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
......
107 108

  
108 109
typedef int (*me_cmp_func)(void /*MpegEncContext*/ *s, uint8_t *blk1/*align width (8 or 16)*/, uint8_t *blk2/*align 1*/, int line_size)/* __attribute__ ((const))*/;
109 110

  
111

  
110 112
/**
111 113
 * DSPContext.
112 114
 */
......
187 189
    qpel_mc_func put_no_rnd_qpel_pixels_tab[2][16];
188 190
    qpel_mc_func avg_no_rnd_qpel_pixels_tab[2][16];
189 191
    qpel_mc_func put_mspel_pixels_tab[8];
192
    
193
    /**
194
     * h264 Chram MC
195
     */
196
    h264_chroma_mc_func put_h264_chroma_pixels_tab[3];
197
    h264_chroma_mc_func avg_h264_chroma_pixels_tab[3];
190 198

  
199
    qpel_mc_func put_h264_qpel_pixels_tab[3][16];
200
    qpel_mc_func avg_h264_qpel_pixels_tab[3][16];
201
    
191 202
    op_pixels_abs_func pix_abs16x16;
192 203
    op_pixels_abs_func pix_abs16x16_x2;
193 204
    op_pixels_abs_func pix_abs16x16_y2;
libavcodec/golomb.c
1
/*
2
 * exp golomb vlc stuff
3
 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2 of the License, or (at your option) any later version.
9
 *
10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 *
19
 */
20
 
21
/**
22
 * @file golomb.c
23
 * @brief 
24
 *     exp golomb vlc stuff
25
 * @author Michael Niedermayer <michaelni@gmx.at>
26
 */
27

  
28
#include <inttypes.h>
29
 
30
const uint8_t ff_golomb_vlc_len[512]={
31
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
32
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
33
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
34
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
35
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
36
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
37
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
38
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
39
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
40
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
41
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
42
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
43
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
44
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
45
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
46
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
47
};
48

  
49
const uint8_t ff_ue_golomb_vlc_code[512]={ 
50
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,
51
 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,14,
52
 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
53
 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
54
 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
55
 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
56
 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
57
 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
58
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
59
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
60
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
61
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
62
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
63
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
64
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
65
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
66
};
67

  
68
const int8_t ff_se_golomb_vlc_code[512]={ 
69
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  8, -8,  9, -9, 10,-10, 11,-11, 12,-12, 13,-13, 14,-14, 15,-15,
70
  4,  4,  4,  4, -4, -4, -4, -4,  5,  5,  5,  5, -5, -5, -5, -5,  6,  6,  6,  6, -6, -6, -6, -6,  7,  7,  7,  7, -7, -7, -7, -7,
71
  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
72
  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3,
73
  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,
74
  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,
75
 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
76
 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
77
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
78
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
79
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
80
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
81
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
82
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
83
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
84
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
85
};
86

  
87

  
88
const uint8_t ff_ue_golomb_len[256]={ 
89
 1, 3, 3, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
90
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,13,
91
13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
92
13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,15,
93
15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
94
15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
95
15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
96
15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,17,
97
};
libavcodec/golomb.h
1
/*
2
 * exp golomb vlc stuff
3
 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2 of the License, or (at your option) any later version.
9
 *
10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 *
19
 */
20
 
21
/**
22
 * @file golomb.h
23
 * @brief 
24
 *     exp golomb vlc stuff
25
 * @author Michael Niedermayer <michaelni@gmx.at>
26
 */
27

  
28
extern const uint8_t ff_golomb_vlc_len[512];
29
extern const uint8_t ff_ue_golomb_vlc_code[512];
30
extern const  int8_t ff_se_golomb_vlc_code[512];
31
extern const uint8_t ff_ue_golomb_len[256];
32

  
33
 
34
 /**
35
 * read unsigned exp golomb code.
36
 */
37
static inline int get_ue_golomb(GetBitContext *gb){
38
    unsigned int buf;
39
    int log;
40
    
41
    OPEN_READER(re, gb);
42
    UPDATE_CACHE(re, gb);
43
    buf=GET_CACHE(re, gb);
44
    
45
    if(buf >= (1<<27)){
46
        buf >>= 32 - 9;
47
        LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]);
48
        CLOSE_READER(re, gb);
49
    
50
        return ff_ue_golomb_vlc_code[buf];
51
    }else{
52
        log= 2*av_log2(buf) - 31;
53
        buf>>= log;
54
        buf--;
55
        LAST_SKIP_BITS(re, gb, 32 - log);
56
        CLOSE_READER(re, gb);
57
    
58
        return buf;
59
    }
60
}
61

  
62
/**
63
 * read unsigned truncated exp golomb code.
64
 */
65
static inline int get_te0_golomb(GetBitContext *gb, int range){
66
    assert(range >= 1);
67
    
68
    if(range==1)      return 0;
69
    else if(range==2) return get_bits1(gb);
70
    else              return get_ue_golomb(gb);
71
}
72

  
73
/**
74
 * read unsigned truncated exp golomb code.
75
 */
76
static inline int get_te_golomb(GetBitContext *gb, int range){
77
    assert(range >= 1);
78
    
79
    if(range==2) return get_bits1(gb);
80
    else         return get_ue_golomb(gb);
81
}
82

  
83

  
84
/**
85
 * read signed exp golomb code.
86
 */
87
static inline int get_se_golomb(GetBitContext *gb){
88
    unsigned int buf;
89
    int log;
90
    
91
    OPEN_READER(re, gb);
92
    UPDATE_CACHE(re, gb);
93
    buf=GET_CACHE(re, gb);
94
    
95
    if(buf >= (1<<27)){
96
        buf >>= 32 - 9;
97
        LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]);
98
        CLOSE_READER(re, gb);
99
    
100
        return ff_se_golomb_vlc_code[buf];
101
    }else{
102
        log= 2*av_log2(buf) - 31;
103
        buf>>= log;
104
        
105
        LAST_SKIP_BITS(re, gb, 32 - log);
106
        CLOSE_READER(re, gb);
107
    
108
        if(buf&1) buf= -(buf>>1);
109
        else      buf=  (buf>>1);
110

  
111
        return buf;
112
    }
113
}
114

  
115
#ifdef TRACE
116

  
117
static inline int get_ue(GetBitContext *s, char *file, char *func, int line){
118
    int show= show_bits(s, 24);
119
    int pos= get_bits_count(s);
120
    int i= get_ue_golomb(s);
121
    int len= get_bits_count(s) - pos;
122
    int bits= show>>(24-len);
123
    
124
    print_bin(bits, len);
125
    
126
    printf("%5d %2d %3d ue  @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line);
127
    
128
    return i;
129
}
130

  
131
static inline int get_se(GetBitContext *s, char *file, char *func, int line){
132
    int show= show_bits(s, 24);
133
    int pos= get_bits_count(s);
134
    int i= get_se_golomb(s);
135
    int len= get_bits_count(s) - pos;
136
    int bits= show>>(24-len);
137
    
138
    print_bin(bits, len);
139
    
140
    printf("%5d %2d %3d se  @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line);
141
    
142
    return i;
143
}
144

  
145
static inline int get_te(GetBitContext *s, int r, char *file, char *func, int line){
146
    int show= show_bits(s, 24);
147
    int pos= get_bits_count(s);
148
    int i= get_te0_golomb(s, r);
149
    int len= get_bits_count(s) - pos;
150
    int bits= show>>(24-len);
151
    
152
    print_bin(bits, len);
153
    
154
    printf("%5d %2d %3d te  @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line);
155
    
156
    return i;
157
}
158

  
159
#define get_ue_golomb(a) get_ue(a, __FILE__, __PRETTY_FUNCTION__, __LINE__)
160
#define get_se_golomb(a) get_se(a, __FILE__, __PRETTY_FUNCTION__, __LINE__)
161
#define get_te_golomb(a, r) get_te(a, r, __FILE__, __PRETTY_FUNCTION__, __LINE__)
162
#define get_te0_golomb(a, r) get_te(a, r, __FILE__, __PRETTY_FUNCTION__, __LINE__)
163

  
164
#endif
165

  
166
/**
167
 * write unsigned exp golomb code.
168
 */
169
static inline void set_ue_golomb(PutBitContext *pb, int i){
170
    int e;
171
    
172
    assert(i>=0);
173

  
174
#if 0
175
    if(i=0){
176
        put_bits(pb, 1, 1);
177
        return;
178
    }
179
#endif
180
    if(i<256)
181
        put_bits(pb, ff_ue_golomb_len[i], i+1);
182
    else{
183
        e= av_log2(i+1);
184
    
185
        put_bits(pb, 2*e+1, i+1);
186
    }
187
}
188

  
189
/**
190
 * write truncated unsigned exp golomb code.
191
 */
192
static inline void set_te_golomb(PutBitContext *pb, int i, int range){
193
    assert(range >= 1);
194
    assert(i<=range);
195

  
196
    if(range==2) put_bits(pb, 1, i);
197
    else         set_ue_golomb(pb, i);
198
}
199

  
200
/**
201
 * write signed exp golomb code.
202
 */
203
static inline void set_se_golomb(PutBitContext *pb, int i){
204
#if 0 
205
    if(i<=0) i= -2*i;
206
    else     i=  2*i-1;
207
#elif 1
208
    i= 2*i-1;
209
    if(i<0) i^= -1; //FIXME check if gcc does the right thing
210
#else
211
    i= 2*i-1;
212
    i^= (i>>31);
213
#endif
214
    set_ue_golomb(pb, i);
215
}
libavcodec/h264.c
1
/*
2
 * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
3
 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2 of the License, or (at your option) any later version.
9
 *
10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 *
19
 */
20
 
21
/**
22
 * @file h264.c
23
 * H.264 / AVC / MPEG4 part10 codec.
24
 * @author Michael Niedermayer <michaelni@gmx.at>
25
 */
26

  
27
#include "common.h"
28
#include "dsputil.h"
29
#include "avcodec.h"
30
#include "mpegvideo.h"
31
#include "h264data.h"
32
#include "golomb.h"
33

  
34
#undef NDEBUG
35
#include <assert.h>
36

  
37
#define interlaced_dct interlaced_dct_is_a_bad_name
38
#define mb_intra mb_intra_isnt_initalized_see_mb_type
39

  
40
#define LUMA_DC_BLOCK_INDEX   25
41
#define CHROMA_DC_BLOCK_INDEX 26
42

  
43
#define CHROMA_DC_COEFF_TOKEN_VLC_BITS 8
44
#define COEFF_TOKEN_VLC_BITS           8
45
#define TOTAL_ZEROS_VLC_BITS           9
46
#define CHROMA_DC_TOTAL_ZEROS_VLC_BITS 3
47
#define RUN_VLC_BITS                   3
48
#define RUN7_VLC_BITS                  6
49

  
50
#define MAX_SPS_COUNT 32
51
#define MAX_PPS_COUNT 256
52

  
53
#define MAX_MMCO_COUNT 66
54

  
55
/**
56
 * Sequence parameter set
57
 */
58
typedef struct SPS{
59
    
60
    int profile_idc;
61
    int level_idc;
62
    int multiple_slice_groups;         ///< more_than_one_slice_group_allowed_flag
63
    int arbitrary_slice_order;         ///< arbitrary_slice_order_allowed_flag
64
    int redundant_slices;              ///< redundant_slices_allowed_flag
65
    int log2_max_frame_num;            ///< log2_max_frame_num_minus4 + 4
66
    int poc_type;                      ///< pic_order_cnt_type
67
    int log2_max_poc_lsb;              ///< log2_max_pic_order_cnt_lsb_minus4
68
    int delta_pic_order_always_zero_flag;
69
    int offset_for_non_ref_pic;
70
    int offset_for_top_to_bottom_field;
71
    int poc_cycle_length;              ///< num_ref_frames_in_pic_order_cnt_cycle
72
    int ref_frame_count;               ///< num_ref_frames
73
    int required_frame_num_update_behaviour_flag;
74
    int mb_width;                      ///< frame_width_in_mbs_minus1 + 1
75
    int mb_height;                     ///< frame_height_in_mbs_minus1 + 1
76
    int frame_mbs_only_flag;
77
    int mb_aff;                        ///<mb_adaptive_frame_field_flag
78
    int direct_8x8_inference_flag;
79
    int vui_parameters_present_flag;
80
    int sar_width;
81
    int sar_height;
82
    short offset_for_ref_frame[256]; //FIXME dyn aloc?
83
}SPS;
84

  
85
/**
86
 * Picture parameter set
87
 */
88
typedef struct PPS{
89
    int sps_id;
90
    int cabac;                  ///< entropy_coding_mode_flag
91
    int pic_order_present;      ///< pic_order_present_flag
92
    int slice_group_count;      ///< num_slice_groups_minus1 + 1
93
    int mb_slice_group_map_type;
94
    int ref_count[2];           ///< num_ref_idx_l0/1_active_minus1 + 1
95
    int weighted_pred;          ///< weighted_pred_flag
96
    int weighted_bipred_idc;
97
    int init_qp;                ///< pic_init_qp_minus26 + 26
98
    int init_qs;                ///< pic_init_qs_minus26 + 26
99
    int chroma_qp_index_offset;
100
    int deblocking_filter_parameters_present; ///< deblocking_filter_parameters_present_flag
101
    int constrained_intra_pred; ///< constrained_intra_pred_flag
102
    int redundant_pic_cnt_present; ///< redundant_pic_cnt_present_flag
103
    int crop;                   ///< frame_cropping_flag
104
    int crop_left;              ///< frame_cropping_rect_left_offset
105
    int crop_right;             ///< frame_cropping_rect_right_offset
106
    int crop_top;               ///< frame_cropping_rect_top_offset
107
    int crop_bottom;            ///< frame_cropping_rect_bottom_offset
108
}PPS;
109

  
110
/**
111
 * Memory management control operation opcode.
112
 */
113
typedef enum MMCOOpcode{
114
    MMCO_END=0,
115
    MMCO_SHORT2UNUSED,
116
    MMCO_LONG2UNUSED,
117
    MMCO_SHORT2LONG,
118
    MMCO_SET_MAX_LONG,
119
    MMCO_RESET, 
120
    MMCO_LONG,
121
} MMCOOpcode;
122

  
123
/**
124
 * Memory management control operation.
125
 */
126
typedef struct MMCO{
127
    MMCOOpcode opcode;
128
    int short_frame_num;
129
    int long_index;
130
} MMCO;
131

  
132
/**
133
 * H264Context
134
 */
135
typedef struct H264Context{
136
    MpegEncContext s;
137
    int nal_ref_idc;	
138
    int nal_unit_type;
139
#define NAL_SLICE		1
140
#define NAL_DPA			2
141
#define NAL_DPB			3
142
#define NAL_DPC			4
143
#define NAL_IDR_SLICE		5
144
#define NAL_SEI			6
145
#define NAL_SPS			7
146
#define NAL_PPS			8
147
#define NAL_PICTURE_DELIMITER	9
148
#define NAL_FILTER_DATA		10
149
    uint8_t *rbsp_buffer;
150
    int rbsp_buffer_size;
151

  
152
    int mb_stride; ///< stride of some mb tables
153

  
154
    int chroma_qp; //QPc
155

  
156
    int prev_mb_skiped; //FIXME remove (IMHO not used)
157

  
158
    //prediction stuff
159
    int chroma_pred_mode;
160
    int intra16x16_pred_mode;
161
    
162
    int8_t intra4x4_pred_mode_cache[5*8];
163
    int8_t (*intra4x4_pred_mode)[8];
164
    void (*pred4x4  [9+3])(uint8_t *src, uint8_t *topright, int stride);//FIXME move to dsp?
165
    void (*pred8x8  [4+3])(uint8_t *src, int stride);
166
    void (*pred16x16[4+3])(uint8_t *src, int stride);
167
    unsigned int topleft_samples_available;
168
    unsigned int top_samples_available;
169
    unsigned int topright_samples_available;
170
    unsigned int left_samples_available;
171

  
172
    /**
173
     * non zero coeff count cache.
174
     * is 64 if not available.
175
     */
176
    uint8_t non_zero_count_cache[6*8];
177
    uint8_t (*non_zero_count)[16];
178

  
179
    /**
180
     * Motion vector cache.
181
     */
182
    int16_t mv_cache[2][5*8][2];
183
    int8_t ref_cache[2][5*8];
184
#define LIST_NOT_USED -1 //FIXME rename?
185
#define PART_NOT_AVAILABLE -2
186
    
187
    /**
188
     * is 1 if the specific list MV&references are set to 0,0,-2.
189
     */
190
    int mv_cache_clean[2];
191

  
192
    int block_offset[16+8];
193
    int chroma_subblock_offset[16]; //FIXME remove
194
    
195
    uint16_t *mb2b_xy; //FIXME are these 4 a good idea?
196
    uint16_t *mb2b8_xy;
197
    int b_stride;
198
    int b8_stride;
199

  
200
    SPS sps_buffer[MAX_SPS_COUNT];
201
    SPS sps; ///< current sps
202
    
203
    PPS pps_buffer[MAX_PPS_COUNT];
204
    /**
205
     * current pps
206
     */
207
    PPS pps; //FIXME move tp Picture perhaps? (->no) do we need that?
208

  
209
    int slice_num;
210
    uint8_t *slice_table_base;
211
    uint8_t *slice_table;      ///< slice_table_base + mb_stride + 1
212
    int slice_type;
213
    int slice_type_fixed;
214
    
215
    //interlacing specific flags
216
    int mb_field_decoding_flag;
217
    
218
    int sub_mb_type[4];
219
    
220
    //POC stuff
221
    int poc_lsb;
222
    int poc_msb;
223
    int delta_poc_bottom;
224
    int delta_poc[2];
225
    int frame_num;
226
    int prev_poc_msb;             ///< poc_msb of the last reference pic for POC type 0
227
    int prev_poc_lsb;             ///< poc_lsb of the last reference pic for POC type 0
228
    int frame_num_offset;         ///< for POC type 2
229
    int prev_frame_num_offset;    ///< for POC type 2
230
    int prev_frame_num;           ///< frame_num of the last pic for POC type 1/2
231

  
232
    /**
233
     * frame_num for frames or 2*frame_num for field pics.
234
     */
235
    int curr_pic_num;
236
    
237
    /**
238
     * max_frame_num or 2*max_frame_num for field pics.
239
     */
240
    int max_pic_num;
241

  
242
    //Weighted pred stuff
243
    int luma_log2_weight_denom;
244
    int chroma_log2_weight_denom;
245
    int luma_weight[2][16];
246
    int luma_offset[2][16];
247
    int chroma_weight[2][16][2];
248
    int chroma_offset[2][16][2];
249
   
250
    //deblock
251
    int disable_deblocking_filter_idc;
252
    int slice_alpha_c0_offset_div2;
253
    int slice_beta_offset_div2;
254
     
255
    int redundant_pic_count;
256
    
257
    int direct_spatial_mv_pred;
258

  
259
    /**
260
     * num_ref_idx_l0/1_active_minus1 + 1
261
     */
262
    int ref_count[2];// FIXME split for AFF
263
    Picture *short_ref[16];
264
    Picture *long_ref[16];
265
    Picture default_ref_list[2][32];
266
    Picture ref_list[2][32]; //FIXME size?
267
    Picture field_ref_list[2][32]; //FIXME size?
268
    
269
    /**
270
     * memory management control operations buffer.
271
     */
272
    MMCO mmco[MAX_MMCO_COUNT];
273
    int mmco_index;
274
    
275
    int long_ref_count;  ///< number of actual long term references
276
    int short_ref_count; ///< number of actual short term references
277
    
278
    //data partitioning
279
    GetBitContext intra_gb;
280
    GetBitContext inter_gb;
281
    GetBitContext *intra_gb_ptr;
282
    GetBitContext *inter_gb_ptr;
283
    
284
    DCTELEM mb[16*24] __align8;
285
}H264Context;
286

  
287
static VLC coeff_token_vlc[4];
288
static VLC chroma_dc_coeff_token_vlc;
289

  
290
static VLC total_zeros_vlc[15];
291
static VLC chroma_dc_total_zeros_vlc[3];
292

  
293
static VLC run_vlc[6];
294
static VLC run7_vlc;
295

  
296
/**
297
 * fill a rectangle.
298
 * @param h height of the recatangle, should be a constant
299
 * @param w width of the recatangle, should be a constant
300
 * @param size the size of val (1 or 4), should be a constant
301
 */
302
static inline void fill_rectangle(void *p, int w, int h, int stride, uint32_t val, int size){ //FIXME ensure this IS inlined
303
    assert(size==1 || size==4);
304
    
305
    w      *= size;
306
    stride *= size;
307
    
308
//FIXME check what gcc generates for 64 bit on x86 and possible write a 32 bit ver of it
309
    if(w==2 && h==2){
310
        *(uint16_t*)(p + 0)=
311
        *(uint16_t*)(p + stride)= size==4 ? val : val*0x0101;
312
    }else if(w==2 && h==4){
313
        *(uint16_t*)(p + 0*stride)=
314
        *(uint16_t*)(p + 1*stride)=
315
        *(uint16_t*)(p + 2*stride)=
316
        *(uint16_t*)(p + 3*stride)= size==4 ? val : val*0x0101;
317
    }else if(w==4 && h==2){
318
        *(uint32_t*)(p + 0*stride)=
319
        *(uint32_t*)(p + 1*stride)= size==4 ? val : val*0x01010101;
320
    }else if(w==4 && h==4){
321
        *(uint32_t*)(p + 0*stride)=
322
        *(uint32_t*)(p + 1*stride)=
323
        *(uint32_t*)(p + 2*stride)=
324
        *(uint32_t*)(p + 3*stride)= size==4 ? val : val*0x01010101;
325
    }else if(w==8 && h==1){
326
        *(uint32_t*)(p + 0)=
327
        *(uint32_t*)(p + 4)= size==4 ? val : val*0x01010101;
328
    }else if(w==8 && h==2){
329
        *(uint32_t*)(p + 0 + 0*stride)=
330
        *(uint32_t*)(p + 4 + 0*stride)=
331
        *(uint32_t*)(p + 0 + 1*stride)=
332
        *(uint32_t*)(p + 4 + 1*stride)=  size==4 ? val : val*0x01010101;
333
    }else if(w==8 && h==4){
334
        *(uint64_t*)(p + 0*stride)=
335
        *(uint64_t*)(p + 1*stride)=
336
        *(uint64_t*)(p + 2*stride)=
337
        *(uint64_t*)(p + 3*stride)= size==4 ? val*0x0100000001ULL : val*0x0101010101010101ULL;
338
    }else if(w==16 && h==2){
339
        *(uint64_t*)(p + 0+0*stride)=
340
        *(uint64_t*)(p + 8+0*stride)=
341
        *(uint64_t*)(p + 0+1*stride)=
342
        *(uint64_t*)(p + 8+1*stride)= size==4 ? val*0x0100000001ULL : val*0x0101010101010101ULL;
343
    }else if(w==16 && h==4){
344
        *(uint64_t*)(p + 0+0*stride)=
345
        *(uint64_t*)(p + 8+0*stride)=
346
        *(uint64_t*)(p + 0+1*stride)=
347
        *(uint64_t*)(p + 8+1*stride)=
348
        *(uint64_t*)(p + 0+2*stride)=
349
        *(uint64_t*)(p + 8+2*stride)=
350
        *(uint64_t*)(p + 0+3*stride)=
351
        *(uint64_t*)(p + 8+3*stride)= size==4 ? val*0x0100000001ULL : val*0x0101010101010101ULL;
352
    }else
353
        assert(0);
354
}
355

  
356
static inline void fill_caches(H264Context *h, int mb_type){
357
    MpegEncContext * const s = &h->s;
358
    const int mb_xy= s->mb_x + s->mb_y*h->mb_stride;
359
    int topleft_xy, top_xy, topright_xy, left_xy[2];
360
    int topleft_type, top_type, topright_type, left_type[2];
361
    int left_block[4];
362
    int i;
363

  
364
    //wow what a mess, why didnt they simplify the interlacing&intra stuff, i cant imagine that these complex rules are worth it 
365
    
366
    if(h->sps.mb_aff){
367
    //FIXME
368
    }else{
369
        topleft_xy = mb_xy-1 - h->mb_stride;
370
        top_xy     = mb_xy   - h->mb_stride;
371
        topright_xy= mb_xy+1 - h->mb_stride;
372
        left_xy[0]   = mb_xy-1;
373
        left_xy[1]   = mb_xy-1;
374
        left_block[0]= 0;
375
        left_block[1]= 1;
376
        left_block[2]= 2;
377
        left_block[3]= 3;
378
    }
379

  
380
    topleft_type = h->slice_table[topleft_xy ] == h->slice_num ? s->current_picture.mb_type[topleft_xy] : 0;
381
    top_type     = h->slice_table[top_xy     ] == h->slice_num ? s->current_picture.mb_type[top_xy]     : 0;
382
    topright_type= h->slice_table[topright_xy] == h->slice_num ? s->current_picture.mb_type[topright_xy]: 0;
383
    left_type[0] = h->slice_table[left_xy[0] ] == h->slice_num ? s->current_picture.mb_type[left_xy[0]] : 0;
384
    left_type[1] = h->slice_table[left_xy[1] ] == h->slice_num ? s->current_picture.mb_type[left_xy[1]] : 0;
385

  
386
    if(IS_INTRA(mb_type)){
387
        h->topleft_samples_available= 
388
        h->top_samples_available= 
389
        h->left_samples_available= 0xFFFF;
390
        h->topright_samples_available= 0xEEEA;
391

  
392
        if(!IS_INTRA(top_type) && (top_type==0 || h->pps.constrained_intra_pred)){
393
            h->topleft_samples_available= 0xB3FF;
394
            h->top_samples_available= 0x33FF;
395
            h->topright_samples_available= 0x26EA;
396
        }
397
        for(i=0; i<2; i++){
398
            if(!IS_INTRA(left_type[i]) && (left_type[i]==0 || h->pps.constrained_intra_pred)){
399
                h->topleft_samples_available&= 0xDF5F;
400
                h->left_samples_available&= 0x5F5F;
401
            }
402
        }
403
        
404
        if(!IS_INTRA(topleft_type) && (topleft_type==0 || h->pps.constrained_intra_pred))
405
            h->topleft_samples_available&= 0x7FFF;
406
        
407
        if(!IS_INTRA(topright_type) && (topright_type==0 || h->pps.constrained_intra_pred))
408
            h->topright_samples_available&= 0xFBFF;
409
    
410
        if(IS_INTRA4x4(mb_type)){
411
            if(IS_INTRA4x4(top_type)){
412
                h->intra4x4_pred_mode_cache[4+8*0]= h->intra4x4_pred_mode[top_xy][4];
413
                h->intra4x4_pred_mode_cache[5+8*0]= h->intra4x4_pred_mode[top_xy][5];
414
                h->intra4x4_pred_mode_cache[6+8*0]= h->intra4x4_pred_mode[top_xy][6];
415
                h->intra4x4_pred_mode_cache[7+8*0]= h->intra4x4_pred_mode[top_xy][3];
416
            }else{
417
                int pred;
418
                if(IS_INTRA16x16(top_type) || (IS_INTER(top_type) && !h->pps.constrained_intra_pred))
419
                    pred= 2;
420
                else{
421
                    pred= -1;
422
                }
423
                h->intra4x4_pred_mode_cache[4+8*0]=
424
                h->intra4x4_pred_mode_cache[5+8*0]=
425
                h->intra4x4_pred_mode_cache[6+8*0]=
426
                h->intra4x4_pred_mode_cache[7+8*0]= pred;
427
            }
428
            for(i=0; i<2; i++){
429
                if(IS_INTRA4x4(left_type[i])){
430
                    h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[0+2*i]];
431
                    h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[1+2*i]];
432
                }else{
433
                    int pred;
434
                    if(IS_INTRA16x16(left_type[i]) || (IS_INTER(left_type[i]) && !h->pps.constrained_intra_pred))
435
                        pred= 2;
436
                    else{
437
                        pred= -1;
438
                    }
439
                    h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]=
440
                    h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= pred;
441
                }
442
            }
443
        }
444
    }
445
    
446
    
447
/*
448
0 . T T. T T T T 
449
1 L . .L . . . . 
450
2 L . .L . . . . 
451
3 . T TL . . . . 
452
4 L . .L . . . . 
453
5 L . .. . . . . 
454
*/
455
//FIXME constraint_intra_pred & partitioning & nnz (lets hope this is just a typo in the spec)
456
    if(top_type){
457
        h->non_zero_count_cache[4+8*0]= h->non_zero_count[top_xy][0];
458
        h->non_zero_count_cache[5+8*0]= h->non_zero_count[top_xy][1];
459
        h->non_zero_count_cache[6+8*0]= h->non_zero_count[top_xy][2];
460
        h->non_zero_count_cache[7+8*0]= h->non_zero_count[top_xy][3];
461
    
462
        h->non_zero_count_cache[1+8*0]= h->non_zero_count[top_xy][7];
463
        h->non_zero_count_cache[2+8*0]= h->non_zero_count[top_xy][8];
464
    
465
        h->non_zero_count_cache[1+8*3]= h->non_zero_count[top_xy][10];
466
        h->non_zero_count_cache[2+8*3]= h->non_zero_count[top_xy][11];
467
    }else{
468
        h->non_zero_count_cache[4+8*0]=      
469
        h->non_zero_count_cache[5+8*0]=
470
        h->non_zero_count_cache[6+8*0]=
471
        h->non_zero_count_cache[7+8*0]=
472
    
473
        h->non_zero_count_cache[1+8*0]=
474
        h->non_zero_count_cache[2+8*0]=
475
    
476
        h->non_zero_count_cache[1+8*3]=
477
        h->non_zero_count_cache[2+8*3]= 64;
478
    }
479
    
480
    if(left_type[0]){
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff