comparison h263.c @ 63:8e2d8dbf89a5 libavcodec

better vol header parsing for mpeg4
author glantau
date Mon, 13 Aug 2001 21:46:21 +0000
parents 20e680e7a490
children c7767df463f4
comparison
equal deleted inserted replaced
62:4bfc845cdfea 63:8e2d8dbf89a5
16 * 16 *
17 * You should have received a copy of the GNU General Public License 17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software 18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */ 20 */
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include "common.h" 21 #include "common.h"
25 #include "dsputil.h" 22 #include "dsputil.h"
26 #include "avcodec.h" 23 #include "avcodec.h"
27 #include "mpegvideo.h" 24 #include "mpegvideo.h"
28 #include "h263data.h" 25 #include "h263data.h"
29 #include "mpeg4data.h" 26 #include "mpeg4data.h"
30
31 #define NDEBUG
32 #include <assert.h>
33 27
34 static void h263_encode_block(MpegEncContext * s, DCTELEM * block, 28 static void h263_encode_block(MpegEncContext * s, DCTELEM * block,
35 int n); 29 int n);
36 static void h263_encode_motion(MpegEncContext * s, int val); 30 static void h263_encode_motion(MpegEncContext * s, int val);
37 static void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block, 31 static void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block,
1164 if (state == 0) 1158 if (state == 0)
1165 return -1; 1159 return -1;
1166 } 1160 }
1167 1161
1168 if (startcode == 0x120) { 1162 if (startcode == 0x120) {
1169 int time_increment_resolution, width, height; 1163 int time_increment_resolution, width, height, vo_ver_id;
1170 1164
1171 /* vol header */ 1165 /* vol header */
1172 skip_bits(&s->gb, 1); /* random access */ 1166 skip_bits(&s->gb, 1); /* random access */
1173 skip_bits(&s->gb, 8); /* vo_type */ 1167 skip_bits(&s->gb, 8); /* vo_type */
1174 skip_bits(&s->gb, 1); /* is_ol_id */ 1168 if (get_bits1(&s->gb) != 0) { /* is_ol_id */
1175 skip_bits(&s->gb, 4); /* vo_ver_id */ 1169 vo_ver_id = get_bits(&s->gb, 4); /* vo_ver_id */
1176 skip_bits(&s->gb, 3); /* vo_priority */ 1170 skip_bits(&s->gb, 3); /* vo_priority */
1171 } else {
1172 vo_ver_id = 1;
1173 }
1177 1174
1178 skip_bits(&s->gb, 4); /* aspect_ratio_info */ 1175 skip_bits(&s->gb, 4); /* aspect_ratio_info */
1179 skip_bits(&s->gb, 1); /* vol control parameter */ 1176 skip_bits1(&s->gb); /* vol control parameter */
1180 skip_bits(&s->gb, 2); /* vol shape */ 1177 s->shape = get_bits(&s->gb, 2); /* vol shape */
1181 skip_bits1(&s->gb); /* marker */ 1178 skip_bits1(&s->gb); /* marker */
1182 1179
1183 time_increment_resolution = get_bits(&s->gb, 16); 1180 time_increment_resolution = get_bits(&s->gb, 16);
1184 s->time_increment_bits = log2(time_increment_resolution - 1) + 1; 1181 s->time_increment_bits = log2(time_increment_resolution - 1) + 1;
1182 if (s->time_increment_bits < 1)
1183 s->time_increment_bits = 1;
1185 skip_bits1(&s->gb); /* marker */ 1184 skip_bits1(&s->gb); /* marker */
1186 1185
1187 skip_bits1(&s->gb); /* vop rate */ 1186 if (get_bits1(&s->gb) != 0) { /* fixed_vop_rate */
1188 skip_bits(&s->gb, s->time_increment_bits); 1187 skip_bits(&s->gb, s->time_increment_bits);
1189 skip_bits1(&s->gb); /* marker */ 1188 }
1190 1189
1191 width = get_bits(&s->gb, 13); 1190 if (s->shape != 2) {
1192 skip_bits1(&s->gb); /* marker */ 1191 if (s->shape == 0) {
1193 height = get_bits(&s->gb, 13); 1192 skip_bits1(&s->gb); /* marker */
1194 skip_bits1(&s->gb); /* marker */ 1193 width = get_bits(&s->gb, 13);
1195 1194 skip_bits1(&s->gb); /* marker */
1196 skip_bits1(&s->gb); /* interfaced */ 1195 height = get_bits(&s->gb, 13);
1197 skip_bits1(&s->gb); /* OBMC */ 1196 skip_bits1(&s->gb); /* marker */
1198 skip_bits(&s->gb, 2); /* vol_sprite_usage */ 1197 }
1199 skip_bits1(&s->gb); /* not_8_bit */ 1198
1200 1199 skip_bits1(&s->gb); /* interlaced */
1201 skip_bits1(&s->gb); /* vol_quant_type */ 1200 skip_bits1(&s->gb); /* OBMC */
1202 skip_bits1(&s->gb); /* vol_quarter_pixel */ 1201 if (vo_ver_id == 1) {
1203 skip_bits1(&s->gb); /* complexity_estimation_disabled */ 1202 s->vol_sprite_usage = get_bits1(&s->gb); /* vol_sprite_usage */
1204 skip_bits1(&s->gb); /* resync_marker_disabled */ 1203 } else {
1205 skip_bits1(&s->gb); /* data_partioning_enabled */ 1204 s->vol_sprite_usage = get_bits(&s->gb, 2); /* vol_sprite_usage */
1205 }
1206 if (get_bits1(&s->gb) == 1) { /* not_8_bit */
1207 s->quant_precision = get_bits(&s->gb, 4); /* quant_precision */
1208 skip_bits(&s->gb, 4); /* bits_per_pixel */
1209 } else {
1210 s->quant_precision = 5;
1211 }
1212
1213 skip_bits1(&s->gb); /* vol_quant_type */
1214 skip_bits1(&s->gb); /* vol_quarter_pixel */
1215 skip_bits1(&s->gb); /* complexity_estimation_disabled */
1216 skip_bits1(&s->gb); /* resync_marker_disabled */
1217 skip_bits1(&s->gb); /* data_partioning_enabled */
1218 if (get_bits1(&s->gb) != 0) { /* scalability */
1219 printf("bad scalability!!!\n");
1220 return -1;
1221 }
1222 }
1206 goto redo; 1223 goto redo;
1207 } else if (startcode != 0x1b6) { 1224 } else if (startcode != 0x1b6) {
1208 goto redo; 1225 goto redo;
1209 } 1226 }
1210 1227
1221 skip_bits1(&s->gb); /* marker */ 1238 skip_bits1(&s->gb); /* marker */
1222 skip_bits(&s->gb, s->time_increment_bits); 1239 skip_bits(&s->gb, s->time_increment_bits);
1223 skip_bits1(&s->gb); /* marker */ 1240 skip_bits1(&s->gb); /* marker */
1224 /* vop coded */ 1241 /* vop coded */
1225 if (get_bits1(&s->gb) != 1) 1242 if (get_bits1(&s->gb) != 1)
1226 return -1; 1243 goto redo;
1227 1244
1228 if (s->pict_type == P_TYPE) { 1245 if (s->shape != 2 && s->pict_type == P_TYPE) {
1229 /* rounding type for motion estimation */ 1246 /* rounding type for motion estimation */
1230 s->no_rounding = get_bits1(&s->gb); 1247 s->no_rounding = get_bits1(&s->gb);
1231 } 1248 } else {
1232 1249 s->no_rounding = 0;
1233 if (get_bits(&s->gb, 3) != 0) 1250 }
1234 return -1; /* intra dc VLC threshold */ 1251
1235 1252 if (s->shape != 0) {
1236 s->qscale = get_bits(&s->gb, 5); 1253 if (s->vol_sprite_usage != 1 || s->pict_type != I_TYPE) {
1237 1254 int width, height, hor_spat_ref, ver_spat_ref;
1238 if (s->pict_type != I_TYPE) { 1255
1239 s->f_code = get_bits(&s->gb, 3); /* fcode_for */ 1256 width = get_bits(&s->gb, 13);
1240 } 1257 skip_bits1(&s->gb); /* marker */
1241 return 0; 1258 height = get_bits(&s->gb, 13);
1259 skip_bits1(&s->gb); /* marker */
1260 hor_spat_ref = get_bits(&s->gb, 13); /* hor_spat_ref */
1261 skip_bits1(&s->gb); /* marker */
1262 ver_spat_ref = get_bits(&s->gb, 13); /* ver_spat_ref */
1263 }
1264 skip_bits1(&s->gb); /* change_CR_disable */
1265
1266 if (get_bits1(&s->gb) != 0) {
1267 skip_bits(&s->gb, 8); /* constant_alpha_value */
1268 }
1269 }
1270
1271 if (s->shape != 2) {
1272 skip_bits(&s->gb, 3); /* intra dc VLC threshold */
1273
1274 /* note: we do not use quant_precision to avoid problem if no
1275 MPEG4 vol header as it is found on some old opendivx
1276 movies */
1277 s->qscale = get_bits(&s->gb, 5);
1278
1279 if (s->pict_type != I_TYPE) {
1280 s->f_code = get_bits(&s->gb, 3); /* fcode_for */
1281 }
1282 if (s->shape && (s->pict_type != I_TYPE)) {
1283 skip_bits1(&s->gb); // vop shape coding type
1284 }
1285 }
1286 return 0;
1242 } 1287 }
1243 1288
1244 /* don't understand why they choose a different header ! */ 1289 /* don't understand why they choose a different header ! */
1245 int intel_h263_decode_picture_header(MpegEncContext *s) 1290 int intel_h263_decode_picture_header(MpegEncContext *s)
1246 { 1291 {