10l (returning negative number of consumed bytes if the first startcode of a frame was split between 2 buffers)
Originally committed as revision 1824 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
		
							parent
							
								
									7c9375f15a
								
							
						
					
					
						commit
						bb463d8102
					
				@ -2190,7 +2190,7 @@ static int mpeg1_find_frame_end(MpegEncContext *s, uint8_t *buf, int buf_size){
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }        
 | 
					    }        
 | 
				
			||||||
    pc->state= state;
 | 
					    pc->state= state;
 | 
				
			||||||
    return -1;
 | 
					    return END_NOT_FOUND;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* handle buffering and image synchronisation */
 | 
					/* handle buffering and image synchronisation */
 | 
				
			||||||
@ -2218,9 +2218,7 @@ static int mpeg_decode_frame(AVCodecContext *avctx,
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(s2->flags&CODEC_FLAG_TRUNCATED){
 | 
					    if(s2->flags&CODEC_FLAG_TRUNCATED){
 | 
				
			||||||
        int next;
 | 
					        int next= mpeg1_find_frame_end(s2, buf, buf_size);
 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        next= mpeg1_find_frame_end(s2, buf, buf_size);
 | 
					 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        if( ff_combine_frame(s2, next, &buf, &buf_size) < 0 )
 | 
					        if( ff_combine_frame(s2, next, &buf, &buf_size) < 0 )
 | 
				
			||||||
            return buf_size;
 | 
					            return buf_size;
 | 
				
			||||||
@ -2288,7 +2286,7 @@ static int mpeg_decode_frame(AVCodecContext *avctx,
 | 
				
			|||||||
                        if (ret == DECODE_SLICE_EOP) {
 | 
					                        if (ret == DECODE_SLICE_EOP) {
 | 
				
			||||||
                            if(s2->last_picture_ptr) //FIXME merge with the stuff in mpeg_decode_slice
 | 
					                            if(s2->last_picture_ptr) //FIXME merge with the stuff in mpeg_decode_slice
 | 
				
			||||||
                                *data_size = sizeof(AVPicture);
 | 
					                                *data_size = sizeof(AVPicture);
 | 
				
			||||||
                            return FFMAX(1, buf_ptr - buf - s2->parse_context.last_index);
 | 
					                            return FFMAX(0, buf_ptr - buf - s2->parse_context.last_index);
 | 
				
			||||||
                        }else if(ret < 0){
 | 
					                        }else if(ret < 0){
 | 
				
			||||||
                            if(ret == DECODE_SLICE_ERROR)
 | 
					                            if(ret == DECODE_SLICE_ERROR)
 | 
				
			||||||
                                ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x, s2->mb_y, AC_ERROR|DC_ERROR|MV_ERROR);
 | 
					                                ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x, s2->mb_y, AC_ERROR|DC_ERROR|MV_ERROR);
 | 
				
			||||||
 | 
				
			|||||||
@ -2770,17 +2770,33 @@ static void encode_mb(MpegEncContext *s, int motion_x, int motion_y)
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
int ff_combine_frame( MpegEncContext *s, int next, uint8_t **buf, int *buf_size){
 | 
					int ff_combine_frame( MpegEncContext *s, int next, uint8_t **buf, int *buf_size){
 | 
				
			||||||
    ParseContext *pc= &s->parse_context;
 | 
					    ParseContext *pc= &s->parse_context;
 | 
				
			||||||
        
 | 
					
 | 
				
			||||||
 | 
					#if 0
 | 
				
			||||||
 | 
					    if(pc->overread){
 | 
				
			||||||
 | 
					        printf("overread %d, state:%X next:%d index:%d o_index:%d\n", pc->overread, pc->state, next, pc->index, pc->overread_index);
 | 
				
			||||||
 | 
					        printf("%X %X %X %X\n", (*buf)[0], (*buf)[1],(*buf)[2],(*buf)[3]);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* copy overreaded byes from last frame into buffer */
 | 
				
			||||||
 | 
					    for(; pc->overread>0; pc->overread--){
 | 
				
			||||||
 | 
					        pc->buffer[pc->index++]= pc->buffer[pc->overread_index++];
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    pc->last_index= pc->index;
 | 
					    pc->last_index= pc->index;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(next==-1){
 | 
					    /* copy into buffer end return */
 | 
				
			||||||
 | 
					    if(next == END_NOT_FOUND){
 | 
				
			||||||
        pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, (*buf_size) + pc->index + FF_INPUT_BUFFER_PADDING_SIZE);
 | 
					        pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, (*buf_size) + pc->index + FF_INPUT_BUFFER_PADDING_SIZE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        memcpy(&pc->buffer[pc->index], *buf, *buf_size);
 | 
					        memcpy(&pc->buffer[pc->index], *buf, *buf_size);
 | 
				
			||||||
        pc->index += *buf_size;
 | 
					        pc->index += *buf_size;
 | 
				
			||||||
        return -1;
 | 
					        return -1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    pc->overread_index= pc->index + next;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    /* append to buffer */
 | 
				
			||||||
    if(pc->index){
 | 
					    if(pc->index){
 | 
				
			||||||
        pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, next + pc->index + FF_INPUT_BUFFER_PADDING_SIZE);
 | 
					        pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, next + pc->index + FF_INPUT_BUFFER_PADDING_SIZE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -2790,6 +2806,19 @@ int ff_combine_frame( MpegEncContext *s, int next, uint8_t **buf, int *buf_size)
 | 
				
			|||||||
        *buf_size= pc->last_index + next;
 | 
					        *buf_size= pc->last_index + next;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* store overread bytes */
 | 
				
			||||||
 | 
					    for(;next < 0; next++){
 | 
				
			||||||
 | 
					        pc->state = (pc->state<<8) | pc->buffer[pc->last_index + next];
 | 
				
			||||||
 | 
					        pc->overread++;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if 0
 | 
				
			||||||
 | 
					    if(pc->overread){
 | 
				
			||||||
 | 
					        printf("overread %d, state:%X next:%d index:%d o_index:%d\n", pc->overread, pc->state, next, pc->index, pc->overread_index);
 | 
				
			||||||
 | 
					        printf("%X %X %X %X\n", (*buf)[0], (*buf)[1],(*buf)[2],(*buf)[3]);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -205,8 +205,10 @@ typedef struct ParseContext{
 | 
				
			|||||||
    int index;
 | 
					    int index;
 | 
				
			||||||
    int last_index;
 | 
					    int last_index;
 | 
				
			||||||
    int buffer_size;
 | 
					    int buffer_size;
 | 
				
			||||||
    int state;
 | 
					    uint32_t state;             ///< contains the last few bytes in MSB order
 | 
				
			||||||
    int frame_start_found;
 | 
					    int frame_start_found;
 | 
				
			||||||
 | 
					    int overread;               ///< the number of bytes which where irreversibly read from the next frame
 | 
				
			||||||
 | 
					    int overread_index;         ///< the index into ParseContext.buffer of the overreaded bytes
 | 
				
			||||||
} ParseContext;
 | 
					} ParseContext;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct MpegEncContext;
 | 
					struct MpegEncContext;
 | 
				
			||||||
@ -709,6 +711,7 @@ void ff_draw_horiz_band(MpegEncContext *s, int y, int h);
 | 
				
			|||||||
void ff_emulated_edge_mc(MpegEncContext *s, uint8_t *src, int linesize, int block_w, int block_h, 
 | 
					void ff_emulated_edge_mc(MpegEncContext *s, uint8_t *src, int linesize, int block_w, int block_h, 
 | 
				
			||||||
                                    int src_x, int src_y, int w, int h);
 | 
					                                    int src_x, int src_y, int w, int h);
 | 
				
			||||||
char ff_get_pict_type_char(int pict_type);
 | 
					char ff_get_pict_type_char(int pict_type);
 | 
				
			||||||
 | 
					#define END_NOT_FOUND -100
 | 
				
			||||||
int ff_combine_frame( MpegEncContext *s, int next, uint8_t **buf, int *buf_size);
 | 
					int ff_combine_frame( MpegEncContext *s, int next, uint8_t **buf, int *buf_size);
 | 
				
			||||||
void ff_print_debug_info(MpegEncContext *s, Picture *pict);
 | 
					void ff_print_debug_info(MpegEncContext *s, Picture *pict);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user