Revision 2d974017 libavcodec/mpegvideo.c

View differences:

libavcodec/mpegvideo.c
927 927

  
928 928
    MPV_encode_defaults(s);
929 929

  
930
    if(avctx->pix_fmt != PIX_FMT_YUVJ420P && avctx->pix_fmt != PIX_FMT_YUV420P){
931
        av_log(avctx, AV_LOG_ERROR, "only YUV420 is supported\n");
932
        return -1;
933
    }
934

  
935
    if(avctx->codec_id == CODEC_ID_MJPEG || avctx->codec_id == CODEC_ID_LJPEG){
936
        if(avctx->strict_std_compliance>FF_COMPLIANCE_INOFFICIAL && avctx->pix_fmt != PIX_FMT_YUVJ420P){
930
    switch (avctx->codec_id) {
931
    case CODEC_ID_MPEG2VIDEO:
932
        if(avctx->pix_fmt != PIX_FMT_YUV420P && avctx->pix_fmt != PIX_FMT_YUV422P){
933
            av_log(avctx, AV_LOG_ERROR, "only YUV420 and YUV422 are supported\n");
934
            return -1;
935
        }
936
        break;
937
    case CODEC_ID_LJPEG:
938
    case CODEC_ID_MJPEG:
939
        if(avctx->pix_fmt != PIX_FMT_YUVJ420P && (avctx->pix_fmt != PIX_FMT_YUV420P || avctx->strict_std_compliance>FF_COMPLIANCE_INOFFICIAL)){
937 940
            av_log(avctx, AV_LOG_ERROR, "colorspace not supported in jpeg\n");
938 941
            return -1;
939 942
        }
940
    }else{
941
        if(avctx->strict_std_compliance>FF_COMPLIANCE_INOFFICIAL && avctx->pix_fmt != PIX_FMT_YUV420P){
942
            av_log(avctx, AV_LOG_ERROR, "colorspace not supported\n");
943
        break;
944
    default:
945
        if(avctx->pix_fmt != PIX_FMT_YUV420P){
946
            av_log(avctx, AV_LOG_ERROR, "only YUV420 is supported\n");
943 947
            return -1;
944 948
        }
945 949
    }
946 950

  
951
    switch (avctx->pix_fmt) {
952
    case PIX_FMT_YUVJ422P:
953
    case PIX_FMT_YUV422P:
954
        s->chroma_format = CHROMA_422;
955
        break;
956
    case PIX_FMT_YUVJ420P:
957
    case PIX_FMT_YUV420P:
958
    default:
959
        s->chroma_format = CHROMA_420;
960
        break;
961
    }
962

  
947 963
    s->bit_rate = avctx->bit_rate;
948 964
    s->width = avctx->width;
949 965
    s->height = avctx->height;
......
2466 2482
    AVFrame *pic_arg = data;
2467 2483
    int i, stuffing_count;
2468 2484

  
2469
    if(avctx->pix_fmt != PIX_FMT_YUV420P && avctx->pix_fmt != PIX_FMT_YUVJ420P){
2470
        av_log(avctx, AV_LOG_ERROR, "this codec supports only YUV420P\n");
2471
        return -1;
2472
    }
2473

  
2474 2485
    for(i=0; i<avctx->thread_count; i++){
2475 2486
        int start_y= s->thread_context[i]->start_mb_y;
2476 2487
        int   end_y= s->thread_context[i]->  end_mb_y;
......
3968 3979
                add_dequant_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale);
3969 3980

  
3970 3981
                if(!(s->flags&CODEC_FLAG_GRAY)){
3971
                    add_dequant_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale);
3972
                    add_dequant_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale);
3982
                    if (s->chroma_y_shift){
3983
                        add_dequant_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale);
3984
                        add_dequant_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale);
3985
                    }else{
3986
                        dct_linesize >>= 1;
3987
                        dct_offset >>=1;
3988
                        add_dequant_dct(s, block[4], 4, dest_cb,              dct_linesize, s->chroma_qscale);
3989
                        add_dequant_dct(s, block[5], 5, dest_cr,              dct_linesize, s->chroma_qscale);
3990
                        add_dequant_dct(s, block[6], 6, dest_cb + dct_offset, dct_linesize, s->chroma_qscale);
3991
                        add_dequant_dct(s, block[7], 7, dest_cr + dct_offset, dct_linesize, s->chroma_qscale);
3992
                    }
