Browse code

Move dca parser to its own file.

Originally committed as revision 8881 to svn://svn.ffmpeg.org/ffmpeg/trunk

Diego Biurrun authored on 2007/05/04 08:50:24
Showing 4 changed files
... ...
@@ -276,6 +276,7 @@ OBJS-$(CONFIG_XVID)                    += xvidff.o xvid_rc.o
276 276
 OBJS-$(CONFIG_AAC_PARSER)              += parser.o
277 277
 OBJS-$(CONFIG_AC3_PARSER)              += parser.o ac3tab.o
278 278
 OBJS-$(CONFIG_CAVSVIDEO_PARSER)        += cavs.o parser.o
279
+OBJS-$(CONFIG_DCA_PARSER)              += dca_parser.o
279 280
 OBJS-$(CONFIG_DVBSUB_PARSER)           += dvbsubdec.o
280 281
 OBJS-$(CONFIG_DVDSUB_PARSER)           += dvdsubdec.o
281 282
 OBJS-$(CONFIG_H261_PARSER)             += h261.o
... ...
@@ -35,15 +35,7 @@
35 35
 #include "bitstream.h"
36 36
 #include "dcadata.h"
37 37
 #include "dcahuff.h"
38
-#include "parser.h"
39
-
40
-/** DCA syncwords, also used for bitstream type detection */
41
-//@{
42
-#define DCA_MARKER_RAW_BE 0x7FFE8001
43
-#define DCA_MARKER_RAW_LE 0xFE7F0180
44
-#define DCA_MARKER_14B_BE 0x1FFFE800
45
-#define DCA_MARKER_14B_LE 0xFF1F00E8
46
-//@}
38
+#include "dca.h"
47 39
 
48 40
 //#define TRACE
49 41
 
... ...
@@ -1255,102 +1247,3 @@ AVCodec dca_decoder = {
1255 1255
     .init = dca_decode_init,
1256 1256
     .decode = dca_decode_frame,
1257 1257
 };
