annotate mjpeg_parser.c @ 12351:3e02e2306209 libavcodec

VP8: unroll splitmv decoding tree Much faster splitmv mode decoding.
author darkshikari
date Tue, 03 Aug 2010 10:37:14 +0000
parents 7dd2a45249a9
children
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 /**
11644
7dd2a45249a9 Remove explicit filename from Doxygen @file commands.
diego
parents: 10002
diff changeset
25 * @file
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,
10002
878d449793e1 cosmetics, reindent
bcoudurier
parents: 10001
diff changeset
74 AVCodecContext *avctx,
878d449793e1 cosmetics, reindent
bcoudurier
parents: 10001
diff changeset
75 const uint8_t **poutbuf, int *poutbuf_size,
878d449793e1 cosmetics, reindent
bcoudurier
parents: 10001
diff changeset
76 const uint8_t *buf, int buf_size)
4977
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
10000
334d727f7f7a fix jpeg parser when PARSER_FLAG_COMPLETE_FRAMES is set
bcoudurier
parents: 8718
diff changeset
81 if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
334d727f7f7a fix jpeg parser when PARSER_FLAG_COMPLETE_FRAMES is set
bcoudurier
parents: 8718
diff changeset
82 next= buf_size;
334d727f7f7a fix jpeg parser when PARSER_FLAG_COMPLETE_FRAMES is set
bcoudurier
parents: 8718
diff changeset
83 }else{
10001
944156621f05 cosmetics, reindent
bcoudurier
parents: 10000
diff changeset
84 next= find_frame_end(pc, buf, buf_size);
4977
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
85
10001
944156621f05 cosmetics, reindent
bcoudurier
parents: 10000
diff changeset
86 if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
944156621f05 cosmetics, reindent
bcoudurier
parents: 10000
diff changeset
87 *poutbuf = NULL;
944156621f05 cosmetics, reindent
bcoudurier
parents: 10000
diff changeset
88 *poutbuf_size = 0;
944156621f05 cosmetics, reindent
bcoudurier
parents: 10000
diff changeset
89 return buf_size;
944156621f05 cosmetics, reindent
bcoudurier
parents: 10000
diff changeset
90 }
10000
334d727f7f7a fix jpeg parser when PARSER_FLAG_COMPLETE_FRAMES is set
bcoudurier
parents: 8718
diff changeset
91 }
4977
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 *poutbuf = buf;
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
94 *poutbuf_size = buf_size;
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
95 return next;
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
96 }
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
97
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
98
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
99 AVCodecParser mjpeg_parser = {
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
100 { CODEC_ID_MJPEG },
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
101 sizeof(ParseContext),
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
102 NULL,
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
103 jpeg_parse,
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
104 ff_parse_close,
9d7c1fbd3359 move mjpeg parser in its own file
aurel
parents:
diff changeset
105 };