| 3698 | } |
| 3699 | |
| 3700 | static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ |
| 3701 | SnowContext *s = avctx->priv_data; |
| 3702 | RangeCoder * const c= &s->c; |
| 3703 | AVFrame *pict = data; |
| 3704 | const int width= s->avctx->width; |
| 3705 | const int height= s->avctx->height; |
| 3706 | int level, orientation, plane_index, i, y; |
| 3707 | uint8_t rc_header_bak[sizeof(s->header_state)]; |
| 3708 | uint8_t rc_block_bak[sizeof(s->block_state)]; |
| 3709 | |
| 3710 | ff_init_range_encoder(c, buf, buf_size); |
| 3711 | ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); |
| 3712 | |
| 3713 | for(i=0; i<3; i++){ |
| 3714 | int shift= !!i; |
| 3715 | for(y=0; y<(height>>shift); y++) |
| 3716 | memcpy(&s->input_picture.data[i][y * s->input_picture.linesize[i]], |
| 3717 | &pict->data[i][y * pict->linesize[i]], |
| 3718 | width>>shift); |
| 3719 | } |
| 3720 | s->new_picture = *pict; |
| 3721 | |
| 3722 | s->m.picture_number= avctx->frame_number; |
| 3723 | if(avctx->flags&CODEC_FLAG_PASS2){ |
| 3724 | s->m.pict_type = |
| 3725 | pict->pict_type= s->m.rc_context.entry[avctx->frame_number].new_pict_type; |
| 3726 | s->keyframe= pict->pict_type==FF_I_TYPE; |
| 3727 | if(!(avctx->flags&CODEC_FLAG_QSCALE)) { |
| 3728 | pict->quality= ff_rate_estimate_qscale(&s->m, 0); |
| 3729 | if (pict->quality < 0) |
| 3730 | return -1; |
| 3731 | } |
| 3732 | }else{ |
| 3733 | s->keyframe= avctx->gop_size==0 || avctx->frame_number % avctx->gop_size == 0; |
| 3734 | s->m.pict_type= |
| 3735 | pict->pict_type= s->keyframe ? FF_I_TYPE : FF_P_TYPE; |
| 3736 | } |
| 3737 | |
| 3738 | if(s->pass1_rc && avctx->frame_number == 0) |
| 3739 | pict->quality= 2*FF_QP2LAMBDA; |
| 3740 | if(pict->quality){ |
| 3741 | s->qlog= qscale2qlog(pict->quality); |
| 3742 | s->lambda = pict->quality * 3/2; |
| 3743 | } |
| 3744 | if(s->qlog < 0 || (!pict->quality && (avctx->flags & CODEC_FLAG_QSCALE))){ |
| 3745 | s->qlog= LOSSLESS_QLOG; |
| 3746 | s->lambda = 0; |
| 3747 | }//else keep previous frame's qlog until after motion estimation |
| 3748 | |
| 3749 | frame_start(s); |
| 3750 | |
| 3751 | s->m.current_picture_ptr= &s->m.current_picture; |
| 3752 | s->m.last_picture.pts= s->m.current_picture.pts; |
| 3753 | s->m.current_picture.pts= pict->pts; |
| 3754 | if(pict->pict_type == FF_P_TYPE){ |
| 3755 | int block_width = (width +15)>>4; |
| 3756 | int block_height= (height+15)>>4; |
| 3757 | int stride= s->current_picture.linesize[0]; |
nothing calls this directly
no test coverage detected