annotate h263dec.c @ 704:9b35329086c7 libavcodec

An easy way to speed up encoding by 6%.
author mellum
date Sat, 28 Sep 2002 02:18:34 +0000
parents 85b071dfc7e3
children 6cba3b6196f0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1 /*
986e461dc072 Initial revision
glantau
parents:
diff changeset
2 * H263 decoder
429
718a22dc121f license/copyright change
glantau
parents: 411
diff changeset
3 * Copyright (c) 2001 Fabrice Bellard.
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
4 *
429
718a22dc121f license/copyright change
glantau
parents: 411
diff changeset
5 * This library is free software; you can redistribute it and/or
718a22dc121f license/copyright change
glantau
parents: 411
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
718a22dc121f license/copyright change
glantau
parents: 411
diff changeset
7 * License as published by the Free Software Foundation; either
718a22dc121f license/copyright change
glantau
parents: 411
diff changeset
8 * version 2 of the License, or (at your option) any later version.
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
9 *
429
718a22dc121f license/copyright change
glantau
parents: 411
diff changeset
10 * This library is distributed in the hope that it will be useful,
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
429
718a22dc121f license/copyright change
glantau
parents: 411
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
718a22dc121f license/copyright change
glantau
parents: 411
diff changeset
13 * Lesser General Public License for more details.
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
14 *
429
718a22dc121f license/copyright change
glantau
parents: 411
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
718a22dc121f license/copyright change
glantau
parents: 411
diff changeset
16 * License along with this library; if not, write to the Free Software
718a22dc121f license/copyright change
glantau
parents: 411
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
18 */
396
fce0a2520551 removed useless header includes - use av memory functions
glantau
parents: 384
diff changeset
19 #include "avcodec.h"
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
20 #include "dsputil.h"
986e461dc072 Initial revision
glantau
parents:
diff changeset
21 #include "mpegvideo.h"
986e461dc072 Initial revision
glantau
parents:
diff changeset
22
986e461dc072 Initial revision
glantau
parents:
diff changeset
23 //#define DEBUG
384
d442918c4698 print frame decoding time support (x86 only)
michaelni
parents: 361
diff changeset
24 //#define PRINT_FRAME_TIME
d442918c4698 print frame decoding time support (x86 only)
michaelni
parents: 361
diff changeset
25 #ifdef PRINT_FRAME_TIME
d442918c4698 print frame decoding time support (x86 only)
michaelni
parents: 361
diff changeset
26 static inline long long rdtsc()
d442918c4698 print frame decoding time support (x86 only)
michaelni
parents: 361
diff changeset
27 {
d442918c4698 print frame decoding time support (x86 only)
michaelni
parents: 361
diff changeset
28 long long l;
d442918c4698 print frame decoding time support (x86 only)
michaelni
parents: 361
diff changeset
29 asm volatile( "rdtsc\n\t"
d442918c4698 print frame decoding time support (x86 only)
michaelni
parents: 361
diff changeset
30 : "=A" (l)
d442918c4698 print frame decoding time support (x86 only)
michaelni
parents: 361
diff changeset
31 );
d442918c4698 print frame decoding time support (x86 only)
michaelni
parents: 361
diff changeset
32 // printf("%d\n", int(l/1000));
d442918c4698 print frame decoding time support (x86 only)
michaelni
parents: 361
diff changeset
33 return l;
d442918c4698 print frame decoding time support (x86 only)
michaelni
parents: 361
diff changeset
34 }
d442918c4698 print frame decoding time support (x86 only)
michaelni
parents: 361
diff changeset
35 #endif
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
36
986e461dc072 Initial revision
glantau
parents:
diff changeset
37 static int h263_decode_init(AVCodecContext *avctx)
986e461dc072 Initial revision
glantau
parents:
diff changeset
38 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
39 MpegEncContext *s = avctx->priv_data;
60
35c1141e23d9 moved matrix init away from MPV_common_init()
glantau
parents: 56
diff changeset
40
67
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
41 s->avctx = avctx;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
42 s->out_format = FMT_H263;
986e461dc072 Initial revision
glantau
parents:
diff changeset
43
986e461dc072 Initial revision
glantau
parents:
diff changeset
44 s->width = avctx->width;
986e461dc072 Initial revision
glantau
parents:
diff changeset
45 s->height = avctx->height;
411
5c8b3a717929 workaround dc_scale bug in old ffmpeg msmpeg4v3 encoder (set workaround_bugs=1 for this)
michaelni
parents: 396
diff changeset
46 s->workaround_bugs= avctx->workaround_bugs;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
47
986e461dc072 Initial revision
glantau
parents:
diff changeset
48 /* select sub codec */
986e461dc072 Initial revision
glantau
parents:
diff changeset
49 switch(avctx->codec->id) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
50 case CODEC_ID_H263:
154
f914f710b8d0 - Fixed a bug on H.263 MV prediction for MB on GOBs limits.
pulento
parents: 144
diff changeset
51 s->gob_number = 0;
454
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
52 s->first_slice_line = 0;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
53 break;
67
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
54 case CODEC_ID_MPEG4:
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
55 s->time_increment_bits = 4; /* default value for broken headers */
986e461dc072 Initial revision
glantau
parents:
diff changeset
56 s->h263_pred = 1;
336
c56b45669214 export delay info
michaelni
parents: 333
diff changeset
57 s->has_b_frames = 1; //default, might be overriden in the vol header during header parsing
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
58 break;
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
59 case CODEC_ID_MSMPEG4V1:
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
60 s->h263_msmpeg4 = 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
61 s->h263_pred = 1;
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
62 s->msmpeg4_version=1;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
63 break;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
64 case CODEC_ID_MSMPEG4V2:
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
65 s->h263_msmpeg4 = 1;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
66 s->h263_pred = 1;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
67 s->msmpeg4_version=2;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
68 break;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
69 case CODEC_ID_MSMPEG4V3:
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
70 s->h263_msmpeg4 = 1;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
71 s->h263_pred = 1;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
72 s->msmpeg4_version=3;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
73 break;
311
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 308
diff changeset
74 case CODEC_ID_WMV1:
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 308
diff changeset
75 s->h263_msmpeg4 = 1;
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 308
diff changeset
76 s->h263_pred = 1;
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 308
diff changeset
77 s->msmpeg4_version=4;
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 308
diff changeset
78 break;
498
0b4450c15067 dc scale simplification/optimization
michaelni
parents: 485
diff changeset
79 case CODEC_ID_WMV2:
0b4450c15067 dc scale simplification/optimization
michaelni
parents: 485
diff changeset
80 s->h263_msmpeg4 = 1;
0b4450c15067 dc scale simplification/optimization
michaelni
parents: 485
diff changeset
81 s->h263_pred = 1;
0b4450c15067 dc scale simplification/optimization
michaelni
parents: 485
diff changeset
82 s->msmpeg4_version=5;
0b4450c15067 dc scale simplification/optimization
michaelni
parents: 485
diff changeset
83 break;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
84 case CODEC_ID_H263I:
986e461dc072 Initial revision
glantau
parents:
diff changeset
85 s->h263_intel = 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
86 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
87 default:
986e461dc072 Initial revision
glantau
parents:
diff changeset
88 return -1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
89 }
344
9f6071a87e17 fixed msmpeg4 infinite loop if buggy stream
michaelni
parents: 341
diff changeset
90 s->codec_id= avctx->codec->id;
553
18ad513d92fe direct rendering method 1 support
michaelni
parents: 543
diff changeset
91
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
92 /* for h263, we allocate the images after having read the header */
274
d0c186bcf075 use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents: 273
diff changeset
93 if (avctx->codec->id != CODEC_ID_H263 && avctx->codec->id != CODEC_ID_MPEG4)
144
cb5dabd00ba2 - Bug fix on inter MCBPC table for inter+q.
pulento
parents: 67
diff changeset
94 if (MPV_common_init(s) < 0)
cb5dabd00ba2 - Bug fix on inter MCBPC table for inter+q.
pulento
parents: 67
diff changeset
95 return -1;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
96
986e461dc072 Initial revision
glantau
parents:
diff changeset
97 if (s->h263_msmpeg4)
498
0b4450c15067 dc scale simplification/optimization
michaelni
parents: 485
diff changeset
98 ff_msmpeg4_decode_init(s);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
99 else
986e461dc072 Initial revision
glantau
parents:
diff changeset
100 h263_decode_init_vlc(s);
986e461dc072 Initial revision
glantau
parents:
diff changeset
101
986e461dc072 Initial revision
glantau
parents:
diff changeset
102 return 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
103 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
104
986e461dc072 Initial revision
glantau
parents:
diff changeset
105 static int h263_decode_end(AVCodecContext *avctx)
986e461dc072 Initial revision
glantau
parents:
diff changeset
106 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
107 MpegEncContext *s = avctx->priv_data;
986e461dc072 Initial revision
glantau
parents:
diff changeset
108
986e461dc072 Initial revision
glantau
parents:
diff changeset
109 MPV_common_end(s);
986e461dc072 Initial revision
glantau
parents:
diff changeset
110 return 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
111 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
112
655
0018e190cc4c m4v input support
michaelni
parents: 589
diff changeset
113 /**
0018e190cc4c m4v input support
michaelni
parents: 589
diff changeset
114 * retunrs the number of bytes consumed for building the current frame
0018e190cc4c m4v input support
michaelni
parents: 589
diff changeset
115 */
0018e190cc4c m4v input support
michaelni
parents: 589
diff changeset
116 static int get_consumed_bytes(MpegEncContext *s, int buf_size){
0018e190cc4c m4v input support
michaelni
parents: 589
diff changeset
117 int pos= (get_bits_count(&s->gb)+7)>>3;
0018e190cc4c m4v input support
michaelni
parents: 589
diff changeset
118
0018e190cc4c m4v input support
michaelni
parents: 589
diff changeset
119 if(s->divx_version>=500){
0018e190cc4c m4v input support
michaelni
parents: 589
diff changeset
120 //we would have to scan through the whole buf to handle the weird reordering ...
0018e190cc4c m4v input support
michaelni
parents: 589
diff changeset
121 return buf_size;
0018e190cc4c m4v input support
michaelni
parents: 589
diff changeset
122 }else{
0018e190cc4c m4v input support
michaelni
parents: 589
diff changeset
123 if(pos==0) pos=1; //avoid infinite loops (i doubt thats needed but ...)
658
dc8df8792a24 avoid nonsense frame-skip messages
michaelni
parents: 657
diff changeset
124 if(pos+10>buf_size) pos=buf_size; // oops ;)
655
0018e190cc4c m4v input support
michaelni
parents: 589
diff changeset
125
0018e190cc4c m4v input support
michaelni
parents: 589
diff changeset
126 return pos;
0018e190cc4c m4v input support
michaelni
parents: 589
diff changeset
127 }
0018e190cc4c m4v input support
michaelni
parents: 589
diff changeset
128 }
0018e190cc4c m4v input support
michaelni
parents: 589
diff changeset
129
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
130 static int h263_decode_frame(AVCodecContext *avctx,
986e461dc072 Initial revision
glantau
parents:
diff changeset
131 void *data, int *data_size,
986e461dc072 Initial revision
glantau
parents:
diff changeset
132 UINT8 *buf, int buf_size)
986e461dc072 Initial revision
glantau
parents:
diff changeset
133 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
134 MpegEncContext *s = avctx->priv_data;
986e461dc072 Initial revision
glantau
parents:
diff changeset
135 int ret;
986e461dc072 Initial revision
glantau
parents:
diff changeset
136 AVPicture *pict = data;
384
d442918c4698 print frame decoding time support (x86 only)
michaelni
parents: 361
diff changeset
137 #ifdef PRINT_FRAME_TIME
d442918c4698 print frame decoding time support (x86 only)
michaelni
parents: 361
diff changeset
138 uint64_t time= rdtsc();
d442918c4698 print frame decoding time support (x86 only)
michaelni
parents: 361
diff changeset
139 #endif
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
140 #ifdef DEBUG
986e461dc072 Initial revision
glantau
parents:
diff changeset
141 printf("*****frame %d size=%d\n", avctx->frame_number, buf_size);
986e461dc072 Initial revision
glantau
parents:
diff changeset
142 printf("bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
143 #endif
345
e05b357a398a export mbskip_table for direct rendering
michaelni
parents: 344
diff changeset
144
e05b357a398a export mbskip_table for direct rendering
michaelni
parents: 344
diff changeset
145 s->hurry_up= avctx->hurry_up;
454
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
146 s->error_resilience= avctx->error_resilience;
701
85b071dfc7e3 ff_get_fourcc() & XVIX support
michaelni
parents: 669
diff changeset
147
454
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
148 s->workaround_bugs= avctx->workaround_bugs;
701
85b071dfc7e3 ff_get_fourcc() & XVIX support
michaelni
parents: 669
diff changeset
149 if(s->avctx->fourcc == ff_get_fourcc("XVIX") && s->workaround_bugs==0)
85b071dfc7e3 ff_get_fourcc() & XVIX support
michaelni
parents: 669
diff changeset
150 s->workaround_bugs=2;
85b071dfc7e3 ff_get_fourcc() & XVIX support
michaelni
parents: 669
diff changeset
151
485
20108840b0e5 grayscale only decoding
michaelni
parents: 465
diff changeset
152 s->flags= avctx->flags;
454
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
153
657
8de2081a39ab uninitialized var ...
michaelni
parents: 655
diff changeset
154 *data_size = 0;
8de2081a39ab uninitialized var ...
michaelni
parents: 655
diff changeset
155
8de2081a39ab uninitialized var ...
michaelni
parents: 655
diff changeset
156 /* no supplementary picture */
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
157 if (buf_size == 0) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
158 return 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
159 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
160
465
76c8afc9c1eb 100l divx501+ seeking bugfix
michaelni
parents: 454
diff changeset
161 if(s->bitstream_buffer_size && buf_size<20){ //divx 5.01+ frame reorder
333
8aa87f1dfc52 divx 5.01 support
michaelni
parents: 311
diff changeset
162 init_get_bits(&s->gb, s->bitstream_buffer, s->bitstream_buffer_size);
353
386f430e93f4 freeze fix
michaelni
parents: 350
diff changeset
163 }else
333
8aa87f1dfc52 divx 5.01 support
michaelni
parents: 311
diff changeset
164 init_get_bits(&s->gb, buf, buf_size);
465
76c8afc9c1eb 100l divx501+ seeking bugfix
michaelni
parents: 454
diff changeset
165 s->bitstream_buffer_size=0;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
166
986e461dc072 Initial revision
glantau
parents:
diff changeset
167 /* let's go :-) */
986e461dc072 Initial revision
glantau
parents:
diff changeset
168 if (s->h263_msmpeg4) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
169 ret = msmpeg4_decode_picture_header(s);
986e461dc072 Initial revision
glantau
parents:
diff changeset
170 } else if (s->h263_pred) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
171 ret = mpeg4_decode_picture_header(s);
336
c56b45669214 export delay info
michaelni
parents: 333
diff changeset
172 s->has_b_frames= !s->low_delay;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
173 } else if (s->h263_intel) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
174 ret = intel_h263_decode_picture_header(s);
986e461dc072 Initial revision
glantau
parents:
diff changeset
175 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
176 ret = h263_decode_picture_header(s);
274
d0c186bcf075 use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents: 273
diff changeset
177 }
556
762c67fd4078 uvlinesize
michaelni
parents: 553
diff changeset
178 avctx->has_b_frames= s->has_b_frames;
585
86ebb02c6693 dump bits per frame / qp / frame complexity support
michaelni
parents: 562
diff changeset
179 #if 0 // dump bits per frame / qp / complexity
86ebb02c6693 dump bits per frame / qp / frame complexity support
michaelni
parents: 562
diff changeset
180 {
86ebb02c6693 dump bits per frame / qp / frame complexity support
michaelni
parents: 562
diff changeset
181 static FILE *f=NULL;
86ebb02c6693 dump bits per frame / qp / frame complexity support
michaelni
parents: 562
diff changeset
182 if(!f) f=fopen("rate_qp_cplx.txt", "w");
589
507e688d57b2 10l found by R«±mi Guyomarch <rguyom at pobox dot com>
michaelni
parents: 585
diff changeset
183 fprintf(f, "%d %d %f\n", buf_size, s->qscale, buf_size*(double)s->qscale);
585
86ebb02c6693 dump bits per frame / qp / frame complexity support
michaelni
parents: 562
diff changeset
184 }
86ebb02c6693 dump bits per frame / qp / frame complexity support
michaelni
parents: 562
diff changeset
185 #endif
553
18ad513d92fe direct rendering method 1 support
michaelni
parents: 543
diff changeset
186
274
d0c186bcf075 use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents: 273
diff changeset
187 /* After H263 & mpeg4 header decode we have the height, width,*/
160
1bf8c111691d - Bug fixed on H.263 decoder initialization.
pulento
parents: 154
diff changeset
188 /* and other parameters. So then we could init the picture */
1bf8c111691d - Bug fixed on H.263 decoder initialization.
pulento
parents: 154
diff changeset
189 /* FIXME: By the way H263 decoder is evolving it should have */
1bf8c111691d - Bug fixed on H.263 decoder initialization.
pulento
parents: 154
diff changeset
190 /* an H263EncContext */
553
18ad513d92fe direct rendering method 1 support
michaelni
parents: 543
diff changeset
191 if (s->width != avctx->width || s->height != avctx->height) {
18ad513d92fe direct rendering method 1 support
michaelni
parents: 543
diff changeset
192 /* H.263 could change picture size any time */
18ad513d92fe direct rendering method 1 support
michaelni
parents: 543
diff changeset
193 MPV_common_end(s);
18ad513d92fe direct rendering method 1 support
michaelni
parents: 543
diff changeset
194 s->context_initialized=0;
18ad513d92fe direct rendering method 1 support
michaelni
parents: 543
diff changeset
195 }
274
d0c186bcf075 use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents: 273
diff changeset
196 if (!s->context_initialized) {
d0c186bcf075 use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents: 273
diff changeset
197 avctx->width = s->width;
d0c186bcf075 use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents: 273
diff changeset
198 avctx->height = s->height;
281
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 274
diff changeset
199 avctx->aspect_ratio_info= s->aspect_ratio_info;
669
b4bddbde44f3 aspect (ext. par too) support for h263 and mpeg4 (inc. build becouse of new vars)
al3x
parents: 658
diff changeset
200 if (s->aspect_ratio_info == FF_ASPECT_EXTENDED)
b4bddbde44f3 aspect (ext. par too) support for h263 and mpeg4 (inc. build becouse of new vars)
al3x
parents: 658
diff changeset
201 {
b4bddbde44f3 aspect (ext. par too) support for h263 and mpeg4 (inc. build becouse of new vars)
al3x
parents: 658
diff changeset
202 avctx->aspected_width = s->aspected_width;
b4bddbde44f3 aspect (ext. par too) support for h263 and mpeg4 (inc. build becouse of new vars)
al3x
parents: 658
diff changeset
203 avctx->aspected_height = s->aspected_height;
b4bddbde44f3 aspect (ext. par too) support for h263 and mpeg4 (inc. build becouse of new vars)
al3x
parents: 658
diff changeset
204 }
274
d0c186bcf075 use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents: 273
diff changeset
205 if (MPV_common_init(s) < 0)
d0c186bcf075 use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents: 273
diff changeset
206 return -1;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
207 }
274
d0c186bcf075 use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents: 273
diff changeset
208
655
0018e190cc4c m4v input support
michaelni
parents: 589
diff changeset
209 if(ret==FRAME_SKIPED) return get_consumed_bytes(s, buf_size);
454
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
210 /* skip if the header was thrashed */
498
0b4450c15067 dc scale simplification/optimization
michaelni
parents: 485
diff changeset
211 if (ret < 0){
0b4450c15067 dc scale simplification/optimization
michaelni
parents: 485
diff changeset
212 fprintf(stderr, "header damaged\n");
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
213 return -1;
498
0b4450c15067 dc scale simplification/optimization
michaelni
parents: 485
diff changeset
214 }
341
bf26081c373c avcodec_flush_buffers()
michaelni
parents: 336
diff changeset
215 /* skip b frames if we dont have reference frames */
655
0018e190cc4c m4v input support
michaelni
parents: 589
diff changeset
216 if(s->num_available_buffers<2 && s->pict_type==B_TYPE) return get_consumed_bytes(s, buf_size);
345
e05b357a398a export mbskip_table for direct rendering
michaelni
parents: 344
diff changeset
217 /* skip b frames if we are in a hurry */
655
0018e190cc4c m4v input support
michaelni
parents: 589
diff changeset
218 if(s->hurry_up && s->pict_type==B_TYPE) return get_consumed_bytes(s, buf_size);
454
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
219
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
220 if(s->next_p_frame_damaged){
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
221 if(s->pict_type==B_TYPE)
655
0018e190cc4c m4v input support
michaelni
parents: 589
diff changeset
222 return get_consumed_bytes(s, buf_size);
454
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
223 else
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
224 s->next_p_frame_damaged=0;
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
225 }
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
226
553
18ad513d92fe direct rendering method 1 support
michaelni
parents: 543
diff changeset
227 MPV_frame_start(s, avctx);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
228
986e461dc072 Initial revision
glantau
parents:
diff changeset
229 #ifdef DEBUG
986e461dc072 Initial revision
glantau
parents:
diff changeset
230 printf("qscale=%d\n", s->qscale);
986e461dc072 Initial revision
glantau
parents:
diff changeset
231 #endif
986e461dc072 Initial revision
glantau
parents:
diff changeset
232
454
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
233 /* init resync/ error resilience specific variables */
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
234 s->next_resync_qscale= s->qscale;
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
235 s->next_resync_gb= s->gb;
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
236 if(s->resync_marker) s->mb_num_left= 0;
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
237 else s->mb_num_left= s->mb_num;
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
238
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
239 /* decode each macroblock */
266
252444e5259b optimization
michaelni
parents: 262
diff changeset
240 s->block_wrap[0]=
252444e5259b optimization
michaelni
parents: 262
diff changeset
241 s->block_wrap[1]=
252444e5259b optimization
michaelni
parents: 262
diff changeset
242 s->block_wrap[2]=
252444e5259b optimization
michaelni
parents: 262
diff changeset
243 s->block_wrap[3]= s->mb_width*2 + 2;
252444e5259b optimization
michaelni
parents: 262
diff changeset
244 s->block_wrap[4]=
252444e5259b optimization
michaelni
parents: 262
diff changeset
245 s->block_wrap[5]= s->mb_width + 2;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
246 for(s->mb_y=0; s->mb_y < s->mb_height; s->mb_y++) {
162
de80712db90b - Preliminary RTP friendly mode for H.263.
pulento
parents: 161
diff changeset
247 /* Check for GOB headers on H.263 */
de80712db90b - Preliminary RTP friendly mode for H.263.
pulento
parents: 161
diff changeset
248 /* FIXME: In the future H.263+ will have intra prediction */
de80712db90b - Preliminary RTP friendly mode for H.263.
pulento
parents: 161
diff changeset
249 /* and we are gonna need another way to detect MPEG4 */
de80712db90b - Preliminary RTP friendly mode for H.263.
pulento
parents: 161
diff changeset
250 if (s->mb_y && !s->h263_pred) {
454
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
251 s->first_slice_line = h263_decode_gob_header(s);
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
252 }
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
253
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
254 if(s->msmpeg4_version==1){
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
255 s->last_dc[0]=
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
256 s->last_dc[1]=
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
257 s->last_dc[2]= 128;
162
de80712db90b - Preliminary RTP friendly mode for H.263.
pulento
parents: 161
diff changeset
258 }
296
c1a8a1b4a24b sizeof(s->block) isnt 64*6*2 anymore bugfix
michaelni
parents: 281
diff changeset
259
498
0b4450c15067 dc scale simplification/optimization
michaelni
parents: 485
diff changeset
260 s->y_dc_scale= s->y_dc_scale_table[ s->qscale ];
0b4450c15067 dc scale simplification/optimization
michaelni
parents: 485
diff changeset
261 s->c_dc_scale= s->c_dc_scale_table[ s->qscale ];
0b4450c15067 dc scale simplification/optimization
michaelni
parents: 485
diff changeset
262
266
252444e5259b optimization
michaelni
parents: 262
diff changeset
263 s->block_index[0]= s->block_wrap[0]*(s->mb_y*2 + 1) - 1;
252444e5259b optimization
michaelni
parents: 262
diff changeset
264 s->block_index[1]= s->block_wrap[0]*(s->mb_y*2 + 1);
252444e5259b optimization
michaelni
parents: 262
diff changeset
265 s->block_index[2]= s->block_wrap[0]*(s->mb_y*2 + 2) - 1;
252444e5259b optimization
michaelni
parents: 262
diff changeset
266 s->block_index[3]= s->block_wrap[0]*(s->mb_y*2 + 2);
252444e5259b optimization
michaelni
parents: 262
diff changeset
267 s->block_index[4]= s->block_wrap[4]*(s->mb_y + 1) + s->block_wrap[0]*(s->mb_height*2 + 2);
252444e5259b optimization
michaelni
parents: 262
diff changeset
268 s->block_index[5]= s->block_wrap[4]*(s->mb_y + 1 + s->mb_height + 2) + s->block_wrap[0]*(s->mb_height*2 + 2);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
269 for(s->mb_x=0; s->mb_x < s->mb_width; s->mb_x++) {
266
252444e5259b optimization
michaelni
parents: 262
diff changeset
270 s->block_index[0]+=2;
252444e5259b optimization
michaelni
parents: 262
diff changeset
271 s->block_index[1]+=2;
252444e5259b optimization
michaelni
parents: 262
diff changeset
272 s->block_index[2]+=2;
252444e5259b optimization
michaelni
parents: 262
diff changeset
273 s->block_index[3]+=2;
252444e5259b optimization
michaelni
parents: 262
diff changeset
274 s->block_index[4]++;
252444e5259b optimization
michaelni
parents: 262
diff changeset
275 s->block_index[5]++;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
276 #ifdef DEBUG
986e461dc072 Initial revision
glantau
parents:
diff changeset
277 printf("**mb x=%d y=%d\n", s->mb_x, s->mb_y);
986e461dc072 Initial revision
glantau
parents:
diff changeset
278 #endif
454
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
279
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
280 if(s->resync_marker){
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
281 if(s->mb_num_left<=0){
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
282 /* except the first block */
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
283 if(s->mb_x!=0 || s->mb_y!=0){
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
284 /* did we miss the next resync marker without noticing an error yet */
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
285 if(((get_bits_count(&s->gb)+8)&(~7)) != s->next_resync_pos && s->decoding_error==0){
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
286 fprintf(stderr, "slice end missmatch x:%d y:%d %d %d\n",
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
287 s->mb_x, s->mb_y, get_bits_count(&s->gb), s->next_resync_pos);
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
288 ff_conceal_past_errors(s, 1);
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
289 }
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
290 }
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
291 s->qscale= s->next_resync_qscale;
498
0b4450c15067 dc scale simplification/optimization
michaelni
parents: 485
diff changeset
292 s->y_dc_scale= s->y_dc_scale_table[ s->qscale ];
0b4450c15067 dc scale simplification/optimization
michaelni
parents: 485
diff changeset
293 s->c_dc_scale= s->c_dc_scale_table[ s->qscale ];
0b4450c15067 dc scale simplification/optimization
michaelni
parents: 485
diff changeset
294
454
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
295 s->gb= s->next_resync_gb;
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
296 s->resync_mb_x= s->mb_x; //we know that the marker is here cuz mb_num_left was the distance to it
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
297 s->resync_mb_y= s->mb_y;
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
298 s->first_slice_line=1;
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
299
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
300 if(s->codec_id==CODEC_ID_MPEG4){
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
301 ff_mpeg4_clean_buffers(s);
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
302 ff_mpeg4_resync(s);
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
303 }
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
304 }
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
305
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
306 if( s->resync_mb_x==s->mb_x
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
307 && s->resync_mb_y==s->mb_y && s->decoding_error!=0){
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
308 fprintf(stderr, "resynced at %d %d\n", s->mb_x, s->mb_y);
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
309 s->decoding_error= 0;
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
310 }
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
311 }
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
312
144
cb5dabd00ba2 - Bug fix on inter MCBPC table for inter+q.
pulento
parents: 67
diff changeset
313 //fprintf(stderr,"\nFrame: %d\tMB: %d",avctx->frame_number, (s->mb_y * s->mb_width) + s->mb_x);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
314 /* DCT & quantize */
454
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
315 if(s->decoding_error!=DECODING_DESYNC){
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
316 int last_error= s->decoding_error;
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
317 clear_blocks(s->block[0]);
296
c1a8a1b4a24b sizeof(s->block) isnt 64*6*2 anymore bugfix
michaelni
parents: 281
diff changeset
318
454
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
319 s->mv_dir = MV_DIR_FORWARD;
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
320 s->mv_type = MV_TYPE_16X16;
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
321 if (s->h263_msmpeg4) {
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
322 if (msmpeg4_decode_mb(s, s->block) < 0) {
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
323 fprintf(stderr,"Error at MB: %d\n", (s->mb_y * s->mb_width) + s->mb_x);
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
324 s->decoding_error=DECODING_DESYNC;
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
325 }
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
326 } else {
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
327 if (h263_decode_mb(s, s->block) < 0) {
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
328 fprintf(stderr,"Error at MB: %d\n", (s->mb_y * s->mb_width) + s->mb_x);
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
329 s->decoding_error=DECODING_DESYNC;
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
330 }
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
331 }
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
332
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
333 if(s->decoding_error!=last_error){
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
334 ff_conceal_past_errors(s, 0);
161
7ce36cf13055 - Added support to Inter4V+Q MBs to H.263 decoder.
pulento
parents: 160
diff changeset
335 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
336 }
454
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
337
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
338 /* conceal errors */
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
339 if( s->decoding_error==DECODING_DESYNC
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
340 || (s->decoding_error==DECODING_ACDC_LOST && s->mb_intra)){
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
341 s->mv_dir = MV_DIR_FORWARD;
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
342 s->mv_type = MV_TYPE_16X16;
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
343 s->mb_skiped=0;
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
344 s->mb_intra=0;
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
345 s->mv[0][0][0]=0; //FIXME this is not optimal
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
346 s->mv[0][0][1]=0;
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
347 clear_blocks(s->block[0]);
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
348 }else if(s->decoding_error && !s->mb_intra){
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
349 clear_blocks(s->block[0]);
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
350 }
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
351 //FIXME remove AC for intra
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
352
12
4d50c7d89e0f use block[] in structure to have it aligned on 8 bytes for mmx optimizations
glantau
parents: 0
diff changeset
353 MPV_decode_mb(s, s->block);
454
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
354
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
355 s->mb_num_left--;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
356 }
341
bf26081c373c avcodec_flush_buffers()
michaelni
parents: 336
diff changeset
357 if ( avctx->draw_horiz_band
bf26081c373c avcodec_flush_buffers()
michaelni
parents: 336
diff changeset
358 && (s->num_available_buffers>=1 || (!s->has_b_frames)) ) {
67
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
359 UINT8 *src_ptr[3];
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
360 int y, h, offset;
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
361 y = s->mb_y * 16;
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
362 h = s->height - y;
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
363 if (h > 16)
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
364 h = 16;
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
365 offset = y * s->linesize;
308
072c4ff05e62 b frames & slices bugfix
michaelni
parents: 307
diff changeset
366 if(s->pict_type==B_TYPE || (!s->has_b_frames)){
072c4ff05e62 b frames & slices bugfix
michaelni
parents: 307
diff changeset
367 src_ptr[0] = s->current_picture[0] + offset;
072c4ff05e62 b frames & slices bugfix
michaelni
parents: 307
diff changeset
368 src_ptr[1] = s->current_picture[1] + (offset >> 2);
072c4ff05e62 b frames & slices bugfix
michaelni
parents: 307
diff changeset
369 src_ptr[2] = s->current_picture[2] + (offset >> 2);
072c4ff05e62 b frames & slices bugfix
michaelni
parents: 307
diff changeset
370 } else {
072c4ff05e62 b frames & slices bugfix
michaelni
parents: 307
diff changeset
371 src_ptr[0] = s->last_picture[0] + offset;
072c4ff05e62 b frames & slices bugfix
michaelni
parents: 307
diff changeset
372 src_ptr[1] = s->last_picture[1] + (offset >> 2);
072c4ff05e62 b frames & slices bugfix
michaelni
parents: 307
diff changeset
373 src_ptr[2] = s->last_picture[2] + (offset >> 2);
072c4ff05e62 b frames & slices bugfix
michaelni
parents: 307
diff changeset
374 }
67
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
375 avctx->draw_horiz_band(avctx, src_ptr, s->linesize,
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
376 y, s->width, h);
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
377 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
378 }
208
2eb04d6be309 (commit by michael)
arpi_esp
parents: 203
diff changeset
379
311
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 308
diff changeset
380 if (s->h263_msmpeg4 && s->msmpeg4_version<4 && s->pict_type==I_TYPE)
208
2eb04d6be309 (commit by michael)
arpi_esp
parents: 203
diff changeset
381 if(msmpeg4_decode_ext_header(s, buf_size) < 0) return -1;
333
8aa87f1dfc52 divx 5.01 support
michaelni
parents: 311
diff changeset
382
8aa87f1dfc52 divx 5.01 support
michaelni
parents: 311
diff changeset
383 /* divx 5.01+ bistream reorder stuff */
655
0018e190cc4c m4v input support
michaelni
parents: 589
diff changeset
384 if(s->codec_id==CODEC_ID_MPEG4 && s->bitstream_buffer_size==0 && s->divx_version>=500){
454
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
385 int current_pos= get_bits_count(&s->gb)>>3;
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
386
333
8aa87f1dfc52 divx 5.01 support
michaelni
parents: 311
diff changeset
387 if( buf_size - current_pos > 5
8aa87f1dfc52 divx 5.01 support
michaelni
parents: 311
diff changeset
388 && buf_size - current_pos < BITSTREAM_BUFFER_SIZE){
454
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
389 int i;
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
390 int startcode_found=0;
655
0018e190cc4c m4v input support
michaelni
parents: 589
diff changeset
391 for(i=current_pos; i<buf_size-3; i++){
454
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
392 if(buf[i]==0 && buf[i+1]==0 && buf[i+2]==1 && buf[i+3]==0xB6){
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
393 startcode_found=1;
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
394 break;
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
395 }
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
396 }
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
397 if(startcode_found){
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
398 memcpy(s->bitstream_buffer, buf + current_pos, buf_size - current_pos);
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
399 s->bitstream_buffer_size= buf_size - current_pos;
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
400 }
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
401 }
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
402 }
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
403
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
404 if(s->bitstream_buffer_size==0 && s->error_resilience>0){
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
405 int left= s->gb.size*8 - get_bits_count(&s->gb);
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
406 int max_extra=8;
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
407
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
408 if(s->codec_id==CODEC_ID_MPEG4) max_extra+=32;
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
409
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
410 if(left>max_extra){
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
411 fprintf(stderr, "discarding %d junk bits at end, next would be %X\n", left, show_bits(&s->gb, 24));
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
412 if(s->decoding_error==0)
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
413 ff_conceal_past_errors(s, 1);
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
414 }
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
415 if(left<0){
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
416 fprintf(stderr, "overreading %d bits\n", -left);
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
417 if(s->decoding_error==0)
eda22d628b2d error concealment / error resilience
michaelni
parents: 429
diff changeset
418 ff_conceal_past_errors(s, 1);
333
8aa87f1dfc52 divx 5.01 support
michaelni
parents: 311
diff changeset
419 }
353
386f430e93f4 freeze fix
michaelni
parents: 350
diff changeset
420 }
333
8aa87f1dfc52 divx 5.01 support
michaelni
parents: 311
diff changeset
421
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
422 MPV_frame_end(s);
361
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
423 #if 0 //dirty show MVs, we should export the MV tables and write a filter to show them
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
424 {
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
425 int mb_y;
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
426 s->has_b_frames=1;
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
427 for(mb_y=0; mb_y<s->mb_height; mb_y++){
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
428 int mb_x;
411
5c8b3a717929 workaround dc_scale bug in old ffmpeg msmpeg4v3 encoder (set workaround_bugs=1 for this)
michaelni
parents: 396
diff changeset
429 int y= mb_y*16 + 8;
361
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
430 for(mb_x=0; mb_x<s->mb_width; mb_x++){
411
5c8b3a717929 workaround dc_scale bug in old ffmpeg msmpeg4v3 encoder (set workaround_bugs=1 for this)
michaelni
parents: 396
diff changeset
431 int x= mb_x*16 + 8;
361
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
432 uint8_t *ptr= s->last_picture[0];
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
433 int xy= 1 + mb_x*2 + (mb_y*2 + 1)*(s->mb_width*2 + 2);
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
434 int mx= (s->motion_val[xy][0]>>1) + x;
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
435 int my= (s->motion_val[xy][1]>>1) + y;
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
436 int i;
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
437 int max;
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
438
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
439 if(mx<0) mx=0;
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
440 if(my<0) my=0;
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
441 if(mx>=s->width) mx= s->width -1;
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
442 if(my>=s->height) my= s->height-1;
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
443 max= ABS(mx-x);
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
444 if(ABS(my-y) > max) max= ABS(my-y);
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
445 /* the ugliest linedrawing routine ... */
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
446 for(i=0; i<max; i++){
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
447 int x1= x + (mx-x)*i/max;
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
448 int y1= y + (my-y)*i/max;
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
449 ptr[y1*s->linesize + x1]+=100;
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
450 }
411
5c8b3a717929 workaround dc_scale bug in old ffmpeg msmpeg4v3 encoder (set workaround_bugs=1 for this)
michaelni
parents: 396
diff changeset
451 ptr[y*s->linesize + x]+=100;
361
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
452 s->mbskip_table[mb_x + mb_y*s->mb_width]=0;
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
453 }
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
454 }
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
455
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
456 }
dc2fb310008d MV visualisation support
michaelni
parents: 353
diff changeset
457 #endif
273
34f40a0fc840 msmpeg4 bugfix (wrong frame displayed if some frames are skipped)
michaelni
parents: 266
diff changeset
458 if(s->pict_type==B_TYPE || (!s->has_b_frames)){
262
7d941b8c4e84 mpeg4 b-frames :)
michaelni
parents: 251
diff changeset
459 pict->data[0] = s->current_picture[0];
7d941b8c4e84 mpeg4 b-frames :)
michaelni
parents: 251
diff changeset
460 pict->data[1] = s->current_picture[1];
7d941b8c4e84 mpeg4 b-frames :)
michaelni
parents: 251
diff changeset
461 pict->data[2] = s->current_picture[2];
7d941b8c4e84 mpeg4 b-frames :)
michaelni
parents: 251
diff changeset
462 } else {
7d941b8c4e84 mpeg4 b-frames :)
michaelni
parents: 251
diff changeset
463 pict->data[0] = s->last_picture[0];
7d941b8c4e84 mpeg4 b-frames :)
michaelni
parents: 251
diff changeset
464 pict->data[1] = s->last_picture[1];
7d941b8c4e84 mpeg4 b-frames :)
michaelni
parents: 251
diff changeset
465 pict->data[2] = s->last_picture[2];
7d941b8c4e84 mpeg4 b-frames :)
michaelni
parents: 251
diff changeset
466 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
467 pict->linesize[0] = s->linesize;
556
762c67fd4078 uvlinesize
michaelni
parents: 553
diff changeset
468 pict->linesize[1] = s->uvlinesize;
762c67fd4078 uvlinesize
michaelni
parents: 553
diff changeset
469 pict->linesize[2] = s->uvlinesize;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
470
986e461dc072 Initial revision
glantau
parents:
diff changeset
471 avctx->quality = s->qscale;
231
840cd25bf259 - Fixes on RTP and GOB headers for H.263.
pulento
parents: 208
diff changeset
472
840cd25bf259 - Fixes on RTP and GOB headers for H.263.
pulento
parents: 208
diff changeset
473 /* Return the Picture timestamp as the frame number */
840cd25bf259 - Fixes on RTP and GOB headers for H.263.
pulento
parents: 208
diff changeset
474 /* we substract 1 because it is added on utils.c */
840cd25bf259 - Fixes on RTP and GOB headers for H.263.
pulento
parents: 208
diff changeset
475 avctx->frame_number = s->picture_number - 1;
840cd25bf259 - Fixes on RTP and GOB headers for H.263.
pulento
parents: 208
diff changeset
476
341
bf26081c373c avcodec_flush_buffers()
michaelni
parents: 336
diff changeset
477 /* dont output the last pic after seeking
bf26081c373c avcodec_flush_buffers()
michaelni
parents: 336
diff changeset
478 note we allready added +1 for the current pix in MPV_frame_end(s) */
bf26081c373c avcodec_flush_buffers()
michaelni
parents: 336
diff changeset
479 if(s->num_available_buffers>=2 || (!s->has_b_frames))
bf26081c373c avcodec_flush_buffers()
michaelni
parents: 336
diff changeset
480 *data_size = sizeof(AVPicture);
384
d442918c4698 print frame decoding time support (x86 only)
michaelni
parents: 361
diff changeset
481 #ifdef PRINT_FRAME_TIME
d442918c4698 print frame decoding time support (x86 only)
michaelni
parents: 361
diff changeset
482 printf("%Ld\n", rdtsc()-time);
d442918c4698 print frame decoding time support (x86 only)
michaelni
parents: 361
diff changeset
483 #endif
655
0018e190cc4c m4v input support
michaelni
parents: 589
diff changeset
484 return get_consumed_bytes(s, buf_size);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
485 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
486
67
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
487 AVCodec mpeg4_decoder = {
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
488 "mpeg4",
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
489 CODEC_TYPE_VIDEO,
67
cdd89f96cbe1 added draw_horiz_band test
glantau
parents: 60
diff changeset
490 CODEC_ID_MPEG4,
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
491 sizeof(MpegEncContext),
986e461dc072 Initial revision
glantau
parents:
diff changeset
492 h263_decode_init,
986e461dc072 Initial revision
glantau
parents:
diff changeset
493 NULL,
986e461dc072 Initial revision
glantau
parents:
diff changeset
494 h263_decode_end,
986e461dc072 Initial revision
glantau
parents:
diff changeset
495 h263_decode_frame,
553
18ad513d92fe direct rendering method 1 support
michaelni
parents: 543
diff changeset
496 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
497 };
986e461dc072 Initial revision
glantau
parents:
diff changeset
498
986e461dc072 Initial revision
glantau
parents:
diff changeset
499 AVCodec h263_decoder = {
986e461dc072 Initial revision
glantau
parents:
diff changeset
500 "h263",
986e461dc072 Initial revision
glantau
parents:
diff changeset
501 CODEC_TYPE_VIDEO,
986e461dc072 Initial revision
glantau
parents:
diff changeset
502 CODEC_ID_H263,
986e461dc072 Initial revision
glantau
parents:
diff changeset
503 sizeof(MpegEncContext),
986e461dc072 Initial revision
glantau
parents:
diff changeset
504 h263_decode_init,
986e461dc072 Initial revision
glantau
parents:
diff changeset
505 NULL,
986e461dc072 Initial revision
glantau
parents:
diff changeset
506 h263_decode_end,
986e461dc072 Initial revision
glantau
parents:
diff changeset
507 h263_decode_frame,
553
18ad513d92fe direct rendering method 1 support
michaelni
parents: 543
diff changeset
508 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
509 };
986e461dc072 Initial revision
glantau
parents:
diff changeset
510
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
511 AVCodec msmpeg4v1_decoder = {
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
512 "msmpeg4v1",
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
513 CODEC_TYPE_VIDEO,
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
514 CODEC_ID_MSMPEG4V1,
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
515 sizeof(MpegEncContext),
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
516 h263_decode_init,
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
517 NULL,
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
518 h263_decode_end,
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
519 h263_decode_frame,
553
18ad513d92fe direct rendering method 1 support
michaelni
parents: 543
diff changeset
520 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
521 };
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
522
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
523 AVCodec msmpeg4v2_decoder = {
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
524 "msmpeg4v2",
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
525 CODEC_TYPE_VIDEO,
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
526 CODEC_ID_MSMPEG4V2,
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
527 sizeof(MpegEncContext),
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
528 h263_decode_init,
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
529 NULL,
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
530 h263_decode_end,
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
531 h263_decode_frame,
553
18ad513d92fe direct rendering method 1 support
michaelni
parents: 543
diff changeset
532 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
533 };
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
534
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
535 AVCodec msmpeg4v3_decoder = {
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
536 "msmpeg4",
986e461dc072 Initial revision
glantau
parents:
diff changeset
537 CODEC_TYPE_VIDEO,
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 296
diff changeset
538 CODEC_ID_MSMPEG4V3,
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
539 sizeof(MpegEncContext),
986e461dc072 Initial revision
glantau
parents:
diff changeset
540 h263_decode_init,
986e461dc072 Initial revision
glantau
parents:
diff changeset
541 NULL,
986e461dc072 Initial revision
glantau
parents:
diff changeset
542 h263_decode_end,
986e461dc072 Initial revision
glantau
parents:
diff changeset
543 h263_decode_frame,
553
18ad513d92fe direct rendering method 1 support
michaelni
parents: 543
diff changeset
544 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
545 };
986e461dc072 Initial revision
glantau
parents:
diff changeset
546
311
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 308
diff changeset
547 AVCodec wmv1_decoder = {
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 308
diff changeset
548 "wmv1",
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 308
diff changeset
549 CODEC_TYPE_VIDEO,
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 308
diff changeset
550 CODEC_ID_WMV1,
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 308
diff changeset
551 sizeof(MpegEncContext),
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 308
diff changeset
552 h263_decode_init,
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 308
diff changeset
553 NULL,
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 308
diff changeset
554 h263_decode_end,
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 308
diff changeset
555 h263_decode_frame,
553
18ad513d92fe direct rendering method 1 support
michaelni
parents: 543
diff changeset
556 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
311
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 308
diff changeset
557 };
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 308
diff changeset
558
498
0b4450c15067 dc scale simplification/optimization
michaelni
parents: 485
diff changeset
559 AVCodec wmv2_decoder = {
0b4450c15067 dc scale simplification/optimization
michaelni
parents: 485
diff changeset
560 "wmv2",
0b4450c15067 dc scale simplification/optimization
michaelni
parents: 485
diff changeset
561 CODEC_TYPE_VIDEO,
0b4450c15067 dc scale simplification/optimization
michaelni
parents: 485
diff changeset
562 CODEC_ID_WMV2,
0b4450c15067 dc scale simplification/optimization
michaelni
parents: 485
diff changeset
563 sizeof(MpegEncContext),
0b4450c15067 dc scale simplification/optimization
michaelni
parents: 485
diff changeset
564 h263_decode_init,
0b4450c15067 dc scale simplification/optimization
michaelni
parents: 485
diff changeset
565 NULL,
0b4450c15067 dc scale simplification/optimization
michaelni
parents: 485
diff changeset
566 h263_decode_end,
0b4450c15067 dc scale simplification/optimization
michaelni
parents: 485
diff changeset
567 h263_decode_frame,
553
18ad513d92fe direct rendering method 1 support
michaelni
parents: 543
diff changeset
568 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
498
0b4450c15067 dc scale simplification/optimization
michaelni
parents: 485
diff changeset
569 };
0b4450c15067 dc scale simplification/optimization
michaelni
parents: 485
diff changeset
570
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
571 AVCodec h263i_decoder = {
986e461dc072 Initial revision
glantau
parents:
diff changeset
572 "h263i",
986e461dc072 Initial revision
glantau
parents:
diff changeset
573 CODEC_TYPE_VIDEO,
986e461dc072 Initial revision
glantau
parents:
diff changeset
574 CODEC_ID_H263I,
986e461dc072 Initial revision
glantau
parents:
diff changeset
575 sizeof(MpegEncContext),
986e461dc072 Initial revision
glantau
parents:
diff changeset
576 h263_decode_init,
986e461dc072 Initial revision
glantau
parents:
diff changeset
577 NULL,
986e461dc072 Initial revision
glantau
parents:
diff changeset
578 h263_decode_end,
986e461dc072 Initial revision
glantau
parents:
diff changeset
579 h263_decode_frame,
553
18ad513d92fe direct rendering method 1 support
michaelni
parents: 543
diff changeset
580 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
581 };
986e461dc072 Initial revision
glantau
parents:
diff changeset
582