| 751 | |
| 752 | #if CONFIG_FFV1_ENCODER |
| 753 | static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ |
| 754 | FFV1Context *f = avctx->priv_data; |
| 755 | RangeCoder * const c= &f->c; |
| 756 | AVFrame *pict = data; |
| 757 | const int width= f->width; |
| 758 | const int height= f->height; |
| 759 | AVFrame * const p= &f->picture; |
| 760 | int used_count= 0; |
| 761 | uint8_t keystate=128; |
| 762 | |
| 763 | ff_init_range_encoder(c, buf, buf_size); |
| 764 | ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); |
| 765 | |
| 766 | *p = *pict; |
| 767 | p->pict_type= FF_I_TYPE; |
| 768 | |
| 769 | if(avctx->gop_size==0 || f->picture_number % avctx->gop_size == 0){ |
| 770 | put_rac(c, &keystate, 1); |
| 771 | p->key_frame= 1; |
| 772 | write_header(f); |
| 773 | clear_state(f); |
| 774 | }else{ |
| 775 | put_rac(c, &keystate, 0); |
| 776 | p->key_frame= 0; |
| 777 | } |
| 778 | |
| 779 | if(!f->ac){ |
| 780 | used_count += ff_rac_terminate(c); |
| 781 | //printf("pos=%d\n", used_count); |
| 782 | init_put_bits(&f->pb, buf + used_count, buf_size - used_count); |
| 783 | }else if (f->ac>1){ |
| 784 | int i; |
| 785 | for(i=1; i<256; i++){ |
| 786 | c->one_state[i]= f->state_transition[i]; |
| 787 | c->zero_state[256-i]= 256-c->one_state[i]; |
| 788 | } |
| 789 | } |
| 790 | |
| 791 | if(f->colorspace==0){ |
| 792 | const int chroma_width = -((-width )>>f->chroma_h_shift); |
| 793 | const int chroma_height= -((-height)>>f->chroma_v_shift); |
| 794 | |
| 795 | encode_plane(f, p->data[0], width, height, p->linesize[0], 0); |
| 796 | |
| 797 | encode_plane(f, p->data[1], chroma_width, chroma_height, p->linesize[1], 1); |
| 798 | encode_plane(f, p->data[2], chroma_width, chroma_height, p->linesize[2], 1); |
| 799 | }else{ |
| 800 | encode_rgb_frame(f, (uint32_t*)(p->data[0]), width, height, p->linesize[0]/4); |
| 801 | } |
| 802 | emms_c(); |
| 803 | |
| 804 | f->picture_number++; |
| 805 | |
| 806 | if(f->ac){ |
| 807 | return ff_rac_terminate(c); |
| 808 | }else{ |
| 809 | flush_put_bits(&f->pb); //nicer padding FIXME |
| 810 | return used_count + (put_bits_count(&f->pb)+7)/8; |
nothing calls this directly
no test coverage detected