Revision d2e911fa

View differences:

libavcodec/Makefile
283 283
OBJS-$(CONFIG_H263_PARSER)             += h263dec.o
284 284
OBJS-$(CONFIG_H264_PARSER)             += h264.o
285 285
OBJS-$(CONFIG_MJPEG_PARSER)            += mjpeg.o
286
OBJS-$(CONFIG_MPEG4VIDEO_PARSER)       += parser.o
286
OBJS-$(CONFIG_MPEG4VIDEO_PARSER)       += mpeg4video_parser.o
287 287
OBJS-$(CONFIG_MPEGAUDIO_PARSER)        += parser.o
288 288
OBJS-$(CONFIG_MPEGVIDEO_PARSER)        += parser.o
289 289
OBJS-$(CONFIG_PNM_PARSER)              += pnm.o
libavcodec/mpeg4video_parser.c
1
/*
2
 * MPEG4 Video frame extraction
3
 * Copyright (c) 2003 Fabrice Bellard.
4
 * Copyright (c) 2003 Michael Niedermayer.
5
 *
6
 * This file is part of FFmpeg.
7
 *
8
 * FFmpeg is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * FFmpeg is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with FFmpeg; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
 */
22

  
23
#include "parser.h"
24
#include "mpegvideo.h"
25

  
26

  
27
/* XXX: make it use less memory */
28
static int av_mpeg4_decode_header(AVCodecParserContext *s1,
29
                                  AVCodecContext *avctx,
30
                                  const uint8_t *buf, int buf_size)
31
{
32
    ParseContext1 *pc = s1->priv_data;
33
    MpegEncContext *s = pc->enc;
34
    GetBitContext gb1, *gb = &gb1;
35
    int ret;
36

  
37
    s->avctx = avctx;
38
    s->current_picture_ptr = &s->current_picture;
39

  
40
    if (avctx->extradata_size && pc->first_picture){
41
        init_get_bits(gb, avctx->extradata, avctx->extradata_size*8);
42
        ret = ff_mpeg4_decode_picture_header(s, gb);
43
    }
44

  
45
    init_get_bits(gb, buf, 8 * buf_size);
46
    ret = ff_mpeg4_decode_picture_header(s, gb);
47
    if (s->width) {
48
        avcodec_set_dimensions(avctx, s->width, s->height);
49
    }
50
    s1->pict_type= s->pict_type;
51
    pc->first_picture = 0;
52
    return ret;
53
}
54

  
55
static int mpeg4video_parse_init(AVCodecParserContext *s)
56
{
57
    ParseContext1 *pc = s->priv_data;
58

  
59
    pc->enc = av_mallocz(sizeof(MpegEncContext));
60
    if (!pc->enc)
61
        return -1;
62
    pc->first_picture = 1;
63
    return 0;
64
}
65

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

  
74
    if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
75
        next= buf_size;
76
    }else{
77
        next= ff_mpeg4_find_frame_end(pc, buf, buf_size);
78

  
79
        if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
80
            *poutbuf = NULL;
81
            *poutbuf_size = 0;
82
            return buf_size;
83
        }
84
    }
85
    av_mpeg4_decode_header(s, avctx, buf, buf_size);
86

  
87
    *poutbuf = (uint8_t *)buf;
88
    *poutbuf_size = buf_size;
89
    return next;
90
}
91

  
92

  
93
AVCodecParser mpeg4video_parser = {
94
    { CODEC_ID_MPEG4 },
95
    sizeof(ParseContext1),
96
    mpeg4video_parse_init,
97
    mpeg4video_parse,
98
    ff_parse1_close,
99
    ff_mpeg4video_split,
100
};
libavcodec/parser.c
298 298

  
299 299
/*************************/
300 300

  
301
#ifdef CONFIG_MPEG4VIDEO_PARSER
302
/* used by parser */
303
/* XXX: make it use less memory */
304
static int av_mpeg4_decode_header(AVCodecParserContext *s1,
305
                                  AVCodecContext *avctx,
306
                                  const uint8_t *buf, int buf_size)
307
{
308
    ParseContext1 *pc = s1->priv_data;
309
    MpegEncContext *s = pc->enc;
310
    GetBitContext gb1, *gb = &gb1;
311
    int ret;
312

  
313
    s->avctx = avctx;
314
    s->current_picture_ptr = &s->current_picture;
315

  
316
    if (avctx->extradata_size && pc->first_picture){
317
        init_get_bits(gb, avctx->extradata, avctx->extradata_size*8);
318
        ret = ff_mpeg4_decode_picture_header(s, gb);
319
    }
320

  
321
    init_get_bits(gb, buf, 8 * buf_size);
322
    ret = ff_mpeg4_decode_picture_header(s, gb);
323
    if (s->width) {
324
        avcodec_set_dimensions(avctx, s->width, s->height);
325
    }
326
    s1->pict_type= s->pict_type;
327
    pc->first_picture = 0;
328
    return ret;
329
}
330

  
331
static int mpeg4video_parse_init(AVCodecParserContext *s)
332
{
333
    ParseContext1 *pc = s->priv_data;
334

  
335
    pc->enc = av_mallocz(sizeof(MpegEncContext));
336
    if (!pc->enc)
337
        return -1;
338
    pc->first_picture = 1;
339
    return 0;
340
}
341

  
342
static int mpeg4video_parse(AVCodecParserContext *s,
343
                           AVCodecContext *avctx,
344
                           uint8_t **poutbuf, int *poutbuf_size,
345
                           const uint8_t *buf, int buf_size)
346
{
347
    ParseContext *pc = s->priv_data;
348
    int next;
349

  
350
    if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
351
        next= buf_size;
352
    }else{
353
        next= ff_mpeg4_find_frame_end(pc, buf, buf_size);
354

  
355
        if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
356
            *poutbuf = NULL;
357
            *poutbuf_size = 0;
358
            return buf_size;
359
        }
360
    }
361
    av_mpeg4_decode_header(s, avctx, buf, buf_size);
362

  
363
    *poutbuf = (uint8_t *)buf;
364
    *poutbuf_size = buf_size;
365
    return next;
366
}
367
#endif
368

  
369 301
int ff_mpeg4video_split(AVCodecContext *avctx,
370 302
                           const uint8_t *buf, int buf_size)
371 303
{
......
847 779
}
848 780
#endif /* CONFIG_AC3_PARSER || CONFIG_AAC_PARSER */
849 781

  
850
#ifdef CONFIG_MPEG4VIDEO_PARSER
851
AVCodecParser mpeg4video_parser = {
852
    { CODEC_ID_MPEG4 },
853
    sizeof(ParseContext1),
854
    mpeg4video_parse_init,
855
    mpeg4video_parse,
856
    ff_parse1_close,
857
    ff_mpeg4video_split,
858
};
859
#endif
860 782
#ifdef CONFIG_MPEGAUDIO_PARSER
861 783
AVCodecParser mpegaudio_parser = {
862 784
    { CODEC_ID_MP2, CODEC_ID_MP3 },

Also available in: Unified diff