Revision c33d9814

View differences:

configure
676 676
dxa_decoder_deps="zlib"
677 677
flashsv_decoder_deps="zlib"
678 678
flashsv_encoder_deps="zlib"
679
h263_decoder_deps="h263_parser"
679 680
mpeg_xvmc_decoder_deps="xvmc"
680 681
png_decoder_deps="zlib"
681 682
png_encoder_deps="zlib"
libavcodec/Makefile
282 282
OBJS-$(CONFIG_DVBSUB_PARSER)           += dvbsub_parser.o
283 283
OBJS-$(CONFIG_DVDSUB_PARSER)           += dvdsub_parser.o
284 284
OBJS-$(CONFIG_H261_PARSER)             += h261_parser.o
285
OBJS-$(CONFIG_H263_PARSER)             += h263dec.o
285
OBJS-$(CONFIG_H263_PARSER)             += h263_parser.o
286 286
OBJS-$(CONFIG_H264_PARSER)             += h264.o
287 287
OBJS-$(CONFIG_MJPEG_PARSER)            += mjpeg.o
288 288
OBJS-$(CONFIG_MPEG4VIDEO_PARSER)       += mpeg4video_parser.o
libavcodec/h263_parser.c
1
/*
2
 * H.263 parser
3
 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
4
 *
5
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * FFmpeg is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with FFmpeg; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
 */
21

  
22
/**
23
 * @file h263_parser.c
24
 * H.263 parser
25
 */
26

  
27
#include "parser.h"
28

  
29
int ff_h263_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){
30
    int vop_found, i;
31
    uint32_t state;
32

  
33
    vop_found= pc->frame_start_found;
34
    state= pc->state;
35

  
36
    i=0;
37
    if(!vop_found){
38
        for(i=0; i<buf_size; i++){
39
            state= (state<<8) | buf[i];
40
            if(state>>(32-22) == 0x20){
41
                i++;
42
                vop_found=1;
43
                break;
44
            }
45
        }
46
    }
47

  
48
    if(vop_found){
49
      for(; i<buf_size; i++){
50
        state= (state<<8) | buf[i];
51
        if(state>>(32-22) == 0x20){
52
            pc->frame_start_found=0;
53
            pc->state=-1;
54
            return i-3;
55
        }
56
      }
57
    }
58
    pc->frame_start_found= vop_found;
59
    pc->state= state;
60

  
61
    return END_NOT_FOUND;
62
}
63

  
64
static int h263_parse(AVCodecParserContext *s,
65
                           AVCodecContext *avctx,
66
                           uint8_t **poutbuf, int *poutbuf_size,
67
                           const uint8_t *buf, int buf_size)
68
{
69
    ParseContext *pc = s->priv_data;
70
    int next;
71

  
72
    next= ff_h263_find_frame_end(pc, buf, buf_size);
73

  
74
    if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
75
        *poutbuf = NULL;
76
        *poutbuf_size = 0;
77
        return buf_size;
78
    }
79

  
80
    *poutbuf = (uint8_t *)buf;
81
    *poutbuf_size = buf_size;
82
    return next;
83
}
84

  
85
AVCodecParser h263_parser = {
86
    { CODEC_ID_H263 },
87
    sizeof(ParseContext),
88
    NULL,
89
    h263_parse,
90
    ff_parse_close,
91
};
libavcodec/h263_parser.h
1
/*
2
 * H.263 parser
3
 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
4
 *
5
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * FFmpeg is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with FFmpeg; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
 */
21

  
22
int ff_h263_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size);
libavcodec/h263dec.c
28 28
#include "avcodec.h"
29 29
#include "dsputil.h"
30 30
#include "mpegvideo.h"
31
#include "h263_parser.h"
31 32

  
32 33
//#define DEBUG
33 34
//#define PRINT_FRAME_TIME
......
358 359
    return END_NOT_FOUND;
359 360
}
360 361

  
361
static int h263_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){
362
    int vop_found, i;
363
    uint32_t state;
364

  
365
    vop_found= pc->frame_start_found;
366
    state= pc->state;
367

  
368
    i=0;
369
    if(!vop_found){
370
        for(i=0; i<buf_size; i++){
371
            state= (state<<8) | buf[i];
372
            if(state>>(32-22) == 0x20){
373
                i++;
374
                vop_found=1;
375
                break;
376
            }
377
        }
378
    }
379

  
380
    if(vop_found){
381
      for(; i<buf_size; i++){
382
        state= (state<<8) | buf[i];
383
        if(state>>(32-22) == 0x20){
384
            pc->frame_start_found=0;
385
            pc->state=-1;
386
            return i-3;
387
        }
388
      }
389
    }
390
    pc->frame_start_found= vop_found;
391
    pc->state= state;
392

  
393
    return END_NOT_FOUND;
394
}
395

  
396
#ifdef CONFIG_H263_PARSER
397
static int h263_parse(AVCodecParserContext *s,
398
                           AVCodecContext *avctx,
399
                           const uint8_t **poutbuf, int *poutbuf_size,
400
                           const uint8_t *buf, int buf_size)
401
{
402
    ParseContext *pc = s->priv_data;
403
    int next;
404

  
405
    next= h263_find_frame_end(pc, buf, buf_size);
406

  
407
    if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
408
        *poutbuf = NULL;
409
        *poutbuf_size = 0;
410
        return buf_size;
411
    }
412

  
413
    *poutbuf = buf;
414
    *poutbuf_size = buf_size;
415
    return next;
416
}
417
#endif
418

  
419 362
int ff_h263_decode_frame(AVCodecContext *avctx,
420 363
                             void *data, int *data_size,
421 364
                             uint8_t *buf, int buf_size)
......
454 397
        if(s->codec_id==CODEC_ID_MPEG4){
455 398
            next= ff_mpeg4_find_frame_end(&s->parse_context, buf, buf_size);
456 399
        }else if(s->codec_id==CODEC_ID_H263){
457
            next= h263_find_frame_end(&s->parse_context, buf, buf_size);
400
            next= ff_h263_find_frame_end(&s->parse_context, buf, buf_size);
458 401
        }else{
459 402
            av_log(s->avctx, AV_LOG_ERROR, "this codec does not support truncated bitstreams\n");
460 403
            return -1;
......
902 845
    ff_h263_decode_frame,
903 846
    CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1
904 847
};
905

  
906
#ifdef CONFIG_H263_PARSER
907
AVCodecParser h263_parser = {
908
    { CODEC_ID_H263 },
909
    sizeof(ParseContext),
910
    NULL,
911
    h263_parse,
912
    ff_parse_close,
913
};
914
#endif

Also available in: Unified diff