annotate mpeg4video_parser.c @ 4925:ff4cd98bc90c libavcodec

simplify
author lorenm
date Sun, 06 May 2007 09:17:50 +0000
parents 5fc99f2a111b
children 0d1cc37d9430
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4912
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
1 /*
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
2 * MPEG4 Video frame extraction
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
3 * Copyright (c) 2003 Fabrice Bellard.
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
4 * Copyright (c) 2003 Michael Niedermayer.
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
5 *
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
6 * This file is part of FFmpeg.
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
7 *
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
12 *
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
16 * Lesser General Public License for more details.
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
17 *
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
21 */
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
22
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
23 #include "parser.h"
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
24 #include "mpegvideo.h"
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
25
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
26
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
27 /* XXX: make it use less memory */
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
28 static int av_mpeg4_decode_header(AVCodecParserContext *s1,
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
29 AVCodecContext *avctx,
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
30 const uint8_t *buf, int buf_size)
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
31 {
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
32 ParseContext1 *pc = s1->priv_data;
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
33 MpegEncContext *s = pc->enc;
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
34 GetBitContext gb1, *gb = &gb1;
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
35 int ret;
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
36
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
37 s->avctx = avctx;
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
38 s->current_picture_ptr = &s->current_picture;
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
39
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
40 if (avctx->extradata_size && pc->first_picture){
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
41 init_get_bits(gb, avctx->extradata, avctx->extradata_size*8);
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
42 ret = ff_mpeg4_decode_picture_header(s, gb);
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
43 }
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
44
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
45 init_get_bits(gb, buf, 8 * buf_size);
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
46 ret = ff_mpeg4_decode_picture_header(s, gb);
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
47 if (s->width) {
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
48 avcodec_set_dimensions(avctx, s->width, s->height);
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
49 }
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
50 s1->pict_type= s->pict_type;
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
51 pc->first_picture = 0;
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
52 return ret;
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
53 }
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
54
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
55 static int mpeg4video_parse_init(AVCodecParserContext *s)
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
56 {
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
57 ParseContext1 *pc = s->priv_data;
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
58
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
59 pc->enc = av_mallocz(sizeof(MpegEncContext));
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
60 if (!pc->enc)
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
61 return -1;
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
62 pc->first_picture = 1;
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
63 return 0;
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
64 }
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
65
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
66 static int mpeg4video_parse(AVCodecParserContext *s,
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
67 AVCodecContext *avctx,
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
68 uint8_t **poutbuf, int *poutbuf_size,
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
69 const uint8_t *buf, int buf_size)
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
70 {
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
71 ParseContext *pc = s->priv_data;
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
72 int next;
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
73
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
74 if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
75 next= buf_size;
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
76 }else{
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
77 next= ff_mpeg4_find_frame_end(pc, buf, buf_size);
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
78
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
79 if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
80 *poutbuf = NULL;
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
81 *poutbuf_size = 0;
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
82 return buf_size;
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
83 }
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
84 }
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
85 av_mpeg4_decode_header(s, avctx, buf, buf_size);
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
86
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
87 *poutbuf = (uint8_t *)buf;
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
88 *poutbuf_size = buf_size;
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
89 return next;
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
90 }
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
91
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
92
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
93 AVCodecParser mpeg4video_parser = {
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
94 { CODEC_ID_MPEG4 },
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
95 sizeof(ParseContext1),
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
96 mpeg4video_parse_init,
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
97 mpeg4video_parse,
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
98 ff_parse1_close,
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
99 ff_mpeg4video_split,
5fc99f2a111b move mpeg4video_parser in it's own file
aurel
parents:
diff changeset
100 };