Changeset 7859740c in ffmpeg


Ignore:
Timestamp:
Dec 18, 2011, 7:51:40 PM (13 years ago)
Author:
Michael Niedermayer <michaelni@gmx.at>
Branches:
master
Children:
af3f2a87
Parents:
6b6b84ae
git-author:
Michael Niedermayer <michaelni@gmx.at> (12/18/11 19:12:16)
git-committer:
Michael Niedermayer <michaelni@gmx.at> (12/18/11 19:51:40)
Message:

adx_parser: rewrite.
The previous code ended in multiple different infinite
loops. See stl_ten_1_big.sfd as example with and without zzuf

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libavcodec/adx_parser.c

    r6b6b84ae r7859740c  
    2323 * ADX audio parser
    2424 *
    25  * Reads header to extradata and splits packets into individual blocks.
     25 * Splits packets into individual blocks.
    2626 */
    2727
     
    3434    int header_size;
    3535    int block_size;
    36     int buf_pos;
     36    int remaining;
    3737} ADXParseContext;
    38 
    39 #define MIN_HEADER_SIZE 24
    4038
    4139static int adx_parse(AVCodecParserContext *s1,
     
    4745    ParseContext *pc = &s->pc;
    4846    int next = END_NOT_FOUND;
     47    int i;
     48    uint64_t state= pc->state64;
    4949
    50     if (!avctx->extradata_size) {
    51         int ret;
     50    if(!s->header_size){
     51        for(i=0; i<buf_size; i++){
     52            state= (state<<8) | buf[i];
     53            if((state&0xFFFF0000FFFFFF00) == 0x8000000003120400ULL && (state&0xFF) && ((state>>32)&0xFFFF)>=4){
     54                s->header_size= ((state>>32)&0xFFFF) + 4;
     55                s->block_size = BLOCK_SIZE * (state&0xFF);
     56                s->remaining  = i - 7 + s->header_size + s->block_size;
     57                break;
     58            }
     59        }
     60        pc->state64= state;
     61    }
    5262
    53         ff_combine_frame(pc, END_NOT_FOUND, &buf, &buf_size);
    54 
    55         if (!s->header_size && pc->index >= MIN_HEADER_SIZE) {
    56             if (ret = avpriv_adx_decode_header(avctx, pc->buffer, pc->index,
    57                                                &s->header_size, NULL))
    58                 return AVERROR_INVALIDDATA;
     63    if (s->header_size) {
     64        if (!s->remaining) {
     65            s->remaining = s->block_size;
    5966        }
    60         if (s->header_size && s->header_size <= pc->index) {
    61             avctx->extradata = av_mallocz(s->header_size + FF_INPUT_BUFFER_PADDING_SIZE);
    62             if (!avctx->extradata)
    63                 return AVERROR(ENOMEM);
    64             avctx->extradata_size = s->header_size;
    65             memcpy(avctx->extradata, pc->buffer, s->header_size);
    66             memmove(pc->buffer, pc->buffer + s->header_size, s->header_size);
    67             pc->index -= s->header_size;
    68         }
    69         *poutbuf      = NULL;
    70         *poutbuf_size = 0;
    71         return buf_size;
     67        if (s->remaining<=buf_size) {
     68            next= s->remaining;
     69            s->remaining = 0;
     70        } else
     71            s->remaining -= buf_size;
    7272    }
    73     s->block_size = BLOCK_SIZE * avctx->channels;
    74 
    75     if (pc->index - s->buf_pos >= s->block_size) {
    76         *poutbuf      = &pc->buffer[s->buf_pos];
    77         *poutbuf_size = s->block_size;
    78         s->buf_pos   += s->block_size;
    79         return 0;
    80     }
    81     if (pc->index && s->buf_pos) {
    82         memmove(pc->buffer, &pc->buffer[s->buf_pos], pc->index - s->buf_pos);
    83         pc->index -= s->buf_pos;
    84         s->buf_pos = 0;
    85     }
    86     if (buf_size + pc->index >= s->block_size)
    87         next = s->block_size - pc->index;
    8873
    8974    if (ff_combine_frame(pc, next, &buf, &buf_size) < 0 || !buf_size) {
Note: See TracChangeset for help on using the changeset viewer.