Mercurial > libavcodec.hg
annotate h263.c @ 12530:63edd10ad4bc libavcodec tip
Try to fix crashes introduced by r25218
r25218 made assumptions about the existence of past reference frames that
weren't necessarily true.
| author | darkshikari |
|---|---|
| date | Tue, 28 Sep 2010 09:06:22 +0000 |
| parents | 7dd2a45249a9 |
| children |
| rev | line source |
|---|---|
| 0 | 1 /* |
| 2 * H263/MPEG4 backend for ffmpeg encoder and decoder | |
|
8629
04423b2f6e0b
cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents:
8627
diff
changeset
|
3 * Copyright (c) 2000,2001 Fabrice Bellard |
| 78 | 4 * H263+ support. |
|
8629
04423b2f6e0b
cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents:
8627
diff
changeset
|
5 * Copyright (c) 2001 Juan J. Sierralta P |
|
1739
07a484280a82
copyright year update of the files i touched and remembered, things look annoyingly unmaintained otherwise
michael
parents:
1708
diff
changeset
|
6 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> |
| 0 | 7 * |
|
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3791
diff
changeset
|
8 * This file is part of FFmpeg. |
|
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3791
diff
changeset
|
9 * |
|
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3791
diff
changeset
|
10 * FFmpeg is free software; you can redistribute it and/or |
| 429 | 11 * modify it under the terms of the GNU Lesser General Public |
| 12 * License as published by the Free Software Foundation; either | |
|
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3791
diff
changeset
|
13 * version 2.1 of the License, or (at your option) any later version. |
| 0 | 14 * |
|
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3791
diff
changeset
|
15 * FFmpeg is distributed in the hope that it will be useful, |
| 0 | 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 429 | 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 * Lesser General Public License for more details. | |
| 0 | 19 * |
| 429 | 20 * You should have received a copy of the GNU Lesser General Public |
|
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3791
diff
changeset
|
21 * License along with FFmpeg; if not, write to the Free Software |
|
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
3024
diff
changeset
|
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 0 | 23 */ |
| 1034 | 24 |
| 25 /** | |
|
11644
7dd2a45249a9
Remove explicit filename from Doxygen @file commands.
diego
parents:
11531
diff
changeset
|
26 * @file |
| 1106 | 27 * h263/mpeg4 codec. |
| 1034 | 28 */ |
| 2967 | 29 |
| 355 | 30 //#define DEBUG |
|
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
31 #include <limits.h> |
|
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
32 |
| 0 | 33 #include "dsputil.h" |
| 34 #include "avcodec.h" | |
| 35 #include "mpegvideo.h" | |
| 10803 | 36 #include "h263.h" |
| 0 | 37 #include "h263data.h" |
|
8627
d6bab465b82c
moves mid_pred() into mathops.h (with arch specific code split by directory)
aurel
parents:
8612
diff
changeset
|
38 #include "mathops.h" |
|
9103
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
39 #include "unary.h" |
| 10787 | 40 #include "flv.h" |
| 10803 | 41 #include "mpeg4video.h" |
| 0 | 42 |
|
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
43 //#undef NDEBUG |
|
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
44 //#include <assert.h> |
|
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
45 |
| 10828 | 46 uint8_t ff_h263_static_rl_table_store[2][2][2*MAX_RUN + MAX_LEVEL + 3]; |
| 2967 | 47 |
| 3247 | 48 |
| 1389 | 49 void ff_h263_update_motion_val(MpegEncContext * s){ |
| 50 const int mb_xy = s->mb_y * s->mb_stride + s->mb_x; | |
|
2646
c735e3e60ca7
Even More spelling errors. patch by (Kevin Baragona <kevinmb500 gawab com)
michael
parents:
2639
diff
changeset
|
51 //FIXME a lot of that is only needed for !low_delay |
|
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
52 const int wrap = s->b8_stride; |
| 1389 | 53 const int xy = s->block_index[0]; |
| 2967 | 54 |
| 55 s->current_picture.mbskip_table[mb_xy]= s->mb_skipped; | |
| 1389 | 56 |
| 57 if(s->mv_type != MV_TYPE_8X8){ | |
| 58 int motion_x, motion_y; | |
| 59 if (s->mb_intra) { | |
| 60 motion_x = 0; | |
| 61 motion_y = 0; | |
| 62 } else if (s->mv_type == MV_TYPE_16X16) { | |
| 63 motion_x = s->mv[0][0][0]; | |
| 64 motion_y = s->mv[0][0][1]; | |
| 65 } else /*if (s->mv_type == MV_TYPE_FIELD)*/ { | |
| 66 int i; | |
| 67 motion_x = s->mv[0][0][0] + s->mv[0][1][0]; | |
| 68 motion_y = s->mv[0][0][1] + s->mv[0][1][1]; | |
| 69 motion_x = (motion_x>>1) | (motion_x&1); | |
| 70 for(i=0; i<2; i++){ | |
| 1708 | 71 s->p_field_mv_table[i][0][mb_xy][0]= s->mv[0][i][0]; |
| 72 s->p_field_mv_table[i][0][mb_xy][1]= s->mv[0][i][1]; | |
| 1389 | 73 } |
|
11531
31033caa5344
Change ref_index structure so it matches how its organized in h264.
michael
parents:
10828
diff
changeset
|
74 s->current_picture.ref_index[0][4*mb_xy ]= |
|
31033caa5344
Change ref_index structure so it matches how its organized in h264.
michael
parents:
10828
diff
changeset
|
75 s->current_picture.ref_index[0][4*mb_xy + 1]= s->field_select[0][0]; |
|
31033caa5344
Change ref_index structure so it matches how its organized in h264.
michael
parents:
10828
diff
changeset
|
76 s->current_picture.ref_index[0][4*mb_xy + 2]= |
|
31033caa5344
Change ref_index structure so it matches how its organized in h264.
michael
parents:
10828
diff
changeset
|
77 s->current_picture.ref_index[0][4*mb_xy + 3]= s->field_select[0][1]; |
| 1389 | 78 } |
| 1948 | 79 |
| 1389 | 80 /* no update if 8X8 because it has been done during parsing */ |
|
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
81 s->current_picture.motion_val[0][xy][0] = motion_x; |
|
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
82 s->current_picture.motion_val[0][xy][1] = motion_y; |
|
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
83 s->current_picture.motion_val[0][xy + 1][0] = motion_x; |
|
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
84 s->current_picture.motion_val[0][xy + 1][1] = motion_y; |
|
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
85 s->current_picture.motion_val[0][xy + wrap][0] = motion_x; |
|
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
86 s->current_picture.motion_val[0][xy + wrap][1] = motion_y; |
|
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
87 s->current_picture.motion_val[0][xy + 1 + wrap][0] = motion_x; |
|
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
88 s->current_picture.motion_val[0][xy + 1 + wrap][1] = motion_y; |
| 1389 | 89 } |
| 90 | |
| 91 if(s->encoding){ //FIXME encoding MUST be cleaned up | |
| 2967 | 92 if (s->mv_type == MV_TYPE_8X8) |
| 1389 | 93 s->current_picture.mb_type[mb_xy]= MB_TYPE_L0 | MB_TYPE_8x8; |
| 1633 | 94 else if(s->mb_intra) |
| 95 s->current_picture.mb_type[mb_xy]= MB_TYPE_INTRA; | |
| 1389 | 96 else |
| 97 s->current_picture.mb_type[mb_xy]= MB_TYPE_L0 | MB_TYPE_16x16; | |
| 98 } | |
| 99 } | |
| 100 | |
| 10828 | 101 int h263_pred_dc(MpegEncContext * s, int n, int16_t **dc_val_ptr) |
|
10752
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
102 { |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
103 int x, y, wrap, a, c, pred_dc; |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
104 int16_t *dc_val; |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
105 |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
106 /* find prediction */ |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
107 if (n < 4) { |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
108 x = 2 * s->mb_x + (n & 1); |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
109 y = 2 * s->mb_y + ((n & 2) >> 1); |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
110 wrap = s->b8_stride; |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
111 dc_val = s->dc_val[0]; |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
112 } else { |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
113 x = s->mb_x; |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
114 y = s->mb_y; |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
115 wrap = s->mb_stride; |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
116 dc_val = s->dc_val[n - 4 + 1]; |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
117 } |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
118 /* B C |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
119 * A X |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
120 */ |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
121 a = dc_val[(x - 1) + (y) * wrap]; |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
122 c = dc_val[(x) + (y - 1) * wrap]; |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
123 |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
124 /* No prediction outside GOB boundary */ |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
125 if(s->first_slice_line && n!=3){ |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
126 if(n!=2) c= 1024; |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
127 if(n!=1 && s->mb_x == s->resync_mb_x) a= 1024; |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
128 } |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
129 /* just DC prediction */ |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
130 if (a != 1024 && c != 1024) |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
131 pred_dc = (a + c) >> 1; |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
132 else if (a != 1024) |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
133 pred_dc = a; |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
134 else |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
135 pred_dc = c; |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
136 |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
137 /* we assume pred is positive */ |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
138 *dc_val_ptr = &dc_val[x + y * wrap]; |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
139 return pred_dc; |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
140 } |
|
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
141 |
| 1656 | 142 void ff_h263_loop_filter(MpegEncContext * s){ |
| 1644 | 143 int qp_c; |
| 144 const int linesize = s->linesize; | |
| 145 const int uvlinesize= s->uvlinesize; | |
| 146 const int xy = s->mb_y * s->mb_stride + s->mb_x; | |
| 147 uint8_t *dest_y = s->dest[0]; | |
| 148 uint8_t *dest_cb= s->dest[1]; | |
| 149 uint8_t *dest_cr= s->dest[2]; | |
| 2967 | 150 |
| 6481 | 151 // if(s->pict_type==FF_B_TYPE && !s->readable) return; |
| 1644 | 152 |
| 153 /* | |
| 154 Diag Top | |
| 155 Left Center | |
| 156 */ | |
| 157 if(!IS_SKIP(s->current_picture.mb_type[xy])){ | |
| 158 qp_c= s->qscale; | |
| 159 s->dsp.h263_v_loop_filter(dest_y+8*linesize , linesize, qp_c); | |
| 160 s->dsp.h263_v_loop_filter(dest_y+8*linesize+8, linesize, qp_c); | |
| 161 }else | |
| 162 qp_c= 0; | |
| 163 | |
| 164 if(s->mb_y){ | |
|
8297
20e0f0809b27
s/qp_t/qp_tt/ to avoid bad examples that could lead to issues with reserved
michael
parents:
8288
diff
changeset
|
165 int qp_dt, qp_tt, qp_tc; |
| 1644 | 166 |
| 167 if(IS_SKIP(s->current_picture.mb_type[xy-s->mb_stride])) | |
|
8297
20e0f0809b27
s/qp_t/qp_tt/ to avoid bad examples that could lead to issues with reserved
michael
parents:
8288
diff
changeset
|
168 qp_tt=0; |
| 2967 | 169 else |
|
8297
20e0f0809b27
s/qp_t/qp_tt/ to avoid bad examples that could lead to issues with reserved
michael
parents:
8288
diff
changeset
|
170 qp_tt= s->current_picture.qscale_table[xy-s->mb_stride]; |
| 1644 | 171 |
| 2967 | 172 if(qp_c) |
| 1644 | 173 qp_tc= qp_c; |
| 174 else | |
|
8297
20e0f0809b27
s/qp_t/qp_tt/ to avoid bad examples that could lead to issues with reserved
michael
parents:
8288
diff
changeset
|
175 qp_tc= qp_tt; |
| 2967 | 176 |
| 1644 | 177 if(qp_tc){ |
| 178 const int chroma_qp= s->chroma_qscale_table[qp_tc]; | |
| 179 s->dsp.h263_v_loop_filter(dest_y , linesize, qp_tc); | |
| 180 s->dsp.h263_v_loop_filter(dest_y+8, linesize, qp_tc); | |
| 2967 | 181 |
| 1644 | 182 s->dsp.h263_v_loop_filter(dest_cb , uvlinesize, chroma_qp); |
| 183 s->dsp.h263_v_loop_filter(dest_cr , uvlinesize, chroma_qp); | |
| 184 } | |
| 2967 | 185 |
|
8297
20e0f0809b27
s/qp_t/qp_tt/ to avoid bad examples that could lead to issues with reserved
michael
parents:
8288
diff
changeset
|
186 if(qp_tt) |
|
20e0f0809b27
s/qp_t/qp_tt/ to avoid bad examples that could lead to issues with reserved
michael
parents:
8288
diff
changeset
|
187 s->dsp.h263_h_loop_filter(dest_y-8*linesize+8 , linesize, qp_tt); |
| 2967 | 188 |
| 1644 | 189 if(s->mb_x){ |
|
8297
20e0f0809b27
s/qp_t/qp_tt/ to avoid bad examples that could lead to issues with reserved
michael
parents:
8288
diff
changeset
|
190 if(qp_tt || IS_SKIP(s->current_picture.mb_type[xy-1-s->mb_stride])) |
|
20e0f0809b27
s/qp_t/qp_tt/ to avoid bad examples that could lead to issues with reserved
michael
parents:
8288
diff
changeset
|
191 qp_dt= qp_tt; |
| 1644 | 192 else |
| 193 qp_dt= s->current_picture.qscale_table[xy-1-s->mb_stride]; | |
| 2967 | 194 |
| 1644 | 195 if(qp_dt){ |
| 196 const int chroma_qp= s->chroma_qscale_table[qp_dt]; | |
| 197 s->dsp.h263_h_loop_filter(dest_y -8*linesize , linesize, qp_dt); | |
| 198 s->dsp.h263_h_loop_filter(dest_cb-8*uvlinesize, uvlinesize, chroma_qp); | |
| 2178 | 199 s->dsp.h263_h_loop_filter(dest_cr-8*uvlinesize, uvlinesize, chroma_qp); |
| 1644 | 200 } |
| 201 } | |
| 202 } | |
| 203 | |
| 204 if(qp_c){ | |
| 205 s->dsp.h263_h_loop_filter(dest_y +8, linesize, qp_c); | |
| 206 if(s->mb_y + 1 == s->mb_height) | |
| 207 s->dsp.h263_h_loop_filter(dest_y+8*linesize+8, linesize, qp_c); | |
| 208 } | |
| 2967 | 209 |
| 1644 | 210 if(s->mb_x){ |
| 211 int qp_lc; | |
| 212 if(qp_c || IS_SKIP(s->current_picture.mb_type[xy-1])) | |
| 213 qp_lc= qp_c; | |
| 214 else | |
| 215 qp_lc= s->current_picture.qscale_table[xy-1]; | |
| 2967 | 216 |
| 1644 | 217 if(qp_lc){ |
| 218 s->dsp.h263_h_loop_filter(dest_y, linesize, qp_lc); | |
| 219 if(s->mb_y + 1 == s->mb_height){ | |
| 220 const int chroma_qp= s->chroma_qscale_table[qp_lc]; | |
| 221 s->dsp.h263_h_loop_filter(dest_y +8* linesize, linesize, qp_lc); | |
| 222 s->dsp.h263_h_loop_filter(dest_cb , uvlinesize, chroma_qp); | |
| 223 s->dsp.h263_h_loop_filter(dest_cr , uvlinesize, chroma_qp); | |
| 224 } | |
| 225 } | |
| 226 } | |
| 227 } | |
| 228 | |
| 10828 | 229 void h263_pred_acdc(MpegEncContext * s, DCTELEM *block, int n) |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
230 { |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
231 int x, y, wrap, a, c, pred_dc, scale, i; |
| 3781 | 232 int16_t *dc_val, *ac_val, *ac_val1; |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
233 |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
234 /* find prediction */ |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
235 if (n < 4) { |
|
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
236 x = 2 * s->mb_x + (n & 1); |
|
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
237 y = 2 * s->mb_y + (n>> 1); |
|
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
238 wrap = s->b8_stride; |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
239 dc_val = s->dc_val[0]; |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
240 ac_val = s->ac_val[0][0]; |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
241 scale = s->y_dc_scale; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
242 } else { |
|
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
243 x = s->mb_x; |
|
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
244 y = s->mb_y; |
|
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
245 wrap = s->mb_stride; |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
246 dc_val = s->dc_val[n - 4 + 1]; |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
247 ac_val = s->ac_val[n - 4 + 1][0]; |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
248 scale = s->c_dc_scale; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
249 } |
| 2967 | 250 |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
251 ac_val += ((y) * wrap + (x)) * 16; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
252 ac_val1 = ac_val; |
| 2967 | 253 |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
254 /* B C |
| 2967 | 255 * A X |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
256 */ |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
257 a = dc_val[(x - 1) + (y) * wrap]; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
258 c = dc_val[(x) + (y - 1) * wrap]; |
| 2967 | 259 |
|
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
260 /* No prediction outside GOB boundary */ |
| 1639 | 261 if(s->first_slice_line && n!=3){ |
| 262 if(n!=2) c= 1024; | |
| 263 if(n!=1 && s->mb_x == s->resync_mb_x) a= 1024; | |
| 264 } | |
| 2967 | 265 |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
266 if (s->ac_pred) { |
| 1639 | 267 pred_dc = 1024; |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
268 if (s->h263_aic_dir) { |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
269 /* left prediction */ |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
270 if (a != 1024) { |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
271 ac_val -= 16; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
272 for(i=1;i<8;i++) { |
| 1092 | 273 block[s->dsp.idct_permutation[i<<3]] += ac_val[i]; |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
274 } |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
275 pred_dc = a; |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
276 } |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
277 } else { |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
278 /* top prediction */ |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
279 if (c != 1024) { |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
280 ac_val -= 16 * wrap; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
281 for(i=1;i<8;i++) { |
| 1092 | 282 block[s->dsp.idct_permutation[i ]] += ac_val[i + 8]; |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
283 } |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
284 pred_dc = c; |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
285 } |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
286 } |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
287 } else { |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
288 /* just DC prediction */ |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
289 if (a != 1024 && c != 1024) |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
290 pred_dc = (a + c) >> 1; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
291 else if (a != 1024) |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
292 pred_dc = a; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
293 else |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
294 pred_dc = c; |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
295 } |
| 2967 | 296 |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
297 /* we assume pred is positive */ |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
298 block[0]=block[0]*scale + pred_dc; |
| 2967 | 299 |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
300 if (block[0] < 0) |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
301 block[0] = 0; |
| 2967 | 302 else |
| 1639 | 303 block[0] |= 1; |
| 2967 | 304 |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
305 /* Update AC/DC tables */ |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
306 dc_val[(x) + (y) * wrap] = block[0]; |
| 2967 | 307 |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
308 /* left copy */ |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
309 for(i=1;i<8;i++) |
| 1092 | 310 ac_val1[i ] = block[s->dsp.idct_permutation[i<<3]]; |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
311 /* top copy */ |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
312 for(i=1;i<8;i++) |
| 1092 | 313 ac_val1[8 + i] = block[s->dsp.idct_permutation[i ]]; |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
314 } |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
315 |
|
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
316 int16_t *h263_pred_motion(MpegEncContext * s, int block, int dir, |
| 0 | 317 int *px, int *py) |
| 318 { | |
|
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
319 int wrap; |
| 1655 | 320 int16_t *A, *B, *C, (*mot_val)[2]; |
| 321 static const int off[4]= {2, 1, 1, -1}; | |
| 322 | |
| 323 wrap = s->b8_stride; | |
|
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
324 mot_val = s->current_picture.motion_val[dir] + s->block_index[block]; |
| 1655 | 325 |
| 326 A = mot_val[ - 1]; | |
| 327 /* special case for first (slice) line */ | |
| 328 if (s->first_slice_line && block<3) { | |
|
2646
c735e3e60ca7
Even More spelling errors. patch by (Kevin Baragona <kevinmb500 gawab com)
michael
parents:
2639
diff
changeset
|
329 // we can't just change some MVs to simulate that as we need them for the B frames (and ME) |
| 1655 | 330 // and if we ever support non rectangular objects than we need to do a few ifs here anyway :( |
| 331 if(block==0){ //most common case | |
| 332 if(s->mb_x == s->resync_mb_x){ //rare | |
| 333 *px= *py = 0; | |
| 334 }else if(s->mb_x + 1 == s->resync_mb_x && s->h263_pred){ //rare | |
| 335 C = mot_val[off[block] - wrap]; | |
| 336 if(s->mb_x==0){ | |
| 337 *px = C[0]; | |
| 338 *py = C[1]; | |
| 339 }else{ | |
| 340 *px = mid_pred(A[0], 0, C[0]); | |
| 341 *py = mid_pred(A[1], 0, C[1]); | |
| 342 } | |
| 343 }else{ | |
| 344 *px = A[0]; | |
| 345 *py = A[1]; | |
| 346 } | |
| 347 }else if(block==1){ | |
| 348 if(s->mb_x + 1 == s->resync_mb_x && s->h263_pred){ //rare | |
| 349 C = mot_val[off[block] - wrap]; | |
| 350 *px = mid_pred(A[0], 0, C[0]); | |
| 351 *py = mid_pred(A[1], 0, C[1]); | |
| 352 }else{ | |
| 353 *px = A[0]; | |
| 354 *py = A[1]; | |
| 355 } | |
| 356 }else{ /* block==2*/ | |
| 357 B = mot_val[ - wrap]; | |
| 358 C = mot_val[off[block] - wrap]; | |
| 359 if(s->mb_x == s->resync_mb_x) //rare | |
| 360 A[0]=A[1]=0; | |
| 2967 | 361 |
| 1655 | 362 *px = mid_pred(A[0], B[0], C[0]); |
| 363 *py = mid_pred(A[1], B[1], C[1]); | |
| 364 } | |
| 365 } else { | |
| 366 B = mot_val[ - wrap]; | |
| 367 C = mot_val[off[block] - wrap]; | |
| 368 *px = mid_pred(A[0], B[0], C[0]); | |
| 369 *py = mid_pred(A[1], B[1], C[1]); | |
| 370 } | |
| 371 return *mot_val; | |
| 372 } | |
| 373 | |
| 0 | 374 |
|
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
375 /** |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
376 * Get the GOB height based on picture height. |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
377 */ |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
378 int ff_h263_get_gob_height(MpegEncContext *s){ |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
379 if (s->height <= 400) |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
380 return 1; |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
381 else if (s->height <= 800) |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
382 return 2; |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
383 else |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
384 return 4; |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
385 } |
