Mercurial > libavcodec.hg
comparison snow.c @ 4331:e571dfe677be libavcodec
store a few values in the header as difference to the last
this makes frames a few bytes smaller (0.1% for high bitrate but >1% for low bitrates)
author | michael |
---|---|
date | Tue, 02 Jan 2007 12:24:31 +0000 |
parents | d6f83e2f8804 |
children | 35812973e0bc |
comparison
equal
deleted
inserted
replaced
4330:0663caaf573c | 4331:e571dfe677be |
---|---|
437 uint8_t block_state[128 + 32*128]; | 437 uint8_t block_state[128 + 32*128]; |
438 int keyframe; | 438 int keyframe; |
439 int always_reset; | 439 int always_reset; |
440 int version; | 440 int version; |
441 int spatial_decomposition_type; | 441 int spatial_decomposition_type; |
442 int last_spatial_decomposition_type; | |
442 int temporal_decomposition_type; | 443 int temporal_decomposition_type; |
443 int spatial_decomposition_count; | 444 int spatial_decomposition_count; |
444 int temporal_decomposition_count; | 445 int temporal_decomposition_count; |
445 int max_ref_frames; | 446 int max_ref_frames; |
446 int ref_frames; | 447 int ref_frames; |
450 int colorspace_type; | 451 int colorspace_type; |
451 int chroma_h_shift; | 452 int chroma_h_shift; |
452 int chroma_v_shift; | 453 int chroma_v_shift; |
453 int spatial_scalability; | 454 int spatial_scalability; |
454 int qlog; | 455 int qlog; |
456 int last_qlog; | |
455 int lambda; | 457 int lambda; |
456 int lambda2; | 458 int lambda2; |
457 int pass1_rc; | 459 int pass1_rc; |
458 int mv_scale; | 460 int mv_scale; |
461 int last_mv_scale; | |
459 int qbias; | 462 int qbias; |
463 int last_qbias; | |
460 #define QBIAS_SHIFT 3 | 464 #define QBIAS_SHIFT 3 |
461 int b_width; | 465 int b_width; |
462 int b_height; | 466 int b_height; |
463 int block_max_depth; | 467 int block_max_depth; |
468 int last_block_max_depth; | |
464 Plane plane[MAX_PLANES]; | 469 Plane plane[MAX_PLANES]; |
465 BlockNode *block; | 470 BlockNode *block; |
466 #define ME_CACHE_SIZE 1024 | 471 #define ME_CACHE_SIZE 1024 |
467 int me_cache[ME_CACHE_SIZE]; | 472 int me_cache[ME_CACHE_SIZE]; |
468 int me_cache_generation; | 473 int me_cache_generation; |
1847 save_state[0] = new_index; | 1852 save_state[0] = new_index; |
1848 | 1853 |
1849 return; | 1854 return; |
1850 } | 1855 } |
1851 | 1856 |
1852 static void reset_contexts(SnowContext *s){ | 1857 static void reset_contexts(SnowContext *s){ //FIXME better initial contexts |
1853 int plane_index, level, orientation; | 1858 int plane_index, level, orientation; |
1854 | 1859 |
1855 for(plane_index=0; plane_index<3; plane_index++){ | 1860 for(plane_index=0; plane_index<3; plane_index++){ |
1856 for(level=0; level<s->spatial_decomposition_count; level++){ | 1861 for(level=0; level<s->spatial_decomposition_count; level++){ |
1857 for(orientation=level ? 1:0; orientation<4; orientation++){ | 1862 for(orientation=level ? 1:0; orientation<4; orientation++){ |
3601 uint8_t kstate[32]; | 3606 uint8_t kstate[32]; |
3602 | 3607 |
3603 memset(kstate, MID_STATE, sizeof(kstate)); | 3608 memset(kstate, MID_STATE, sizeof(kstate)); |
3604 | 3609 |
3605 put_rac(&s->c, kstate, s->keyframe); | 3610 put_rac(&s->c, kstate, s->keyframe); |
3606 if(s->keyframe || s->always_reset) | 3611 if(s->keyframe || s->always_reset){ |
3607 reset_contexts(s); | 3612 reset_contexts(s); |
3613 s->last_spatial_decomposition_type= | |
3614 s->last_qlog= | |
3615 s->last_qbias= | |
3616 s->last_mv_scale= | |
3617 s->last_block_max_depth= 0; | |
3618 } | |
3608 if(s->keyframe){ | 3619 if(s->keyframe){ |
3609 put_symbol(&s->c, s->header_state, s->version, 0); | 3620 put_symbol(&s->c, s->header_state, s->version, 0); |
3610 put_rac(&s->c, s->header_state, s->always_reset); | 3621 put_rac(&s->c, s->header_state, s->always_reset); |
3611 put_symbol(&s->c, s->header_state, s->temporal_decomposition_type, 0); | 3622 put_symbol(&s->c, s->header_state, s->temporal_decomposition_type, 0); |
3612 put_symbol(&s->c, s->header_state, s->temporal_decomposition_count, 0); | 3623 put_symbol(&s->c, s->header_state, s->temporal_decomposition_count, 0); |
3625 put_symbol(&s->c, s->header_state, s->plane[plane_index].band[level][orientation].qlog, 1); | 3636 put_symbol(&s->c, s->header_state, s->plane[plane_index].band[level][orientation].qlog, 1); |
3626 } | 3637 } |
3627 } | 3638 } |
3628 } | 3639 } |
3629 } | 3640 } |
3630 put_symbol(&s->c, s->header_state, s->spatial_decomposition_type, 0); | 3641 put_symbol(&s->c, s->header_state, s->spatial_decomposition_type - s->last_spatial_decomposition_type, 1); |
3631 put_symbol(&s->c, s->header_state, s->qlog, 1); | 3642 put_symbol(&s->c, s->header_state, s->qlog - s->last_qlog , 1); |
3632 put_symbol(&s->c, s->header_state, s->mv_scale, 0); | 3643 put_symbol(&s->c, s->header_state, s->mv_scale - s->last_mv_scale, 1); |
3633 put_symbol(&s->c, s->header_state, s->qbias, 1); | 3644 put_symbol(&s->c, s->header_state, s->qbias - s->last_qbias , 1); |
3634 put_symbol(&s->c, s->header_state, s->block_max_depth, 0); | 3645 put_symbol(&s->c, s->header_state, s->block_max_depth - s->last_block_max_depth, 1); |
3646 | |
3647 s->last_spatial_decomposition_type= s->spatial_decomposition_type; | |
3648 s->last_qlog = s->qlog; | |
3649 s->last_qbias = s->qbias; | |
3650 s->last_mv_scale = s->mv_scale; | |
3651 s->last_block_max_depth = s->block_max_depth; | |
3635 } | 3652 } |
3636 | 3653 |
3637 static int decode_header(SnowContext *s){ | 3654 static int decode_header(SnowContext *s){ |
3638 int plane_index, level, orientation; | 3655 int plane_index, level, orientation; |
3639 uint8_t kstate[32]; | 3656 uint8_t kstate[32]; |
3640 | 3657 |
3641 memset(kstate, MID_STATE, sizeof(kstate)); | 3658 memset(kstate, MID_STATE, sizeof(kstate)); |
3642 | 3659 |
3643 s->keyframe= get_rac(&s->c, kstate); | 3660 s->keyframe= get_rac(&s->c, kstate); |
3644 if(s->keyframe || s->always_reset) | 3661 if(s->keyframe || s->always_reset){ |
3645 reset_contexts(s); | 3662 reset_contexts(s); |
3663 s->spatial_decomposition_type= | |
3664 s->qlog= | |
3665 s->qbias= | |
3666 s->mv_scale= | |
3667 s->block_max_depth= 0; | |
3668 } | |
3646 if(s->keyframe){ | 3669 if(s->keyframe){ |
3647 s->version= get_symbol(&s->c, s->header_state, 0); | 3670 s->version= get_symbol(&s->c, s->header_state, 0); |
3648 if(s->version>0){ | 3671 if(s->version>0){ |
3649 av_log(s->avctx, AV_LOG_ERROR, "version %d not supported", s->version); | 3672 av_log(s->avctx, AV_LOG_ERROR, "version %d not supported", s->version); |
3650 return -1; | 3673 return -1; |
3671 } | 3694 } |
3672 } | 3695 } |
3673 } | 3696 } |
3674 } | 3697 } |
3675 | 3698 |
3676 s->spatial_decomposition_type= get_symbol(&s->c, s->header_state, 0); | 3699 s->spatial_decomposition_type+= get_symbol(&s->c, s->header_state, 1); |
3677 if(s->spatial_decomposition_type > 2){ | 3700 if(s->spatial_decomposition_type > 2){ |
3678 av_log(s->avctx, AV_LOG_ERROR, "spatial_decomposition_type %d not supported", s->spatial_decomposition_type); | 3701 av_log(s->avctx, AV_LOG_ERROR, "spatial_decomposition_type %d not supported", s->spatial_decomposition_type); |
3679 return -1; | 3702 return -1; |
3680 } | 3703 } |
3681 | 3704 |
3682 s->qlog= get_symbol(&s->c, s->header_state, 1); | 3705 s->qlog += get_symbol(&s->c, s->header_state, 1); |
3683 s->mv_scale= get_symbol(&s->c, s->header_state, 0); | 3706 s->mv_scale += get_symbol(&s->c, s->header_state, 1); |
3684 s->qbias= get_symbol(&s->c, s->header_state, 1); | 3707 s->qbias += get_symbol(&s->c, s->header_state, 1); |
3685 s->block_max_depth= get_symbol(&s->c, s->header_state, 0); | 3708 s->block_max_depth+= get_symbol(&s->c, s->header_state, 1); |
3686 if(s->block_max_depth > 1 || s->block_max_depth < 0){ | 3709 if(s->block_max_depth > 1 || s->block_max_depth < 0){ |
3687 av_log(s->avctx, AV_LOG_ERROR, "block_max_depth= %d is too large", s->block_max_depth); | 3710 av_log(s->avctx, AV_LOG_ERROR, "block_max_depth= %d is too large", s->block_max_depth); |
3688 s->block_max_depth= 0; | 3711 s->block_max_depth= 0; |
3689 return -1; | 3712 return -1; |
3690 } | 3713 } |
4168 ff_init_range_encoder(c, buf, buf_size); | 4191 ff_init_range_encoder(c, buf, buf_size); |
4169 ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); | 4192 ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); |
4170 pict->pict_type= FF_I_TYPE; | 4193 pict->pict_type= FF_I_TYPE; |
4171 s->keyframe=1; | 4194 s->keyframe=1; |
4172 s->current_picture.key_frame=1; | 4195 s->current_picture.key_frame=1; |
4173 reset_contexts(s); | |
4174 goto redo_frame; | 4196 goto redo_frame; |
4175 } | 4197 } |
4176 | 4198 |
4177 if(s->qlog == LOSSLESS_QLOG){ | 4199 if(s->qlog == LOSSLESS_QLOG){ |
4178 for(y=0; y<h; y++){ | 4200 for(y=0; y<h; y++){ |