Go to the documentation of this file. 1 /*
2 * ITU H.263 bitstream decoder
3 * Copyright (c) 2000,2001 Fabrice Bellard
4 * H.263+ support.
5 * Copyright (c) 2001 Juan J. Sierralta P
6 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
7 *
8 * This file is part of FFmpeg.
9 *
10 * FFmpeg is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * FFmpeg is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with FFmpeg; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 /**
26 * @file
27 * H.263 decoder.
28 */
29
30 #define UNCHECKED_BITSTREAM_READER 1
31
32 #include "config_components.h"
33
53
54 // The defines below define the number of bits that are read at once for
55 // reading vlc values. Changing these may improve speed and data cache needs
56 // be aware though that decreasing them may need the number of stages that is
57 // passed to get_vlc* to be increased.
58 #define H263_MBTYPE_B_VLC_BITS 6
59 #define CBPC_B_VLC_BITS 3
60
74 0, //stuffing
77 };
78
83 s->gb.size_in_bits, 1-
s->no_rounding,
85 s->umvplus ?
" UMV" :
"",
86 s->h263_long_vectors ?
" LONG" :
"",
87 s->h263_plus ?
" +" :
"",
88 s->h263_aic ?
" AIC" :
"",
89 s->alt_inter_vlc ?
" AIV" :
"",
90 s->modified_quant ?
" MQ" :
"",
91 s->loop_filter ?
" LOOP" :
"",
92 s->h263_slice_structured ?
" SS" :
"",
93 s->avctx->framerate.num,
s->avctx->framerate.den
94 );
95 }
96 }
97
98 /***********************************************/
99 /* decoding */
100
107
108 /* init vlcs */
109
111 {
133 }
134
136 {
139 }
140
142 {
144
145 for (
i = 0;
i < 6;
i++)
147 break;
149 s->mb_x = mb_pos %
s->mb_width;
150 s->mb_y = mb_pos /
s->mb_width;
151
152 return mb_pos;
153 }
154
155 /**
156 * Decode the group of blocks header or slice header.
157 * @return <0 if an error occurred
158 */
160 {
161 unsigned int val, gob_number;
163
164 /* Check for GOB Start Code */
167 return -1;
168
169 /* We have a GBSC probably with GSTUFF */
173 //MN: we must check the bits left or we might end in an infinite loop (or segfault)
175 if(
get_bits1(&
s->gb))
break;
/* Seek the '1' bit */
176 }
178 return -1;
179
180 if(
s->h263_slice_structured){
182 return -1;
183
185
188 return -1;
189
192 return -1;
194 }else{
195 gob_number =
get_bits(&
s->gb, 5);
/* GN */
197 s->mb_y=
s->gob_index* gob_number;
200 }
201
202 if(
s->mb_y >=
s->mb_height)
203 return -1;
204
206 return -1;
207
208 return 0;
209 }
210
211 /**
212 * Decode the group of blocks / video packet header / slice header (MPEG-4 Studio).
213 * @return bit position of the resync_marker, or <0 if none was found
214 */
217
218 /* In MPEG-4 studio mode look for a new slice startcode
219 * and decode slice header */
222
225 }
226
229 else
230 return -1;
231 }
232
236 }
237
242 else
246 }
247 //OK, it's not where it is supposed to be ...
248 s->gb=
s->last_resync_gb;
251
255
259 else
263
265 }
267 }
268
269 return -1;
270 }
271
273 {
276
280 return 0xffff;
281
289 }
290 if (sign)
293
294 /* modulo decoding */
295 if (!
s->h263_long_vectors) {
297 } else {
298 /* horrible H.263 long vector mode */
303
304 }
306 }
307
308
309 /* Decode RVLC of H.263+ UMV */
311 {
313
314 if (
get_bits1(&
s->gb))
/* Motion difference = 0 */
316
318
320 {
325 return 0xffff;
326 }
327 }
330
334
335 }
336
337 /**
338 * read the next MVs for OBMC. yes this is an ugly hack, feel free to send a patch :)
339 */
342
343 int cbpc,
i, pred_x, pred_y, mx, my;
344 int16_t *mot_val;
345 const int xy=
s->mb_x + 1 +
s->mb_y *
s->mb_stride;
346 const int stride=
s->b8_stride*2;
347
349 s->block_index[
i]+= 2;
351 s->block_index[
i]+= 1;
353
355
356 do{
358 /* skip mb */
359 mot_val =
s->current_picture.motion_val[0][
s->block_index[0]];
360 mot_val[0 ]= mot_val[2 ]=
362 mot_val[1 ]= mot_val[3 ]=
364
366 goto end;
367 }
369 }while(cbpc == 20);
370
371 if(cbpc & 4){
373 }else{
375 if (cbpc & 8) {
376 if(
s->modified_quant){
379 }else
381 }
382
383 if ((cbpc & 16) == 0) {
385 /* 16x16 motion prediction */
389 else
391
394 else
396
397 mot_val[0 ]= mot_val[2 ]=
399 mot_val[1 ]= mot_val[3 ]=
401 } else {
407 else
409
412 else
414 if (
s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
415 skip_bits1(&
s->gb);
/* Bit stuffing to prevent PSC */
416 mot_val[0] = mx;
417 mot_val[1] = my;
418 }
419 }
420 }
421 end:
422
424 s->block_index[
i]-= 2;
426 s->block_index[
i]-= 1;
428
430 }
431
433 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
434
435 if(
s->modified_quant){
438 else
440 }else
443 }
444
446 {
448 int16_t *dc_val, *ac_val, *ac_val1;
449
450 /* find prediction */
451 if (n < 4) {
452 x = 2 *
s->mb_x + (n & 1);
453 y = 2 *
s->mb_y + (n>> 1);
455 dc_val =
s->dc_val[0];
456 ac_val =
s->ac_val[0][0];
458 } else {
462 dc_val =
s->dc_val[n - 4 + 1];
463 ac_val =
s->ac_val[n - 4 + 1][0];
465 }
466
467 ac_val += ((y) *
wrap + (x)) * 16;
468 ac_val1 = ac_val;
469
470 /* B C
471 * A X
472 */
473 a = dc_val[(x - 1) + (y) *
wrap];
474 c = dc_val[(x) + (y - 1) *
wrap];
475
476 /* No prediction outside GOB boundary */
477 if (
s->first_slice_line && n != 3) {
479 if (n != 1 &&
s->mb_x ==
s->resync_mb_x)
a= 1024;
480 }
481
484 if (
s->h263_aic_dir) {
485 /* left prediction */
487 ac_val -= 16;
488 for (
int i = 1;
i < 8;
i++) {
489 block[
s->idsp.idct_permutation[
i << 3]] += ac_val[
i];
490 }
492 }
493 } else {
494 /* top prediction */
497 for (
int i = 1;
i < 8;
i++) {
498 block[
s->idsp.idct_permutation[
i]] += ac_val[
i + 8];
499 }
501 }
502 }
503 } else {
504 /* just DC prediction */
505 if (
a != 1024 &&
c != 1024)
509 else
511 }
512
513 /* we assume pred is positive */
515
518 else
520
521 /* Update AC/DC tables */
523
524 /* left copy */
525 for (
int i = 1;
i < 8;
i++)
526 ac_val1[
i] =
block[
s->idsp.idct_permutation[
i << 3]];
527 /* top copy */
528 for (
int i = 1;
i < 8;
i++)
529 ac_val1[8 +
i] =
block[
s->idsp.idct_permutation[
i]];
530 }
531
533 int n, int coded)
534 {
537 const uint8_t *scan_table;
539
540 scan_table =
s->intra_scantable.permutated;
541 if (
s->h263_aic &&
s->mb_intra) {
546 scan_table =
s->intra_v_scantable.permutated;
/* left */
547 else
548 scan_table =
s->intra_h_scantable.permutated;
/* top */
549 }
550 }
else if (
s->mb_intra) {
551 /* DC coef */
555 component = (n <= 3 ? 0 : n - 4 + 1);
556 level =
s->last_dc[component];
557 if (
s->rv10_first_dc_coded[component]) {
560 return -1;
563 s->last_dc[component] =
level;
564 } else {
565 s->rv10_first_dc_coded[component] = 1;
566 }
567 } else {
571 }
572 }else{
574 if((
level&0x7F) == 0){
577 return -1;
578 }
581 }
584 } else {
586 }
587 if (!coded) {
588 if (
s->mb_intra &&
s->h263_aic)
589 goto not_coded;
590 s->block_last_index[n] =
i - 1;
591 return 0;
592 }
593 retry:
594 {
596 i--;
// offset by -1 to allow direct indexing of scan_table
597 for(;;) {
604 return -1;
605 }
606 /* escape */
607 if (CONFIG_FLV_DECODER &&
s->h263_flv > 1) {
611 if (is11) {
616 } else {
620 }
621 } else {
629 /* XXX: should patch encoder too */
632 }else{
637 }
638 }
639 }
640 } else {
644 }
648 // redo update without last flag, revert -1 offset
651 // only last marker, no overrun
653 break;
654 }
656 //Looks like a hack but no, it's the way it is supposed to work ...
660 s->bdsp.clear_block(
block);
661 goto retry;
662 }
664 return -1;
665 }
668 }
669 }
670 not_coded:
671 if (
s->mb_intra &&
s->h263_aic) {
674 }
675 s->block_last_index[n] =
i;
676 return 0;
677 }
678
680 {
683 int bli[6];
684
685 /* we have to set s->mb_intra to zero to decode B-part of PB-frame correctly
686 * but real value should be restored in order to be used later (in OBMC condition)
687 */
689 memcpy(bli,
s->block_last_index,
sizeof(bli));
691 for (
i = 0;
i < 6;
i++) {
693 return -1;
694 cbp+=cbp;
695 }
697 memcpy(
s->block_last_index, bli,
sizeof(bli));
698 return 0;
699 }
700
702 {
704
705 if (pb_frame < 3) { // h.263 Annex G and i263 PB-frame
707 if (pb_frame == 2 &&
c)
709 } else { // h.263 Annex M improved PB-frame
713 }
717 }
718
719 #define tab_size ((signed)FF_ARRAY_ELEMS(s->direct_scale_mv[0]))
720 #define tab_bias (tab_size / 2)
722 {
723 int xy =
s->block_index[
i];
724 uint16_t time_pp =
s->pp_time;
725 uint16_t time_pb =
s->pb_time;
726 int p_mx, p_my;
727
730 s->mv[0][
i][0] =
s->direct_scale_mv[0][p_mx +
tab_bias];
731 s->mv[1][
i][0] =
s->direct_scale_mv[1][p_mx +
tab_bias];
732 } else {
733 s->mv[0][
i][0] = p_mx * time_pb / time_pp;
734 s->mv[1][
i][0] = p_mx * (time_pb - time_pp) / time_pp;
735 }
738 s->mv[0][
i][1] =
s->direct_scale_mv[0][p_my +
tab_bias];
739 s->mv[1][
i][1] =
s->direct_scale_mv[1][p_my +
tab_bias];
740 } else {
741 s->mv[0][
i][1] = p_my * time_pb / time_pp;
742 s->mv[1][
i][1] = p_my * (time_pb - time_pp) / time_pp;
743 }
744 }
745
746 /**
747 * @return the mb_type
748 */
750 {
751 const int mb_index =
s->mb_x +
s->mb_y *
s->mb_stride;
753 int colocated_mb_type = p->
mb_type[mb_index];
755
757 p = &
s->last_picture;
758 colocated_mb_type = p->
mb_type[mb_index];
759 }
760
761 if (
IS_8X8(colocated_mb_type)) {
763 for (
i = 0;
i < 4;
i++)
766 } else {
770 s->mv[0][3][0] =
s->mv[0][0][0];
773 s->mv[0][3][1] =
s->mv[0][0][1];
776 s->mv[1][3][0] =
s->mv[1][0][0];
779 s->mv[1][3][1] =
s->mv[1][0][1];
781 // Note see prev line
783 }
784 }
785
787 int16_t
block[6][64])
788 {
789 int cbpc, cbpy,
i, cbp, pred_x, pred_y, mx, my, dquant;
790 int16_t *mot_val;
791 const int xy=
s->mb_x +
s->mb_y *
s->mb_stride;
792 int cbpb = 0, pb_mv_count = 0;
793
795
797 do{
799 /* skip mb */
802 s->block_last_index[
i] = -1;
808 s->mb_skipped = !(
s->obmc |
s->loop_filter);
809 goto end;
810 }
812 if (cbpc < 0){
815 }
816 }while(cbpc == 20);
817
818 s->bdsp.clear_blocks(
s->block[0]);
819
820 dquant = cbpc & 8;
821 s->mb_intra = ((cbpc & 4) != 0);
822 if (
s->mb_intra)
goto intra;
823
827
828 if (cbpy < 0) {
831 }
832
833 if(
s->alt_inter_vlc==0 || (cbpc & 3)!=3)
834 cbpy ^= 0xF;
835
836 cbp = (cbpc & 3) | (cbpy << 2);
837 if (dquant) {
839 }
840
842 if ((cbpc & 16) == 0) {
844 /* 16x16 motion prediction */
849 else
851
852 if (mx >= 0xffff)
854
857 else
859
860 if (my >= 0xffff)
864
865 if (
s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
866 skip_bits1(&
s->gb);
/* Bit stuffing to prevent PSC */
867 } else {
874 else
876 if (mx >= 0xffff)
878
881 else
883 if (my >= 0xffff)
887 if (
s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
888 skip_bits1(&
s->gb);
/* Bit stuffing to prevent PSC */
889 mot_val[0] = mx;
890 mot_val[1] = my;
891 }
892 }
894 int mb_type;
895 const int stride=
s->b8_stride;
896 int16_t *mot_val0 =
s->current_picture.motion_val[0][2 * (
s->mb_x +
s->mb_y *
stride)];
897 int16_t *mot_val1 =
s->current_picture.motion_val[1][2 * (
s->mb_x +
s->mb_y *
stride)];
898 // const int mv_xy= s->mb_x + 1 + s->mb_y * s->mb_stride;
899
900 //FIXME ugly
901 mot_val0[0 ]= mot_val0[2 ]= mot_val0[0+2*
stride]= mot_val0[2+2*
stride]=
902 mot_val0[1 ]= mot_val0[3 ]= mot_val0[1+2*
stride]= mot_val0[3+2*
stride]=
903 mot_val1[0 ]= mot_val1[2 ]= mot_val1[0+2*
stride]= mot_val1[2+2*
stride]=
904 mot_val1[1 ]= mot_val1[3 ]= mot_val1[1+2*
stride]= mot_val1[3+2*
stride]= 0;
905
906 do{
908 if (mb_type < 0){
911 }
912
914 }while(!mb_type);
915
918 s->bdsp.clear_blocks(
s->block[0]);
922 goto intra;
923 }
924
926
927 if (cbpy < 0){
930 }
931
932 if(
s->alt_inter_vlc==0 || (cbpc & 3)!=3)
933 cbpy ^= 0xF;
934
935 cbp = (cbpc & 3) | (cbpy << 2);
936 }else
937 cbp=0;
938
940
943 }
944
948 }else{
951 //FIXME UMV
952
956
959 else
961 if (mx >= 0xffff)
963
966 else
968 if (my >= 0xffff)
970
971 if (
s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
972 skip_bits1(&
s->gb);
/* Bit stuffing to prevent PSC */
973
976 mot_val[0 ]= mot_val[2 ]= mot_val[0+2*
stride]= mot_val[2+2*
stride]= mx;
977 mot_val[1 ]= mot_val[3 ]= mot_val[1+2*
stride]= mot_val[3+2*
stride]= my;
978 }
979
983
986 else
988 if (mx >= 0xffff)
990
993 else
995 if (my >= 0xffff)
997
998 if (
s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
999 skip_bits1(&
s->gb);
/* Bit stuffing to prevent PSC */
1000
1001 s->mv[1][0][0] = mx;
1002 s->mv[1][0][1] = my;
1003 mot_val[0 ]= mot_val[2 ]= mot_val[0+2*
stride]= mot_val[2+2*
stride]= mx;
1004 mot_val[1 ]= mot_val[3 ]= mot_val[1+2*
stride]= mot_val[3+2*
stride]= my;
1005 }
1006 }
1007
1008 s->current_picture.mb_type[xy] = mb_type;
1009 } else { /* I-Frame */
1010 do{
1012 if (cbpc < 0){
1015 }
1016 }while(cbpc == 8);
1017
1018 s->bdsp.clear_blocks(
s->block[0]);
1019
1020 dquant = cbpc & 4;
1022 intra:
1028
1030 }
1031 }else
1033
1037 if(cbpy<0){
1040 }
1041 cbp = (cbpc & 3) | (cbpy << 2);
1042 if (dquant) {
1044 }
1045
1046 pb_mv_count += !!
s->pb_frame;
1047 }
1048
1049 while(pb_mv_count--){
1052 }
1053
1054 /* decode each block */
1055 for (
i = 0;
i < 6;
i++) {
1057 return -1;
1058 cbp+=cbp;
1059 }
1060
1062 return -1;
1063 if(
s->obmc && !
s->mb_intra){
1066 }
1067 end:
1068
1071
1072 /* per-MB end of slice check */
1073 {
1075
1078 }
1079
1080 if(v==0)
1082 }
1083
1085 }
1086
1087 /* Most is hardcoded; should extend to handle all H.263 streams. */
1089 {
1091 uint32_t startcode;
1092
1094
1095 if (
show_bits(&
s->gb, 2) == 2 &&
s->avctx->frame_number == 0) {
1097 }
1098
1100
1102 startcode = ((startcode << 8) |
get_bits(&
s->gb, 8)) & 0x003FFFFF;
1103
1104 if(startcode == 0x20)
1105 break;
1106 }
1107
1108 if (startcode != 0x20) {
1110 return -1;
1111 }
1112 /* temporal reference */
1113 i =
get_bits(&
s->gb, 8);
/* picture timestamp */
1114
1115 i -= (
i - (
s->picture_number & 0xFF) + 128) & ~0xFF;
1116
1117 s->picture_number= (
s->picture_number&~0xFF) +
i;
1118
1119 /* PTYPE starts here */
1121 return -1;
1122 }
1125 return -1; /* H.263 id */
1126 }
1129 skip_bits1(&
s->gb);
/* freeze picture release off */
1130
1132 /*
1133 0 forbidden
1134 1 sub-QCIF
1135 10 QCIF
1136 7 extended PTYPE (PLUSPTYPE)
1137 */
1138
1141 /* H.263v1 */
1145 return -1;
1146
1148
1150
1153 return -1; /* SAC: off */
1154 }
1155 s->obmc=
get_bits1(&
s->gb);
/* Advanced prediction mode */
1156
1158 s->chroma_qscale=
s->qscale =
get_bits(&
s->gb, 5);
1159 skip_bits1(&
s->gb);
/* Continuous Presence Multipoint mode: off */
1160
1163 s->avctx->sample_aspect_ratio= (
AVRational){12,11};
1164 s->avctx->framerate = (
AVRational){ 30000, 1001 };
1165 } else {
1166 int ufep;
1167
1168 /* H.263v2 */
1170 ufep =
get_bits(&
s->gb, 3);
/* Update Full Extended PTYPE */
1171
1172 /* ufep other than 0 and 1 are reserved */
1173 if (ufep == 1) {
1174 /* OPPTYPE */
1178 s->umvplus =
get_bits1(&
s->gb);
/* Unrestricted Motion Vector */
1181 }
1182 s->obmc=
get_bits1(&
s->gb);
/* Advanced prediction mode */
1183 s->h263_aic =
get_bits1(&
s->gb);
/* Advanced Intra Coding (AIC) */
1185 if(
s->avctx->lowres)
1187
1191 }
1194 }
1197 if(
s->modified_quant)
1199
1200 skip_bits(&
s->gb, 1);
/* Prevent start code emulation */
1201
1203 } else if (ufep != 0) {
1205 return -1;
1206 }
1207
1208 /* MPPTYPE */
1210 switch(
s->pict_type){
1216 default:
1217 return -1;
1218 }
1222
1223 /* Get the picture dimensions */
1224 if (ufep) {
1226 /* Custom Picture Format (CPFMT) */
1227 int aspect_ratio_info =
get_bits(&
s->gb, 4);
1228 ff_dlog(
s->avctx,
"aspect: %d\n", aspect_ratio_info);
1229 /* aspect ratios:
1230 0 - forbidden
1231 1 - 1:1
1232 2 - 12:11 (CIF 4:3)
1233 3 - 10:11 (525-type 4:3)
1234 4 - 16:11 (CIF 16:9)
1235 5 - 40:33 (525-type 16:9)
1236 6-14 - reserved
1237 */
1243 /* expected dimensions */
1244 s->avctx->sample_aspect_ratio.num=
get_bits(&
s->gb, 8);
1245 s->avctx->sample_aspect_ratio.den=
get_bits(&
s->gb, 8);
1246 }else{
1248 }
1249 } else {
1252 s->avctx->sample_aspect_ratio= (
AVRational){12,11};
1253 }
1254 s->avctx->sample_aspect_ratio.den <<=
s->ehc_mode;
1256 return -1;
1259
1261 int gcd;
1262 s->avctx->framerate.num = 1800000;
1263 s->avctx->framerate.den = 1000 +
get_bits1(&
s->gb);
1264 s->avctx->framerate.den *=
get_bits(&
s->gb, 7);
1265 if(
s->avctx->framerate.den == 0){
1267 return -1;
1268 }
1269 gcd=
av_gcd(
s->avctx->framerate.den,
s->avctx->framerate.num);
1270 s->avctx->framerate.den /= gcd;
1271 s->avctx->framerate.num /= gcd;
1272 }else{
1273 s->avctx->framerate = (
AVRational){ 30000, 1001 };
1274 }
1275 }
1276
1278 skip_bits(&
s->gb, 2);
//extended Temporal reference
1279 }
1280
1281 if (ufep) {
1283 if(
get_bits1(&
s->gb)==0)
/* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
1285 }
1286 if(
s->h263_slice_structured){
1289 }
1292 }
1293 }
1296 if (ufep == 1) {
1298 }
1299 }
1300 }
1301
1303 }
1304
1307
1311 }
1312
1313 s->mb_width = (
s->width + 15) / 16;
1314 s->mb_height = (
s->height + 15) / 16;
1315 s->mb_num =
s->mb_width *
s->mb_height;
1316
1318 skip_bits(&
s->gb, 3);
/* Temporal reference for B-pictures */
1320 skip_bits(&
s->gb, 2);
//extended Temporal reference
1321 skip_bits(&
s->gb, 2);
/* Quantization information for B-pictures */
1322 }
1323
1325 s->time =
s->picture_number;
1326 s->pp_time =
s->time -
s->last_non_b_time;
1327 s->last_non_b_time =
s->time;
1328 }else{
1329 s->time =
s->picture_number;
1330 s->pb_time =
s->pp_time - (
s->last_non_b_time -
s->time);
1331 if (
s->pp_time <=
s->pb_time ||
1332 s->pp_time <=
s->pp_time -
s->pb_time ||
1336 }
1338 }
1339
1340 /* PEI */
1343
1344 if(
s->h263_slice_structured){
1346 return -1;
1347 }
1348
1350
1352 return -1;
1353 }
1354 }
1356
1359
1361 s->y_dc_scale_table=
1363 }else{
1364 s->y_dc_scale_table=
1366 }
1367
1373 for(
i=0;
i<13;
i++){
1374 for(j=0; j<3; j++){
1378 }
1380 }
1382 }
1383
1384 return 0;
1385 }
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled left