Browse code

NIST SPHERE demuxer

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

Paul B Mahol authored on 2012/12/19 05:38:49
Showing 7 changed files
... ...
@@ -49,6 +49,7 @@ version <next>:
49 49
 - adaptive frame-level multithreading for H.264
50 50
 - documentation split into per-component manuals
51 51
 - pp (postproc) filter ported from MPlayer
52
+- NIST Sphere demuxer
52 53
 
53 54
 
54 55
 version 1.0:
... ...
@@ -362,6 +362,7 @@ Muxers/Demuxers:
362 362
   mtv.c                                 Reynaldo H. Verdejo Pinochet
363 363
   mxf*                                  Baptiste Coudurier
364 364
   mxfdec.c                              Tomas Härdin
365
+  nistspheredec.c                       Paul B Mahol
365 366
   nsvdec.c                              Francois Revol
366 367
   nut.c                                 Michael Niedermayer
367 368
   nuv.c                                 Reimar Doeffinger
... ...
@@ -280,6 +280,7 @@ library:
280 280
     @tab SMPTE 386M, D-10/IMX Mapping.
281 281
 @item NC camera feed            @tab   @tab X
282 282
     @tab NC (AVIP NC4600) camera streams
283
+@item NIST SPeech HEader REsources @tab   @tab X
283 284
 @item NTT TwinVQ (VQF)          @tab   @tab X
284 285
     @tab Nippon Telegraph and Telephone Corporation TwinVQ.
285 286
 @item Nullsoft Streaming Video  @tab   @tab X
... ...
@@ -227,6 +227,7 @@ OBJS-$(CONFIG_MXF_DEMUXER)               += mxfdec.o mxf.o
227 227
 OBJS-$(CONFIG_MXF_MUXER)                 += mxfenc.o mxf.o audiointerleave.o
228 228
 OBJS-$(CONFIG_MXG_DEMUXER)               += mxg.o
229 229
 OBJS-$(CONFIG_NC_DEMUXER)                += ncdec.o
230
+OBJS-$(CONFIG_NISTSPHERE_DEMUXER)        += nistspheredec.o pcm.o
230 231
 OBJS-$(CONFIG_NSV_DEMUXER)               += nsvdec.o
231 232
 OBJS-$(CONFIG_NULL_MUXER)                += nullenc.o
232 233
 OBJS-$(CONFIG_NUT_DEMUXER)               += nutdec.o nut.o
... ...
@@ -178,6 +178,7 @@ void av_register_all(void)
178 178
     REGISTER_MUXER    (MXF_D10, mxf_d10);
179 179
     REGISTER_DEMUXER  (MXG, mxg);
180 180
     REGISTER_DEMUXER  (NC, nc);
181
+    REGISTER_DEMUXER  (NISTSPHERE, nistsphere);
181 182
     REGISTER_DEMUXER  (NSV, nsv);
182 183
     REGISTER_MUXER    (NULL, null);
183 184
     REGISTER_MUXDEMUX (NUT, nut);
