annotate pnm_parser.c @ 9084:0d39a5203bf0 libavcodec

xvmc works with MPEG-2 as well as MPEG-1, note this in the codec long_name.
author diego
date Mon, 02 Mar 2009 05:20:00 +0000
parents 04423b2f6e0b
children a6bb56636f90
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4978
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
1 /*
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
2 * PNM image parser
8629
04423b2f6e0b cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 4978
diff changeset
3 * Copyright (c) 2002, 2003 Fabrice Bellard
4978
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
4 *
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
5 * This file is part of FFmpeg.
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
6 *
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
11 *
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
15 * Lesser General Public License for more details.
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
16 *
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
20 */
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
21
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
22 #include "parser.h" //for ParseContext
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
23 #include "pnm.h"
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
24
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
25
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
26 static int pnm_parse(AVCodecParserContext *s,
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
27 AVCodecContext *avctx,
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
28 const uint8_t **poutbuf, int *poutbuf_size,
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
29 const uint8_t *buf, int buf_size)
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
30 {
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
31 ParseContext *pc = s->priv_data;
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
32 PNMContext pnmctx;
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
33 int next;
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
34
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
35 for(; pc->overread>0; pc->overread--){
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
36 pc->buffer[pc->index++]= pc->buffer[pc->overread_index++];
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
37 }
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
38 retry:
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
39 if(pc->index){
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
40 pnmctx.bytestream_start=
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
41 pnmctx.bytestream= pc->buffer;
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
42 pnmctx.bytestream_end= pc->buffer + pc->index;
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
43 }else{
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
44 pnmctx.bytestream_start=
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
45 pnmctx.bytestream= (uint8_t *) buf; /* casts avoid warnings */
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
46 pnmctx.bytestream_end= (uint8_t *) buf + buf_size;
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
47 }
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
48 if(ff_pnm_decode_header(avctx, &pnmctx) < 0){
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
49 if(pnmctx.bytestream < pnmctx.bytestream_end){
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
50 if(pc->index){
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
51 pc->index=0;
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
52 }else{
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
53 buf++;
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
54 buf_size--;
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
55 }
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
56 goto retry;
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
57 }
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
58 #if 0
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
59 if(pc->index && pc->index*2 + FF_INPUT_BUFFER_PADDING_SIZE < pc->buffer_size && buf_size > pc->index){
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
60 memcpy(pc->buffer + pc->index, buf, pc->index);
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
61 pc->index += pc->index;
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
62 buf += pc->index;
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
63 buf_size -= pc->index;
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
64 goto retry;
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
65 }
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
66 #endif
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
67 next= END_NOT_FOUND;
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
68 }else{
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
69 next= pnmctx.bytestream - pnmctx.bytestream_start
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
70 + avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
71 if(pnmctx.bytestream_start!=buf)
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
72 next-= pc->index;
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
73 if(next > buf_size)
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
74 next= END_NOT_FOUND;
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
75 }
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
76
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
77 if(ff_combine_frame(pc, next, &buf, &buf_size)<0){
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
78 *poutbuf = NULL;
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
79 *poutbuf_size = 0;
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
80 return buf_size;
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
81 }
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
82 *poutbuf = buf;
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
83 *poutbuf_size = buf_size;
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
84 return next;
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
85 }
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
86
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
87 AVCodecParser pnm_parser = {
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
88 { CODEC_ID_PGM, CODEC_ID_PGMYUV, CODEC_ID_PPM, CODEC_ID_PBM, CODEC_ID_PAM},
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
89 sizeof(ParseContext),
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
90 NULL,
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
91 pnm_parse,
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
92 ff_parse_close,
95934eef9589 move pnm parser in its own file
aurel
parents:
diff changeset
93 };