diff options
Diffstat (limited to 'src/libffmpeg/libavcodec/h263dec.c')
-rw-r--r-- | src/libffmpeg/libavcodec/h263dec.c | 137 |
1 files changed, 39 insertions, 98 deletions
diff --git a/src/libffmpeg/libavcodec/h263dec.c b/src/libffmpeg/libavcodec/h263dec.c index 98215bf4c..efc43cd67 100644 --- a/src/libffmpeg/libavcodec/h263dec.c +++ b/src/libffmpeg/libavcodec/h263dec.c @@ -325,87 +325,56 @@ static int mpeg4_find_frame_end(MpegEncContext *s, uint8_t *buf, int buf_size){ } } } - - for(; i<buf_size; i++){ + + if(vop_found){ + for(; i<buf_size; i++){ state= (state<<8) | buf[i]; if((state&0xFFFFFF00) == 0x100){ pc->frame_start_found=0; pc->state=-1; return i-3; } + } } pc->frame_start_found= vop_found; pc->state= state; - return -1; + return END_NOT_FOUND; } -/** - * draws an line from (ex, ey) -> (sx, sy). - * @param w width of the image - * @param h height of the image - * @param stride stride/linesize of the image - * @param color color of the arrow - */ -static void draw_line(uint8_t *buf, int sx, int sy, int ex, int ey, int w, int h, int stride, int color){ - int t, x, y, f; - - ex= clip(ex, 0, w-1); - ey= clip(ey, 0, h-1); +static int h263_find_frame_end(MpegEncContext *s, uint8_t *buf, int buf_size){ + ParseContext *pc= &s->parse_context; + int vop_found, i; + uint32_t state; - buf[sy*stride + sx]+= color; + vop_found= pc->frame_start_found; + state= pc->state; - if(ABS(ex - sx) > ABS(ey - sy)){ - if(sx > ex){ - t=sx; sx=ex; ex=t; - t=sy; sy=ey; ey=t; - } - buf+= sx + sy*stride; - ex-= sx; - f= ((ey-sy)<<16)/ex; - for(x= 0; x <= ex; x++){ - y= ((x*f) + (1<<15))>>16; - buf[y*stride + x]+= color; - } - }else{ - if(sy > ey){ - t=sx; sx=ex; ex=t; - t=sy; sy=ey; ey=t; - } - buf+= sx + sy*stride; - ey-= sy; - if(ey) f= ((ex-sx)<<16)/ey; - else f= 0; - for(y= 0; y <= ey; y++){ - x= ((y*f) + (1<<15))>>16; - buf[y*stride + x]+= color; + i=0; + if(!vop_found){ + for(i=0; i<buf_size; i++){ + state= (state<<8) | buf[i]; + if(state>>(32-22) == 0x20){ + i++; + vop_found=1; + break; + } } } -} -/** - * draws an arrow from (ex, ey) -> (sx, sy). - * @param w width of the image - * @param h height of the image - * @param stride stride/linesize of the image - * @param color color of the arrow - */ -static void draw_arrow(uint8_t *buf, int sx, int sy, int ex, int ey, int w, int h, int stride, int color){ - int dx= ex - sx; - int dy= ey - sy; - - if(dx*dx + dy*dy > 3*3){ - int rx= dx + dy; - int ry= -dx + dy; - int length= ff_sqrt((rx*rx + ry*ry)<<8); - - //FIXME subpixel accuracy - rx= ROUNDED_DIV(rx*3<<4, length); - ry= ROUNDED_DIV(ry*3<<4, length); - - draw_line(buf, sx, sy, sx + rx, sy + ry, w, h, stride, color); - draw_line(buf, sx, sy, sx - ry, sy + rx, w, h, stride, color); + if(vop_found){ + for(; i<buf_size; i++){ + state= (state<<8) | buf[i]; + if(state>>(32-22) == 0x20){ + pc->frame_start_found=0; + pc->state=-1; + return i-3; + } + } } - draw_line(buf, sx, sy, ex, ey, w, h, stride, color); + pc->frame_start_found= vop_found; + pc->state= state; + + return END_NOT_FOUND; } int ff_h263_decode_frame(AVCodecContext *avctx, @@ -438,6 +407,8 @@ uint64_t time= rdtsc(); if(s->codec_id==CODEC_ID_MPEG4){ next= mpeg4_find_frame_end(s, buf, buf_size); + }else if(s->codec_id==CODEC_ID_H263){ + next= h263_find_frame_end(s, buf, buf_size); }else{ fprintf(stderr, "this codec doesnt support truncated bitstreams\n"); return -1; @@ -700,39 +671,8 @@ retry: MPV_frame_end(s); - if((avctx->debug&FF_DEBUG_VIS_MV) && s->last_picture_ptr){ - const int shift= 1 + s->quarter_sample; - int mb_y; - uint8_t *ptr= s->last_picture.data[0]; - s->low_delay=0; //needed to see the vectors without trashing the buffers - - for(mb_y=0; mb_y<s->mb_height; mb_y++){ - int mb_x; - for(mb_x=0; mb_x<s->mb_width; mb_x++){ - const int mb_index= mb_x + mb_y*s->mb_stride; - if(IS_8X8(s->current_picture.mb_type[mb_index])){ - int i; - for(i=0; i<4; i++){ - int sx= mb_x*16 + 4 + 8*(i&1); - int sy= mb_y*16 + 4 + 8*(i>>1); - int xy= 1 + mb_x*2 + (i&1) + (mb_y*2 + 1 + (i>>1))*(s->mb_width*2 + 2); - int mx= (s->motion_val[xy][0]>>shift) + sx; - int my= (s->motion_val[xy][1]>>shift) + sy; - draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100); - } - }else{ - int sx= mb_x*16 + 8; - int sy= mb_y*16 + 8; - int xy= 1 + mb_x*2 + (mb_y*2 + 1)*(s->mb_width*2 + 2); - int mx= (s->motion_val[xy][0]>>shift) + sx; - int my= (s->motion_val[xy][1]>>shift) + sy; - draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100); - } - s->mbskip_table[mb_index]=0; - } - } - } - +assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type); +assert(s->current_picture.pict_type == s->pict_type); if(s->pict_type==B_TYPE || s->low_delay){ *pict= *(AVFrame*)&s->current_picture; ff_print_debug_info(s, s->current_picture_ptr); @@ -751,6 +691,7 @@ retry: #ifdef PRINT_FRAME_TIME printf("%Ld\n", rdtsc()-time); #endif + return get_consumed_bytes(s, buf_size); } @@ -782,7 +723,7 @@ AVCodec h263_decoder = { NULL, ff_h263_decode_end, ff_h263_decode_frame, - CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, + CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED, }; AVCodec msmpeg4v1_decoder = { |