annotate mpeg4videoenc.c @ 10803:4605bd2fdb7f libavcodec

Split the mpeg4 encoder and decoder off h263.c
author michael
date Thu, 07 Jan 2010 23:53:49 +0000
parents
children 55c01e916c08
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1 /*
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2 * MPEG4 encoder.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
3 * Copyright (c) 2000,2001 Fabrice Bellard
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
4 * Copyright (c) 2002-2010 Michael Niedermayer <michaelni@gmx.at>
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
5 *
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
6 * This file is part of FFmpeg.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
7 *
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
12 *
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
16 * Lesser General Public License for more details.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
17 *
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
21 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
22
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
23 #include "mpegvideo.h"
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
24 #include "h263.h"
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
25 #include "mpeg4video.h"
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
26
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
27 //The uni_DCtab_* tables below contain unified bits+length tables to encode DC
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
28 //differences in mpeg4. Unified in the sense that the specification specifies
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
29 //this encoding in several steps.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
30 static uint8_t uni_DCtab_lum_len[512];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
31 static uint8_t uni_DCtab_chrom_len[512];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
32 static uint16_t uni_DCtab_lum_bits[512];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
33 static uint16_t uni_DCtab_chrom_bits[512];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
34
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
35 //unified encoding tables for run length encoding of coefficients
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
36 //unified in the sense that the specification specifies the encoding in several steps.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
37 static uint32_t uni_mpeg4_intra_rl_bits[64*64*2*2];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
38 static uint8_t uni_mpeg4_intra_rl_len [64*64*2*2];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
39 static uint32_t uni_mpeg4_inter_rl_bits[64*64*2*2];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
40 static uint8_t uni_mpeg4_inter_rl_len [64*64*2*2];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
41 //#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128 + (run)*256 + (level))
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
42 //#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run) + (level)*64)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
43 #define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run)*128 + (level))
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
44
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
45 /* mpeg4
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
46 inter
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
47 max level: 24/6
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
48 max run: 53/63
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
49
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
50 intra
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
51 max level: 53/16
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
52 max run: 29/41
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
53 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
54
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
55
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
56 /**
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
57 * Returns the number of bits that encoding the 8x8 block in block would need.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
58 * @param[in] block_last_index last index in scantable order that refers to a non zero element in block.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
59 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
60 static inline int get_block_rate(MpegEncContext * s, DCTELEM block[64], int block_last_index, uint8_t scantable[64]){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
61 int last=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
62 int j;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
63 int rate=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
64
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
65 for(j=1; j<=block_last_index; j++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
66 const int index= scantable[j];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
67 int level= block[index];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
68 if(level){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
69 level+= 64;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
70 if((level&(~127)) == 0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
71 if(j<block_last_index) rate+= s->intra_ac_vlc_length [UNI_AC_ENC_INDEX(j-last-1, level)];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
72 else rate+= s->intra_ac_vlc_last_length[UNI_AC_ENC_INDEX(j-last-1, level)];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
73 }else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
74 rate += s->ac_esc_length;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
75
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
76 last= j;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
77 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
78 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
79
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
80 return rate;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
81 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
82
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
83
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
84 /**
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
85 * Restores the ac coefficients in block that have been changed by decide_ac_pred().
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
86 * This function also restores s->block_last_index.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
87 * @param[in,out] block MB coefficients, these will be restored
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
88 * @param[in] dir ac prediction direction for each 8x8 block
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
89 * @param[out] st scantable for each 8x8 block
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
90 * @param[in] zigzag_last_index index refering to the last non zero coefficient in zigzag order
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
91 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
92 static inline void restore_ac_coeffs(MpegEncContext * s, DCTELEM block[6][64], const int dir[6], uint8_t *st[6], const int zigzag_last_index[6])
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
93 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
94 int i, n;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
95 memcpy(s->block_last_index, zigzag_last_index, sizeof(int)*6);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
96
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
97 for(n=0; n<6; n++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
98 int16_t *ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
99
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
100 st[n]= s->intra_scantable.permutated;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
101 if(dir[n]){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
102 /* top prediction */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
103 for(i=1; i<8; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
104 block[n][s->dsp.idct_permutation[i ]] = ac_val[i+8];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
105 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
106 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
107 /* left prediction */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
108 for(i=1; i<8; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
109 block[n][s->dsp.idct_permutation[i<<3]]= ac_val[i ];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
110 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
111 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
112 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
113 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
114
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
115 /**
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
116 * Returns the optimal value (0 or 1) for the ac_pred element for the given MB in mpeg4.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
117 * This function will also update s->block_last_index and s->ac_val.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
118 * @param[in,out] block MB coefficients, these will be updated if 1 is returned
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
119 * @param[in] dir ac prediction direction for each 8x8 block
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
120 * @param[out] st scantable for each 8x8 block
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
121 * @param[out] zigzag_last_index index refering to the last non zero coefficient in zigzag order
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
122 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
123 static inline int decide_ac_pred(MpegEncContext * s, DCTELEM block[6][64], const int dir[6], uint8_t *st[6], int zigzag_last_index[6])
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
124 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
125 int score= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
126 int i, n;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
127 int8_t * const qscale_table= s->current_picture.qscale_table;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
128
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
129 memcpy(zigzag_last_index, s->block_last_index, sizeof(int)*6);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
130
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
131 for(n=0; n<6; n++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
132 int16_t *ac_val, *ac_val1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
133
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
134 score -= get_block_rate(s, block[n], s->block_last_index[n], s->intra_scantable.permutated);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
135
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
136 ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
137 ac_val1= ac_val;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
138 if(dir[n]){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
139 const int xy= s->mb_x + s->mb_y*s->mb_stride - s->mb_stride;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
140 /* top prediction */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
141 ac_val-= s->block_wrap[n]*16;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
142 if(s->mb_y==0 || s->qscale == qscale_table[xy] || n==2 || n==3){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
143 /* same qscale */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
144 for(i=1; i<8; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
145 const int level= block[n][s->dsp.idct_permutation[i ]];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
146 block[n][s->dsp.idct_permutation[i ]] = level - ac_val[i+8];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
147 ac_val1[i ]= block[n][s->dsp.idct_permutation[i<<3]];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
148 ac_val1[i+8]= level;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
149 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
150 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
151 /* different qscale, we must rescale */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
152 for(i=1; i<8; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
153 const int level= block[n][s->dsp.idct_permutation[i ]];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
154 block[n][s->dsp.idct_permutation[i ]] = level - ROUNDED_DIV(ac_val[i + 8]*qscale_table[xy], s->qscale);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
155 ac_val1[i ]= block[n][s->dsp.idct_permutation[i<<3]];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
156 ac_val1[i+8]= level;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
157 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
158 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
159 st[n]= s->intra_h_scantable.permutated;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
160 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
161 const int xy= s->mb_x-1 + s->mb_y*s->mb_stride;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
162 /* left prediction */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
163 ac_val-= 16;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
164 if(s->mb_x==0 || s->qscale == qscale_table[xy] || n==1 || n==3){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
165 /* same qscale */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
166 for(i=1; i<8; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
167 const int level= block[n][s->dsp.idct_permutation[i<<3]];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
168 block[n][s->dsp.idct_permutation[i<<3]]= level - ac_val[i];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
169 ac_val1[i ]= level;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
170 ac_val1[i+8]= block[n][s->dsp.idct_permutation[i ]];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
171 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
172 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
173 /* different qscale, we must rescale */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
174 for(i=1; i<8; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
175 const int level= block[n][s->dsp.idct_permutation[i<<3]];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
176 block[n][s->dsp.idct_permutation[i<<3]]= level - ROUNDED_DIV(ac_val[i]*qscale_table[xy], s->qscale);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
177 ac_val1[i ]= level;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
178 ac_val1[i+8]= block[n][s->dsp.idct_permutation[i ]];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
179 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
180 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
181 st[n]= s->intra_v_scantable.permutated;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
182 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
183
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
184 for(i=63; i>0; i--) //FIXME optimize
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
185 if(block[n][ st[n][i] ]) break;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
186 s->block_last_index[n]= i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
187
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
188 score += get_block_rate(s, block[n], s->block_last_index[n], st[n]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
189 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
190
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
191 if(score < 0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
192 return 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
193 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
194 restore_ac_coeffs(s, block, dir, st, zigzag_last_index);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
195 return 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
196 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
197 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
198
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
199 /**
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
200 * modify mb_type & qscale so that encoding is acually possible in mpeg4
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
201 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
202 void ff_clean_mpeg4_qscales(MpegEncContext *s){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
203 int i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
204 int8_t * const qscale_table= s->current_picture.qscale_table;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
205
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
206 ff_clean_h263_qscales(s);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
207
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
208 if(s->pict_type== FF_B_TYPE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
209 int odd=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
210 /* ok, come on, this isn't funny anymore, there's more code for handling this mpeg4 mess than for the actual adaptive quantization */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
211
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
212 for(i=0; i<s->mb_num; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
213 int mb_xy= s->mb_index2xy[i];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
214 odd += qscale_table[mb_xy]&1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
215 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
216
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
217 if(2*odd > s->mb_num) odd=1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
218 else odd=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
219
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
220 for(i=0; i<s->mb_num; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
221 int mb_xy= s->mb_index2xy[i];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
222 if((qscale_table[mb_xy]&1) != odd)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
223 qscale_table[mb_xy]++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
224 if(qscale_table[mb_xy] > 31)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
225 qscale_table[mb_xy]= 31;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
226 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
227
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
228 for(i=1; i<s->mb_num; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
229 int mb_xy= s->mb_index2xy[i];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
230 if(qscale_table[mb_xy] != qscale_table[s->mb_index2xy[i-1]] && (s->mb_type[mb_xy]&CANDIDATE_MB_TYPE_DIRECT)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
231 s->mb_type[mb_xy]|= CANDIDATE_MB_TYPE_BIDIR;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
232 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
233 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
234 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
235 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
236
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
237
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
238 /**
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
239 * encodes the dc value.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
240 * @param n block index (0-3 are luma, 4-5 are chroma)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
241 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
242 static inline void mpeg4_encode_dc(PutBitContext * s, int level, int n)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
243 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
244 #if 1
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
245 level+=256;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
246 if (n < 4) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
247 /* luminance */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
248 put_bits(s, uni_DCtab_lum_len[level], uni_DCtab_lum_bits[level]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
249 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
250 /* chrominance */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
251 put_bits(s, uni_DCtab_chrom_len[level], uni_DCtab_chrom_bits[level]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
252 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
253 #else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
254 int size, v;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
255 /* find number of bits */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
256 size = 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
257 v = abs(level);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
258 while (v) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
259 v >>= 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
260 size++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
261 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
262
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
263 if (n < 4) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
264 /* luminance */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
265 put_bits(&s->pb, DCtab_lum[size][1], DCtab_lum[size][0]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
266 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
267 /* chrominance */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
268 put_bits(&s->pb, DCtab_chrom[size][1], DCtab_chrom[size][0]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
269 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
270
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
271 /* encode remaining bits */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
272 if (size > 0) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
273 if (level < 0)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
274 level = (-level) ^ ((1 << size) - 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
275 put_bits(&s->pb, size, level);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
276 if (size > 8)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
277 put_bits(&s->pb, 1, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
278 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
279 #endif
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
280 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
281
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
282 static inline int mpeg4_get_dc_length(int level, int n){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
283 if (n < 4) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
284 return uni_DCtab_lum_len[level + 256];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
285 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
286 return uni_DCtab_chrom_len[level + 256];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
287 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
288 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
289
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
290 /**
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
291 * encodes a 8x8 block
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
292 * @param n block index (0-3 are luma, 4-5 are chroma)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
293 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
294 static inline void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n, int intra_dc,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
295 uint8_t *scan_table, PutBitContext *dc_pb, PutBitContext *ac_pb)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
296 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
297 int i, last_non_zero;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
298 #if 0 //variables for the outcommented version
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
299 int code, sign, last;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
300 #endif
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
301 const RLTable *rl;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
302 uint32_t *bits_tab;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
303 uint8_t *len_tab;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
304 const int last_index = s->block_last_index[n];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
305
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
306 if (s->mb_intra) { //Note gcc (3.2.1 at least) will optimize this away
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
307 /* mpeg4 based DC predictor */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
308 mpeg4_encode_dc(dc_pb, intra_dc, n);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
309 if(last_index<1) return;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
310 i = 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
311 rl = &rl_intra;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
312 bits_tab= uni_mpeg4_intra_rl_bits;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
313 len_tab = uni_mpeg4_intra_rl_len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
314 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
315 if(last_index<0) return;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
316 i = 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
317 rl = &rl_inter;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
318 bits_tab= uni_mpeg4_inter_rl_bits;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
319 len_tab = uni_mpeg4_inter_rl_len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
320 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
321
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
322 /* AC coefs */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
323 last_non_zero = i - 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
324 #if 1
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
325 for (; i < last_index; i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
326 int level = block[ scan_table[i] ];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
327 if (level) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
328 int run = i - last_non_zero - 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
329 level+=64;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
330 if((level&(~127)) == 0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
331 const int index= UNI_MPEG4_ENC_INDEX(0, run, level);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
332 put_bits(ac_pb, len_tab[index], bits_tab[index]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
333 }else{ //ESC3
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
334 put_bits(ac_pb, 7+2+1+6+1+12+1, (3<<23)+(3<<21)+(0<<20)+(run<<14)+(1<<13)+(((level-64)&0xfff)<<1)+1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
335 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
336 last_non_zero = i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
337 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
338 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
339 /*if(i<=last_index)*/{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
340 int level = block[ scan_table[i] ];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
341 int run = i - last_non_zero - 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
342 level+=64;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
343 if((level&(~127)) == 0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
344 const int index= UNI_MPEG4_ENC_INDEX(1, run, level);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
345 put_bits(ac_pb, len_tab[index], bits_tab[index]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
346 }else{ //ESC3
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
347 put_bits(ac_pb, 7+2+1+6+1+12+1, (3<<23)+(3<<21)+(1<<20)+(run<<14)+(1<<13)+(((level-64)&0xfff)<<1)+1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
348 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
349 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
350 #else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
351 for (; i <= last_index; i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
352 const int slevel = block[ scan_table[i] ];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
353 if (slevel) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
354 int level;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
355 int run = i - last_non_zero - 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
356 last = (i == last_index);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
357 sign = 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
358 level = slevel;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
359 if (level < 0) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
360 sign = 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
361 level = -level;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
362 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
363 code = get_rl_index(rl, last, run, level);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
364 put_bits(ac_pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
365 if (code == rl->n) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
366 int level1, run1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
367 level1 = level - rl->max_level[last][run];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
368 if (level1 < 1)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
369 goto esc2;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
370 code = get_rl_index(rl, last, run, level1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
371 if (code == rl->n) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
372 esc2:
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
373 put_bits(ac_pb, 1, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
374 if (level > MAX_LEVEL)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
375 goto esc3;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
376 run1 = run - rl->max_run[last][level] - 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
377 if (run1 < 0)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
378 goto esc3;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
379 code = get_rl_index(rl, last, run1, level);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
380 if (code == rl->n) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
381 esc3:
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
382 /* third escape */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
383 put_bits(ac_pb, 1, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
384 put_bits(ac_pb, 1, last);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
385 put_bits(ac_pb, 6, run);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
386 put_bits(ac_pb, 1, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
387 put_sbits(ac_pb, 12, slevel);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
388 put_bits(ac_pb, 1, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
389 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
390 /* second escape */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
391 put_bits(ac_pb, 1, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
392 put_bits(ac_pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
393 put_bits(ac_pb, 1, sign);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
394 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
395 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
396 /* first escape */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
397 put_bits(ac_pb, 1, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
398 put_bits(ac_pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
399 put_bits(ac_pb, 1, sign);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
400 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
401 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
402 put_bits(ac_pb, 1, sign);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
403 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
404 last_non_zero = i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
405 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
406 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
407 #endif
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
408 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
409
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
410 static int mpeg4_get_block_length(MpegEncContext * s, DCTELEM * block, int n, int intra_dc,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
411 uint8_t *scan_table)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
412 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
413 int i, last_non_zero;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
414 uint8_t *len_tab;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
415 const int last_index = s->block_last_index[n];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
416 int len=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
417
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
418 if (s->mb_intra) { //Note gcc (3.2.1 at least) will optimize this away
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
419 /* mpeg4 based DC predictor */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
420 len += mpeg4_get_dc_length(intra_dc, n);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
421 if(last_index<1) return len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
422 i = 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
423 len_tab = uni_mpeg4_intra_rl_len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
424 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
425 if(last_index<0) return 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
426 i = 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
427 len_tab = uni_mpeg4_inter_rl_len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
428 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
429
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
430 /* AC coefs */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
431 last_non_zero = i - 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
432 for (; i < last_index; i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
433 int level = block[ scan_table[i] ];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
434 if (level) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
435 int run = i - last_non_zero - 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
436 level+=64;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
437 if((level&(~127)) == 0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
438 const int index= UNI_MPEG4_ENC_INDEX(0, run, level);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
439 len += len_tab[index];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
440 }else{ //ESC3
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
441 len += 7+2+1+6+1+12+1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
442 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
443 last_non_zero = i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
444 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
445 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
446 /*if(i<=last_index)*/{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
447 int level = block[ scan_table[i] ];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
448 int run = i - last_non_zero - 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
449 level+=64;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
450 if((level&(~127)) == 0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
451 const int index= UNI_MPEG4_ENC_INDEX(1, run, level);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
452 len += len_tab[index];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
453 }else{ //ESC3
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
454 len += 7+2+1+6+1+12+1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
455 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
456 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
457
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
458 return len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
459 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
460
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
461 static inline void mpeg4_encode_blocks(MpegEncContext * s, DCTELEM block[6][64], int intra_dc[6],
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
462 uint8_t **scan_table, PutBitContext *dc_pb, PutBitContext *ac_pb){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
463 int i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
464
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
465 if(scan_table){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
466 if(s->flags2 & CODEC_FLAG2_NO_OUTPUT){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
467 for (i = 0; i < 6; i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
468 skip_put_bits(&s->pb, mpeg4_get_block_length(s, block[i], i, intra_dc[i], scan_table[i]));
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
469 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
470 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
471 /* encode each block */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
472 for (i = 0; i < 6; i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
473 mpeg4_encode_block(s, block[i], i, intra_dc[i], scan_table[i], dc_pb, ac_pb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
474 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
475 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
476 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
477 if(s->flags2 & CODEC_FLAG2_NO_OUTPUT){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
478 for (i = 0; i < 6; i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
479 skip_put_bits(&s->pb, mpeg4_get_block_length(s, block[i], i, 0, s->intra_scantable.permutated));
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
480 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
481 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
482 /* encode each block */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
483 for (i = 0; i < 6; i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
484 mpeg4_encode_block(s, block[i], i, 0, s->intra_scantable.permutated, dc_pb, ac_pb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
485 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
486 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
487 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
488 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
489
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
490 //FIXME this is duplicated to h263.c
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
491 static const int dquant_code[5]= {1,0,9,2,3};
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
492
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
493 void mpeg4_encode_mb(MpegEncContext * s,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
494 DCTELEM block[6][64],
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
495 int motion_x, int motion_y)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
496 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
497 int cbpc, cbpy, pred_x, pred_y;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
498 PutBitContext * const pb2 = s->data_partitioning ? &s->pb2 : &s->pb;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
499 PutBitContext * const tex_pb = s->data_partitioning && s->pict_type!=FF_B_TYPE ? &s->tex_pb : &s->pb;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
500 PutBitContext * const dc_pb = s->data_partitioning && s->pict_type!=FF_I_TYPE ? &s->pb2 : &s->pb;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
501 const int interleaved_stats= (s->flags&CODEC_FLAG_PASS1) && !s->data_partitioning ? 1 : 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
502
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
503 if (!s->mb_intra) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
504 int i, cbp;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
505
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
506 if(s->pict_type==FF_B_TYPE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
507 static const int mb_type_table[8]= {-1, 3, 2, 1,-1,-1,-1, 0}; /* convert from mv_dir to type */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
508 int mb_type= mb_type_table[s->mv_dir];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
509
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
510 if(s->mb_x==0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
511 for(i=0; i<2; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
512 s->last_mv[i][0][0]=
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
513 s->last_mv[i][0][1]=
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
514 s->last_mv[i][1][0]=
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
515 s->last_mv[i][1][1]= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
516 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
517 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
518
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
519 assert(s->dquant>=-2 && s->dquant<=2);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
520 assert((s->dquant&1)==0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
521 assert(mb_type>=0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
522
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
523 /* nothing to do if this MB was skipped in the next P Frame */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
524 if(s->next_picture.mbskip_table[s->mb_y * s->mb_stride + s->mb_x]){ //FIXME avoid DCT & ...
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
525 s->skip_count++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
526 s->mv[0][0][0]=
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
527 s->mv[0][0][1]=
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
528 s->mv[1][0][0]=
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
529 s->mv[1][0][1]= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
530 s->mv_dir= MV_DIR_FORWARD; //doesn't matter
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
531 s->qscale -= s->dquant;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
532 // s->mb_skipped=1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
533
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
534 return;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
535 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
536
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
537 cbp= get_b_cbp(s, block, motion_x, motion_y, mb_type);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
538
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
539 if ((cbp | motion_x | motion_y | mb_type) ==0) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
540 /* direct MB with MV={0,0} */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
541 assert(s->dquant==0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
542
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
543 put_bits(&s->pb, 1, 1); /* mb not coded modb1=1 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
544
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
545 if(interleaved_stats){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
546 s->misc_bits++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
547 s->last_bits++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
548 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
549 s->skip_count++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
550 return;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
551 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
552
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
553 put_bits(&s->pb, 1, 0); /* mb coded modb1=0 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
554 put_bits(&s->pb, 1, cbp ? 0 : 1); /* modb2 */ //FIXME merge
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
555 put_bits(&s->pb, mb_type+1, 1); // this table is so simple that we don't need it :)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
556 if(cbp) put_bits(&s->pb, 6, cbp);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
557
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
558 if(cbp && mb_type){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
559 if(s->dquant)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
560 put_bits(&s->pb, 2, (s->dquant>>2)+3);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
561 else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
562 put_bits(&s->pb, 1, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
563 }else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
564 s->qscale -= s->dquant;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
565
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
566 if(!s->progressive_sequence){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
567 if(cbp)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
568 put_bits(&s->pb, 1, s->interlaced_dct);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
569 if(mb_type) // not direct mode
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
570 put_bits(&s->pb, 1, s->mv_type == MV_TYPE_FIELD);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
571 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
572
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
573 if(interleaved_stats){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
574 s->misc_bits+= get_bits_diff(s);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
575 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
576
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
577 if(mb_type == 0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
578 assert(s->mv_dir & MV_DIRECT);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
579 ff_h263_encode_motion_vector(s, motion_x, motion_y, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
580 s->b_count++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
581 s->f_count++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
582 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
583 assert(mb_type > 0 && mb_type < 4);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
584 if(s->mv_type != MV_TYPE_FIELD){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
585 if(s->mv_dir & MV_DIR_FORWARD){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
586 ff_h263_encode_motion_vector(s, s->mv[0][0][0] - s->last_mv[0][0][0],
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
587 s->mv[0][0][1] - s->last_mv[0][0][1], s->f_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
588 s->last_mv[0][0][0]= s->last_mv[0][1][0]= s->mv[0][0][0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
589 s->last_mv[0][0][1]= s->last_mv[0][1][1]= s->mv[0][0][1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
590 s->f_count++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
591 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
592 if(s->mv_dir & MV_DIR_BACKWARD){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
593 ff_h263_encode_motion_vector(s, s->mv[1][0][0] - s->last_mv[1][0][0],
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
594 s->mv[1][0][1] - s->last_mv[1][0][1], s->b_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
595 s->last_mv[1][0][0]= s->last_mv[1][1][0]= s->mv[1][0][0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
596 s->last_mv[1][0][1]= s->last_mv[1][1][1]= s->mv[1][0][1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
597 s->b_count++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
598 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
599 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
600 if(s->mv_dir & MV_DIR_FORWARD){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
601 put_bits(&s->pb, 1, s->field_select[0][0]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
602 put_bits(&s->pb, 1, s->field_select[0][1]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
603 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
604 if(s->mv_dir & MV_DIR_BACKWARD){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
605 put_bits(&s->pb, 1, s->field_select[1][0]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
606 put_bits(&s->pb, 1, s->field_select[1][1]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
607 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
608 if(s->mv_dir & MV_DIR_FORWARD){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
609 for(i=0; i<2; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
610 ff_h263_encode_motion_vector(s, s->mv[0][i][0] - s->last_mv[0][i][0] ,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
611 s->mv[0][i][1] - s->last_mv[0][i][1]/2, s->f_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
612 s->last_mv[0][i][0]= s->mv[0][i][0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
613 s->last_mv[0][i][1]= s->mv[0][i][1]*2;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
614 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
615 s->f_count++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
616 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
617 if(s->mv_dir & MV_DIR_BACKWARD){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
618 for(i=0; i<2; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
619 ff_h263_encode_motion_vector(s, s->mv[1][i][0] - s->last_mv[1][i][0] ,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
620 s->mv[1][i][1] - s->last_mv[1][i][1]/2, s->b_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
621 s->last_mv[1][i][0]= s->mv[1][i][0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
622 s->last_mv[1][i][1]= s->mv[1][i][1]*2;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
623 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
624 s->b_count++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
625 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
626 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
627 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
628
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
629 if(interleaved_stats){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
630 s->mv_bits+= get_bits_diff(s);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
631 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
632
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
633 mpeg4_encode_blocks(s, block, NULL, NULL, NULL, &s->pb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
634
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
635 if(interleaved_stats){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
636 s->p_tex_bits+= get_bits_diff(s);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
637 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
638
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
639 }else{ /* s->pict_type==FF_B_TYPE */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
640 cbp= get_p_cbp(s, block, motion_x, motion_y);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
641
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
642 if ((cbp | motion_x | motion_y | s->dquant) == 0 && s->mv_type==MV_TYPE_16X16) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
643 /* check if the B frames can skip it too, as we must skip it if we skip here
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
644 why didn't they just compress the skip-mb bits instead of reusing them ?! */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
645 if(s->max_b_frames>0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
646 int i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
647 int x,y, offset;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
648 uint8_t *p_pic;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
649
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
650 x= s->mb_x*16;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
651 y= s->mb_y*16;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
652 if(x+16 > s->width) x= s->width-16;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
653 if(y+16 > s->height) y= s->height-16;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
654
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
655 offset= x + y*s->linesize;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
656 p_pic= s->new_picture.data[0] + offset;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
657
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
658 s->mb_skipped=1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
659 for(i=0; i<s->max_b_frames; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
660 uint8_t *b_pic;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
661 int diff;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
662 Picture *pic= s->reordered_input_picture[i+1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
663
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
664 if(pic==NULL || pic->pict_type!=FF_B_TYPE) break;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
665
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
666 b_pic= pic->data[0] + offset;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
667 if(pic->type != FF_BUFFER_TYPE_SHARED)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
668 b_pic+= INPLACE_OFFSET;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
669 diff= s->dsp.sad[0](NULL, p_pic, b_pic, s->linesize, 16);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
670 if(diff>s->qscale*70){ //FIXME check that 70 is optimal
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
671 s->mb_skipped=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
672 break;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
673 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
674 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
675 }else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
676 s->mb_skipped=1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
677
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
678 if(s->mb_skipped==1){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
679 /* skip macroblock */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
680 put_bits(&s->pb, 1, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
681
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
682 if(interleaved_stats){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
683 s->misc_bits++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
684 s->last_bits++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
685 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
686 s->skip_count++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
687
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
688 return;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
689 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
690 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
691
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
692 put_bits(&s->pb, 1, 0); /* mb coded */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
693 cbpc = cbp & 3;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
694 cbpy = cbp >> 2;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
695 cbpy ^= 0xf;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
696 if(s->mv_type==MV_TYPE_16X16){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
697 if(s->dquant) cbpc+= 8;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
698 put_bits(&s->pb,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
699 inter_MCBPC_bits[cbpc],
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
700 inter_MCBPC_code[cbpc]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
701
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
702 put_bits(pb2, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
703 if(s->dquant)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
704 put_bits(pb2, 2, dquant_code[s->dquant+2]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
705
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
706 if(!s->progressive_sequence){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
707 if(cbp)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
708 put_bits(pb2, 1, s->interlaced_dct);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
709 put_bits(pb2, 1, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
710 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
711
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
712 if(interleaved_stats){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
713 s->misc_bits+= get_bits_diff(s);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
714 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
715
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
716 /* motion vectors: 16x16 mode */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
717 h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
718
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
719 ff_h263_encode_motion_vector(s, motion_x - pred_x,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
720 motion_y - pred_y, s->f_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
721 }else if(s->mv_type==MV_TYPE_FIELD){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
722 if(s->dquant) cbpc+= 8;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
723 put_bits(&s->pb,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
724 inter_MCBPC_bits[cbpc],
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
725 inter_MCBPC_code[cbpc]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
726
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
727 put_bits(pb2, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
728 if(s->dquant)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
729 put_bits(pb2, 2, dquant_code[s->dquant+2]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
730
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
731 assert(!s->progressive_sequence);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
732 if(cbp)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
733 put_bits(pb2, 1, s->interlaced_dct);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
734 put_bits(pb2, 1, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
735
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
736 if(interleaved_stats){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
737 s->misc_bits+= get_bits_diff(s);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
738 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
739
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
740 /* motion vectors: 16x8 interlaced mode */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
741 h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
742 pred_y /=2;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
743
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
744 put_bits(&s->pb, 1, s->field_select[0][0]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
745 put_bits(&s->pb, 1, s->field_select[0][1]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
746
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
747 ff_h263_encode_motion_vector(s, s->mv[0][0][0] - pred_x,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
748 s->mv[0][0][1] - pred_y, s->f_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
749 ff_h263_encode_motion_vector(s, s->mv[0][1][0] - pred_x,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
750 s->mv[0][1][1] - pred_y, s->f_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
751 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
752 assert(s->mv_type==MV_TYPE_8X8);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
753 put_bits(&s->pb,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
754 inter_MCBPC_bits[cbpc+16],
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
755 inter_MCBPC_code[cbpc+16]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
756 put_bits(pb2, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
757
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
758 if(!s->progressive_sequence){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
759 if(cbp)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
760 put_bits(pb2, 1, s->interlaced_dct);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
761 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
762
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
763 if(interleaved_stats){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
764 s->misc_bits+= get_bits_diff(s);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
765 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
766
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
767 for(i=0; i<4; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
768 /* motion vectors: 8x8 mode*/
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
769 h263_pred_motion(s, i, 0, &pred_x, &pred_y);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
770
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
771 ff_h263_encode_motion_vector(s, s->current_picture.motion_val[0][ s->block_index[i] ][0] - pred_x,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
772 s->current_picture.motion_val[0][ s->block_index[i] ][1] - pred_y, s->f_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
773 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
774 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
775
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
776 if(interleaved_stats){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
777 s->mv_bits+= get_bits_diff(s);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
778 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
779
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
780 mpeg4_encode_blocks(s, block, NULL, NULL, NULL, tex_pb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
781
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
782 if(interleaved_stats){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
783 s->p_tex_bits+= get_bits_diff(s);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
784 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
785 s->f_count++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
786 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
787 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
788 int cbp;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
789 int dc_diff[6]; //dc values with the dc prediction subtracted
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
790 int dir[6]; //prediction direction
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
791 int zigzag_last_index[6];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
792 uint8_t *scan_table[6];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
793 int i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
794
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
795 for(i=0; i<6; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
796 dc_diff[i]= ff_mpeg4_pred_dc(s, i, block[i][0], &dir[i], 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
797 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
798
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
799 if(s->flags & CODEC_FLAG_AC_PRED){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
800 s->ac_pred= decide_ac_pred(s, block, dir, scan_table, zigzag_last_index);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
801 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
802 for(i=0; i<6; i++)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
803 scan_table[i]= s->intra_scantable.permutated;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
804 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
805
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
806 /* compute cbp */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
807 cbp = 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
808 for (i = 0; i < 6; i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
809 if (s->block_last_index[i] >= 1)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
810 cbp |= 1 << (5 - i);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
811 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
812
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
813 cbpc = cbp & 3;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
814 if (s->pict_type == FF_I_TYPE) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
815 if(s->dquant) cbpc+=4;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
816 put_bits(&s->pb,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
817 intra_MCBPC_bits[cbpc],
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
818 intra_MCBPC_code[cbpc]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
819 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
820 if(s->dquant) cbpc+=8;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
821 put_bits(&s->pb, 1, 0); /* mb coded */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
822 put_bits(&s->pb,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
823 inter_MCBPC_bits[cbpc + 4],
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
824 inter_MCBPC_code[cbpc + 4]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
825 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
826 put_bits(pb2, 1, s->ac_pred);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
827 cbpy = cbp >> 2;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
828 put_bits(pb2, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
829 if(s->dquant)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
830 put_bits(dc_pb, 2, dquant_code[s->dquant+2]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
831
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
832 if(!s->progressive_sequence){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
833 put_bits(dc_pb, 1, s->interlaced_dct);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
834 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
835
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
836 if(interleaved_stats){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
837 s->misc_bits+= get_bits_diff(s);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
838 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
839
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
840 mpeg4_encode_blocks(s, block, dc_diff, scan_table, dc_pb, tex_pb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
841
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
842 if(interleaved_stats){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
843 s->i_tex_bits+= get_bits_diff(s);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
844 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
845 s->i_count++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
846
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
847 /* restore ac coeffs & last_index stuff if we messed them up with the prediction */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
848 if(s->ac_pred)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
849 restore_ac_coeffs(s, block, dir, scan_table, zigzag_last_index);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
850 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
851 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
852
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
853 /**
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
854 * add mpeg4 stuffing bits (01...1)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
855 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
856 void ff_mpeg4_stuffing(PutBitContext * pbc)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
857 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
858 int length;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
859 put_bits(pbc, 1, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
860 length= (-put_bits_count(pbc))&7;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
861 if(length) put_bits(pbc, length, (1<<length)-1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
862 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
863
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
864 /* must be called before writing the header */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
865 void ff_set_mpeg4_time(MpegEncContext * s){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
866 if(s->pict_type==FF_B_TYPE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
867 ff_mpeg4_init_direct_mv(s);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
868 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
869 s->last_time_base= s->time_base;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
870 s->time_base= s->time/s->avctx->time_base.den;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
871 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
872 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
873
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
874 static void mpeg4_encode_gop_header(MpegEncContext * s){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
875 int hours, minutes, seconds;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
876 int64_t time;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
877
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
878 put_bits(&s->pb, 16, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
879 put_bits(&s->pb, 16, GOP_STARTCODE);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
880
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
881 time= s->current_picture_ptr->pts;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
882 if(s->reordered_input_picture[1])
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
883 time= FFMIN(time, s->reordered_input_picture[1]->pts);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
884 time= time*s->avctx->time_base.num;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
885
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
886 seconds= time/s->avctx->time_base.den;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
887 minutes= seconds/60; seconds %= 60;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
888 hours= minutes/60; minutes %= 60;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
889 hours%=24;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
890
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
891 put_bits(&s->pb, 5, hours);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
892 put_bits(&s->pb, 6, minutes);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
893 put_bits(&s->pb, 1, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
894 put_bits(&s->pb, 6, seconds);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
895
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
896 put_bits(&s->pb, 1, !!(s->flags&CODEC_FLAG_CLOSED_GOP));
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
897 put_bits(&s->pb, 1, 0); //broken link == NO
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
898
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
899 s->last_time_base= time / s->avctx->time_base.den;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
900
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
901 ff_mpeg4_stuffing(&s->pb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
902 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
903
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
904 static void mpeg4_encode_visual_object_header(MpegEncContext * s){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
905 int profile_and_level_indication;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
906 int vo_ver_id;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
907
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
908 if(s->avctx->profile != FF_PROFILE_UNKNOWN){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
909 profile_and_level_indication = s->avctx->profile << 4;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
910 }else if(s->max_b_frames || s->quarter_sample){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
911 profile_and_level_indication= 0xF0; // adv simple
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
912 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
913 profile_and_level_indication= 0x00; // simple
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
914 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
915
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
916 if(s->avctx->level != FF_LEVEL_UNKNOWN){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
917 profile_and_level_indication |= s->avctx->level;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
918 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
919 profile_and_level_indication |= 1; //level 1
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
920 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
921
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
922 if(profile_and_level_indication>>4 == 0xF){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
923 vo_ver_id= 5;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
924 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
925 vo_ver_id= 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
926 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
927
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
928 //FIXME levels
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
929
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
930 put_bits(&s->pb, 16, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
931 put_bits(&s->pb, 16, VOS_STARTCODE);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
932
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
933 put_bits(&s->pb, 8, profile_and_level_indication);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
934
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
935 put_bits(&s->pb, 16, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
936 put_bits(&s->pb, 16, VISUAL_OBJ_STARTCODE);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
937
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
938 put_bits(&s->pb, 1, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
939 put_bits(&s->pb, 4, vo_ver_id);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
940 put_bits(&s->pb, 3, 1); //priority
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
941
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
942 put_bits(&s->pb, 4, 1); //visual obj type== video obj
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
943
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
944 put_bits(&s->pb, 1, 0); //video signal type == no clue //FIXME
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
945
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
946 ff_mpeg4_stuffing(&s->pb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
947 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
948
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
949 static void mpeg4_encode_vol_header(MpegEncContext * s, int vo_number, int vol_number)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
950 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
951 int vo_ver_id;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
952
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
953 if (!CONFIG_MPEG4_ENCODER) return;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
954
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
955 if(s->max_b_frames || s->quarter_sample){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
956 vo_ver_id= 5;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
957 s->vo_type= ADV_SIMPLE_VO_TYPE;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
958 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
959 vo_ver_id= 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
960 s->vo_type= SIMPLE_VO_TYPE;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
961 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
962
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
963 put_bits(&s->pb, 16, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
964 put_bits(&s->pb, 16, 0x100 + vo_number); /* video obj */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
965 put_bits(&s->pb, 16, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
966 put_bits(&s->pb, 16, 0x120 + vol_number); /* video obj layer */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
967
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
968 put_bits(&s->pb, 1, 0); /* random access vol */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
969 put_bits(&s->pb, 8, s->vo_type); /* video obj type indication */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
970 if(s->workaround_bugs & FF_BUG_MS) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
971 put_bits(&s->pb, 1, 0); /* is obj layer id= no */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
972 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
973 put_bits(&s->pb, 1, 1); /* is obj layer id= yes */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
974 put_bits(&s->pb, 4, vo_ver_id); /* is obj layer ver id */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
975 put_bits(&s->pb, 3, 1); /* is obj layer priority */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
976 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
977
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
978 s->aspect_ratio_info= ff_h263_aspect_to_info(s->avctx->sample_aspect_ratio);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
979
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
980 put_bits(&s->pb, 4, s->aspect_ratio_info);/* aspect ratio info */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
981 if (s->aspect_ratio_info == FF_ASPECT_EXTENDED){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
982 put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.num);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
983 put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.den);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
984 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
985
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
986 if(s->workaround_bugs & FF_BUG_MS) { //
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
987 put_bits(&s->pb, 1, 0); /* vol control parameters= no @@@ */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
988 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
989 put_bits(&s->pb, 1, 1); /* vol control parameters= yes */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
990 put_bits(&s->pb, 2, 1); /* chroma format YUV 420/YV12 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
991 put_bits(&s->pb, 1, s->low_delay);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
992 put_bits(&s->pb, 1, 0); /* vbv parameters= no */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
993 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
994
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
995 put_bits(&s->pb, 2, RECT_SHAPE); /* vol shape= rectangle */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
996 put_bits(&s->pb, 1, 1); /* marker bit */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
997
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
998 put_bits(&s->pb, 16, s->avctx->time_base.den);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
999 if (s->time_increment_bits < 1)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1000 s->time_increment_bits = 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1001 put_bits(&s->pb, 1, 1); /* marker bit */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1002 put_bits(&s->pb, 1, 0); /* fixed vop rate=no */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1003 put_bits(&s->pb, 1, 1); /* marker bit */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1004 put_bits(&s->pb, 13, s->width); /* vol width */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1005 put_bits(&s->pb, 1, 1); /* marker bit */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1006 put_bits(&s->pb, 13, s->height); /* vol height */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1007 put_bits(&s->pb, 1, 1); /* marker bit */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1008 put_bits(&s->pb, 1, s->progressive_sequence ? 0 : 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1009 put_bits(&s->pb, 1, 1); /* obmc disable */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1010 if (vo_ver_id == 1) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1011 put_bits(&s->pb, 1, s->vol_sprite_usage); /* sprite enable */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1012 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1013 put_bits(&s->pb, 2, s->vol_sprite_usage); /* sprite enable */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1014 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1015
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1016 put_bits(&s->pb, 1, 0); /* not 8 bit == false */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1017 put_bits(&s->pb, 1, s->mpeg_quant); /* quant type= (0=h263 style)*/
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1018
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1019 if(s->mpeg_quant){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1020 ff_write_quant_matrix(&s->pb, s->avctx->intra_matrix);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1021 ff_write_quant_matrix(&s->pb, s->avctx->inter_matrix);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1022 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1023
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1024 if (vo_ver_id != 1)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1025 put_bits(&s->pb, 1, s->quarter_sample);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1026 put_bits(&s->pb, 1, 1); /* complexity estimation disable */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1027 s->resync_marker= s->rtp_mode;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1028 put_bits(&s->pb, 1, s->resync_marker ? 0 : 1);/* resync marker disable */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1029 put_bits(&s->pb, 1, s->data_partitioning ? 1 : 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1030 if(s->data_partitioning){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1031 put_bits(&s->pb, 1, 0); /* no rvlc */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1032 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1033
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1034 if (vo_ver_id != 1){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1035 put_bits(&s->pb, 1, 0); /* newpred */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1036 put_bits(&s->pb, 1, 0); /* reduced res vop */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1037 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1038 put_bits(&s->pb, 1, 0); /* scalability */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1039
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1040 ff_mpeg4_stuffing(&s->pb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1041
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1042 /* user data */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1043 if(!(s->flags & CODEC_FLAG_BITEXACT)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1044 put_bits(&s->pb, 16, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1045 put_bits(&s->pb, 16, 0x1B2); /* user_data */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1046 ff_put_string(&s->pb, LIBAVCODEC_IDENT, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1047 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1048 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1049
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1050 /* write mpeg4 VOP header */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1051 void mpeg4_encode_picture_header(MpegEncContext * s, int picture_number)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1052 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1053 int time_incr;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1054 int time_div, time_mod;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1055
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1056 if(s->pict_type==FF_I_TYPE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1057 if(!(s->flags&CODEC_FLAG_GLOBAL_HEADER)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1058 if(s->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT) //HACK, the reference sw is buggy
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1059 mpeg4_encode_visual_object_header(s);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1060 if(s->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT || picture_number==0) //HACK, the reference sw is buggy
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1061 mpeg4_encode_vol_header(s, 0, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1062 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1063 if(!(s->workaround_bugs & FF_BUG_MS))
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1064 mpeg4_encode_gop_header(s);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1065 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1066
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1067 s->partitioned_frame= s->data_partitioning && s->pict_type!=FF_B_TYPE;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1068
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1069 put_bits(&s->pb, 16, 0); /* vop header */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1070 put_bits(&s->pb, 16, VOP_STARTCODE); /* vop header */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1071 put_bits(&s->pb, 2, s->pict_type - 1); /* pict type: I = 0 , P = 1 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1072
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1073 assert(s->time>=0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1074 time_div= s->time/s->avctx->time_base.den;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1075 time_mod= s->time%s->avctx->time_base.den;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1076 time_incr= time_div - s->last_time_base;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1077 assert(time_incr >= 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1078 while(time_incr--)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1079 put_bits(&s->pb, 1, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1080
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1081 put_bits(&s->pb, 1, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1082
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1083 put_bits(&s->pb, 1, 1); /* marker */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1084 put_bits(&s->pb, s->time_increment_bits, time_mod); /* time increment */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1085 put_bits(&s->pb, 1, 1); /* marker */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1086 put_bits(&s->pb, 1, 1); /* vop coded */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1087 if ( s->pict_type == FF_P_TYPE
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1088 || (s->pict_type == FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE)) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1089 put_bits(&s->pb, 1, s->no_rounding); /* rounding type */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1090 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1091 put_bits(&s->pb, 3, 0); /* intra dc VLC threshold */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1092 if(!s->progressive_sequence){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1093 put_bits(&s->pb, 1, s->current_picture_ptr->top_field_first);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1094 put_bits(&s->pb, 1, s->alternate_scan);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1095 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1096 //FIXME sprite stuff
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1097
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1098 put_bits(&s->pb, 5, s->qscale);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1099
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1100 if (s->pict_type != FF_I_TYPE)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1101 put_bits(&s->pb, 3, s->f_code); /* fcode_for */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1102 if (s->pict_type == FF_B_TYPE)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1103 put_bits(&s->pb, 3, s->b_code); /* fcode_back */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1104 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1105
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1106
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1107 static void init_uni_dc_tab(void)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1108 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1109 int level, uni_code, uni_len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1110
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1111 for(level=-256; level<256; level++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1112 int size, v, l;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1113 /* find number of bits */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1114 size = 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1115 v = abs(level);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1116 while (v) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1117 v >>= 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1118 size++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1119 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1120
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1121 if (level < 0)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1122 l= (-level) ^ ((1 << size) - 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1123 else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1124 l= level;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1125
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1126 /* luminance */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1127 uni_code= DCtab_lum[size][0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1128 uni_len = DCtab_lum[size][1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1129
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1130 if (size > 0) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1131 uni_code<<=size; uni_code|=l;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1132 uni_len+=size;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1133 if (size > 8){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1134 uni_code<<=1; uni_code|=1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1135 uni_len++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1136 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1137 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1138 uni_DCtab_lum_bits[level+256]= uni_code;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1139 uni_DCtab_lum_len [level+256]= uni_len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1140
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1141 /* chrominance */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1142 uni_code= DCtab_chrom[size][0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1143 uni_len = DCtab_chrom[size][1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1144
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1145 if (size > 0) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1146 uni_code<<=size; uni_code|=l;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1147 uni_len+=size;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1148 if (size > 8){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1149 uni_code<<=1; uni_code|=1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1150 uni_len++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1151 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1152 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1153 uni_DCtab_chrom_bits[level+256]= uni_code;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1154 uni_DCtab_chrom_len [level+256]= uni_len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1155
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1156 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1157 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1158
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1159 static void init_uni_mpeg4_rl_tab(RLTable *rl, uint32_t *bits_tab, uint8_t *len_tab){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1160 int slevel, run, last;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1161
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1162 assert(MAX_LEVEL >= 64);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1163 assert(MAX_RUN >= 63);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1164
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1165 for(slevel=-64; slevel<64; slevel++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1166 if(slevel==0) continue;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1167 for(run=0; run<64; run++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1168 for(last=0; last<=1; last++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1169 const int index= UNI_MPEG4_ENC_INDEX(last, run, slevel+64);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1170 int level= slevel < 0 ? -slevel : slevel;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1171 int sign= slevel < 0 ? 1 : 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1172 int bits, len, code;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1173 int level1, run1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1174
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1175 len_tab[index]= 100;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1176
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1177 /* ESC0 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1178 code= get_rl_index(rl, last, run, level);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1179 bits= rl->table_vlc[code][0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1180 len= rl->table_vlc[code][1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1181 bits=bits*2+sign; len++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1182
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1183 if(code!=rl->n && len < len_tab[index]){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1184 bits_tab[index]= bits;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1185 len_tab [index]= len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1186 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1187 /* ESC1 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1188 bits= rl->table_vlc[rl->n][0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1189 len= rl->table_vlc[rl->n][1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1190 bits=bits*2; len++; //esc1
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1191 level1= level - rl->max_level[last][run];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1192 if(level1>0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1193 code= get_rl_index(rl, last, run, level1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1194 bits<<= rl->table_vlc[code][1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1195 len += rl->table_vlc[code][1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1196 bits += rl->table_vlc[code][0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1197 bits=bits*2+sign; len++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1198
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1199 if(code!=rl->n && len < len_tab[index]){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1200 bits_tab[index]= bits;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1201 len_tab [index]= len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1202 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1203 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1204 /* ESC2 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1205 bits= rl->table_vlc[rl->n][0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1206 len= rl->table_vlc[rl->n][1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1207 bits=bits*4+2; len+=2; //esc2
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1208 run1 = run - rl->max_run[last][level] - 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1209 if(run1>=0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1210 code= get_rl_index(rl, last, run1, level);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1211 bits<<= rl->table_vlc[code][1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1212 len += rl->table_vlc[code][1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1213 bits += rl->table_vlc[code][0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1214 bits=bits*2+sign; len++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1215
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1216 if(code!=rl->n && len < len_tab[index]){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1217 bits_tab[index]= bits;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1218 len_tab [index]= len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1219 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1220 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1221 /* ESC3 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1222 bits= rl->table_vlc[rl->n][0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1223 len = rl->table_vlc[rl->n][1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1224 bits=bits*4+3; len+=2; //esc3
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1225 bits=bits*2+last; len++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1226 bits=bits*64+run; len+=6;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1227 bits=bits*2+1; len++; //marker
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1228 bits=bits*4096+(slevel&0xfff); len+=12;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1229 bits=bits*2+1; len++; //marker
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1230
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1231 if(len < len_tab[index]){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1232 bits_tab[index]= bits;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1233 len_tab [index]= len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1234 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1235 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1236 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1237 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1238 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1239
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1240 static av_cold int encode_init(AVCodecContext *avctx)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1241 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1242 MpegEncContext *s = avctx->priv_data;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1243 int ret;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1244 static int done = 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1245
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1246 if((ret=MPV_encode_init(avctx)) < 0)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1247 return ret;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1248
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1249 if (!done) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1250 done = 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1251
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1252 init_uni_dc_tab();
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1253
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1254 init_rl(&rl_intra, ff_mpeg4_static_rl_table_store[0]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1255
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1256 init_uni_mpeg4_rl_tab(&rl_intra, uni_mpeg4_intra_rl_bits, uni_mpeg4_intra_rl_len);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1257 init_uni_mpeg4_rl_tab(&rl_inter, uni_mpeg4_inter_rl_bits, uni_mpeg4_inter_rl_len);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1258 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1259
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1260 s->min_qcoeff= -2048;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1261 s->max_qcoeff= 2047;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1262 s->intra_ac_vlc_length = uni_mpeg4_intra_rl_len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1263 s->intra_ac_vlc_last_length= uni_mpeg4_intra_rl_len + 128*64;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1264 s->inter_ac_vlc_length = uni_mpeg4_inter_rl_len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1265 s->inter_ac_vlc_last_length= uni_mpeg4_inter_rl_len + 128*64;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1266 s->luma_dc_vlc_length= uni_DCtab_lum_len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1267 s->chroma_dc_vlc_length= uni_DCtab_chrom_len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1268 s->ac_esc_length= 7+2+1+6+1+12+1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1269 s->y_dc_scale_table= ff_mpeg4_y_dc_scale_table;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1270 s->c_dc_scale_table= ff_mpeg4_c_dc_scale_table;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1271
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1272 if(s->flags & CODEC_FLAG_GLOBAL_HEADER){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1273
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1274 s->avctx->extradata= av_malloc(1024);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1275 init_put_bits(&s->pb, s->avctx->extradata, 1024);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1276
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1277 if(!(s->workaround_bugs & FF_BUG_MS))
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1278 mpeg4_encode_visual_object_header(s);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1279 mpeg4_encode_vol_header(s, 0, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1280
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1281 // ff_mpeg4_stuffing(&s->pb); ?
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1282 flush_put_bits(&s->pb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1283 s->avctx->extradata_size= (put_bits_count(&s->pb)+7)>>3;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1284 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1285 return 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1286 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1287
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1288 void ff_mpeg4_init_partitions(MpegEncContext *s)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1289 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1290 uint8_t *start= put_bits_ptr(&s->pb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1291 uint8_t *end= s->pb.buf_end;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1292 int size= end - start;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1293 int pb_size = (((intptr_t)start + size/3)&(~3)) - (intptr_t)start;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1294 int tex_size= (size - 2*pb_size)&(~3);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1295
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1296 set_put_bits_buffer_size(&s->pb, pb_size);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1297 init_put_bits(&s->tex_pb, start + pb_size , tex_size);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1298 init_put_bits(&s->pb2 , start + pb_size + tex_size, pb_size);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1299 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1300
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1301 void ff_mpeg4_merge_partitions(MpegEncContext *s)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1302 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1303 const int pb2_len = put_bits_count(&s->pb2 );
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1304 const int tex_pb_len= put_bits_count(&s->tex_pb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1305 const int bits= put_bits_count(&s->pb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1306
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1307 if(s->pict_type==FF_I_TYPE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1308 put_bits(&s->pb, 19, DC_MARKER);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1309 s->misc_bits+=19 + pb2_len + bits - s->last_bits;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1310 s->i_tex_bits+= tex_pb_len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1311 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1312 put_bits(&s->pb, 17, MOTION_MARKER);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1313 s->misc_bits+=17 + pb2_len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1314 s->mv_bits+= bits - s->last_bits;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1315 s->p_tex_bits+= tex_pb_len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1316 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1317
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1318 flush_put_bits(&s->pb2);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1319 flush_put_bits(&s->tex_pb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1320
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1321 set_put_bits_buffer_size(&s->pb, s->pb2.buf_end - s->pb.buf);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1322 ff_copy_bits(&s->pb, s->pb2.buf , pb2_len);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1323 ff_copy_bits(&s->pb, s->tex_pb.buf, tex_pb_len);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1324 s->last_bits= put_bits_count(&s->pb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1325 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1326
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1327
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1328 void ff_mpeg4_encode_video_packet_header(MpegEncContext *s)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1329 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1330 int mb_num_bits= av_log2(s->mb_num - 1) + 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1331
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1332 put_bits(&s->pb, ff_mpeg4_get_video_packet_prefix_length(s), 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1333 put_bits(&s->pb, 1, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1334
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1335 put_bits(&s->pb, mb_num_bits, s->mb_x + s->mb_y*s->mb_width);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1336 put_bits(&s->pb, s->quant_precision, s->qscale);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1337 put_bits(&s->pb, 1, 0); /* no HEC */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1338 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1339
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1340 AVCodec mpeg4_encoder = {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1341 "mpeg4",
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1342 CODEC_TYPE_VIDEO,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1343 CODEC_ID_MPEG4,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1344 sizeof(MpegEncContext),
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1345 encode_init,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1346 MPV_encode_picture,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1347 MPV_encode_end,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1348 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1349 .capabilities= CODEC_CAP_DELAY,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1350 .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2"),
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1351 };