1258
-
1259
-#ifdef CONFIG_DCA_PARSER
1260
-
1261
-typedef struct DCAParseContext {
1262
-    ParseContext pc;
1263
-    uint32_t lastmarker;
1264
-} DCAParseContext;
1265
-
1266
-#define IS_MARKER(state, i, buf, buf_size) \
1267
- ((state == DCA_MARKER_14B_LE && (i < buf_size-2) && (buf[i+1] & 0xF0) == 0xF0 && buf[i+2] == 0x07) \
1268
- || (state == DCA_MARKER_14B_BE && (i < buf_size-2) && buf[i+1] == 0x07 && (buf[i+2] & 0xF0) == 0xF0) \
1269
- || state == DCA_MARKER_RAW_LE || state == DCA_MARKER_RAW_BE)
1270
-
1271
-/**
1272
- * finds the end of the current frame in the bitstream.
1273
- * @return the position of the first byte of the next frame, or -1
1274
- */
1275
-static int dca_find_frame_end(DCAParseContext * pc1, const uint8_t * buf,
1276
-                              int buf_size)
1277
-{
1278
-    int start_found, i;
1279
-    uint32_t state;
1280
-    ParseContext *pc = &pc1->pc;
1281
-
1282
-    start_found = pc->frame_start_found;
1283
-    state = pc->state;
1284
-
1285
-    i = 0;
1286
-    if (!start_found) {
1287
-        for (i = 0; i < buf_size; i++) {
1288
-            state = (state << 8) | buf[i];
1289
-            if (IS_MARKER(state, i, buf, buf_size)) {
1290
-                if (pc1->lastmarker && state == pc1->lastmarker) {
1291
-                    start_found = 1;
1292
-                    break;
1293
-                } else if (!pc1->lastmarker) {
1294
-                    start_found = 1;
1295
-                    pc1->lastmarker = state;
1296
-                    break;
1297
-                }
1298
-            }
1299
-        }
1300
-    }
1301
-    if (start_found) {
1302
-        for (; i < buf_size; i++) {
1303
-            state = (state << 8) | buf[i];
1304
-            if (state == pc1->lastmarker && IS_MARKER(state, i, buf, buf_size)) {
1305
-                pc->frame_start_found = 0;
1306
-                pc->state = -1;
1307
-                return i - 3;
1308
-            }
1309
-        }
1310
-    }
1311
-    pc->frame_start_found = start_found;
1312
-    pc->state = state;
1313
-    return END_NOT_FOUND;
1314
-}
1315
-
1316
-static int dca_parse_init(AVCodecParserContext * s)
1317
-{
1318
-    DCAParseContext *pc1 = s->priv_data;
1319
-
1320
-    pc1->lastmarker = 0;
1321
-    return 0;
1322
-}
1323
-
1324
-static int dca_parse(AVCodecParserContext * s,
1325
-                     AVCodecContext * avctx,
1326
-                     uint8_t ** poutbuf, int *poutbuf_size,
1327
-                     const uint8_t * buf, int buf_size)
1328
-{
1329
-    DCAParseContext *pc1 = s->priv_data;
1330
-    ParseContext *pc = &pc1->pc;
1331
-    int next;
1332
-
1333
-    if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
1334
-        next = buf_size;
1335
-    } else {
1336
-        next = dca_find_frame_end(pc1, buf, buf_size);
1337
-
1338
-        if (ff_combine_frame(pc, next, (uint8_t **) & buf, &buf_size) < 0) {
1339
-            *poutbuf = NULL;
1340
-            *poutbuf_size = 0;
1341
-            return buf_size;
1342
-        }
1343
-    }
1344
-    *poutbuf = (uint8_t *) buf;
1345
-    *poutbuf_size = buf_size;
1346
-    return next;
1347
-}
1348
-
1349
-AVCodecParser dca_parser = {
1350
-    {CODEC_ID_DTS},
1351
-    sizeof(DCAParseContext),
1352
-    dca_parse_init,
1353
-    dca_parse,
1354
-    ff_parse_close,
1355
-};
1356
-#endif /* CONFIG_DCA_PARSER */
1357 1258
new file mode 100644
... ...
@@ -0,0 +1,29 @@
0
+/*
1
+ * DCA compatible decoder
2
+ * Copyright (C) 2004 Gildas Bazin
3
+ * Copyright (C) 2004 Benjamin Zores
4
+ * Copyright (C) 2006 Benjamin Larsson
5
+ * Copyright (C) 2007 Konstantin Shishkov
6
+ *
7
+ * This file is part of FFmpeg.
8
+ *
9
+ * FFmpeg is free software; you can redistribute it and/or
10
+ * modify it under the terms of the GNU Lesser General Public
11
+ * License as published by the Free Software Foundation; either
12
+ * version 2.1 of the License, or (at your option) any later version.
13
+ *
14
+ * FFmpeg is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
+ * Lesser General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU Lesser General Public
20
+ * License along with FFmpeg; if not, write to the Free Software
21
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
+ */
23
+
24
+/** DCA syncwords, also used for bitstream type detection */
25
+#define DCA_MARKER_RAW_BE 0x7FFE8001
26
+#define DCA_MARKER_RAW_LE 0xFE7F0180
27
+#define DCA_MARKER_14B_BE 0x1FFFE800
28
+#define DCA_MARKER_14B_LE 0xFF1F00E8
0 29
new file mode 100644
... ...
@@ -0,0 +1,127 @@
0
+/*
1
+ * DCA parser
2
+ * Copyright (C) 2004 Gildas Bazin
3
+ * Copyright (C) 2004 Benjamin Zores
4
+ * Copyright (C) 2006 Benjamin Larsson
5
+ * Copyright (C) 2007 Konstantin Shishkov
6
+ *
7
+ * This file is part of FFmpeg.
8
+ *
9
+ * FFmpeg is free software; you can redistribute it and/or
10
+ * modify it under the terms of the GNU Lesser General Public
11
+ * License as published by the Free Software Foundation; either
12
+ * version 2.1 of the License, or (at your option) any later version.
13
+ *
14
+ * FFmpeg is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
+ * Lesser General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU Lesser General Public
20
+ * License along with FFmpeg; if not, write to the Free Software
21
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
+ */
23
+
24
+/**
25
+ * @file dca_parser.c
26
+ */
27
+
28
+#include "avcodec.h"
29
+#include "parser.h"
30
+#include "dca.h"
31
+
32
+typedef struct DCAParseContext {
33
+    ParseContext pc;
34
+    uint32_t lastmarker;
35
+} DCAParseContext;
36
+
37
+#define IS_MARKER(state, i, buf, buf_size) \
38
+ ((state == DCA_MARKER_14B_LE && (i < buf_size-2) && (buf[i+1] & 0xF0) == 0xF0 && buf[i+2] == 0x07) \
39
+ || (state == DCA_MARKER_14B_BE && (i < buf_size-2) && buf[i+1] == 0x07 && (buf[i+2] & 0xF0) == 0xF0) \
40
+ || state == DCA_MARKER_RAW_LE || state == DCA_MARKER_RAW_BE)
41
+
42
+/**
43
+ * finds the end of the current frame in the bitstream.
44
+ * @return the position of the first byte of the next frame, or -1
45
+ */
46
+static int dca_find_frame_end(DCAParseContext * pc1, const uint8_t * buf,
47
+                              int buf_size)
48
+{
49
+    int start_found, i;
50
+    uint32_t state;
51
+    ParseContext *pc = &pc1->pc;
52
+
53
+    start_found = pc->frame_start_found;
54
+    state = pc->state;
55
+
56
+    i = 0;
57
+    if (!start_found) {
58
+        for (i = 0; i < buf_size; i++) {
59
+            state = (state << 8) | buf[i];
60
+            if (IS_MARKER(state, i, buf, buf_size)) {
61
+                if (pc1->lastmarker && state == pc1->lastmarker) {
62
+                    start_found = 1;
63
+                    break;
64
+                } else if (!pc1->lastmarker) {
65
+                    start_found = 1;
66
+                    pc1->lastmarker = state;
67
+                    break;
68
+                }
69
+            }
70
+        }
71
+    }
72
+    if (start_found) {
73
+        for (; i < buf_size; i++) {
74
+            state = (state << 8) | buf[i];
75
+            if (state == pc1->lastmarker && IS_MARKER(state, i, buf, buf_size)) {
76
+                pc->frame_start_found = 0;
77
+                pc->state = -1;
78
+                return i - 3;
79
+            }
80
+        }
81
+    }
82
+    pc->frame_start_found = start_found;
83
+    pc->state = state;
84
+    return END_NOT_FOUND;
85
+}
86
+
87
+static int dca_parse_init(AVCodecParserContext * s)
88
+{
89
+    DCAParseContext *pc1 = s->priv_data;
90
+
91
+    pc1->lastmarker = 0;
92
+    return 0;
93
+}
94
+
95
+static int dca_parse(AVCodecParserContext * s,
96
+                     AVCodecContext * avctx,
97
+                     uint8_t ** poutbuf, int *poutbuf_size,
98
+                     const uint8_t * buf, int buf_size)
99
+{
100
+    DCAParseContext *pc1 = s->priv_data;
101
+    ParseContext *pc = &pc1->pc;
102
+    int next;
103
+
104
+    if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
105
+        next = buf_size;
106
+    } else {
107
+        next = dca_find_frame_end(pc1, buf, buf_size);
108
+
109
+        if (ff_combine_frame(pc, next, (uint8_t **) & buf, &buf_size) < 0) {
110
+            *poutbuf = NULL;
111
+            *poutbuf_size = 0;
112
+            return buf_size;
113
+        }
114
+    }
115
+    *poutbuf = (uint8_t *) buf;
116
+    *poutbuf_size = buf_size;
117
+    return next;
118
+}
119
+
120
+AVCodecParser dca_parser = {
121
+    {CODEC_ID_DTS},
122
+    sizeof(DCAParseContext),
123
+    dca_parse_init,
124
+    dca_parse,
125
+    ff_parse_close,
126
+};