annotate mpeg4videoenc.c @ 11567:1025297f5624 libavcodec

Add function to export EDGE_WIDTH from libavcodec.
author koorogi
date Thu, 01 Apr 2010 06:41:16 +0000
parents 8a4984c5cacc
children fdafbcef52f5
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
10808
55c01e916c08 Explain why the level variable is magically inceased in mpeg4_encode_dc().
diego
parents: 10803
diff changeset
245 /* DC will overflow if level is outside the [-255,255] range. */
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
246 level+=256;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
247 if (n < 4) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
248 /* luminance */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
249 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
250 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
251 /* chrominance */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
252 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
253 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
254 #else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
255 int size, v;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
256 /* find number of bits */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
257 size = 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
258 v = abs(level);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
259 while (v) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
260 v >>= 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
261 size++;
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
264 if (n < 4) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
265 /* luminance */
10816
9abebeca7d1b Rename DCtab_*, its a global variable and it helps understanding if mpeg4
michael
parents: 10808
diff changeset
266 put_bits(&s->pb, ff_mpeg4_DCtab_lum[size][1], ff_mpeg4_DCtab_lum[size][0]);
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
267 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
268 /* chrominance */
10816
9abebeca7d1b Rename DCtab_*, its a global variable and it helps understanding if mpeg4
michael
parents: 10808
diff changeset
269 put_bits(&s->pb, ff_mpeg4_DCtab_chrom[size][1], ff_mpeg4_DCtab_chrom[size][0]);
10803
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
272 /* encode remaining bits */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
273 if (size > 0) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
274 if (level < 0)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
275 level = (-level) ^ ((1 << size) - 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
276 put_bits(&s->pb, size, level);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
277 if (size > 8)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
278 put_bits(&s->pb, 1, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
279 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
280 #endif
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
283 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
284 if (n < 4) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
285 return uni_DCtab_lum_len[level + 256];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
286 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
287 return uni_DCtab_chrom_len[level + 256];
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 /**
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
292 * encodes a 8x8 block
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
293 * @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
294 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
295 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
296 uint8_t *scan_table, PutBitContext *dc_pb, PutBitContext *ac_pb)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
297 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
298 int i, last_non_zero;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
299 #if 0 //variables for the outcommented version
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
300 int code, sign, last;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
301 #endif
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
302 const RLTable *rl;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
303 uint32_t *bits_tab;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
304 uint8_t *len_tab;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
305 const int last_index = s->block_last_index[n];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
306
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
307 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
308 /* mpeg4 based DC predictor */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
309 mpeg4_encode_dc(dc_pb, intra_dc, n);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
310 if(last_index<1) return;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
311 i = 1;
10817
d1fe22d92a65 Rename mpeg4 intra vlc tables so they contain "mpeg4", this improves readability
michael
parents: 10816
diff changeset
312 rl = &ff_mpeg4_rl_intra;
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
313 bits_tab= uni_mpeg4_intra_rl_bits;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
314 len_tab = uni_mpeg4_intra_rl_len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
315 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
316 if(last_index<0) return;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
317 i = 0;
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10817
diff changeset
318 rl = &ff_h263_rl_inter;
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
319 bits_tab= uni_mpeg4_inter_rl_bits;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
320 len_tab = uni_mpeg4_inter_rl_len;
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
323 /* AC coefs */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
324 last_non_zero = i - 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
325 #if 1
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
326 for (; i < last_index; i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
327 int level = block[ scan_table[i] ];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
328 if (level) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
329 int run = i - last_non_zero - 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
330 level+=64;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
331 if((level&(~127)) == 0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
332 const int index= UNI_MPEG4_ENC_INDEX(0, run, level);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
333 put_bits(ac_pb, len_tab[index], bits_tab[index]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
334 }else{ //ESC3
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
335 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
336 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
337 last_non_zero = i;
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 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
340 /*if(i<=last_index)*/{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
341 int level = block[ scan_table[i] ];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
342 int run = i - last_non_zero - 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
343 level+=64;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
344 if((level&(~127)) == 0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
345 const int index= UNI_MPEG4_ENC_INDEX(1, run, level);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
346 put_bits(ac_pb, len_tab[index], bits_tab[index]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
347 }else{ //ESC3
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
348 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
349 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
350 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
351 #else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
352 for (; i <= last_index; i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
353 const int slevel = block[ scan_table[i] ];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
354 if (slevel) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
355 int level;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
356 int run = i - last_non_zero - 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
357 last = (i == last_index);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
358 sign = 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
359 level = slevel;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
360 if (level < 0) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
361 sign = 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
362 level = -level;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
363 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
364 code = get_rl_index(rl, last, run, level);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
365 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
366 if (code == rl->n) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
367 int level1, run1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
368 level1 = level - rl->max_level[last][run];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
369 if (level1 < 1)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
370 goto esc2;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
371 code = get_rl_index(rl, last, run, level1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
372 if (code == rl->n) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
373 esc2:
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
374 put_bits(ac_pb, 1, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
375 if (level > MAX_LEVEL)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
376 goto esc3;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
377 run1 = run - rl->max_run[last][level] - 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
378 if (run1 < 0)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
379 goto esc3;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
380 code = get_rl_index(rl, last, run1, level);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
381 if (code == rl->n) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
382 esc3:
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
383 /* third escape */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
384 put_bits(ac_pb, 1, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
385 put_bits(ac_pb, 1, last);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
386 put_bits(ac_pb, 6, run);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
387 put_bits(ac_pb, 1, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
388 put_sbits(ac_pb, 12, slevel);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
389 put_bits(ac_pb, 1, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
390 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
391 /* second escape */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
392 put_bits(ac_pb, 1, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
393 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
394 put_bits(ac_pb, 1, sign);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
395 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
396 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
397 /* first escape */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
398 put_bits(ac_pb, 1, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
399 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
400 put_bits(ac_pb, 1, sign);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
401 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
402 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
403 put_bits(ac_pb, 1, sign);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
404 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
405 last_non_zero = i;
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 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
408 #endif
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
411 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
412 uint8_t *scan_table)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
413 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
414 int i, last_non_zero;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
415 uint8_t *len_tab;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
416 const int last_index = s->block_last_index[n];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
417 int len=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
418
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
419 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
420 /* mpeg4 based DC predictor */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
421 len += mpeg4_get_dc_length(intra_dc, n);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
422 if(last_index<1) return len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
423 i = 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
424 len_tab = uni_mpeg4_intra_rl_len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
425 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
426 if(last_index<0) return 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
427 i = 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
428 len_tab = uni_mpeg4_inter_rl_len;
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
431 /* AC coefs */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
432 last_non_zero = i - 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
433 for (; i < last_index; i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
434 int level = block[ scan_table[i] ];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
435 if (level) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
436 int run = i - last_non_zero - 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
437 level+=64;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
438 if((level&(~127)) == 0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
439 const int index= UNI_MPEG4_ENC_INDEX(0, run, level);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
440 len += len_tab[index];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
441 }else{ //ESC3
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
442 len += 7+2+1+6+1+12+1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
443 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
444 last_non_zero = i;
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 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
447 /*if(i<=last_index)*/{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
448 int level = block[ scan_table[i] ];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
449 int run = i - last_non_zero - 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
450 level+=64;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
451 if((level&(~127)) == 0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
452 const int index= UNI_MPEG4_ENC_INDEX(1, run, level);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
453 len += len_tab[index];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
454 }else{ //ESC3
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
455 len += 7+2+1+6+1+12+1;
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
459 return len;
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
462 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
463 uint8_t **scan_table, PutBitContext *dc_pb, PutBitContext *ac_pb){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
464 int i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
465
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
466 if(scan_table){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
467 if(s->flags2 & CODEC_FLAG2_NO_OUTPUT){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
468 for (i = 0; i < 6; i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
469 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
470 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
471 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
472 /* encode each block */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
473 for (i = 0; i < 6; i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
474 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
475 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
476 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
477 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
478 if(s->flags2 & CODEC_FLAG2_NO_OUTPUT){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
479 for (i = 0; i < 6; i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
480 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
481 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
482 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
483 /* encode each block */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
484 for (i = 0; i < 6; i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
485 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
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
491 //FIXME this is duplicated to h263.c
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
492 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
493
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
494 void mpeg4_encode_mb(MpegEncContext * s,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
495 DCTELEM block[6][64],
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
496 int motion_x, int motion_y)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
497 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
498 int cbpc, cbpy, pred_x, pred_y;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
499 PutBitContext * const pb2 = s->data_partitioning ? &s->pb2 : &s->pb;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
500 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
501 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
502 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
503
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
504 if (!s->mb_intra) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
505 int i, cbp;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
506
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
507 if(s->pict_type==FF_B_TYPE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
508 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
509 int mb_type= mb_type_table[s->mv_dir];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
510
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
511 if(s->mb_x==0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
512 for(i=0; i<2; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
513 s->last_mv[i][0][0]=
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
514 s->last_mv[i][0][1]=
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
515 s->last_mv[i][1][0]=
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
516 s->last_mv[i][1][1]= 0;
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
520 assert(s->dquant>=-2 && s->dquant<=2);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
521 assert((s->dquant&1)==0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
522 assert(mb_type>=0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
523
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
524 /* 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
525 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
526 s->skip_count++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
527 s->mv[0][0][0]=
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
528 s->mv[0][0][1]=
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
529 s->mv[1][0][0]=
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
530 s->mv[1][0][1]= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
531 s->mv_dir= MV_DIR_FORWARD; //doesn't matter
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
532 s->qscale -= s->dquant;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
533 // s->mb_skipped=1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
534
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
535 return;
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
538 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
539
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
540 if ((cbp | motion_x | motion_y | mb_type) ==0) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
541 /* direct MB with MV={0,0} */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
542 assert(s->dquant==0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
543
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
544 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
545
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
546 if(interleaved_stats){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
547 s->misc_bits++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
548 s->last_bits++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
549 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
550 s->skip_count++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
551 return;
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
554 put_bits(&s->pb, 1, 0); /* mb coded modb1=0 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
555 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
556 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
557 if(cbp) put_bits(&s->pb, 6, cbp);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
558
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
559 if(cbp && mb_type){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
560 if(s->dquant)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
561 put_bits(&s->pb, 2, (s->dquant>>2)+3);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
562 else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
563 put_bits(&s->pb, 1, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
564 }else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
565 s->qscale -= s->dquant;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
566
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
567 if(!s->progressive_sequence){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
568 if(cbp)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
569 put_bits(&s->pb, 1, s->interlaced_dct);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
570 if(mb_type) // not direct mode
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
571 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
572 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
573
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
574 if(interleaved_stats){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
575 s->misc_bits+= get_bits_diff(s);
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
578 if(mb_type == 0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
579 assert(s->mv_dir & MV_DIRECT);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
580 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
581 s->b_count++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
582 s->f_count++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
583 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
584 assert(mb_type > 0 && mb_type < 4);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
585 if(s->mv_type != MV_TYPE_FIELD){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
586 if(s->mv_dir & MV_DIR_FORWARD){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
587 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
588 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
589 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
590 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
591 s->f_count++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
592 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
593 if(s->mv_dir & MV_DIR_BACKWARD){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
594 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
595 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
596 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
597 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
598 s->b_count++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
599 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
600 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
601 if(s->mv_dir & MV_DIR_FORWARD){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
602 put_bits(&s->pb, 1, s->field_select[0][0]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
603 put_bits(&s->pb, 1, s->field_select[0][1]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
604 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
605 if(s->mv_dir & MV_DIR_BACKWARD){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
606 put_bits(&s->pb, 1, s->field_select[1][0]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
607 put_bits(&s->pb, 1, s->field_select[1][1]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
608 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
609 if(s->mv_dir & MV_DIR_FORWARD){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
610 for(i=0; i<2; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
611 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
612 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
613 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
614 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
615 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
616 s->f_count++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
617 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
618 if(s->mv_dir & MV_DIR_BACKWARD){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
619 for(i=0; i<2; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
620 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
621 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
622 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
623 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
624 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
625 s->b_count++;
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
630 if(interleaved_stats){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
631 s->mv_bits+= get_bits_diff(s);
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
634 mpeg4_encode_blocks(s, block, NULL, NULL, NULL, &s->pb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
635
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
636 if(interleaved_stats){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
637 s->p_tex_bits+= get_bits_diff(s);
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
640 }else{ /* s->pict_type==FF_B_TYPE */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
641 cbp= get_p_cbp(s, block, motion_x, motion_y);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
642
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
643 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
644 /* 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
645 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
646 if(s->max_b_frames>0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
647 int i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
648 int x,y, offset;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
649 uint8_t *p_pic;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
650
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
651 x= s->mb_x*16;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
652 y= s->mb_y*16;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
653 if(x+16 > s->width) x= s->width-16;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
654 if(y+16 > s->height) y= s->height-16;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
655
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
656 offset= x + y*s->linesize;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
657 p_pic= s->new_picture.data[0] + offset;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
658
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
659 s->mb_skipped=1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
660 for(i=0; i<s->max_b_frames; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
661 uint8_t *b_pic;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
662 int diff;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
663 Picture *pic= s->reordered_input_picture[i+1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
664
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
665 if(pic==NULL || pic->pict_type!=FF_B_TYPE) break;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
666
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
667 b_pic= pic->data[0] + offset;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
668 if(pic->type != FF_BUFFER_TYPE_SHARED)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
669 b_pic+= INPLACE_OFFSET;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
670 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
671 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
672 s->mb_skipped=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
673 break;
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 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
676 }else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
677 s->mb_skipped=1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
678
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
679 if(s->mb_skipped==1){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
680 /* skip macroblock */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
681 put_bits(&s->pb, 1, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
682
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
683 if(interleaved_stats){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
684 s->misc_bits++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
685 s->last_bits++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
686 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
687 s->skip_count++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
688
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
689 return;
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
693 put_bits(&s->pb, 1, 0); /* mb coded */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
694 cbpc = cbp & 3;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
695 cbpy = cbp >> 2;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
696 cbpy ^= 0xf;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
697 if(s->mv_type==MV_TYPE_16X16){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
698 if(s->dquant) cbpc+= 8;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
699 put_bits(&s->pb,
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10817
diff changeset
700 ff_h263_inter_MCBPC_bits[cbpc],
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10817
diff changeset
701 ff_h263_inter_MCBPC_code[cbpc]);
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
702
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10817
diff changeset
703 put_bits(pb2, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]);
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
704 if(s->dquant)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
705 put_bits(pb2, 2, dquant_code[s->dquant+2]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
706
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
707 if(!s->progressive_sequence){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
708 if(cbp)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
709 put_bits(pb2, 1, s->interlaced_dct);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
710 put_bits(pb2, 1, 0);
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
713 if(interleaved_stats){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
714 s->misc_bits+= get_bits_diff(s);
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
717 /* motion vectors: 16x16 mode */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
718 h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
719
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
720 ff_h263_encode_motion_vector(s, motion_x - pred_x,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
721 motion_y - pred_y, s->f_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
722 }else if(s->mv_type==MV_TYPE_FIELD){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
723 if(s->dquant) cbpc+= 8;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
724 put_bits(&s->pb,
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10817
diff changeset
725 ff_h263_inter_MCBPC_bits[cbpc],
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10817
diff changeset
726 ff_h263_inter_MCBPC_code[cbpc]);
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
727
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10817
diff changeset
728 put_bits(pb2, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]);
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
729 if(s->dquant)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
730 put_bits(pb2, 2, dquant_code[s->dquant+2]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
731
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
732 assert(!s->progressive_sequence);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
733 if(cbp)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
734 put_bits(pb2, 1, s->interlaced_dct);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
735 put_bits(pb2, 1, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
736
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
737 if(interleaved_stats){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
738 s->misc_bits+= get_bits_diff(s);
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
741 /* motion vectors: 16x8 interlaced mode */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
742 h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
743 pred_y /=2;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
744
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
745 put_bits(&s->pb, 1, s->field_select[0][0]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
746 put_bits(&s->pb, 1, s->field_select[0][1]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
747
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
748 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
749 s->mv[0][0][1] - pred_y, s->f_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
750 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
751 s->mv[0][1][1] - pred_y, s->f_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
752 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
753 assert(s->mv_type==MV_TYPE_8X8);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
754 put_bits(&s->pb,
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10817
diff changeset
755 ff_h263_inter_MCBPC_bits[cbpc+16],
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10817
diff changeset
756 ff_h263_inter_MCBPC_code[cbpc+16]);
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10817
diff changeset
757 put_bits(pb2, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]);
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
758
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
759 if(!s->progressive_sequence){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
760 if(cbp)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
761 put_bits(pb2, 1, s->interlaced_dct);
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
764 if(interleaved_stats){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
765 s->misc_bits+= get_bits_diff(s);
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
768 for(i=0; i<4; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
769 /* motion vectors: 8x8 mode*/
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
770 h263_pred_motion(s, i, 0, &pred_x, &pred_y);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
771
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
772 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
773 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
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
777 if(interleaved_stats){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
778 s->mv_bits+= get_bits_diff(s);
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
781 mpeg4_encode_blocks(s, block, NULL, NULL, NULL, tex_pb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
782
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
783 if(interleaved_stats){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
784 s->p_tex_bits+= get_bits_diff(s);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
785 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
786 s->f_count++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
787 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
788 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
789 int cbp;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
790 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
791 int dir[6]; //prediction direction
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
792 int zigzag_last_index[6];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
793 uint8_t *scan_table[6];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
794 int i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
795
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
796 for(i=0; i<6; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
797 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
798 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
799
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
800 if(s->flags & CODEC_FLAG_AC_PRED){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
801 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
802 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
803 for(i=0; i<6; i++)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
804 scan_table[i]= s->intra_scantable.permutated;
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
807 /* compute cbp */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
808 cbp = 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
809 for (i = 0; i < 6; i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
810 if (s->block_last_index[i] >= 1)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
811 cbp |= 1 << (5 - i);
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
814 cbpc = cbp & 3;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
815 if (s->pict_type == FF_I_TYPE) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
816 if(s->dquant) cbpc+=4;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
817 put_bits(&s->pb,
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10817
diff changeset
818 ff_h263_intra_MCBPC_bits[cbpc],
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10817
diff changeset
819 ff_h263_intra_MCBPC_code[cbpc]);
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
820 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
821 if(s->dquant) cbpc+=8;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
822 put_bits(&s->pb, 1, 0); /* mb coded */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
823 put_bits(&s->pb,
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10817
diff changeset
824 ff_h263_inter_MCBPC_bits[cbpc + 4],
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10817
diff changeset
825 ff_h263_inter_MCBPC_code[cbpc + 4]);
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
826 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
827 put_bits(pb2, 1, s->ac_pred);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
828 cbpy = cbp >> 2;
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10817
diff changeset
829 put_bits(pb2, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]);
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
830 if(s->dquant)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
831 put_bits(dc_pb, 2, dquant_code[s->dquant+2]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
832
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
833 if(!s->progressive_sequence){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
834 put_bits(dc_pb, 1, s->interlaced_dct);
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
837 if(interleaved_stats){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
838 s->misc_bits+= get_bits_diff(s);
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
841 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
842
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
843 if(interleaved_stats){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
844 s->i_tex_bits+= get_bits_diff(s);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
845 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
846 s->i_count++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
847
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
848 /* 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
849 if(s->ac_pred)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
850 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
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 /**
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
855 * add mpeg4 stuffing bits (01...1)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
856 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
857 void ff_mpeg4_stuffing(PutBitContext * pbc)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
858 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
859 int length;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
860 put_bits(pbc, 1, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
861 length= (-put_bits_count(pbc))&7;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
862 if(length) put_bits(pbc, length, (1<<length)-1);
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
865 /* must be called before writing the header */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
866 void ff_set_mpeg4_time(MpegEncContext * s){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
867 if(s->pict_type==FF_B_TYPE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
868 ff_mpeg4_init_direct_mv(s);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
869 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
870 s->last_time_base= s->time_base;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
871 s->time_base= s->time/s->avctx->time_base.den;
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
875 static void mpeg4_encode_gop_header(MpegEncContext * s){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
876 int hours, minutes, seconds;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
877 int64_t time;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
878
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
879 put_bits(&s->pb, 16, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
880 put_bits(&s->pb, 16, GOP_STARTCODE);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
881
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
882 time= s->current_picture_ptr->pts;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
883 if(s->reordered_input_picture[1])
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
884 time= FFMIN(time, s->reordered_input_picture[1]->pts);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
885 time= time*s->avctx->time_base.num;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
886
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
887 seconds= time/s->avctx->time_base.den;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
888 minutes= seconds/60; seconds %= 60;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
889 hours= minutes/60; minutes %= 60;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
890 hours%=24;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
891
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
892 put_bits(&s->pb, 5, hours);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
893 put_bits(&s->pb, 6, minutes);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
894 put_bits(&s->pb, 1, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
895 put_bits(&s->pb, 6, seconds);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
896
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
897 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
898 put_bits(&s->pb, 1, 0); //broken link == NO
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
899
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
900 s->last_time_base= time / s->avctx->time_base.den;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
901
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
902 ff_mpeg4_stuffing(&s->pb);
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
905 static void mpeg4_encode_visual_object_header(MpegEncContext * s){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
906 int profile_and_level_indication;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
907 int vo_ver_id;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
908
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
909 if(s->avctx->profile != FF_PROFILE_UNKNOWN){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
910 profile_and_level_indication = s->avctx->profile << 4;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
911 }else if(s->max_b_frames || s->quarter_sample){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
912 profile_and_level_indication= 0xF0; // adv simple
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
913 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
914 profile_and_level_indication= 0x00; // simple
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
917 if(s->avctx->level != FF_LEVEL_UNKNOWN){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
918 profile_and_level_indication |= s->avctx->level;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
919 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
920 profile_and_level_indication |= 1; //level 1
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
923 if(profile_and_level_indication>>4 == 0xF){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
924 vo_ver_id= 5;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
925 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
926 vo_ver_id= 1;
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
929 //FIXME levels
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
930
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
931 put_bits(&s->pb, 16, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
932 put_bits(&s->pb, 16, VOS_STARTCODE);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
933
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
934 put_bits(&s->pb, 8, profile_and_level_indication);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
935
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
936 put_bits(&s->pb, 16, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
937 put_bits(&s->pb, 16, VISUAL_OBJ_STARTCODE);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
938
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
939 put_bits(&s->pb, 1, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
940 put_bits(&s->pb, 4, vo_ver_id);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
941 put_bits(&s->pb, 3, 1); //priority
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
942
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
943 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
944
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
945 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
946
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
947 ff_mpeg4_stuffing(&s->pb);
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
950 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
951 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
952 int vo_ver_id;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
953
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
954 if (!CONFIG_MPEG4_ENCODER) return;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
955
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
956 if(s->max_b_frames || s->quarter_sample){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
957 vo_ver_id= 5;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
958 s->vo_type= ADV_SIMPLE_VO_TYPE;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
959 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
960 vo_ver_id= 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
961 s->vo_type= SIMPLE_VO_TYPE;
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
964 put_bits(&s->pb, 16, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
965 put_bits(&s->pb, 16, 0x100 + vo_number); /* video obj */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
966 put_bits(&s->pb, 16, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
967 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
968
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
969 put_bits(&s->pb, 1, 0); /* random access vol */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
970 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
971 if(s->workaround_bugs & FF_BUG_MS) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
972 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
973 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
974 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
975 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
976 put_bits(&s->pb, 3, 1); /* is obj layer priority */
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
979 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
980
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
981 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
982 if (s->aspect_ratio_info == FF_ASPECT_EXTENDED){
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.num);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
984 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
985 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
986
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
987 if(s->workaround_bugs & FF_BUG_MS) { //
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
988 put_bits(&s->pb, 1, 0); /* vol control parameters= no @@@ */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
989 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
990 put_bits(&s->pb, 1, 1); /* vol control parameters= yes */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
991 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
992 put_bits(&s->pb, 1, s->low_delay);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
993 put_bits(&s->pb, 1, 0); /* vbv parameters= no */
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
996 put_bits(&s->pb, 2, RECT_SHAPE); /* vol shape= rectangle */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
997 put_bits(&s->pb, 1, 1); /* marker bit */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
998
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
999 put_bits(&s->pb, 16, s->avctx->time_base.den);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1000 if (s->time_increment_bits < 1)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1001 s->time_increment_bits = 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1002 put_bits(&s->pb, 1, 1); /* marker bit */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1003 put_bits(&s->pb, 1, 0); /* fixed vop rate=no */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1004 put_bits(&s->pb, 1, 1); /* marker bit */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1005 put_bits(&s->pb, 13, s->width); /* vol width */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1006 put_bits(&s->pb, 1, 1); /* marker bit */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1007 put_bits(&s->pb, 13, s->height); /* vol height */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1008 put_bits(&s->pb, 1, 1); /* marker bit */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1009 put_bits(&s->pb, 1, s->progressive_sequence ? 0 : 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1010 put_bits(&s->pb, 1, 1); /* obmc disable */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1011 if (vo_ver_id == 1) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1012 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
1013 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1014 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
1015 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1016
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1017 put_bits(&s->pb, 1, 0); /* not 8 bit == false */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1018 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
1019
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1020 if(s->mpeg_quant){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1021 ff_write_quant_matrix(&s->pb, s->avctx->intra_matrix);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1022 ff_write_quant_matrix(&s->pb, s->avctx->inter_matrix);
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1025 if (vo_ver_id != 1)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1026 put_bits(&s->pb, 1, s->quarter_sample);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1027 put_bits(&s->pb, 1, 1); /* complexity estimation disable */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1028 s->resync_marker= s->rtp_mode;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1029 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
1030 put_bits(&s->pb, 1, s->data_partitioning ? 1 : 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1031 if(s->data_partitioning){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1032 put_bits(&s->pb, 1, 0); /* no rvlc */
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1035 if (vo_ver_id != 1){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1036 put_bits(&s->pb, 1, 0); /* newpred */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1037 put_bits(&s->pb, 1, 0); /* reduced res vop */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1038 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1039 put_bits(&s->pb, 1, 0); /* scalability */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1040
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1041 ff_mpeg4_stuffing(&s->pb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1042
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1043 /* user data */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1044 if(!(s->flags & CODEC_FLAG_BITEXACT)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1045 put_bits(&s->pb, 16, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1046 put_bits(&s->pb, 16, 0x1B2); /* user_data */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1047 ff_put_string(&s->pb, LIBAVCODEC_IDENT, 0);
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1051 /* write mpeg4 VOP header */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1052 void mpeg4_encode_picture_header(MpegEncContext * s, int picture_number)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1053 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1054 int time_incr;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1055 int time_div, time_mod;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1056
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1057 if(s->pict_type==FF_I_TYPE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1058 if(!(s->flags&CODEC_FLAG_GLOBAL_HEADER)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1059 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
1060 mpeg4_encode_visual_object_header(s);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1061 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
1062 mpeg4_encode_vol_header(s, 0, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1063 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1064 if(!(s->workaround_bugs & FF_BUG_MS))
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1065 mpeg4_encode_gop_header(s);
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1068 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
1069
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1070 put_bits(&s->pb, 16, 0); /* vop header */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1071 put_bits(&s->pb, 16, VOP_STARTCODE); /* vop header */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1072 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
1073
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1074 assert(s->time>=0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1075 time_div= s->time/s->avctx->time_base.den;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1076 time_mod= s->time%s->avctx->time_base.den;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1077 time_incr= time_div - s->last_time_base;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1078 assert(time_incr >= 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1079 while(time_incr--)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1080 put_bits(&s->pb, 1, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1081
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1082 put_bits(&s->pb, 1, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1083
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1084 put_bits(&s->pb, 1, 1); /* marker */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1085 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
1086 put_bits(&s->pb, 1, 1); /* marker */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1087 put_bits(&s->pb, 1, 1); /* vop coded */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1088 if ( s->pict_type == FF_P_TYPE
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1089 || (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
1090 put_bits(&s->pb, 1, s->no_rounding); /* rounding type */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1091 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1092 put_bits(&s->pb, 3, 0); /* intra dc VLC threshold */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1093 if(!s->progressive_sequence){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1094 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
1095 put_bits(&s->pb, 1, s->alternate_scan);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1096 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1097 //FIXME sprite stuff
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1098
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1099 put_bits(&s->pb, 5, s->qscale);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1100
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1101 if (s->pict_type != FF_I_TYPE)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1102 put_bits(&s->pb, 3, s->f_code); /* fcode_for */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1103 if (s->pict_type == FF_B_TYPE)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1104 put_bits(&s->pb, 3, s->b_code); /* fcode_back */
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1108 static void init_uni_dc_tab(void)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1109 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1110 int level, uni_code, uni_len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1111
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1112 for(level=-256; level<256; level++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1113 int size, v, l;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1114 /* find number of bits */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1115 size = 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1116 v = abs(level);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1117 while (v) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1118 v >>= 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1119 size++;
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1122 if (level < 0)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1123 l= (-level) ^ ((1 << size) - 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1124 else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1125 l= level;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1126
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1127 /* luminance */
10816
9abebeca7d1b Rename DCtab_*, its a global variable and it helps understanding if mpeg4
michael
parents: 10808
diff changeset
1128 uni_code= ff_mpeg4_DCtab_lum[size][0];
9abebeca7d1b Rename DCtab_*, its a global variable and it helps understanding if mpeg4
michael
parents: 10808
diff changeset
1129 uni_len = ff_mpeg4_DCtab_lum[size][1];
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1130
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1131 if (size > 0) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1132 uni_code<<=size; uni_code|=l;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1133 uni_len+=size;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1134 if (size > 8){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1135 uni_code<<=1; uni_code|=1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1136 uni_len++;
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 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1139 uni_DCtab_lum_bits[level+256]= uni_code;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1140 uni_DCtab_lum_len [level+256]= uni_len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1141
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1142 /* chrominance */
10816
9abebeca7d1b Rename DCtab_*, its a global variable and it helps understanding if mpeg4
michael
parents: 10808
diff changeset
1143 uni_code= ff_mpeg4_DCtab_chrom[size][0];
9abebeca7d1b Rename DCtab_*, its a global variable and it helps understanding if mpeg4
michael
parents: 10808
diff changeset
1144 uni_len = ff_mpeg4_DCtab_chrom[size][1];
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1145
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1146 if (size > 0) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1147 uni_code<<=size; uni_code|=l;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1148 uni_len+=size;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1149 if (size > 8){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1150 uni_code<<=1; uni_code|=1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1151 uni_len++;
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 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1154 uni_DCtab_chrom_bits[level+256]= uni_code;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1155 uni_DCtab_chrom_len [level+256]= uni_len;
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1160 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
1161 int slevel, run, last;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1162
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1163 assert(MAX_LEVEL >= 64);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1164 assert(MAX_RUN >= 63);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1165
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1166 for(slevel=-64; slevel<64; slevel++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1167 if(slevel==0) continue;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1168 for(run=0; run<64; run++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1169 for(last=0; last<=1; last++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1170 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
1171 int level= slevel < 0 ? -slevel : slevel;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1172 int sign= slevel < 0 ? 1 : 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1173 int bits, len, code;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1174 int level1, run1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1175
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1176 len_tab[index]= 100;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1177
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1178 /* ESC0 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1179 code= get_rl_index(rl, last, run, level);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1180 bits= rl->table_vlc[code][0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1181 len= rl->table_vlc[code][1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1182 bits=bits*2+sign; len++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1183
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1184 if(code!=rl->n && len < len_tab[index]){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1185 bits_tab[index]= bits;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1186 len_tab [index]= len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1187 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1188 /* ESC1 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1189 bits= rl->table_vlc[rl->n][0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1190 len= rl->table_vlc[rl->n][1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1191 bits=bits*2; len++; //esc1
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1192 level1= level - rl->max_level[last][run];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1193 if(level1>0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1194 code= get_rl_index(rl, last, run, level1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1195 bits<<= rl->table_vlc[code][1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1196 len += rl->table_vlc[code][1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1197 bits += rl->table_vlc[code][0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1198 bits=bits*2+sign; len++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1199
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1200 if(code!=rl->n && len < len_tab[index]){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1201 bits_tab[index]= bits;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1202 len_tab [index]= len;
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 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1205 /* ESC2 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1206 bits= rl->table_vlc[rl->n][0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1207 len= rl->table_vlc[rl->n][1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1208 bits=bits*4+2; len+=2; //esc2
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1209 run1 = run - rl->max_run[last][level] - 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1210 if(run1>=0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1211 code= get_rl_index(rl, last, run1, level);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1212 bits<<= rl->table_vlc[code][1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1213 len += rl->table_vlc[code][1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1214 bits += rl->table_vlc[code][0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1215 bits=bits*2+sign; len++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1216
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1217 if(code!=rl->n && len < len_tab[index]){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1218 bits_tab[index]= bits;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1219 len_tab [index]= len;
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 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1222 /* ESC3 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1223 bits= rl->table_vlc[rl->n][0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1224 len = rl->table_vlc[rl->n][1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1225 bits=bits*4+3; len+=2; //esc3
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1226 bits=bits*2+last; len++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1227 bits=bits*64+run; len+=6;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1228 bits=bits*2+1; len++; //marker
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1229 bits=bits*4096+(slevel&0xfff); len+=12;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1230 bits=bits*2+1; len++; //marker
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1231
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1232 if(len < len_tab[index]){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1233 bits_tab[index]= bits;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1234 len_tab [index]= len;
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1241 static av_cold int encode_init(AVCodecContext *avctx)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1242 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1243 MpegEncContext *s = avctx->priv_data;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1244 int ret;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1245 static int done = 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1246
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1247 if((ret=MPV_encode_init(avctx)) < 0)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1248 return ret;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1249
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1250 if (!done) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1251 done = 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1252
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1253 init_uni_dc_tab();
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1254
10817
d1fe22d92a65 Rename mpeg4 intra vlc tables so they contain "mpeg4", this improves readability
michael
parents: 10816
diff changeset
1255 init_rl(&ff_mpeg4_rl_intra, ff_mpeg4_static_rl_table_store[0]);
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1256
10817
d1fe22d92a65 Rename mpeg4 intra vlc tables so they contain "mpeg4", this improves readability
michael
parents: 10816
diff changeset
1257 init_uni_mpeg4_rl_tab(&ff_mpeg4_rl_intra, uni_mpeg4_intra_rl_bits, uni_mpeg4_intra_rl_len);
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10817
diff changeset
1258 init_uni_mpeg4_rl_tab(&ff_h263_rl_inter, uni_mpeg4_inter_rl_bits, uni_mpeg4_inter_rl_len);
10803
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1261 s->min_qcoeff= -2048;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1262 s->max_qcoeff= 2047;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1263 s->intra_ac_vlc_length = uni_mpeg4_intra_rl_len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1264 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
1265 s->inter_ac_vlc_length = uni_mpeg4_inter_rl_len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1266 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
1267 s->luma_dc_vlc_length= uni_DCtab_lum_len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1268 s->chroma_dc_vlc_length= uni_DCtab_chrom_len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1269 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
1270 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
1271 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
1272
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1273 if(s->flags & CODEC_FLAG_GLOBAL_HEADER){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1274
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1275 s->avctx->extradata= av_malloc(1024);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1276 init_put_bits(&s->pb, s->avctx->extradata, 1024);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1277
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1278 if(!(s->workaround_bugs & FF_BUG_MS))
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1279 mpeg4_encode_visual_object_header(s);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1280 mpeg4_encode_vol_header(s, 0, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1281
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1282 // ff_mpeg4_stuffing(&s->pb); ?
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1283 flush_put_bits(&s->pb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1284 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
1285 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1286 return 0;
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1289 void ff_mpeg4_init_partitions(MpegEncContext *s)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1290 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1291 uint8_t *start= put_bits_ptr(&s->pb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1292 uint8_t *end= s->pb.buf_end;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1293 int size= end - start;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1294 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
1295 int tex_size= (size - 2*pb_size)&(~3);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1296
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1297 set_put_bits_buffer_size(&s->pb, pb_size);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1298 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
1299 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
1300 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1301
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1302 void ff_mpeg4_merge_partitions(MpegEncContext *s)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1303 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1304 const int pb2_len = put_bits_count(&s->pb2 );
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1305 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
1306 const int bits= put_bits_count(&s->pb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1307
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1308 if(s->pict_type==FF_I_TYPE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1309 put_bits(&s->pb, 19, DC_MARKER);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1310 s->misc_bits+=19 + pb2_len + bits - s->last_bits;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1311 s->i_tex_bits+= tex_pb_len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1312 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1313 put_bits(&s->pb, 17, MOTION_MARKER);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1314 s->misc_bits+=17 + pb2_len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1315 s->mv_bits+= bits - s->last_bits;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1316 s->p_tex_bits+= tex_pb_len;
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1319 flush_put_bits(&s->pb2);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1320 flush_put_bits(&s->tex_pb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1321
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1322 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
1323 ff_copy_bits(&s->pb, s->pb2.buf , pb2_len);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1324 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
1325 s->last_bits= put_bits_count(&s->pb);
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1329 void ff_mpeg4_encode_video_packet_header(MpegEncContext *s)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1330 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1331 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
1332
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1333 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
1334 put_bits(&s->pb, 1, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1335
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1336 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
1337 put_bits(&s->pb, s->quant_precision, s->qscale);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1338 put_bits(&s->pb, 1, 0); /* no HEC */
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1341 AVCodec mpeg4_encoder = {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1342 "mpeg4",
11560
8a4984c5cacc Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 10818
diff changeset
1343 AVMEDIA_TYPE_VIDEO,
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1344 CODEC_ID_MPEG4,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1345 sizeof(MpegEncContext),
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1346 encode_init,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1347 MPV_encode_picture,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1348 MPV_encode_end,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1349 .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
1350 .capabilities= CODEC_CAP_DELAY,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1351 .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2"),
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1352 };