Browse code

avcodec: add dpx parser

Signed-off-by: Paul B Mahol <onemda@gmail.com>

Paul B Mahol authored on 2013/10/06 21:51:08
Showing 5 changed files
... ...
@@ -37,6 +37,7 @@ version <next>
37 37
   the skip_alpha flag.
38 38
 - ladspa wrapper filter
39 39
 - native VP9 decoder
40
+- dpx parser
40 41
 
41 42
 
42 43
 version 2.0:
... ...
@@ -744,6 +744,7 @@ OBJS-$(CONFIG_COOK_PARSER)             += cook_parser.o
744 744
 OBJS-$(CONFIG_DCA_PARSER)              += dca_parser.o dca.o
745 745
 OBJS-$(CONFIG_DIRAC_PARSER)            += dirac_parser.o
746 746
 OBJS-$(CONFIG_DNXHD_PARSER)            += dnxhd_parser.o
747
+OBJS-$(CONFIG_DPX_PARSER)              += dpx_parser.o
747 748
 OBJS-$(CONFIG_DVBSUB_PARSER)           += dvbsub_parser.o
748 749
 OBJS-$(CONFIG_DVD_NAV_PARSER)          += dvd_nav_parser.o
749 750
 OBJS-$(CONFIG_DVDSUB_PARSER)           += dvdsub_parser.o
... ...
@@ -525,6 +525,7 @@ void avcodec_register_all(void)
525 525
     REGISTER_PARSER(DCA,                dca);
526 526
     REGISTER_PARSER(DIRAC,              dirac);
527 527
     REGISTER_PARSER(DNXHD,              dnxhd);
528
+    REGISTER_PARSER(DPX,                dpx);
528 529
     REGISTER_PARSER(DVBSUB,             dvbsub);
529 530
     REGISTER_PARSER(DVDSUB,             dvdsub);
530 531
     REGISTER_PARSER(DVD_NAV,            dvd_nav);
531 532
new file mode 100644
... ...
@@ -0,0 +1,108 @@
0
+/*
1
+ * DPX parser
2
+ * Copyright (c) 2013 Paul B Mahol
3
+ *
4
+ * This file is part of FFmpeg.
5
+ *
6
+ * FFmpeg is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * FFmpeg is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with FFmpeg; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+/**
22
+ * @file
23
+ * DPX parser
24
+ */
25
+
26
+#include "libavutil/bswap.h"
27
+#include "parser.h"
28
+
29
+typedef struct DPXParseContext {
30
+    ParseContext pc;
31
+    uint32_t index;
32
+    uint32_t fsize;
33
+    uint32_t remaining_size;
34
+    int is_be;
35
+} DPXParseContext;
36
+
37
+static int dpx_parse(AVCodecParserContext *s, AVCodecContext *avctx,
38
+                     const uint8_t **poutbuf, int *poutbuf_size,
39
+                     const uint8_t *buf, int buf_size)
40
+{
41
+    DPXParseContext *d = s->priv_data;
42
+    uint32_t state = d->pc.state;
43
+    int next = END_NOT_FOUND;
44
+    int i = 0;
45
+
46
+    s->pict_type = AV_PICTURE_TYPE_I;
47
+
48
+    *poutbuf_size = 0;
49
+    if (buf_size == 0)
50
+        return 0;
51
+
52
+    if (!d->pc.frame_start_found) {
53
+        for (; i < buf_size; i++) {
54
+            state = (state << 8) | buf[i];
55
+            if (state == MKBETAG('S','D','P','X') ||
56
+                state == MKTAG('S','D','P','X')) {
57
+                d->pc.frame_start_found = 1;
58
+                d->is_be = state == MKBETAG('S','D','P','X');
59
+                break;
60
+            }
61
+        }
62
+        d->pc.state = state;
63
+    } else {
64
+        if (d->remaining_size) {
65
+            i = FFMIN(d->remaining_size, buf_size);
66
+            d->remaining_size -= i;
67
+            if (d->remaining_size)
68
+                goto flush;
69
+            next = i;
70
+        }
71
+    }
72
+
73
+    for (;d->pc.frame_start_found && i < buf_size; i++) {
74
+        d->pc.state = (d->pc.state << 8) | buf[i];
75
+        if (d->index == 16) {
76
+            d->fsize = d->is_be ? d->pc.state : av_bswap32(d->pc.state);
77
+            if (d->fsize <= 1664) {
78
+                d->index = d->pc.frame_start_found = 0;
79
+                goto flush;
80
+            }
81
+            d->index = 0;
82
+            if (d->fsize > buf_size - i + 19)
83
+                d->remaining_size = d->fsize - buf_size + i - 19;
84
+            else
85
+                next = d->fsize + i - 19;
86
+            break;
87
+        }
88
+        d->index++;
89
+    }
90
+
91
+flush:
92
+    if (ff_combine_frame(&d->pc, next, &buf, &buf_size) < 0)
93
+        return buf_size;
94
+
95
+    d->index = d->pc.frame_start_found = 0;
96
+
97
+    *poutbuf      = buf;
98
+    *poutbuf_size = buf_size;
99
+    return next;
100
+}
101
+
102
+AVCodecParser ff_dpx_parser = {
103
+    .codec_ids      = { AV_CODEC_ID_DPX },
104
+    .priv_data_size = sizeof(DPXParseContext),
105
+    .parser_parse   = dpx_parse,
106
+    .parser_close   = ff_parse_close,
107
+};
... ...
@@ -29,7 +29,7 @@
29 29
 #include "libavutil/avutil.h"
30 30
 
31 31
 #define LIBAVCODEC_VERSION_MAJOR 55
32
-#define LIBAVCODEC_VERSION_MINOR  34
32
+#define LIBAVCODEC_VERSION_MINOR  35
33 33
 #define LIBAVCODEC_VERSION_MICRO 100
34 34
 
35 35
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \