annotate mjpeg_parser.c @ 9003:b595a8a59967 libavcodec

Change the type of pblocks from pointers to short array into pointers to array of 64 DCTELEM, similarly to other block fields. This also get rid of some casts and fixes a warning.
author iive
date Sun, 22 Feb 2009 09:02:06 +0000
parents e9d9d946f213
children 334d727f7f7a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4977
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
1 /*
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
2 * MJPEG parser
8629
04423b2f6e0b cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 4977
diff changeset
3 * Copyright (c) 2000, 2001 Fabrice Bellard
4977
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
4 * Copyright (c) 2003 Alex Beregszaszi
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
5 * Copyright (c) 2003-2004 Michael Niedermayer
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
6 *
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
7 * This file is part of FFmpeg.
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
8 *
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
9 * FFmpeg is free software; you can redistribute it and/or
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
10 * modify it under the terms of the GNU Lesser General Public
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
11 * License as published by the Free Software Foundation; either
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
12 * version 2.1 of the License, or (at your option) any later version.
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
13 *
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
14 * FFmpeg is distributed in the hope that it will be useful,
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
17 * Lesser General Public License for more details.
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
18 *
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
19 * You should have received a copy of the GNU Lesser General Public
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
20 * License along with FFmpeg; if not, write to the Free Software
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
22 */
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
23
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
24 /**
8718
e9d9d946f213 Use full internal pathname in doxygen @file directives.
diego
parents: 8629
diff changeset
25 * @file libavcodec/mjpeg_parser.c
4977
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
26 * MJPEG parser.
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
27 */
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
28
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
29 #include "parser.h"
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
30
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
31
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
32 /**
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
33 * finds the end of the current frame in the bitstream.
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
34 * @return the position of the first byte of the next frame, or -1
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
35 */
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
36 static int find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
37 int vop_found, i;
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
38 uint16_t state;
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
39
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
40 vop_found= pc->frame_start_found;
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
41 state= pc->state;
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
42
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
43 i=0;
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
44 if(!vop_found){
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
45 for(i=0; i<buf_size; i++){
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
46 state= (state<<8) | buf[i];
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
47 if(state == 0xFFD8){
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
48 i++;
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
49 vop_found=1;
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
50 break;
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
51 }
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
52 }
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
53 }
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
54
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
55 if(vop_found){
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
56 /* EOF considered as end of frame */
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
57 if (buf_size == 0)
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
58 return 0;
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
59 for(; i<buf_size; i++){
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
60 state= (state<<8) | buf[i];
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
61 if(state == 0xFFD8){
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
62 pc->frame_start_found=0;
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
63 pc->state=0;
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
64 return i-1;
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
65 }
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
66 }
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
67 }
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
68 pc->frame_start_found= vop_found;
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
69 pc->state= state;
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
70 return END_NOT_FOUND;
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
71 }
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
72
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
73 static int jpeg_parse(AVCodecParserContext *s,
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
74 AVCodecContext *avctx,
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
75 const uint8_t **poutbuf, int *poutbuf_size,
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
76 const uint8_t *buf, int buf_size)
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
77 {
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
78 ParseContext *pc = s->priv_data;
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
79 int next;
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
80
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
81 next= find_frame_end(pc, buf, buf_size);
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
82
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
83 if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
84 *poutbuf = NULL;
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
85 *poutbuf_size = 0;
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
86 return buf_size;
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
87 }
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
88
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
89 *poutbuf = buf;
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
90 *poutbuf_size = buf_size;
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
91 return next;
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
92 }
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
93
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
94
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
95 AVCodecParser mjpeg_parser = {
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
96 { CODEC_ID_MJPEG },
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
97 sizeof(ParseContext),
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
98 NULL,
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
99 jpeg_parse,
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
100 ff_parse_close,
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
101 };