Mercurial > libavcodec.hg
comparison h263.c @ 79:82e579c37bc3 libavcodec
Moved some H.263+ variables to MpegEncContext to be thread-safe.
Increase video_buffer on ffmpeg to avoid buffer overrun on big pictures.
author | pulento |
---|---|
date | Fri, 31 Aug 2001 06:21:27 +0000 |
parents | 92ed1c4f94fa |
children | e00e5d93457c |
comparison
equal
deleted
inserted
replaced
78:92ed1c4f94fa | 79:82e579c37bc3 |
---|---|
36 static int h263_decode_block(MpegEncContext * s, DCTELEM * block, | 36 static int h263_decode_block(MpegEncContext * s, DCTELEM * block, |
37 int n, int coded); | 37 int n, int coded); |
38 static int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, | 38 static int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, |
39 int n, int coded); | 39 int n, int coded); |
40 | 40 |
41 /* This are for H.263+ UMV */ | |
42 /* Shouldn't be here */ | |
43 static int umvplus = 0; | |
44 static int umvplus_dec = 0; | |
45 | 41 |
46 int h263_get_picture_format(int width, int height) | 42 int h263_get_picture_format(int width, int height) |
47 { | 43 { |
48 int format; | 44 int format; |
49 | 45 |
100 put_bits(&s->pb,3,6); /* Custom Source Format */ | 96 put_bits(&s->pb,3,6); /* Custom Source Format */ |
101 else | 97 else |
102 put_bits(&s->pb, 3, format); | 98 put_bits(&s->pb, 3, format); |
103 | 99 |
104 put_bits(&s->pb,1,0); /* Custom PCF: off */ | 100 put_bits(&s->pb,1,0); /* Custom PCF: off */ |
105 umvplus = (s->pict_type == P_TYPE) && s->unrestricted_mv; | 101 s->umvplus = (s->pict_type == P_TYPE) && s->unrestricted_mv; |
106 put_bits(&s->pb, 1, umvplus); /* Unrestricted Motion Vector */ | 102 put_bits(&s->pb, 1, s->umvplus); /* Unrestricted Motion Vector */ |
107 put_bits(&s->pb,1,0); /* SAC: off */ | 103 put_bits(&s->pb,1,0); /* SAC: off */ |
108 put_bits(&s->pb,1,0); /* Advanced Prediction Mode: off */ | 104 put_bits(&s->pb,1,0); /* Advanced Prediction Mode: off */ |
109 put_bits(&s->pb,1,0); /* Advanced Intra Coding: off */ | 105 put_bits(&s->pb,1,0); /* Advanced Intra Coding: off */ |
110 put_bits(&s->pb,1,0); /* Deblocking Filter: off */ | 106 put_bits(&s->pb,1,0); /* Deblocking Filter: off */ |
111 put_bits(&s->pb,1,0); /* Slice Structured: off */ | 107 put_bits(&s->pb,1,0); /* Slice Structured: off */ |
135 put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ | 131 put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ |
136 put_bits(&s->pb,9,(s->height >> 2)); | 132 put_bits(&s->pb,9,(s->height >> 2)); |
137 } | 133 } |
138 | 134 |
139 /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ | 135 /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ |
140 if (umvplus) | 136 if (s->umvplus) |
141 put_bits(&s->pb,1,1); /* Limited according tables of Annex D */ | 137 put_bits(&s->pb,1,1); /* Limited according tables of Annex D */ |
142 put_bits(&s->pb, 5, s->qscale); | 138 put_bits(&s->pb, 5, s->qscale); |
143 } | 139 } |
144 | 140 |
145 put_bits(&s->pb, 1, 0); /* no PEI */ | 141 put_bits(&s->pb, 1, 0); /* no PEI */ |
174 put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); | 170 put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); |
175 | 171 |
176 /* motion vectors: 16x16 mode only now */ | 172 /* motion vectors: 16x16 mode only now */ |
177 h263_pred_motion(s, 0, &pred_x, &pred_y); | 173 h263_pred_motion(s, 0, &pred_x, &pred_y); |
178 | 174 |
179 if (!umvplus) { | 175 if (!s->umvplus) { |
180 h263_encode_motion(s, motion_x - pred_x); | 176 h263_encode_motion(s, motion_x - pred_x); |
181 h263_encode_motion(s, motion_y - pred_y); | 177 h263_encode_motion(s, motion_y - pred_y); |
182 } | 178 } |
183 else { | 179 else { |
184 h263p_encode_umotion(s, motion_x - pred_x); | 180 h263p_encode_umotion(s, motion_x - pred_x); |
823 s->mv_dir = MV_DIR_FORWARD; | 819 s->mv_dir = MV_DIR_FORWARD; |
824 if ((cbpc & 16) == 0) { | 820 if ((cbpc & 16) == 0) { |
825 /* 16x16 motion prediction */ | 821 /* 16x16 motion prediction */ |
826 s->mv_type = MV_TYPE_16X16; | 822 s->mv_type = MV_TYPE_16X16; |
827 h263_pred_motion(s, 0, &pred_x, &pred_y); | 823 h263_pred_motion(s, 0, &pred_x, &pred_y); |
828 if (umvplus_dec) | 824 if (s->umvplus_dec) |
829 mx = h263p_decode_umotion(s, pred_x); | 825 mx = h263p_decode_umotion(s, pred_x); |
830 else | 826 else |
831 mx = h263_decode_motion(s, pred_x); | 827 mx = h263_decode_motion(s, pred_x); |
832 if (mx >= 0xffff) | 828 if (mx >= 0xffff) |
833 return -1; | 829 return -1; |
834 | 830 |
835 if (umvplus_dec) | 831 if (s->umvplus_dec) |
836 my = h263p_decode_umotion(s, pred_y); | 832 my = h263p_decode_umotion(s, pred_y); |
837 else | 833 else |
838 my = h263_decode_motion(s, pred_y); | 834 my = h263_decode_motion(s, pred_y); |
839 if (my >= 0xffff) | 835 if (my >= 0xffff) |
840 return -1; | 836 return -1; |
841 s->mv[0][0][0] = mx; | 837 s->mv[0][0][0] = mx; |
842 s->mv[0][0][1] = my; | 838 s->mv[0][0][1] = my; |
843 if (umvplus_dec && (mx - pred_x) == 1 && (my - pred_y) == 1) | 839 if (s->umvplus_dec && (mx - pred_x) == 1 && (my - pred_y) == 1) |
844 skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ | 840 skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ |
845 | 841 |
846 } else { | 842 } else { |
847 s->mv_type = MV_TYPE_8X8; | 843 s->mv_type = MV_TYPE_8X8; |
848 for(i=0;i<4;i++) { | 844 for(i=0;i<4;i++) { |
849 mot_val = h263_pred_motion(s, i, &pred_x, &pred_y); | 845 mot_val = h263_pred_motion(s, i, &pred_x, &pred_y); |
850 if (umvplus_dec) | 846 if (s->umvplus_dec) |
851 mx = h263p_decode_umotion(s, pred_x); | 847 mx = h263p_decode_umotion(s, pred_x); |
852 else | 848 else |
853 mx = h263_decode_motion(s, pred_x); | 849 mx = h263_decode_motion(s, pred_x); |
854 if (mx >= 0xffff) | 850 if (mx >= 0xffff) |
855 return -1; | 851 return -1; |
856 | 852 |
857 if (umvplus_dec) | 853 if (s->umvplus_dec) |
858 my = h263p_decode_umotion(s, pred_y); | 854 my = h263p_decode_umotion(s, pred_y); |
859 else | 855 else |
860 my = h263_decode_motion(s, pred_y); | 856 my = h263_decode_motion(s, pred_y); |
861 if (my >= 0xffff) | 857 if (my >= 0xffff) |
862 return -1; | 858 return -1; |
863 s->mv[0][i][0] = mx; | 859 s->mv[0][i][0] = mx; |
864 s->mv[0][i][1] = my; | 860 s->mv[0][i][1] = my; |
865 if (umvplus_dec && (mx - pred_x) == 1 && (my - pred_y) == 1) | 861 if (s->umvplus_dec && (mx - pred_x) == 1 && (my - pred_y) == 1) |
866 skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ | 862 skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ |
867 mot_val[0] = mx; | 863 mot_val[0] = mx; |
868 mot_val[1] = my; | 864 mot_val[1] = my; |
869 } | 865 } |
870 } | 866 } |
1220 if (get_bits(&s->gb, 3) != 1) /* Update Full Extended PTYPE */ | 1216 if (get_bits(&s->gb, 3) != 1) /* Update Full Extended PTYPE */ |
1221 return -1; | 1217 return -1; |
1222 format = get_bits(&s->gb, 3); | 1218 format = get_bits(&s->gb, 3); |
1223 | 1219 |
1224 skip_bits(&s->gb,1); /* Custom PCF */ | 1220 skip_bits(&s->gb,1); /* Custom PCF */ |
1225 umvplus_dec = get_bits(&s->gb, 1); /* Unrestricted Motion Vector */ | 1221 s->umvplus_dec = get_bits(&s->gb, 1); /* Unrestricted Motion Vector */ |
1226 skip_bits(&s->gb, 10); | 1222 skip_bits(&s->gb, 10); |
1227 skip_bits(&s->gb, 3); /* Reserved */ | 1223 skip_bits(&s->gb, 3); /* Reserved */ |
1228 | 1224 |
1229 /* MPPTYPE */ | 1225 /* MPPTYPE */ |
1230 s->pict_type = get_bits(&s->gb, 3) + 1; | 1226 s->pict_type = get_bits(&s->gb, 3) + 1; |
1250 } | 1246 } |
1251 | 1247 |
1252 if ((width == 0) || (height == 0)) | 1248 if ((width == 0) || (height == 0)) |
1253 return -1; | 1249 return -1; |
1254 | 1250 |
1255 if (umvplus_dec) { | 1251 if (s->umvplus_dec) { |
1256 skip_bits1(&s->gb); /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ | 1252 skip_bits1(&s->gb); /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ |
1257 } | 1253 } |
1258 | 1254 |
1259 s->qscale = get_bits(&s->gb, 5); | 1255 s->qscale = get_bits(&s->gb, 5); |
1260 } | 1256 } |