Update of /cvsroot/xine/xine-lib/src/libffmpeg/libavcodec In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4051/libavcodec Modified Files: 4xm.c Makefile.am asv1.c avcodec.h cinepak.c common.h cyuv.c dsputil.c dsputil.h dv.c h263.c h263dec.c h264.c huffyuv.c mdec.c mjpeg.c motion_est.c mpeg12.c mpeg12data.h mpegvideo.c mpegvideo.h svq1.c svq1_cb.h svq1_vlc.h utils.c vcr1.c vp3.c vp3dsp.c Added Files: integer.c integer.h parser.c Log Message: sync --- NEW FILE: integer.c --- /* * arbitrary precision integers * Copyright (c) 2004 Michael Niedermayer <mic...@gm...> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /** * @file integer.c * arbitrary precision integers. * @author Michael Niedermayer <mic...@gm...> */ #include "common.h" #include "integer.h" AVInteger av_add_i(AVInteger a, AVInteger b){ int i, carry=0; for(i=0; i<AV_INTEGER_SIZE; i++){ carry= (carry>>16) + a.v[i] + b.v[i]; a.v[i]= carry; } return a; } AVInteger av_sub_i(AVInteger a, AVInteger b){ int i, carry=0; for(i=0; i<AV_INTEGER_SIZE; i++){ carry= (carry>>16) + a.v[i] - b.v[i]; a.v[i]= carry; } return a; } int av_log2_i(AVInteger a){ int i; for(i=AV_INTEGER_SIZE-1; i>=0; i--){ if(a.v[i]) return av_log2_16bit(a.v[i]) + 16*i; } return -1; } AVInteger av_mul_i(AVInteger a, AVInteger b){ AVInteger out; int i, j; int na= (av_log2_i(a)+16) >> 4; int nb= (av_log2_i(b)+16) >> 4; memset(&out, 0, sizeof(out)); for(i=0; i<na; i++){ unsigned int carry=0; if(a.v[i]) for(j=i; j<AV_INTEGER_SIZE && j-i<=nb; j++){ carry= (carry>>16) + out.v[j] + a.v[i]*b.v[j-i]; out.v[j]= carry; } } return out; } int av_cmp_i(AVInteger a, AVInteger b){ int i; int v= (int16_t)a.v[AV_INTEGER_SIZE-1] - (int16_t)b.v[AV_INTEGER_SIZE-1]; if(v) return (v>>16)|1; for(i=AV_INTEGER_SIZE-2; i>=0; i--){ int v= a.v[i] - b.v[i]; if(v) return (v>>16)|1; } return 0; } AVInteger av_shr_i(AVInteger a, int s){ AVInteger out; int i; for(i=0; i<AV_INTEGER_SIZE; i++){ int index= i + (s>>4); unsigned int v=0; if(index+1<AV_INTEGER_SIZE && index+1>=0) v = a.v[index+1]<<16; if(index <AV_INTEGER_SIZE && index >=0) v+= a.v[index ]; out.v[i]= v >> (s&15); } return out; } AVInteger av_mod_i(AVInteger *quot, AVInteger a, AVInteger b){ int i= av_log2_i(a) - av_log2_i(b); AVInteger quot_temp; if(!quot) quot = "_temp; assert((int16_t)a[AV_INTEGER_SIZE-1] >= 0 && (int16_t)b[AV_INTEGER_SIZE-1] >= 0); assert(av_log2(b)>=0); if(i > 0) b= av_shr_i(b, -i); memset(quot, 0, sizeof(AVInteger)); while(i-- >= 0){ *quot= av_shr_i(*quot, -1); if(av_cmp_i(a, b) >= 0){ a= av_sub_i(a, b); quot->v[0] += 1; } b= av_shr_i(b, 1); } return a; } AVInteger av_div_i(AVInteger a, AVInteger b){ AVInteger quot; av_mod_i(", a, b); return quot; } AVInteger av_int2i(int64_t a){ AVInteger out; int i; for(i=0; i<AV_INTEGER_SIZE; i++){ out.v[i]= a; a>>=16; } return out; } int64_t av_i2int(AVInteger a){ int i; int64_t out=(int8_t)a.v[AV_INTEGER_SIZE-1]; for(i= AV_INTEGER_SIZE-2; i>=0; i--){ out = (out<<16) + a.v[i]; } return out; } #if 0 #undef NDEBUG #include <assert.h> const uint8_t ff_log2_tab[256]={ 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 }; main(){ int64_t a,b; for(a=7; a<256*256*256; a+=13215){ for(b=3; b<256*256*256; b+=27118){ AVInteger ai= av_int2i(a); AVInteger bi= av_int2i(b); assert(av_i2int(ai) == a); assert(av_i2int(bi) == b); assert(av_i2int(av_add_i(ai,bi)) == a+b); assert(av_i2int(av_sub_i(ai,bi)) == a-b); assert(av_i2int(av_mul_i(ai,bi)) == a*b); assert(av_i2int(av_shr_i(ai, 9)) == a>>9); assert(av_i2int(av_shr_i(ai,-9)) == a<<9); assert(av_i2int(av_shr_i(ai, 17)) == a>>17); assert(av_i2int(av_shr_i(ai,-17)) == a<<17); assert(av_log2_i(ai) == av_log2(a)); assert(av_i2int(av_div_i(ai,bi)) == a/b); } } } #endif --- NEW FILE: integer.h --- /* * arbitrary precision integers * Copyright (c) 2004 Michael Niedermayer <mic...@gm...> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /** * @file integer.h * arbitrary precision integers * @author Michael Niedermayer <mic...@gm...> */ #ifndef INTEGER_H #define INTEGER_H #define AV_INTEGER_SIZE 8 typedef struct AVInteger{ uint16_t v[AV_INTEGER_SIZE]; } AVInteger; AVInteger av_add_i(AVInteger a, AVInteger b); AVInteger av_sub_i(AVInteger a, AVInteger b); int av_log2_i(AVInteger a); AVInteger av_mul_i(AVInteger a, AVInteger b); int av_cmp_i(AVInteger a, AVInteger b); AVInteger av_shr_i(AVInteger a, int s); AVInteger av_mod_i(AVInteger *quot, AVInteger a, AVInteger b); AVInteger av_div_i(AVInteger a, AVInteger b); AVInteger av_int2i(int64_t a); int64_t av_i2int(AVInteger a); #endif // INTEGER_H --- NEW FILE: parser.c --- /* * Audio and Video frame extraction * Copyright (c) 2003 Fabrice Bellard. * Copyright (c) 2003 Michael Niedermayer. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "avcodec.h" #include "mpegvideo.h" #include "mpegaudio.h" AVCodecParser *av_first_parser = NULL; void av_register_codec_parser(AVCodecParser *parser) { parser->next = av_first_parser; av_first_parser = parser; } AVCodecParserContext *av_parser_init(int codec_id) { AVCodecParserContext *s; AVCodecParser *parser; int ret; for(parser = av_first_parser; parser != NULL; parser = parser->next) { if (parser->codec_ids[0] == codec_id || parser->codec_ids[1] == codec_id || parser->codec_ids[2] == codec_id) goto found; } return NULL; found: s = av_mallocz(sizeof(AVCodecParserContext)); if (!s) return NULL; s->parser = parser; s->priv_data = av_mallocz(parser->priv_data_size); if (!s->priv_data) { av_free(s); return NULL; } if (parser->parser_init) { ret = parser->parser_init(s); if (ret != 0) { av_free(s->priv_data); av_free(s); return NULL; } } return s; } /* NOTE: buf_size == 0 is used to signal EOF so that the last frame can be returned if necessary */ int av_parser_parse(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int64_t pts, int64_t dts) { int index, i, k; uint8_t dummy_buf[FF_INPUT_BUFFER_PADDING_SIZE]; if (buf_size == 0) { /* padding is always necessary even if EOF, so we add it here */ memset(dummy_buf, 0, sizeof(dummy_buf)); buf = dummy_buf; } else { /* add a new packet descriptor */ k = (s->cur_frame_start_index + 1) & (AV_PARSER_PTS_NB - 1); s->cur_frame_start_index = k; s->cur_frame_offset[k] = s->cur_offset; s->cur_frame_pts[k] = pts; s->cur_frame_dts[k] = dts; /* fill first PTS/DTS */ if (s->cur_offset == 0) { s->last_pts = pts; s->last_dts = dts; } } /* WARNING: the returned index can be negative */ index = s->parser->parser_parse(s, avctx, poutbuf, poutbuf_size, buf, buf_size); /* update the file pointer */ if (*poutbuf_size) { /* fill the data for the current frame */ s->frame_offset = s->last_frame_offset; s->pts = s->last_pts; s->dts = s->last_dts; /* offset of the next frame */ s->last_frame_offset = s->cur_offset + index; /* find the packet in which the new frame starts. It is tricky because of MPEG video start codes which can begin in one packet and finish in another packet. In the worst case, an MPEG video start code could be in 4 different packets. */ k = s->cur_frame_start_index; for(i = 0; i < AV_PARSER_PTS_NB; i++) { if (s->last_frame_offset >= s->cur_frame_offset[k]) break; k = (k - 1) & (AV_PARSER_PTS_NB - 1); } s->last_pts = s->cur_frame_pts[k]; s->last_dts = s->cur_frame_dts[k]; } if (index < 0) index = 0; s->cur_offset += index; return index; } void av_parser_close(AVCodecParserContext *s) { if (s->parser->parser_close) s->parser->parser_close(s); av_free(s->priv_data); av_free(s); } /*****************************************************/ //#define END_NOT_FOUND (-100) #define PICTURE_START_CODE 0x00000100 #define SEQ_START_CODE 0x000001b3 #define EXT_START_CODE 0x000001b5 #define SLICE_MIN_START_CODE 0x00000101 #define SLICE_MAX_START_CODE 0x000001af typedef struct ParseContext1{ ParseContext pc; /* XXX/FIXME PC1 vs. PC */ /* MPEG2 specific */ int frame_rate; int progressive_sequence; int width, height; /* XXX: suppress that, needed by MPEG4 */ MpegEncContext *enc; int first_picture; } ParseContext1; /** * combines the (truncated) bitstream to a complete frame * @returns -1 if no complete frame could be created */ int ff_combine_frame(ParseContext *pc, int next, uint8_t **buf, int *buf_size) { #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 bytes 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; /* 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); memcpy(&pc->buffer[pc->index], *buf, *buf_size); pc->index += *buf_size; return -1; } *buf_size= pc->overread_index= pc->index + next; /* append to buffer */ if(pc->index){ pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, next + pc->index + FF_INPUT_BUFFER_PADDING_SIZE); memcpy(&pc->buffer[pc->index], *buf, next + FF_INPUT_BUFFER_PADDING_SIZE ); pc->index = 0; *buf= pc->buffer; } /* 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; } static int find_start_code(const uint8_t **pbuf_ptr, const uint8_t *buf_end) { const uint8_t *buf_ptr; unsigned int state=0xFFFFFFFF, v; int val; buf_ptr = *pbuf_ptr; while (buf_ptr < buf_end) { v = *buf_ptr++; if (state == 0x000001) { state = ((state << 8) | v) & 0xffffff; val = state; goto found; } state = ((state << 8) | v) & 0xffffff; } val = -1; found: *pbuf_ptr = buf_ptr; return val; } /* XXX: merge with libavcodec ? */ #define MPEG1_FRAME_RATE_BASE 1001 static const int frame_rate_tab[16] = { 0, 24000, 24024, 25025, 30000, 30030, 50050, 60000, 60060, // Xing's 15fps: (9) 15015, // libmpeg3's "Unofficial economy rates": (10-13) 5005, 10010, 12012, 15015, // random, just to avoid segfault !never encode these 25025, 25025, }; static void mpegvideo_extract_headers(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t *buf, int buf_size) { ParseContext1 *pc = s->priv_data; const uint8_t *buf_end; int32_t start_code; int frame_rate_index, ext_type, bytes_left; int frame_rate_ext_n, frame_rate_ext_d; int top_field_first, repeat_first_field, progressive_frame; int horiz_size_ext, vert_size_ext; s->repeat_pict = 0; buf_end = buf + buf_size; while (buf < buf_end) { start_code = find_start_code(&buf, buf_end); bytes_left = buf_end - buf; switch(start_code) { case PICTURE_START_CODE: if (bytes_left >= 2) { s->pict_type = (buf[1] >> 3) & 7; } break; case SEQ_START_CODE: if (bytes_left >= 4) { pc->width = avctx->width = (buf[0] << 4) | (buf[1] >> 4); pc->height = avctx->height = ((buf[1] & 0x0f) << 8) | buf[2]; frame_rate_index = buf[3] & 0xf; pc->frame_rate = avctx->frame_rate = frame_rate_tab[frame_rate_index]; avctx->frame_rate_base = MPEG1_FRAME_RATE_BASE; avctx->codec_id = CODEC_ID_MPEG1VIDEO; avctx->sub_id = 1; } break; case EXT_START_CODE: if (bytes_left >= 1) { ext_type = (buf[0] >> 4); switch(ext_type) { case 0x1: /* sequence extension */ if (bytes_left >= 6) { horiz_size_ext = ((buf[1] & 1) << 1) | (buf[2] >> 7); vert_size_ext = (buf[2] >> 5) & 3; frame_rate_ext_n = (buf[5] >> 5) & 3; frame_rate_ext_d = (buf[5] & 0x1f); pc->progressive_sequence = buf[1] & (1 << 3); avctx->width = pc->width | (horiz_size_ext << 12); avctx->height = pc->height | (vert_size_ext << 12); avctx->frame_rate = pc->frame_rate * (frame_rate_ext_n + 1); avctx->frame_rate_base = MPEG1_FRAME_RATE_BASE * (frame_rate_ext_d + 1); avctx->codec_id = CODEC_ID_MPEG2VIDEO; avctx->sub_id = 2; /* forces MPEG2 */ } break; case 0x8: /* picture coding extension */ if (bytes_left >= 5) { top_field_first = buf[3] & (1 << 7); repeat_first_field = buf[3] & (1 << 1); progressive_frame = buf[4] & (1 << 7); /* check if we must repeat the frame */ if (repeat_first_field) { if (pc->progressive_sequence) { if (top_field_first) s->repeat_pict = 4; else s->repeat_pict = 2; } else if (progressive_frame) { s->repeat_pict = 1; } } } break; } } break; case -1: goto the_end; default: /* we stop parsing when we encounter a slice. It ensures that this function takes a negligible amount of time */ if (start_code >= SLICE_MIN_START_CODE && start_code <= SLICE_MAX_START_CODE) goto the_end; break; } } the_end: ; } static int mpegvideo_parse(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size) { ParseContext1 *pc1 = s->priv_data; ParseContext *pc= &pc1->pc; int next; next= ff_mpeg1_find_frame_end(pc, buf, buf_size); if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) { *poutbuf = NULL; *poutbuf_size = 0; return buf_size; } /* we have a full frame : we just parse the first few MPEG headers to have the full timing information. The time take by this function should be negligible for uncorrupted streams */ mpegvideo_extract_headers(s, avctx, buf, buf_size); #if 0 printf("pict_type=%d frame_rate=%0.3f repeat_pict=%d\n", s->pict_type, (double)avctx->frame_rate / avctx->frame_rate_base, s->repeat_pict); #endif *poutbuf = (uint8_t *)buf; *poutbuf_size = buf_size; return next; } void ff_parse_close(AVCodecParserContext *s) { ParseContext *pc = s->priv_data; av_free(pc->buffer); } static void parse1_close(AVCodecParserContext *s) { ParseContext1 *pc1 = s->priv_data; av_free(pc1->pc.buffer); av_free(pc1->enc); } /*************************/ /* used by parser */ /* XXX: make it use less memory */ static int av_mpeg4_decode_header(AVCodecParserContext *s1, AVCodecContext *avctx, const uint8_t *buf, int buf_size) { ParseContext1 *pc = s1->priv_data; MpegEncContext *s = pc->enc; GetBitContext gb1, *gb = &gb1; int ret; s->avctx = avctx; s->current_picture_ptr = &s->current_picture; if (avctx->extradata_size && pc->first_picture){ init_get_bits(gb, avctx->extradata, avctx->extradata_size*8); ret = ff_mpeg4_decode_picture_header(s, gb); } init_get_bits(gb, buf, 8 * buf_size); ret = ff_mpeg4_decode_picture_header(s, gb); if (s->width) { avctx->width = s->width; avctx->height = s->height; } pc->first_picture = 0; return ret; } int mpeg4video_parse_init(AVCodecParserContext *s) { ParseContext1 *pc = s->priv_data; pc->enc = av_mallocz(sizeof(MpegEncContext)); if (!pc->enc) return -1; pc->first_picture = 1; return 0; } static int mpeg4video_parse(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size) { ParseContext *pc = s->priv_data; int next; next= ff_mpeg4_find_frame_end(pc, buf, buf_size); if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) { *poutbuf = NULL; *poutbuf_size = 0; return buf_size; } av_mpeg4_decode_header(s, avctx, buf, buf_size); *poutbuf = (uint8_t *)buf; *poutbuf_size = buf_size; return next; } /*************************/ typedef struct MpegAudioParseContext { uint8_t inbuf[MPA_MAX_CODED_FRAME_SIZE]; /* input buffer */ uint8_t *inbuf_ptr; int frame_size; int free_format_frame_size; int free_format_next_header; } MpegAudioParseContext; #define MPA_HEADER_SIZE 4 /* header + layer + bitrate + freq + lsf/mpeg25 */ #define SAME_HEADER_MASK \ (0xffe00000 | (3 << 17) | (0xf << 12) | (3 << 10) | (3 << 19)) static int mpegaudio_parse_init(AVCodecParserContext *s1) { MpegAudioParseContext *s = s1->priv_data; s->inbuf_ptr = s->inbuf; return 0; } static int mpegaudio_parse(AVCodecParserContext *s1, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size) { MpegAudioParseContext *s = s1->priv_data; int len, ret; uint32_t header; const uint8_t *buf_ptr; *poutbuf = NULL; *poutbuf_size = 0; buf_ptr = buf; while (buf_size > 0) { len = s->inbuf_ptr - s->inbuf; if (s->frame_size == 0) { /* special case for next header for first frame in free format case (XXX: find a simpler method) */ if (s->free_format_next_header != 0) { s->inbuf[0] = s->free_format_next_header >> 24; s->inbuf[1] = s->free_format_next_header >> 16; s->inbuf[2] = s->free_format_next_header >> 8; s->inbuf[3] = s->free_format_next_header; s->inbuf_ptr = s->inbuf + 4; s->free_format_next_header = 0; goto got_header; } /* no header seen : find one. We need at least MPA_HEADER_SIZE bytes to parse it */ len = MPA_HEADER_SIZE - len; if (len > buf_size) len = buf_size; if (len > 0) { memcpy(s->inbuf_ptr, buf_ptr, len); buf_ptr += len; buf_size -= len; s->inbuf_ptr += len; } if ((s->inbuf_ptr - s->inbuf) >= MPA_HEADER_SIZE) { got_header: header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) | (s->inbuf[2] << 8) | s->inbuf[3]; ret = mpa_decode_header(avctx, header); if (ret < 0) { /* no sync found : move by one byte (inefficient, but simple!) */ memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1); s->inbuf_ptr--; dprintf("skip %x\n", header); /* reset free format frame size to give a chance to get a new bitrate */ s->free_format_frame_size = 0; } else { s->frame_size = ret; #if 0 /* free format: prepare to compute frame size */ if (decode_header(s, header) == 1) { s->frame_size = -1; } #endif } } } else #if 0 if (s->frame_size == -1) { /* free format : find next sync to compute frame size */ len = MPA_MAX_CODED_FRAME_SIZE - len; if (len > buf_size) len = buf_size; if (len == 0) { /* frame too long: resync */ s->frame_size = 0; memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1); s->inbuf_ptr--; } else { uint8_t *p, *pend; uint32_t header1; int padding; memcpy(s->inbuf_ptr, buf_ptr, len); /* check for header */ p = s->inbuf_ptr - 3; pend = s->inbuf_ptr + len - 4; while (p <= pend) { header = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; header1 = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) | (s->inbuf[2] << 8) | s->inbuf[3]; /* check with high probability that we have a valid header */ if ((header & SAME_HEADER_MASK) == (header1 & SAME_HEADER_MASK)) { /* header found: update pointers */ len = (p + 4) - s->inbuf_ptr; buf_ptr += len; buf_size -= len; s->inbuf_ptr = p; /* compute frame size */ s->free_format_next_header = header; s->free_format_frame_size = s->inbuf_ptr - s->inbuf; padding = (header1 >> 9) & 1; if (s->layer == 1) s->free_format_frame_size -= padding * 4; else s->free_format_frame_size -= padding; dprintf("free frame size=%d padding=%d\n", s->free_format_frame_size, padding); decode_header(s, header1); goto next_data; } p++; } /* not found: simply increase pointers */ buf_ptr += len; s->inbuf_ptr += len; buf_size -= len; } } else #endif if (len < s->frame_size) { if (s->frame_size > MPA_MAX_CODED_FRAME_SIZE) s->frame_size = MPA_MAX_CODED_FRAME_SIZE; len = s->frame_size - len; if (len > buf_size) len = buf_size; memcpy(s->inbuf_ptr, buf_ptr, len); buf_ptr += len; s->inbuf_ptr += len; buf_size -= len; } // next_data: if (s->frame_size > 0 && (s->inbuf_ptr - s->inbuf) >= s->frame_size) { *poutbuf = s->inbuf; *poutbuf_size = s->inbuf_ptr - s->inbuf; s->inbuf_ptr = s->inbuf; s->frame_size = 0; break; } } return buf_ptr - buf; } #ifdef CONFIG_AC3 extern int a52_syncinfo (const uint8_t * buf, int * flags, int * sample_rate, int * bit_rate); typedef struct AC3ParseContext { uint8_t inbuf[4096]; /* input buffer */ uint8_t *inbuf_ptr; int frame_size; int flags; } AC3ParseContext; #define AC3_HEADER_SIZE 7 #define A52_LFE 16 static int ac3_parse_init(AVCodecParserContext *s1) { AC3ParseContext *s = s1->priv_data; s->inbuf_ptr = s->inbuf; return 0; } static int ac3_parse(AVCodecParserContext *s1, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size) { AC3ParseContext *s = s1->priv_data; const uint8_t *buf_ptr; int len, sample_rate, bit_rate; static const int ac3_channels[8] = { 2, 1, 2, 3, 3, 4, 4, 5 }; *poutbuf = NULL; *poutbuf_size = 0; buf_ptr = buf; while (buf_size > 0) { len = s->inbuf_ptr - s->inbuf; if (s->frame_size == 0) { /* no header seen : find one. We need at least 7 bytes to parse it */ len = AC3_HEADER_SIZE - len; if (len > buf_size) len = buf_size; memcpy(s->inbuf_ptr, buf_ptr, len); buf_ptr += len; s->inbuf_ptr += len; buf_size -= len; if ((s->inbuf_ptr - s->inbuf) == AC3_HEADER_SIZE) { len = a52_syncinfo(s->inbuf, &s->flags, &sample_rate, &bit_rate); if (len == 0) { /* no sync found : move by one byte (inefficient, but simple!) */ memmove(s->inbuf, s->inbuf + 1, AC3_HEADER_SIZE - 1); s->inbuf_ptr--; } else { s->frame_size = len; /* update codec info */ avctx->sample_rate = sample_rate; /* set channels,except if the user explicitly requests 1 or 2 channels, XXX/FIXME this is a bit ugly */ if(avctx->channels!=1 && avctx->channels!=2){ avctx->channels = ac3_channels[s->flags & 7]; if (s->flags & A52_LFE) avctx->channels++; } avctx->bit_rate = bit_rate; avctx->frame_size = 6 * 256; } } } else if (len < s->frame_size) { len = s->frame_size - len; if (len > buf_size) len = buf_size; memcpy(s->inbuf_ptr, buf_ptr, len); buf_ptr += len; s->inbuf_ptr += len; buf_size -= len; } else { *poutbuf = s->inbuf; *poutbuf_size = s->frame_size; s->inbuf_ptr = s->inbuf; s->frame_size = 0; break; } } return buf_ptr - buf; } #endif AVCodecParser mpegvideo_parser = { { CODEC_ID_MPEG1VIDEO, CODEC_ID_MPEG2VIDEO }, sizeof(ParseContext1), NULL, mpegvideo_parse, parse1_close, }; AVCodecParser mpeg4video_parser = { { CODEC_ID_MPEG4 }, sizeof(ParseContext1), mpeg4video_parse_init, mpeg4video_parse, parse1_close, }; AVCodecParser mpegaudio_parser = { { CODEC_ID_MP2, CODEC_ID_MP3 }, sizeof(MpegAudioParseContext), mpegaudio_parse_init, mpegaudio_parse, NULL, }; #ifdef CONFIG_AC3 AVCodecParser ac3_parser = { { CODEC_ID_AC3 }, sizeof(AC3ParseContext), ac3_parse_init, ac3_parse, NULL, }; #endif Index: 4xm.c =================================================================== RCS file: /cvsroot/xine/xine-lib/src/libffmpeg/libavcodec/4xm.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- 4xm.c 1 Feb 2004 05:31:16 -0000 1.3 +++ 4xm.c 9 May 2004 23:31:59 -0000 1.4 @@ -738,8 +738,6 @@ } free_vlc(&f->pre_vlc); - avcodec_default_free_buffers(avctx); - return 0; } Index: Makefile.am =================================================================== RCS file: /cvsroot/xine/xine-lib/src/libffmpeg/libavcodec/Makefile.am,v retrieving revision 1.56 retrieving revision 1.57 diff -u -r1.56 -r1.57 --- Makefile.am 25 Apr 2004 18:58:17 -0000 1.56 +++ Makefile.am 9 May 2004 23:31:59 -0000 1.57 @@ -36,6 +36,7 @@ idcinvideo.c \ imgconvert.c \ indeo3.c \ + integer.c \ interplayvideo.c \ jfdctfst.c \ jfdctint.c \ @@ -53,6 +54,7 @@ msrle.c \ msvideo1.c \ opts.c \ + parser.c \ pcm.c \ qtrle.c \ ra144.c \ @@ -96,6 +98,7 @@ golomb.h \ imgconvert_template.h \ indeo3data.h \ + integer.h \ h263data.h \ h264data.h \ mangle.h \ Index: asv1.c =================================================================== RCS file: /cvsroot/xine/xine-lib/src/libffmpeg/libavcodec/asv1.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- asv1.c 14 Mar 2004 21:14:08 -0000 1.4 +++ asv1.c 9 May 2004 23:31:59 -0000 1.5 @@ -613,8 +613,6 @@ av_freep(&a->picture.qscale_table); a->bitstream_buffer_size=0; - avcodec_default_free_buffers(avctx); - return 0; } Index: avcodec.h =================================================================== RCS file: /cvsroot/xine/xine-lib/src/libffmpeg/libavcodec/avcodec.h,v retrieving revision 1.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- avcodec.h 25 Apr 2004 18:58:17 -0000 1.33 +++ avcodec.h 9 May 2004 23:31:59 -0000 1.34 @@ -24,7 +24,7 @@ #define FFMPEG_VERSION_INT 0x000408 #define FFMPEG_VERSION "0.4.8" -#define LIBAVCODEC_BUILD 4710 +#define LIBAVCODEC_BUILD 4713 #define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT #define LIBAVCODEC_VERSION FFMPEG_VERSION @@ -848,6 +848,7 @@ #define FF_BUG_XVID_ILACE 4 #define FF_BUG_UMP4 8 #define FF_BUG_NO_PADDING 16 +#define FF_BUG_AMV 32 #define FF_BUG_AC_VLC 0 ///< will be removed, libavcodec can now handle these non compliant files by default #define FF_BUG_QPEL_CHROMA 64 #define FF_BUG_STD_QPEL 128 @@ -855,6 +856,7 @@ #define FF_BUG_DIRECT_BLOCKSIZE 512 #define FF_BUG_EDGE 1024 #define FF_BUG_HPEL_CHROMA 2048 +#define FF_BUG_DC_CLIP 4096 //#define FF_BUG_FAKE_SCALABILITY 16 //autodetection should work 100% /** @@ -1591,6 +1593,13 @@ * - decoding: unused */ int mb_threshold; + + /** + * + * - encoding: set by user + * - decoding: unused + */ + int intra_dc_precision; } AVCodecContext; @@ -1717,6 +1726,7 @@ extern AVCodec ffv1_encoder; extern AVCodec mdec_encoder; extern AVCodec zlib_encoder; +extern AVCodec svq1_encoder; extern AVCodec h263_decoder; extern AVCodec mpeg4_decoder; @@ -1934,7 +1944,6 @@ int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic); void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic); -void avcodec_default_free_buffers(AVCodecContext *s); int avcodec_thread_init(AVCodecContext *s, int thread_count); void avcodec_thread_free(AVCodecContext *s); @@ -1986,7 +1995,7 @@ * rescale a 64bit integer. * a simple a*b/c isnt possible as it can overflow */ -int64_t av_rescale(int64_t a, int b, int c); +int64_t av_rescale(int64_t a, int64_t b, int64_t c); /** Index: cinepak.c =================================================================== RCS file: /cvsroot/xine/xine-lib/src/libffmpeg/libavcodec/cinepak.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- cinepak.c 14 Mar 2004 21:14:08 -0000 1.4 +++ cinepak.c 9 May 2004 23:31:59 -0000 1.5 @@ -57,7 +57,6 @@ AVCodecContext *avctx; DSPContext dsp; AVFrame frame; - AVFrame prev_frame; unsigned char *data; int size; @@ -125,7 +124,7 @@ uint8_t *eod = (data + size); uint32_t flag, mask; cvid_codebook_t *codebook; - unsigned int i, j, x, y; + unsigned int x, y; uint32_t iy[4]; uint32_t iu[2]; uint32_t iv[2]; @@ -250,22 +249,6 @@ } } - } else { - /* copy from the previous frame */ - for (i = 0; i < 4; i++) { - for (j = 0; j < 4; j++) { - s->frame.data[0][iy[i] + j] = - s->prev_frame.data[0][iy[i] + j]; - } - } - for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++) { - s->frame.data[1][iu[i] + j] = - s->prev_frame.data[1][iu[i] + j]; - s->frame.data[2][iv[i] + j] = - s->prev_frame.data[2][iv[i] + j]; - } - } } iy[0] += 4; iy[1] += 4; @@ -397,7 +380,7 @@ avctx->has_b_frames = 0; dsputil_init(&s->dsp, avctx); - s->frame.data[0] = s->prev_frame.data[0] = NULL; + s->frame.data[0] = NULL; return 0; } @@ -411,19 +394,16 @@ s->data = buf; s->size = buf_size; - if (avctx->get_buffer(avctx, &s->frame)) { - av_log(avctx, AV_LOG_ERROR, " Cinepak: get_buffer() failed\n"); + s->frame.reference = 1; + s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | + FF_BUFFER_HINTS_REUSABLE; + if (avctx->reget_buffer(avctx, &s->frame)) { + av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); return -1; } cinepak_decode(s); - if (s->prev_frame.data[0]) - avctx->release_buffer(avctx, &s->prev_frame); - - /* shuffle frames */ - s->prev_frame = s->frame; - *data_size = sizeof(AVFrame); *(AVFrame*)data = s->frame; @@ -435,8 +415,8 @@ { CinepakContext *s = (CinepakContext *)avctx->priv_data; - if (s->prev_frame.data[0]) - avctx->release_buffer(avctx, &s->prev_frame); + if (s->frame.data[0]) + avctx->release_buffer(avctx, &s->frame); return 0; } Index: common.h =================================================================== RCS file: /cvsroot/xine/xine-lib/src/libffmpeg/libavcodec/common.h,v retrieving revision 1.36 retrieving revision 1.37 diff -u -r1.36 -r1.37 --- common.h 25 Apr 2004 18:58:30 -0000 1.36 +++ common.h 9 May 2004 23:31:59 -0000 1.37 @@ -81,17 +81,21 @@ # define restrict #endif +#ifndef always_inline #if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0) # define always_inline __attribute__((always_inline)) inline #else # define always_inline inline #endif +#endif +#ifndef attribute_used #if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0) # define attribute_used __attribute__((used)) #else # define attribute_used #endif +#endif #ifndef EMULATE_INTTYPES # include <inttypes.h> Index: cyuv.c =================================================================== RCS file: /cvsroot/xine/xine-lib/src/libffmpeg/libavcodec/cyuv.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- cyuv.c 1 Feb 2004 05:31:16 -0000 1.3 +++ cyuv.c 9 May 2004 23:31:59 -0000 1.4 @@ -100,6 +100,7 @@ if(s->frame.data[0]) avctx->release_buffer(avctx, &s->frame); + s->frame.buffer_hints = FF_BUFFER_HINTS_VALID; s->frame.reference = 0; if(avctx->get_buffer(avctx, &s->frame) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); @@ -180,7 +181,7 @@ NULL, cyuv_decode_end, cyuv_decode_frame, - 0, + CODEC_CAP_DR1, NULL }; Index: dsputil.c =================================================================== RCS file: /cvsroot/xine/xine-lib/src/libffmpeg/libavcodec/dsputil.c,v retrieving revision 1.35 retrieving revision 1.36 diff -u -r1.35 -r1.36 --- dsputil.c 25 Apr 2004 18:58:31 -0000 1.35 +++ dsputil.c 9 May 2004 23:31:59 -0000 1.36 @@ -332,6 +332,27 @@ } } +static void put_signed_pixels_clamped_c(const DCTELEM *block, + uint8_t *restrict pixels, + int line_size) +{ + int i, j; + + for (i = 0; i < 8; i++) { + for (j = 0; j < 8; j++) { + if (*block < -128) + *pixels = 0; + else if (*block > 127) + *pixels = 255; + else + *pixels = (uint8_t)(*block + 128); + block++; + pixels++; + } + pixels += (line_size - 8); + } +} + static void add_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels, int line_size) { @@ -3126,12 +3147,12 @@ /* VP3 DSP support */ c->vp3_dsp_init = vp3_dsp_init_c; - c->vp3_idct_put = vp3_idct_put_c; - c->vp3_idct_add = vp3_idct_add_c; + c->vp3_idct = vp3_idct_c; c->get_pixels = get_pixels_c; c->diff_pixels = diff_pixels_c; c->put_pixels_clamped = put_pixels_clamped_c; + c->put_signed_pixels_clamped = put_signed_pixels_clamped_c; c->add_pixels_clamped = add_pixels_clamped_c; c->gmc1 = gmc1_c; c->gmc = gmc_c; Index: dsputil.h =================================================================== RCS file: /cvsroot/xine/xine-lib/src/libffmpeg/libavcodec/dsputil.h,v retrieving revision 1.28 retrieving revision 1.29 diff -u -r1.28 -r1.29 --- dsputil.h 25 Apr 2004 18:58:36 -0000 1.28 +++ dsputil.h 9 May 2004 23:32:00 -0000 1.29 @@ -65,23 +65,16 @@ /* VP3 DSP functions */ void vp3_dsp_init_c(void); -void vp3_idct_put_c(int16_t *input_data, int16_t *dequant_matrix, - int coeff_count, uint8_t *dest, int stride); -void vp3_idct_add_c(int16_t *input_data, int16_t *dequant_matrix, - int coeff_count, uint8_t *dest, int stride); +void vp3_idct_c(int16_t *input_data, int16_t *dequant_matrix, + int coeff_count, DCTELEM *output_data); void vp3_dsp_init_mmx(void); -void vp3_idct_put_mmx(int16_t *input_data, int16_t *dequant_matrix, - int coeff_count, uint8_t *dest, int stride); -void vp3_idct_add_mmx(int16_t *input_data, int16_t *dequant_matrix, - int coeff_count, uint8_t *dest, int stride); +void vp3_idct_mmx(int16_t *input_data, int16_t *dequant_matrix, + int coeff_count, DCTELEM *output_data); void vp3_dsp_init_sse2(void); -void vp3_idct_put_sse2(int16_t *input_data, int16_t *dequant_matrix, - int coeff_count, uint8_t *dest, int stride); -void vp3_idct_add_sse2(int16_t *input_data, int16_t *dequant_matrix, - int coeff_count, uint8_t *dest, int stride); - +void vp3_idct_sse2(int16_t *input_data, int16_t *dequant_matrix, + int coeff_count, DCTELEM *output_data); /* minimum alignment rules ;) if u notice errors in the align stuff, need more alignment for some asm code for some cpu @@ -147,6 +140,7 @@ void (*get_pixels)(DCTELEM *block/*align 16*/, const uint8_t *pixels/*align 8*/, int line_size); void (*diff_pixels)(DCTELEM *block/*align 16*/, const uint8_t *s1/*align 8*/, const uint8_t *s2/*align 8*/, int stride); void (*put_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size); + void (*put_signed_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size); void (*add_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size); /** * translational global motion compensation. @@ -321,32 +315,16 @@ /** * This function is responsible for taking a block of zigzag'd, - * quantized DCT coefficients, reconstructing the original block of - * samples, and placing it into the output. - * @param input_data 64 zigzag'd, quantized DCT coefficients - * @param dequant_matrix 64 zigzag'd quantizer coefficients - * @param coeff_count index of the last coefficient - * @param dest the final output location where the transformed samples - * are to be placed - * @param stride the width in 8-bit samples of a line on this plane - */ - void (*vp3_idct_put)(int16_t *input_data, int16_t *dequant_matrix, - int coeff_count, uint8_t *dest, int stride); - - /** - * This function is responsible for taking a block of zigzag'd, - * quantized DCT coefficients, reconstructing the original block of - * samples, and adding the transformed samples to an existing block of - * samples in the output. + * quantized DCT coefficients and reconstructing the original block of + * samples. * @param input_data 64 zigzag'd, quantized DCT coefficients * @param dequant_matrix 64 zigzag'd quantizer coefficients * @param coeff_count index of the last coefficient - * @param dest the final output location where the transformed samples - * are to be placed - * @param stride the width in 8-bit samples of a line on this plane + * @param output_samples space for 64 DCTELEMs where the transformed + * samples will be stored */ - void (*vp3_idct_add)(int16_t *input_data, int16_t *dequant_matrix, - int coeff_count, uint8_t *dest, int stride); + void (*vp3_idct)(int16_t *input_data, int16_t *dequant_matrix, + int coeff_count, DCTELEM *output_samples); } DSPContext; @@ -400,6 +378,7 @@ void add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size); void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size); +void put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size); static inline void emms(void) { Index: dv.c =================================================================== RCS file: /cvsroot/xine/xine-lib/src/libffmpeg/libavcodec/dv.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- dv.c 25 Apr 2004 18:58:37 -0000 1.14 +++ dv.c 9 May 2004 23:32:00 -0000 1.15 @@ -235,12 +235,6 @@ return 0; } -static int dvvideo_end(AVCodecContext *avctx) -{ - avcodec_default_free_buffers(avctx); - return 0; -} - // #define VLC_DEBUG // #define printf(...) av_log(NULL, AV_LOG_ERROR, __VA_ARGS__) @@ -954,7 +948,7 @@ sizeof(DVVideoContext), dvvideo_init, dvvideo_encode_frame, - dvvideo_end, + NULL, NULL, CODEC_CAP_DR1, NULL @@ -967,7 +961,7 @@ sizeof(DVVideoContext), dvvideo_init, NULL, - dvvideo_end, + NULL, dvvideo_decode_frame, CODEC_CAP_DR1, NULL Index: h263.c =================================================================== RCS file: /cvsroot/xine/xine-lib/src/libffmpeg/libavcodec/h263.c,v retrieving revision 1.37 retrieving revision 1.38 diff -u -r1.37 -r1.38 --- h263.c 25 Apr 2004 18:58:48 -0000 1.37 +++ h263.c 9 May 2004 23:32:00 -0000 1.38 @@ -76,7 +76,7 @@ static void mpeg4_encode_vol_header(MpegEncContext * s, int vo_number, int vol_number); #endif //CONFIG_ENCODERS static void mpeg4_decode_sprite_trajectory(MpegEncContext * s, GetBitContext *gb); -static inline int ff_mpeg4_pred_dc(MpegEncContext * s, int n, uint16_t **dc_val_ptr, int *dir_ptr); +static inline int ff_mpeg4_pred_dc(MpegEncContext * s, int n, int level, int *dir_ptr, int encoding); #ifdef CONFIG_ENCODERS static uint8_t uni_DCtab_lum_len[512]; @@ -496,6 +496,17 @@ if(qscale_table[ s->mb_index2xy[i] ] - qscale_table[ s->mb_index2xy[i+1] ] >2) qscale_table[ s->mb_index2xy[i] ]= qscale_table[ s->mb_index2xy[i+1] ]+2; } + + if(s->codec_id != CODEC_ID_H263P){ + for(i=1; i<s->mb_num; i++){ + int mb_xy= s->mb_index2xy[i]; + + if(qscale_table[mb_xy] != qscale_table[s->mb_index2xy[i-1]] && (s->mb_type[mb_xy]&CANDIDATE_MB_TYPE_INTER4V)){ + s->mb_type[mb_xy]&= ~CANDIDATE_MB_TYPE_INTER4V; + s->mb_type[mb_xy]|= CANDIDATE_MB_TYPE_INTER; + } + } + } } /** @@ -507,15 +518,6 @@ ff_clean_h263_qscales(s); - for(i=1; i<s->mb_num; i++){ - int mb_xy= s->mb_index2xy[i]; - - if(qscale_table[mb_xy] != qscale_table[s->mb_index2xy[i-1]] && (s->mb_type[mb_xy]&CANDIDATE_MB_TYPE_INTER4V)){ - s->mb_type[mb_xy]&= ~CANDIDATE_MB_TYPE_INTER4V; - s->mb_type[mb_xy]|= CANDIDATE_MB_TYPE_INTER; - } - } - if(s->pict_type== B_TYPE){ int odd=0; /* ok, come on, this isnt funny anymore, theres more code for handling this mpeg4 mess than @@ -1071,15 +1073,7 @@ int i; for(i=0; i<6; i++){ - const int level= block[i][0]; - uint16_t *dc_ptr; - - dc_diff[i]= level - ff_mpeg4_pred_dc(s, i, &dc_ptr, &dir[i]); - if (i < 4) { - *dc_ptr = level * s->y_dc_scale; - } else { - *dc_ptr = level * s->c_dc_scale; - } + dc_diff[i]= ff_mpeg4_pred_dc(s, i, block[i][0], &dir[i], 1); } if(s->flags & CODEC_FLAG_AC_PRED){ @@ -2380,14 +2374,14 @@ /** * predicts the dc. + * encoding quantized level -> quantized diff + * decoding quantized diff -> quantized level * @param n block index (0-3 are luma, 4-5 are chroma) - * @param dc_val_ptr a pointer to the dc_val entry for the current MB will be stored here * @param dir_ptr pointer to an integer where the prediction direction will be stored - * @return the quantized predicted dc */ -static inline int ff_mpeg4_pred_dc(MpegEncContext * s, int n, uint16_t **dc_val_ptr, int *dir_ptr) +static inline int ff_mpeg4_pred_dc(MpegEncContext * s, int n, int level, int *dir_ptr, int encoding) { - int a, b, c, wrap, pred, scale; + int a, b, c, wrap, pred, scale, ret; uint16_t *dc_val; /* find prediction */ @@ -2429,10 +2423,32 @@ /* we assume pred is positive */ pred = FASTDIV((pred + (scale >> 1)), scale); - /* prepare address for prediction update */ - *dc_val_ptr = &dc_val[0]; + if(encoding){ + ret = level - pred; + }else{ + level += pred; + ret= level; + if(s->error_resilience>=3){ + if(level<0){ + av_log(s->avctx, AV_LOG_ERROR, "dc<0 at %dx%d\n", s->mb_x, s->mb_y); + return -1; + } + if(level*scale > 2048 + scale){ + av_log(s->avctx, AV_LOG_ERROR, "dc overflow at %dx%d\n", s->mb_x, s->mb_y); + return -1; + } + } + } + level *=scale; + if(level&(~2047)){ + if(level<0) + level=0; + else if(!(s->workaround_bugs&FF_BUG_DC_CLIP)) + level=2047; + } + dc_val[0]= level; - return pred; + return ret; } /** @@ -3219,6 +3235,9 @@ int x, y, mb_v, sum, dx, dy, shift; int len = 1 << (s->f_code + 4); const int a= s->sprite_warping_accuracy; + + if(s->workaround_bugs & FF_BUG_AMV) + len >>= s->quarter_sample; if(s->real_sprite_warping_points==1){ if(s->divx_version==500 && s->divx_build==413) @@ -4433,6 +4452,8 @@ } } else { level = get_bits(&s->gb, 8); + if (level == 255) + level = 128; } }else{ level = get_bits(&s->gb, 8); @@ -4530,8 +4551,7 @@ */ static inline int mpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr) { - int level, pred, code; - uint16_t *dc_val; + int level, code; if (n < 4) code = get_vlc2(&s->gb, dc_lum.table, DC_VLC_BITS, 1); @@ -4566,30 +4586,8 @@ } } } - pred = ff_mpeg4_pred_dc(s, n, &dc_val, dir_ptr); - level += pred; - if (level < 0){ - if(s->error_resilience>=3){ - av_log(s->avctx, AV_LOG_ERROR, "dc<0 at %dx%d\n", s->mb_x, s->mb_y); - return -1; - } - level = 0; - } - if (n < 4) { - *dc_val = level * s->y_dc_scale; - } else { - *dc_val = level * s->c_dc_scale; - } - if(IS_3IV1) - *dc_val = level * 8; - - if(s->error_resilience>=3){ - if(*dc_val > 2048 + s->y_dc_scale + s->c_dc_scale){ - av_log(s->avctx, AV_LOG_ERROR, "dc overflow at %dx%d\n", s->mb_x, s->mb_y); - return -1; - } - } - return level; + + return ff_mpeg4_pred_dc(s, n, level, dir_ptr, 0); } /** @@ -4720,6 +4718,8 @@ if (cache&0x80000000) { if (cache&0x40000000) { + int ulevel; + /* third escape */ SKIP_CACHE(re, &s->gb, 2); last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1); @@ -4745,10 +4745,16 @@ SKIP_COUNTER(re, &s->gb, 1+12+1); } - if(level*s->qscale>1024 || level*s->qscale<-1024){ + if(s->mpeg_quant){ + if(intra) ulevel= level*s->qscale*s->intra_matrix[scan_table[1]]; + else ulevel= level*s->qscale*s->inter_matrix[scan_table[0]]; + }else + ulevel= level*s->qscale*16; + if(ulevel>1030*16 || ulevel<-1030*16){ av_log(s->avctx, AV_LOG_ERROR, "|level| overflow in 3. esc, qp=%d\n", s->qscale); return -1; } + #if 0 if(s->error_resilience >= FF_ER_COMPLIANT){ const int abs_level= ABS(level); @@ -4827,14 +4833,8 @@ not_coded: if (intra) { if(s->qscale >= s->intra_dc_threshold){ - uint16_t *dc_val; - block[0] += ff_mpeg4_pred_dc(s, n, &dc_val, &dc_pred_dir); - if (n < 4) { - *dc_val = block[0] * s->y_dc_scale; - } else { - *dc_val = block[0] * s->c_dc_scale; - } - + block[0] = ff_mpeg4_pred_dc(s, n, block[0], &dc_pred_dir, 0); + if(i == -1) i=0; } Index: h263dec.c =================================================================== RCS file: /cvsroot/xine/xine-lib/src/libffmpeg/libavcodec/h263dec.c,v retrieving revision 1.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- h263dec.c 25 Apr 2004 18:58:52 -0000 1.29 +++ h263dec.c 9 May 2004 23:32:00 -0000 1.30 @@ -306,8 +306,7 @@ * finds the end of the current frame in the bitstream. * @return the position of the first byte of the next frame, or -1 */ -static int mpeg4_find_frame_end(MpegEncContext *s, uint8_t *buf, int buf_size){ - ParseContext *pc= &s->parse_context; +int ff_mpeg4_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){ int vop_found, i; uint32_t state; @@ -326,23 +325,25 @@ } } - 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; + if(vop_found){ + /* EOF considered as end of frame */ + if (buf_size == 0) + return 0; + 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 END_NOT_FOUND; } -static int h263_find_frame_end(MpegEncContext *s, uint8_t *buf, int buf_size){ - ParseContext *pc= &s->parse_context; +static int h263_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){ int vop_found, i; uint32_t state; @@ -377,6 +378,27 @@ return END_NOT_FOUND; } +static int h263_parse(AVCodecParserContext *s, + AVCodecContext *avctx, + uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + ParseContext *pc = s->priv_data; + int next; + + next= h263_find_frame_end(pc, buf, buf_size); + + if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) { + *poutbuf = NULL; + *poutbuf_size = 0; + return buf_size; + } + + *poutbuf = (uint8_t *)buf; + *poutbuf_size = buf_size; + return next; +} + int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) @@ -414,15 +436,15 @@ int next; if(s->codec_id==CODEC_ID_MPEG4){ - next= mpeg4_find_frame_end(s, buf, buf_size); + next= ff_mpeg4_find_frame_end(&s->parse_context, buf, buf_size); }else if(s->codec_id==CODEC_ID_H263){ - next= h263_find_frame_end(s, buf, buf_size); + next= h263_find_frame_end(&s->parse_context, buf, buf_size); }else{ av_log(s->avctx, AV_LOG_ERROR, "this codec doesnt support truncated bitstreams\n"); return -1; } - if( ff_combine_frame(s, next, &buf, &buf_size) < 0 ) + if( ff_combine_frame(&s->parse_context, next, &buf, &buf_size) < 0 ) return buf_size; } @@ -526,6 +548,9 @@ if(s->xvid_build && s->xvid_build<=12) s->workaround_bugs|= FF_BUG_EDGE; + if(s->xvid_build && s->xvid_build<=32) + s->workaround_bugs|= FF_BUG_DC_CLIP; + #define SET_QPEL_FUNC(postfix1, postfix2) \ s->dsp.put_ ## postfix1 = ff_put_ ## postfix2;\ s->dsp.put_no_rnd_ ## postfix1 = ff_put_no_rnd_ ## postfix2;\ @@ -540,6 +565,9 @@ if(s->lavc_build && s->lavc_build<4670){ s->workaround_bugs|= FF_BUG_EDGE; } + + if(s->lavc_build && s->lavc_build<=4712) + s->workaround_bugs|= FF_BUG_DC_CLIP; if(s->divx_version) s->workaround_bugs|= FF_BUG_DIRECT_BLOCKSIZE; @@ -843,3 +871,11 @@ ff_h263_decode_frame, CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 }; + +AVCodecParser h263_parser = { + { CODEC_ID_H263 }, + sizeof(ParseContext), + NULL, + h263_parse, + ff_parse_close, +}; Index: h264.c =================================================================== RCS file: /cvsroot/xine/xine-lib/src/libffmpeg/libavcodec/h264.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- h264.c 25 Apr 2004 18:58:54 -0000 1.12 +++ h264.c 9 May 2004 23:32:00 -0000 1.13 @@ -5520,8 +5520,7 @@ * finds the end of the current frame in the bitstream. * @return the position of the first byte of the next frame, or -1 */ -static int find_frame_end(MpegEncContext *s, uint8_t *buf, int buf_size){ - ParseContext *pc= &s->parse_context; +static int find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){ int i; uint32_t state; //printf("first %02X%02X%02X%02X\n", buf[0], buf[1],buf[2],buf[3]); @@ -5544,6 +5543,27 @@ return END_NOT_FOUND; } +static int h264_parse(AVCodecParserContext *s, + AVCodecContext *avctx, + uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + ParseContext *pc = s->priv_data; + int next; + + next= find_frame_end(pc, buf, buf_size); + + if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) { + *poutbuf = NULL; + *poutbuf_size = 0; + return buf_size; + } + + *poutbuf = (uint8_t *)buf; + *poutbuf_size = buf_size; + return next; +} + static int decode_nal_units(H264Context *h, uint8_t *buf, int buf_size){ MpegEncContext * const s = &h->s; AVCodecContext * const avctx= s->avctx; @@ -5701,9 +5721,9 @@ } if(s->flags&CODEC_FLAG_TRUNCATED){ - int next= find_frame_end(s, buf, buf_size); + int next= find_frame_end(&s->parse_context, buf, buf_size); - if( ff_combine_frame(s, next, &buf, &buf_size) < 0 ) + if( ff_combine_frame(&s->parse_context, next, &buf, &buf_size) < 0 ) return buf_size; //printf("next:%d buf_size:%d last_index:%d\n", next, buf_size, s->parse_context.last_index); } @@ -5970,4 +5990,12 @@ /*CODEC_CAP_DRAW_HORIZ_BAND |*/ CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED, }; +AVCodecParser h264_parser = { + { CODEC_ID_H264 }, + sizeof(ParseContext), + NULL, + h264_parse, + ff_parse_close, +}; + #include "svq3.c" Index: huffyuv.c =================================================================== RCS file: /cvsroot/xine/xine-lib/src/libffmpeg/libavcodec/huffyuv.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- huffyuv.c 14 Mar 2004 21:14:08 -0000 1.15 +++ huffyuv.c 9 May 2004 23:32:00 -0000 1.16 @@ -916,8 +916,6 @@ for(i=0; i<3; i++){ free_vlc(&s->vlc[i]); } - - avcodec_default_free_buffers(avctx); return 0; } Index: mdec.c =================================================================== RCS file: /cvsroot/xine/xine-lib/src/libffmpeg/libavcodec/mdec.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- mdec.c 1 Feb 2004 05:31:16 -0000 1.2 +++ mdec.c 9 May 2004 23:32:00 -0000 1.3 @@ -257,... [truncated message content] |