comparison snow.c @ 2199:e0b08bdf565d libavcodec

10l (keyframes and context resets)
author michael
date Tue, 31 Aug 2004 16:28:49 +0000
parents 970c2de19b2e
children 713ad427a3c7
comparison
equal deleted inserted replaced
2198:970c2de19b2e 2199:e0b08bdf565d
398 AVFrame mconly_picture; 398 AVFrame mconly_picture;
399 // uint8_t q_context[16]; 399 // uint8_t q_context[16];
400 uint8_t header_state[32]; 400 uint8_t header_state[32];
401 uint8_t block_state[128 + 32*128]; 401 uint8_t block_state[128 + 32*128];
402 int keyframe; 402 int keyframe;
403 int always_reset;
403 int version; 404 int version;
404 int spatial_decomposition_type; 405 int spatial_decomposition_type;
405 int temporal_decomposition_type; 406 int temporal_decomposition_type;
406 int spatial_decomposition_count; 407 int spatial_decomposition_count;
407 int temporal_decomposition_count; 408 int temporal_decomposition_count;
1524 } 1525 }
1525 1526
1526 static void reset_contexts(SnowContext *s){ 1527 static void reset_contexts(SnowContext *s){
1527 int plane_index, level, orientation; 1528 int plane_index, level, orientation;
1528 1529
1529 for(plane_index=0; plane_index<2; plane_index++){ 1530 for(plane_index=0; plane_index<3; plane_index++){
1530 for(level=0; level<s->spatial_decomposition_count; level++){ 1531 for(level=0; level<s->spatial_decomposition_count; level++){
1531 for(orientation=level ? 1:0; orientation<4; orientation++){ 1532 for(orientation=level ? 1:0; orientation<4; orientation++){
1532 memset(s->plane[plane_index].band[level][orientation].state, 0, sizeof(s->plane[plane_index].band[level][orientation].state)); 1533 memset(s->plane[plane_index].band[level][orientation].state, 0, sizeof(s->plane[plane_index].band[level][orientation].state));
1533 } 1534 }
1534 } 1535 }
2259 } 2260 }
2260 } 2261 }
2261 2262
2262 static void encode_header(SnowContext *s){ 2263 static void encode_header(SnowContext *s){
2263 int plane_index, level, orientation; 2264 int plane_index, level, orientation;
2264 2265 uint8_t kstate[32]={0};
2265 put_cabac(&s->c, s->header_state, s->keyframe); // state clearing stuff? 2266
2267 put_cabac(&s->c, kstate, s->keyframe);
2268 if(s->keyframe || s->always_reset)
2269 reset_contexts(s);
2266 if(s->keyframe){ 2270 if(s->keyframe){
2267 put_symbol(&s->c, s->header_state, s->version, 0); 2271 put_symbol(&s->c, s->header_state, s->version, 0);
2272 put_cabac(&s->c, s->header_state, s->always_reset);
2268 put_symbol(&s->c, s->header_state, s->temporal_decomposition_type, 0); 2273 put_symbol(&s->c, s->header_state, s->temporal_decomposition_type, 0);
2269 put_symbol(&s->c, s->header_state, s->temporal_decomposition_count, 0); 2274 put_symbol(&s->c, s->header_state, s->temporal_decomposition_count, 0);
2270 put_symbol(&s->c, s->header_state, s->spatial_decomposition_count, 0); 2275 put_symbol(&s->c, s->header_state, s->spatial_decomposition_count, 0);
2271 put_symbol(&s->c, s->header_state, s->colorspace_type, 0); 2276 put_symbol(&s->c, s->header_state, s->colorspace_type, 0);
2272 put_symbol(&s->c, s->header_state, s->chroma_h_shift, 0); 2277 put_symbol(&s->c, s->header_state, s->chroma_h_shift, 0);
2290 put_symbol(&s->c, s->header_state, s->block_max_depth, 0); 2295 put_symbol(&s->c, s->header_state, s->block_max_depth, 0);
2291 } 2296 }
2292 2297
2293 static int decode_header(SnowContext *s){ 2298 static int decode_header(SnowContext *s){
2294 int plane_index, level, orientation; 2299 int plane_index, level, orientation;
2295 2300 uint8_t kstate[32]={0};
2296 s->keyframe= get_cabac(&s->c, s->header_state); 2301
2302 s->keyframe= get_cabac(&s->c, kstate);
2303 if(s->keyframe || s->always_reset)
2304 reset_contexts(s);
2297 if(s->keyframe){ 2305 if(s->keyframe){
2298 s->version= get_symbol(&s->c, s->header_state, 0); 2306 s->version= get_symbol(&s->c, s->header_state, 0);
2299 if(s->version>0){ 2307 if(s->version>0){
2300 av_log(s->avctx, AV_LOG_ERROR, "version %d not supported", s->version); 2308 av_log(s->avctx, AV_LOG_ERROR, "version %d not supported", s->version);
2301 return -1; 2309 return -1;
2302 } 2310 }
2311 s->always_reset= get_cabac(&s->c, s->header_state);
2303 s->temporal_decomposition_type= get_symbol(&s->c, s->header_state, 0); 2312 s->temporal_decomposition_type= get_symbol(&s->c, s->header_state, 0);
2304 s->temporal_decomposition_count= get_symbol(&s->c, s->header_state, 0); 2313 s->temporal_decomposition_count= get_symbol(&s->c, s->header_state, 0);
2305 s->spatial_decomposition_count= get_symbol(&s->c, s->header_state, 0); 2314 s->spatial_decomposition_count= get_symbol(&s->c, s->header_state, 0);
2306 s->colorspace_type= get_symbol(&s->c, s->header_state, 0); 2315 s->colorspace_type= get_symbol(&s->c, s->header_state, 0);
2307 s->chroma_h_shift= get_symbol(&s->c, s->header_state, 0); 2316 s->chroma_h_shift= get_symbol(&s->c, s->header_state, 0);
2520 static int frame_start(SnowContext *s){ 2529 static int frame_start(SnowContext *s){
2521 AVFrame tmp; 2530 AVFrame tmp;
2522 int w= s->avctx->width; //FIXME round up to x16 ? 2531 int w= s->avctx->width; //FIXME round up to x16 ?
2523 int h= s->avctx->height; 2532 int h= s->avctx->height;
2524 2533
2525 if(s->keyframe)
2526 reset_contexts(s);
2527
2528 if(s->current_picture.data[0]){ 2534 if(s->current_picture.data[0]){
2529 draw_edges(s->current_picture.data[0], s->current_picture.linesize[0], w , h , EDGE_WIDTH ); 2535 draw_edges(s->current_picture.data[0], s->current_picture.linesize[0], w , h , EDGE_WIDTH );
2530 draw_edges(s->current_picture.data[1], s->current_picture.linesize[1], w>>1, h>>1, EDGE_WIDTH/2); 2536 draw_edges(s->current_picture.data[1], s->current_picture.linesize[1], w>>1, h>>1, EDGE_WIDTH/2);
2531 draw_edges(s->current_picture.data[2], s->current_picture.linesize[2], w>>1, h>>1, EDGE_WIDTH/2); 2537 draw_edges(s->current_picture.data[2], s->current_picture.linesize[2], w>>1, h>>1, EDGE_WIDTH/2);
2532 } 2538 }
2555 ff_init_cabac_encoder(c, buf, buf_size); 2561 ff_init_cabac_encoder(c, buf, buf_size);
2556 ff_init_cabac_states(c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64); 2562 ff_init_cabac_states(c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64);
2557 2563
2558 s->input_picture = *pict; 2564 s->input_picture = *pict;
2559 2565
2560 memset(s->header_state, 0, sizeof(s->header_state));
2561
2562 s->keyframe=avctx->gop_size==0 || avctx->frame_number % avctx->gop_size == 0; 2566 s->keyframe=avctx->gop_size==0 || avctx->frame_number % avctx->gop_size == 0;
2563 pict->pict_type= s->keyframe ? FF_I_TYPE : FF_P_TYPE; 2567 pict->pict_type= s->keyframe ? FF_I_TYPE : FF_P_TYPE;
2564 2568
2565 if(pict->quality){ 2569 if(pict->quality){
2566 s->qlog= rint(QROOT*log(pict->quality / (float)FF_QP2LAMBDA)/log(2)); 2570 s->qlog= rint(QROOT*log(pict->quality / (float)FF_QP2LAMBDA)/log(2));
2569 }else{ 2573 }else{
2570 s->qlog= LOSSLESS_QLOG; 2574 s->qlog= LOSSLESS_QLOG;
2571 } 2575 }
2572 2576
2573 frame_start(s); 2577 frame_start(s);
2578 s->current_picture.key_frame= s->keyframe;
2574 2579
2575 if(pict->pict_type == P_TYPE){ 2580 if(pict->pict_type == P_TYPE){
2576 int block_width = (width +15)>>4; 2581 int block_width = (width +15)>>4;
2577 int block_height= (height+15)>>4; 2582 int block_height= (height+15)>>4;
2578 int stride= s->current_picture.linesize[0]; 2583 int stride= s->current_picture.linesize[0];
2775 return 0; 2780 return 0;
2776 2781
2777 ff_init_cabac_decoder(c, buf, buf_size); 2782 ff_init_cabac_decoder(c, buf, buf_size);
2778 ff_init_cabac_states(c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64); 2783 ff_init_cabac_states(c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64);
2779 2784
2780 memset(s->header_state, 0, sizeof(s->header_state));
2781
2782 s->current_picture.pict_type= FF_I_TYPE; //FIXME I vs. P 2785 s->current_picture.pict_type= FF_I_TYPE; //FIXME I vs. P
2783 decode_header(s); 2786 decode_header(s);
2784 if(!s->block) alloc_blocks(s); 2787 if(!s->block) alloc_blocks(s);
2785 2788
2786 frame_start(s); 2789 frame_start(s);