comparison h263dec.c @ 655:0018e190cc4c libavcodec

m4v input support return the correct number of bytes consumed for decding h263 like formats (needed for reading raw streams) this could break some divx files with b frames, so please tell me ASAP if u notice any problems
author michaelni
date Thu, 12 Sep 2002 11:10:33 +0000
parents 507e688d57b2
children 8de2081a39ab
comparison
equal deleted inserted replaced
654:850098147a3c 655:0018e190cc4c
108 108
109 MPV_common_end(s); 109 MPV_common_end(s);
110 return 0; 110 return 0;
111 } 111 }
112 112
113 /**
114 * retunrs the number of bytes consumed for building the current frame
115 */
116 static int get_consumed_bytes(MpegEncContext *s, int buf_size){
117 int pos= (get_bits_count(&s->gb)+7)>>3;
118
119 if(s->divx_version>=500){
120 //we would have to scan through the whole buf to handle the weird reordering ...
121 return buf_size;
122 }else{
123 if(pos==0) pos=1; //avoid infinite loops (i doubt thats needed but ...)
124 if(pos>buf_size) pos=buf_size; // oops ;)
125
126 return pos;
127 }
128 }
129
113 static int h263_decode_frame(AVCodecContext *avctx, 130 static int h263_decode_frame(AVCodecContext *avctx,
114 void *data, int *data_size, 131 void *data, int *data_size,
115 UINT8 *buf, int buf_size) 132 UINT8 *buf, int buf_size)
116 { 133 {
117 MpegEncContext *s = avctx->priv_data; 134 MpegEncContext *s = avctx->priv_data;
177 avctx->aspect_ratio_info= s->aspect_ratio_info; 194 avctx->aspect_ratio_info= s->aspect_ratio_info;
178 if (MPV_common_init(s) < 0) 195 if (MPV_common_init(s) < 0)
179 return -1; 196 return -1;
180 } 197 }
181 198
182 if(ret==FRAME_SKIPED) return buf_size; 199 if(ret==FRAME_SKIPED) return get_consumed_bytes(s, buf_size);
183 /* skip if the header was thrashed */ 200 /* skip if the header was thrashed */
184 if (ret < 0){ 201 if (ret < 0){
185 fprintf(stderr, "header damaged\n"); 202 fprintf(stderr, "header damaged\n");
186 return -1; 203 return -1;
187 } 204 }
188 /* skip b frames if we dont have reference frames */ 205 /* skip b frames if we dont have reference frames */
189 if(s->num_available_buffers<2 && s->pict_type==B_TYPE) return buf_size; 206 if(s->num_available_buffers<2 && s->pict_type==B_TYPE) return get_consumed_bytes(s, buf_size);
190 /* skip b frames if we are in a hurry */ 207 /* skip b frames if we are in a hurry */
191 if(s->hurry_up && s->pict_type==B_TYPE) return buf_size; 208 if(s->hurry_up && s->pict_type==B_TYPE) return get_consumed_bytes(s, buf_size);
192 209
193 if(s->next_p_frame_damaged){ 210 if(s->next_p_frame_damaged){
194 if(s->pict_type==B_TYPE) 211 if(s->pict_type==B_TYPE)
195 return buf_size; 212 return get_consumed_bytes(s, buf_size);
196 else 213 else
197 s->next_p_frame_damaged=0; 214 s->next_p_frame_damaged=0;
198 } 215 }
199 216
200 MPV_frame_start(s, avctx); 217 MPV_frame_start(s, avctx);
352 369
353 if (s->h263_msmpeg4 && s->msmpeg4_version<4 && s->pict_type==I_TYPE) 370 if (s->h263_msmpeg4 && s->msmpeg4_version<4 && s->pict_type==I_TYPE)
354 if(msmpeg4_decode_ext_header(s, buf_size) < 0) return -1; 371 if(msmpeg4_decode_ext_header(s, buf_size) < 0) return -1;
355 372
356 /* divx 5.01+ bistream reorder stuff */ 373 /* divx 5.01+ bistream reorder stuff */
357 if(s->codec_id==CODEC_ID_MPEG4 && s->bitstream_buffer_size==0){ 374 if(s->codec_id==CODEC_ID_MPEG4 && s->bitstream_buffer_size==0 && s->divx_version>=500){
358 int current_pos= get_bits_count(&s->gb)>>3; 375 int current_pos= get_bits_count(&s->gb)>>3;
359 376
360 if( buf_size - current_pos > 5 377 if( buf_size - current_pos > 5
361 && buf_size - current_pos < BITSTREAM_BUFFER_SIZE){ 378 && buf_size - current_pos < BITSTREAM_BUFFER_SIZE){
362 int i; 379 int i;
363 int startcode_found=0; 380 int startcode_found=0;
364 for(i=current_pos; i<buf_size; i++){ 381 for(i=current_pos; i<buf_size-3; i++){
365 if(buf[i]==0 && buf[i+1]==0 && buf[i+2]==1 && buf[i+3]==0xB6){ 382 if(buf[i]==0 && buf[i+1]==0 && buf[i+2]==1 && buf[i+3]==0xB6){
366 startcode_found=1; 383 startcode_found=1;
367 break; 384 break;
368 } 385 }
369 } 386 }
452 if(s->num_available_buffers>=2 || (!s->has_b_frames)) 469 if(s->num_available_buffers>=2 || (!s->has_b_frames))
453 *data_size = sizeof(AVPicture); 470 *data_size = sizeof(AVPicture);
454 #ifdef PRINT_FRAME_TIME 471 #ifdef PRINT_FRAME_TIME
455 printf("%Ld\n", rdtsc()-time); 472 printf("%Ld\n", rdtsc()-time);
456 #endif 473 #endif
457 return buf_size; 474 return get_consumed_bytes(s, buf_size);
458 } 475 }
459 476
460 AVCodec mpeg4_decoder = { 477 AVCodec mpeg4_decoder = {
461 "mpeg4", 478 "mpeg4",
462 CODEC_TYPE_VIDEO, 479 CODEC_TYPE_VIDEO,