Originally committed as revision 13041 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diego Biurrun authored on 2008/05/03 12:33:21... | ... |
@@ -333,6 +333,7 @@ OBJS-$(CONFIG_AAC_PARSER) += aac_parser.o aac_ac3_parser.o mpeg4aud |
333 | 333 |
OBJS-$(CONFIG_AC3_PARSER) += ac3_parser.o ac3tab.o aac_ac3_parser.o |
334 | 334 |
OBJS-$(CONFIG_CAVSVIDEO_PARSER) += cavs_parser.o |
335 | 335 |
OBJS-$(CONFIG_DCA_PARSER) += dca_parser.o |
336 |
+OBJS-$(CONFIG_DIRAC_PARSER) += dirac_parser.o |
|
336 | 337 |
OBJS-$(CONFIG_DVBSUB_PARSER) += dvbsub_parser.o |
337 | 338 |
OBJS-$(CONFIG_DVDSUB_PARSER) += dvdsub_parser.o |
338 | 339 |
OBJS-$(CONFIG_H261_PARSER) += h261_parser.o |
... | ... |
@@ -292,6 +292,7 @@ void avcodec_register_all(void) |
292 | 292 |
REGISTER_PARSER (AC3, ac3); |
293 | 293 |
REGISTER_PARSER (CAVSVIDEO, cavsvideo); |
294 | 294 |
REGISTER_PARSER (DCA, dca); |
295 |
+ REGISTER_PARSER (DIRAC, dirac); |
|
295 | 296 |
REGISTER_PARSER (DVBSUB, dvbsub); |
296 | 297 |
REGISTER_PARSER (DVDSUB, dvdsub); |
297 | 298 |
REGISTER_PARSER (H261, h261); |
298 | 299 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,88 @@ |
0 |
+/* |
|
1 |
+ * Dirac parser |
|
2 |
+ * |
|
3 |
+ * Copyright (c) 2007 Marco Gerards <marco@gnu.org> |
|
4 |
+ * |
|
5 |
+ * This file is part of FFmpeg. |
|
6 |
+ * |
|
7 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
8 |
+ * modify it under the terms of the GNU Lesser General Public |
|
9 |
+ * License as published by the Free Software Foundation; either |
|
10 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
11 |
+ * |
|
12 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
13 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
15 |
+ * Lesser General Public License for more details. |
|
16 |
+ * |
|
17 |
+ * You should have received a copy of the GNU Lesser General Public |
|
18 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
19 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
20 |
+ */ |
|
21 |
+ |
|
22 |
+/** |
|
23 |
+ * @file dirac_parser.c |
|
24 |
+ * Dirac Parser |
|
25 |
+ * @author Marco Gerards <marco@gnu.org> |
|
26 |
+ */ |
|
27 |
+ |
|
28 |
+#include "parser.h" |
|
29 |
+ |
|
30 |
+#define DIRAC_PARSE_INFO_PREFIX 0x42424344 |
|
31 |
+ |
|
32 |
+/** |
|
33 |
+ * Finds the end of the current frame in the bitstream. |
|
34 |
+ * @return the position of the first byte of the next frame or -1 |
|
35 |
+ */ |
|
36 |
+static int find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size) |
|
37 |
+{ |
|
38 |
+ uint32_t state = pc->state; |
|
39 |
+ int i; |
|
40 |
+ |
|
41 |
+ for (i = 0; i < buf_size; i++) { |
|
42 |
+ state = (state << 8) | buf[i]; |
|
43 |
+ if (state == DIRAC_PARSE_INFO_PREFIX) { |
|
44 |
+ pc->frame_start_found ^= 1; |
|
45 |
+ if (!pc->frame_start_found) { |
|
46 |
+ pc->state = -1; |
|
47 |
+ return i - 3; |
|
48 |
+ } |
|
49 |
+ } |
|
50 |
+ } |
|
51 |
+ |
|
52 |
+ pc->state = state; |
|
53 |
+ |
|
54 |
+ return END_NOT_FOUND; |
|
55 |
+} |
|
56 |
+ |
|
57 |
+static int dirac_parse(AVCodecParserContext *s, AVCodecContext *avctx, |
|
58 |
+ const uint8_t **poutbuf, int *poutbuf_size, |
|
59 |
+ const uint8_t *buf, int buf_size) |
|
60 |
+{ |
|
61 |
+ ParseContext *pc = s->priv_data; |
|
62 |
+ int next; |
|
63 |
+ |
|
64 |
+ if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) { |
|
65 |
+ next = buf_size; |
|
66 |
+ }else{ |
|
67 |
+ next = find_frame_end(pc, buf, buf_size); |
|
68 |
+ |
|
69 |
+ if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { |
|
70 |
+ *poutbuf = NULL; |
|
71 |
+ *poutbuf_size = 0; |
|
72 |
+ return buf_size; |
|
73 |
+ } |
|
74 |
+ } |
|
75 |
+ |
|
76 |
+ *poutbuf = buf; |
|
77 |
+ *poutbuf_size = buf_size; |
|
78 |
+ return next; |
|
79 |
+} |
|
80 |
+ |
|
81 |
+AVCodecParser dirac_parser = { |
|
82 |
+ { CODEC_ID_DIRAC }, |
|
83 |
+ sizeof(ParseContext), |
|
84 |
+ NULL, |
|
85 |
+ dirac_parse, |
|
86 |
+ ff_parse_close, |
|
87 |
+}; |