3973 3993
                }
3974 3994
            } else if(s->codec_id != CODEC_ID_WMV2){
3975 3995
                add_dct(s, block[0], 0, dest_y                          , dct_linesize);
......
4011 4031
                put_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale);
4012 4032

  
4013 4033
                if(!(s->flags&CODEC_FLAG_GRAY)){
4014
                    put_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale);
4015
                    put_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale);
4034
                    if(s->chroma_y_shift){
4035
                        put_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale);
4036
                        put_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale);
4037
                    }else{
4038
                        dct_offset >>=1;
4039
                        dct_linesize >>=1;
4040
                        put_dct(s, block[4], 4, dest_cb,              dct_linesize, s->chroma_qscale);
4041
                        put_dct(s, block[5], 5, dest_cr,              dct_linesize, s->chroma_qscale);
4042
                        put_dct(s, block[6], 6, dest_cb + dct_offset, dct_linesize, s->chroma_qscale);
4043
                        put_dct(s, block[7], 7, dest_cr + dct_offset, dct_linesize, s->chroma_qscale);
4044
                    }
4016 4045
                }
4017 4046
            }else{
4018 4047
                s->dsp.idct_put(dest_y                          , dct_linesize, block[0]);
......
4234 4263
    }
4235 4264
}
4236 4265

  
4237
static void encode_mb(MpegEncContext *s, int motion_x, int motion_y)
4266
static always_inline void encode_mb_internal(MpegEncContext *s, int motion_x, int motion_y, int mb_block_height, int mb_block_count)
4238 4267
{
4239
    int16_t weight[6][64];
4240
    DCTELEM orig[6][64];
4268
    int16_t weight[8][64];
4269
    DCTELEM orig[8][64];
4241 4270
    const int mb_x= s->mb_x;
4242 4271
    const int mb_y= s->mb_y;
4243 4272
    int i;
4244
    int skip_dct[6];
4273
    int skip_dct[8];
4245 4274
    int dct_offset   = s->linesize*8; //default for progressive frames
4246 4275
    uint8_t *ptr_y, *ptr_cb, *ptr_cr;
4247 4276
    int wrap_y, wrap_c;
4248 4277

  
4249
    for(i=0; i<6; i++) skip_dct[i]=0;
4278
    for(i=0; i<mb_block_count; i++) skip_dct[i]=0;
4250 4279

  
4251 4280
    if(s->adaptive_quant){
4252 4281
        const int last_qp= s->qscale;
......
4282 4311
    wrap_y = s->linesize;
4283 4312
    wrap_c = s->uvlinesize;
4284 4313
    ptr_y = s->new_picture.data[0] + (mb_y * 16 * wrap_y) + mb_x * 16;
4285
    ptr_cb = s->new_picture.data[1] + (mb_y * 8 * wrap_c) + mb_x * 8;
4286
    ptr_cr = s->new_picture.data[2] + (mb_y * 8 * wrap_c) + mb_x * 8;
4314
    ptr_cb = s->new_picture.data[1] + (mb_y * mb_block_height * wrap_c) + mb_x * 8;
4315
    ptr_cr = s->new_picture.data[2] + (mb_y * mb_block_height * wrap_c) + mb_x * 8;
4287 4316

  
4288 4317
    if(mb_x*16+16 > s->width || mb_y*16+16 > s->height){
4289 4318
        uint8_t *ebuf= s->edge_emu_buffer + 32;
4290 4319
        ff_emulated_edge_mc(ebuf            , ptr_y , wrap_y,16,16,mb_x*16,mb_y*16, s->width   , s->height);
4291 4320
        ptr_y= ebuf;
4292
        ff_emulated_edge_mc(ebuf+18*wrap_y  , ptr_cb, wrap_c, 8, 8, mb_x*8, mb_y*8, s->width>>1, s->height>>1);
4321
        ff_emulated_edge_mc(ebuf+18*wrap_y  , ptr_cb, wrap_c, 8, mb_block_height, mb_x*8, mb_y*8, s->width>>1, s->height>>1);
4293 4322
        ptr_cb= ebuf+18*wrap_y;
4294
        ff_emulated_edge_mc(ebuf+18*wrap_y+8, ptr_cr, wrap_c, 8, 8, mb_x*8, mb_y*8, s->width>>1, s->height>>1);
4323
        ff_emulated_edge_mc(ebuf+18*wrap_y+8, ptr_cr, wrap_c, 8, mb_block_height, mb_x*8, mb_y*8, s->width>>1, s->height>>1);
4295 4324
        ptr_cr= ebuf+18*wrap_y+8;
4296 4325
    }
4297 4326

  
......
4311 4340

  
4312 4341
                    dct_offset= wrap_y;
4313 4342
                    wrap_y<<=1;
4343
                    if (s->chroma_format == CHROMA_422)
4344
                        wrap_c<<=1;
4314 4345
                }
4315 4346
            }
4316 4347
        }
......
4326 4357
        }else{
4327 4358
            s->dsp.get_pixels(s->block[4], ptr_cb, wrap_c);
4328 4359
            s->dsp.get_pixels(s->block[5], ptr_cr, wrap_c);
4360
            if(!s->chroma_y_shift){ /* 422 */
4361
                s->dsp.get_pixels(s->block[6], ptr_cb + (dct_offset>>1), wrap_c);
4362
                s->dsp.get_pixels(s->block[7], ptr_cr + (dct_offset>>1), wrap_c);
4363
            }
4329 4364
        }
4330 4365
    }else{
4331 4366
        op_pixels_func (*op_pix)[4];
......
4371 4406

  
4372 4407
                    dct_offset= wrap_y;
4373 4408
                    wrap_y<<=1;
4409
                    if (s->chroma_format == CHROMA_422)
4410
                        wrap_c<<=1;
4374 4411
                }
4375 4412
            }
4376 4413
        }
......
4386 4423
        }else{
4387 4424
            s->dsp.diff_pixels(s->block[4], ptr_cb, dest_cb, wrap_c);
4388 4425
            s->dsp.diff_pixels(s->block[5], ptr_cr, dest_cr, wrap_c);
4426
            if(!s->chroma_y_shift){ /* 422 */
4427
                s->dsp.diff_pixels(s->block[6], ptr_cb + (dct_offset>>1), dest_cb + (dct_offset>>1), wrap_c);
4428
                s->dsp.diff_pixels(s->block[7], ptr_cr + (dct_offset>>1), dest_cr + (dct_offset>>1), wrap_c);
4429
            }
4389 4430
        }
4390 4431
        /* pre quantization */
4391 4432
        if(s->current_picture.mc_mb_var[s->mb_stride*mb_y+ mb_x]<2*s->qscale*s->qscale){
......
4396 4437
            if(s->dsp.sad[1](NULL, ptr_y +dct_offset+ 8, dest_y +dct_offset+ 8, wrap_y, 8) < 20*s->qscale) skip_dct[3]= 1;
4397 4438
            if(s->dsp.sad[1](NULL, ptr_cb              , dest_cb              , wrap_c, 8) < 20*s->qscale) skip_dct[4]= 1;
4398 4439
            if(s->dsp.sad[1](NULL, ptr_cr              , dest_cr              , wrap_c, 8) < 20*s->qscale) skip_dct[5]= 1;
4440
            if(!s->chroma_y_shift){ /* 422 */
4441
                if(s->dsp.sad[1](NULL, ptr_cb +(dct_offset>>1), dest_cb +(dct_offset>>1), wrap_c, 8) < 20*s->qscale) skip_dct[6]= 1;
4442
                if(s->dsp.sad[1](NULL, ptr_cr +(dct_offset>>1), dest_cr +(dct_offset>>1), wrap_c, 8) < 20*s->qscale) skip_dct[7]= 1;
4443
            }
4399 4444
        }
4400 4445
    }
