Browse code

avcodec: add XMA2 parser

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

Paul B Mahol authored on 2017/01/20 04:43:40
Showing 4 changed files
... ...
@@ -950,6 +950,7 @@ OBJS-$(CONFIG_VC1_PARSER)              += vc1_parser.o vc1.o vc1data.o  \
950 950
 OBJS-$(CONFIG_VP3_PARSER)              += vp3_parser.o
951 951
 OBJS-$(CONFIG_VP8_PARSER)              += vp8_parser.o
952 952
 OBJS-$(CONFIG_VP9_PARSER)              += vp9_parser.o
953
+OBJS-$(CONFIG_XMA_PARSER)              += xma_parser.o
953 954
 
954 955
 # bitstream filters
955 956
 OBJS-$(CONFIG_AAC_ADTSTOASC_BSF)          += aac_adtstoasc_bsf.o aacadtsdec.o \
... ...
@@ -709,4 +709,5 @@ void avcodec_register_all(void)
709 709
     REGISTER_PARSER(VP3,                vp3);
710 710
     REGISTER_PARSER(VP8,                vp8);
711 711
     REGISTER_PARSER(VP9,                vp9);
712
+    REGISTER_PARSER(XMA,                xma);
712 713
 }
... ...
@@ -28,7 +28,7 @@
28 28
 #include "libavutil/version.h"
29 29
 
30 30
 #define LIBAVCODEC_VERSION_MAJOR  57
31
-#define LIBAVCODEC_VERSION_MINOR  74
31
+#define LIBAVCODEC_VERSION_MINOR  75
32 32
 #define LIBAVCODEC_VERSION_MICRO 100
33 33
 
34 34
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
35 35
new file mode 100644
... ...
@@ -0,0 +1,62 @@
0
+/*
1
+ * This file is part of FFmpeg.
2
+ *
3
+ * FFmpeg is free software; you can redistribute it and/or
4
+ * modify it under the terms of the GNU Lesser General Public
5
+ * License as published by the Free Software Foundation; either
6
+ * version 2.1 of the License, or (at your option) any later version.
7
+ *
8
+ * FFmpeg is distributed in the hope that it will be useful,
9
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
+ * Lesser General Public License for more details.
12
+ *
13
+ * You should have received a copy of the GNU Lesser General Public
14
+ * License along with FFmpeg; if not, write to the Free Software
15
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+ */
17
+
18
+/**
19
+ * @file
20
+ * XMA2 audio parser
21
+ */
22
+
23
+#include "parser.h"
24
+
25
+typedef struct XMAParserContext{
26
+    int skip_packets;
27
+} XMAParserContext;
28
+
29
+static int xma_parse(AVCodecParserContext *s1, AVCodecContext *avctx,
30
+                     const uint8_t **poutbuf, int *poutbuf_size,
31
+                     const uint8_t *buf, int buf_size)
32
+{
33
+    XMAParserContext *s = s1->priv_data;
34
+
35
+    if (buf_size % 2048 == 0) {
36
+        int duration = 0, packet, nb_packets = buf_size / 2048;
37
+
38
+        for (packet = 0; packet < nb_packets; packet++) {
39
+            if (s->skip_packets == 0) {
40
+                duration += buf[packet * 2048] * 128;
41
+                s->skip_packets = buf[packet * 2048 + 3] + 1;
42
+            }
43
+            s->skip_packets--;
44
+        }
45
+
46
+        s1->duration = duration;
47
+        s1->key_frame = !!duration;
48
+    }
49
+
50
+    /* always return the full packet. this parser isn't doing any splitting or
51
+       combining, only packet analysis */
52
+    *poutbuf      = buf;
53
+    *poutbuf_size = buf_size;
54
+    return buf_size;
55
+}
56
+
57
+AVCodecParser ff_xma_parser = {
58
+    .codec_ids      = { AV_CODEC_ID_XMA2 },
59
+    .priv_data_size = sizeof(XMAParserContext),
60
+    .parser_parse   = xma_parse,
61
+};