184 185
new file mode 100644
... ...
@@ -0,0 +1,128 @@
0
+/*
1
+ * NIST Sphere demuxer
2
+ * Copyright (c) 2012 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
+#include "libavutil/avstring.h"
22
+#include "libavutil/intreadwrite.h"
23
+#include "avformat.h"
24
+#include "internal.h"
25
+#include "pcm.h"
26
+
27
+static int nist_probe(AVProbeData *p)
28
+{
29
+    if (AV_RL64(p->buf) == AV_RL64("NIST_1A\x0a"))
30
+        return AVPROBE_SCORE_MAX;
31
+    return 0;
32
+}
33
+
34
+static int nist_read_header(AVFormatContext *s)
35
+{
36
+    char buffer[32], coding[32] = "pcm", format[32] = "01";
37
+    int bps = 0, be = 0;
38
+    int32_t header_size;
39
+    AVStream *st;
40
+
41
+    st = avformat_new_stream(s, NULL);
42
+    if (!st)
43
+        return AVERROR(ENOMEM);
44
+
45
+    st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
46
+
47
+    ff_get_line(s->pb, buffer, sizeof(buffer));
48
+    ff_get_line(s->pb, buffer, sizeof(buffer));
49
+    sscanf(buffer, "%"SCNd32, &header_size);
50
+    if (header_size <= 0)
51
+        return AVERROR_INVALIDDATA;
52
+
53
+    while (!url_feof(s->pb)) {
54
+        ff_get_line(s->pb, buffer, sizeof(buffer));
55
+
56
+        if (avio_tell(s->pb) >= header_size)
57
+            return AVERROR_INVALIDDATA;
58
+
59
+        if (!memcmp(buffer, "end_head", 8)) {
60
+            if (!st->codec->bits_per_coded_sample)
61
+                st->codec->bits_per_coded_sample = bps << 3;
62
+
63
+            if (!av_strcasecmp(coding, "pcm")) {
64
+                st->codec->codec_id = ff_get_pcm_codec_id(st->codec->bits_per_coded_sample,
65
+                                                          0, be, 0xFFFF);
66
+            } else if (!av_strcasecmp(coding, "alaw")) {
67
+                st->codec->codec_id = AV_CODEC_ID_PCM_ALAW;
68
+            } else if (!av_strcasecmp(coding, "ulaw") ||
69
+                       !av_strcasecmp(coding, "mu-law")) {
70
+                st->codec->codec_id = AV_CODEC_ID_PCM_MULAW;
71
+            } else {
72
+                av_log_ask_for_sample(s, "unsupported coding: %s\n", coding);
73
+            }
74
+
75
+            avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
76
+
77
+            st->codec->block_align = st->codec->bits_per_coded_sample * st->codec->channels / 8;
78
+
79
+            if (avio_tell(s->pb) > header_size)
80
+                return AVERROR_INVALIDDATA;
81
+
82
+            avio_skip(s->pb, header_size - avio_tell(s->pb));
83
+
84
+            return 0;
85
+        } else if (!memcmp(buffer, "channel_count", 13)) {
86
+            sscanf(buffer, "%*s %*s %"SCNd32, &st->codec->channels);
87
+        } else if (!memcmp(buffer, "sample_byte_format", 18)) {
88
+            sscanf(buffer, "%*s %*s %31s", format);
89
+
90
+            if (!av_strcasecmp(format, "01")) {
91
+                be = 0;
92
+            } else if (!av_strcasecmp(format, "10")) {
93
+                be = 1;
94
+            } else if (av_strcasecmp(format, "1")) {
95
+                av_log_ask_for_sample(s, "unsupported sample byte format: %s\n", format);
96
+                return AVERROR_PATCHWELCOME;
97
+            }
98
+        } else if (!memcmp(buffer, "sample_coding", 13)) {
99
+            sscanf(buffer, "%*s %*s %31s", coding);
100
+        } else if (!memcmp(buffer, "sample_count", 12)) {
101
+            sscanf(buffer, "%*s %*s %"SCNd64, &st->duration);
102
+        } else if (!memcmp(buffer, "sample_n_bytes", 14)) {
103
+            sscanf(buffer, "%*s %*s %"SCNd32, &bps);
104
+        } else if (!memcmp(buffer, "sample_rate", 11)) {
105
+            sscanf(buffer, "%*s %*s %"SCNd32, &st->codec->sample_rate);
106
+        } else if (!memcmp(buffer, "sample_sig_bits", 15)) {
107
+            sscanf(buffer, "%*s %*s %"SCNd32, &st->codec->bits_per_coded_sample);
108
+        } else {
109
+            char key[32], value[32];
110
+            sscanf(buffer, "%31s %*s %31s", key, value);
111
+            av_dict_set(&s->metadata, key, value, AV_DICT_APPEND);
112
+        }
113
+    }
114
+
115
+    return AVERROR_EOF;
116
+}
117
+
118
+AVInputFormat ff_nistsphere_demuxer = {
119
+    .name           = "nistsphere",
120
+    .long_name      = NULL_IF_CONFIG_SMALL("NIST SPeech HEader REsources"),
121
+    .read_probe     = nist_probe,
122
+    .read_header    = nist_read_header,
123
+    .read_packet    = ff_pcm_read_packet,
124
+    .read_seek      = ff_pcm_read_seek,
125
+    .extensions     = "nist,sph",
126
+    .flags          = AVFMT_GENERIC_INDEX,
127
+};
... ...
@@ -30,7 +30,7 @@
30 30
 #include "libavutil/avutil.h"
31 31
 
32 32
 #define LIBAVFORMAT_VERSION_MAJOR 54
33
-#define LIBAVFORMAT_VERSION_MINOR 49
33
+#define LIBAVFORMAT_VERSION_MINOR 50
34 34
 #define LIBAVFORMAT_VERSION_MICRO 102
35 35
 
36 36
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \