Browse code

Add support for speex in ogg

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

Reimar Döffinger authored on 2008/02/06 21:37:37
Showing 5 changed files
... ...
@@ -276,6 +276,7 @@ enum CodecID {
276 276
     CODEC_ID_APE,
277 277
     CODEC_ID_NELLYMOSER,
278 278
     CODEC_ID_MUSEPACK8,
279
+    CODEC_ID_SPEEX,
279 280
 
280 281
     /* subtitle codecs */
281 282
     CODEC_ID_DVD_SUBTITLE= 0x17000,
... ...
@@ -110,6 +110,7 @@ OBJS-$(CONFIG_NUV_DEMUXER)               += nuv.o riff.o
110 110
 OBJS-$(CONFIG_OGG_DEMUXER)               += oggdec.o         \
111 111
                                             oggparseflac.o   \
112 112
                                             oggparseogm.o    \
113
+                                            oggparsespeex.o  \
113 114
                                             oggparsetheora.o \
114 115
                                             oggparsevorbis.o \
115 116
                                             riff.o
... ...
@@ -38,6 +38,7 @@
38 38
 #define DECODER_BUFFER_SIZE MAX_PAGE_SIZE
39 39
 
40 40
 static ogg_codec_t *ogg_codecs[] = {
41
+    &speex_codec,
41 42
     &vorbis_codec,
42 43
     &theora_codec,
43 44
     &flac_codec,
... ...
@@ -81,6 +81,7 @@ extern ogg_codec_t ogm_old_codec;
81 81
 extern ogg_codec_t ogm_text_codec;
82 82
 extern ogg_codec_t ogm_video_codec;
83 83
 extern ogg_codec_t old_flac_codec;
84
+extern ogg_codec_t speex_codec;
84 85
 extern ogg_codec_t theora_codec;
85 86
 extern ogg_codec_t vorbis_codec;
86 87
 
87 88
new file mode 100644
... ...
@@ -0,0 +1,61 @@
0
+/*
1
+      Copyright (C) 2008  Reimar Döffinger
2
+
3
+      Permission is hereby granted, free of charge, to any person
4
+      obtaining a copy of this software and associated documentation
5
+      files (the "Software"), to deal in the Software without
6
+      restriction, including without limitation the rights to use, copy,
7
+      modify, merge, publish, distribute, sublicense, and/or sell copies
8
+      of the Software, and to permit persons to whom the Software is
9
+      furnished to do so, subject to the following conditions:
10
+
11
+      The above copyright notice and this permission notice shall be
12
+      included in all copies or substantial portions of the Software.
13
+
14
+      THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+      EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+      MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+      NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18
+      HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19
+      WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+      OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
+      DEALINGS IN THE SOFTWARE.
22
+**/
23
+
24
+#include <stdlib.h>
25
+#include "avformat.h"
26
+#include "bitstream.h"
27
+#include "bytestream.h"
28
+#include "bswap.h"
29
+#include "oggdec.h"
30
+#include "avstring.h"
31
+
32
+static int speex_header(AVFormatContext *s, int idx) {
33
+    ogg_t *ogg = s->priv_data;
34
+    ogg_stream_t *os = ogg->streams + idx;
35
+    AVStream *st = s->streams[idx];
36
+    uint8_t *p = os->buf + os->pstart;
37
+
38
+    if (os->psize < 80)
39
+        return 1;
40
+
41
+    st->codec->codec_type = CODEC_TYPE_AUDIO;
42
+    st->codec->codec_id = CODEC_ID_SPEEX;
43
+
44
+    st->codec->sample_rate = AV_RL32(p + 36);
45
+    st->codec->channels = AV_RL32(p + 48);
46
+    st->codec->extradata_size = os->psize;
47
+    st->codec->extradata = av_malloc(st->codec->extradata_size);
48
+    memcpy(st->codec->extradata, p, st->codec->extradata_size);
49
+
50
+    st->time_base.num = 1;
51
+    st->time_base.den = st->codec->sample_rate;
52
+
53
+    return 0;
54
+}
55
+
56
+ogg_codec_t speex_codec = {
57
+    .magic = "Speex   ",
58
+    .magicsize = 8,
59
+    .header = speex_header
60
+};