4401 4446

  
......
4406 4451
        if(!skip_dct[3]) get_vissual_weight(weight[3], ptr_y + dct_offset + 8, wrap_y);
4407 4452
        if(!skip_dct[4]) get_vissual_weight(weight[4], ptr_cb                , wrap_c);
4408 4453
        if(!skip_dct[5]) get_vissual_weight(weight[5], ptr_cr                , wrap_c);
4409
        memcpy(orig[0], s->block[0], sizeof(DCTELEM)*64*6);
4454
        if(!s->chroma_y_shift){ /* 422 */
4455
            if(!skip_dct[6]) get_vissual_weight(weight[6], ptr_cb + (dct_offset>>1), wrap_c);
4456
            if(!skip_dct[7]) get_vissual_weight(weight[7], ptr_cr + (dct_offset>>1), wrap_c);
4457
        }
4458
        memcpy(orig[0], s->block[0], sizeof(DCTELEM)*64*mb_block_count);
4410 4459
    }
4411 4460

  
4412 4461
    /* DCT & quantize */
4413 4462
    assert(s->out_format!=FMT_MJPEG || s->qscale==8);
4414 4463
    {
4415
        for(i=0;i<6;i++) {
4464
        for(i=0;i<mb_block_count;i++) {
4416 4465
            if(!skip_dct[i]){
4417 4466
                int overflow;
4418 4467
                s->block_last_index[i] = s->dct_quantize(s, s->block[i], i, s->qscale, &overflow);
......
4424 4473
                s->block_last_index[i]= -1;
4425 4474
        }
4426 4475
        if(s->avctx->quantizer_noise_shaping){
4427
            for(i=0;i<6;i++) {
4476
            for(i=0;i<mb_block_count;i++) {
4428 4477
                if(!skip_dct[i]){
4429 4478
                    s->block_last_index[i] = dct_quantize_refine(s, s->block[i], weight[i], orig[i], i, s->qscale);
4430 4479
                }
......
4435 4484
            for(i=0; i<4; i++)
4436 4485
                dct_single_coeff_elimination(s, i, s->luma_elim_threshold);
4437 4486
        if(s->chroma_elim_threshold && !s->mb_intra)
4438
            for(i=4; i<6; i++)
4487
            for(i=4; i<mb_block_count; i++)
4439 4488
                dct_single_coeff_elimination(s, i, s->chroma_elim_threshold);
4440 4489

  
4441 4490
        if(s->flags & CODEC_FLAG_CBP_RD){
4442
            for(i=0;i<6;i++) {
4491
            for(i=0;i<mb_block_count;i++) {
4443 4492
                if(s->block_last_index[i] == -1)
4444 4493
                    s->coded_score[i]= INT_MAX/256;
4445 4494
            }
......
4455 4504

  
4456 4505
    //non c quantize code returns incorrect block_last_index FIXME
4457 4506
    if(s->alternate_scan && s->dct_quantize != dct_quantize_c){
4458
        for(i=0; i<6; i++){
4507
        for(i=0; i<mb_block_count; i++){
4459 4508
            int j;
4460 4509
            if(s->block_last_index[i]>0){
4461 4510
                for(j=63; j>0; j--){
......
4496 4545
    }
4497 4546
}
4498 4547

  
4548
static always_inline void encode_mb(MpegEncContext *s, int motion_x, int motion_y)
4549
{
4550
    if (s->chroma_format == CHROMA_420) encode_mb_internal(s, motion_x, motion_y,  8, 6);
4551
    else                                encode_mb_internal(s, motion_x, motion_y, 16, 8);
4552
}
4553

  
4499 4554
#endif //CONFIG_ENCODERS
4500 4555

  
4501 4556
void ff_mpeg_flush(AVCodecContext *avctx){
......
4605 4660
        d->tex_pb= s->tex_pb;
4606 4661
    }
4607 4662
    d->block= s->block;
4608
    for(i=0; i<6; i++)
4663
    for(i=0; i<8; i++)
4609 4664
        d->block_last_index[i]= s->block_last_index[i];
4610 4665
    d->interlaced_dct= s->interlaced_dct;
4611 4666
    d->qscale= s->qscale;

Also available in: Unified diff