This patch also introduces CODEC_ID_CELT.
Signed-off-by: Nicolas George <nicolas.george@normalesup.org>
| ... | ... |
@@ -164,6 +164,7 @@ OBJS-$(CONFIG_NUT_DEMUXER) += nutdec.o nut.o riff.o |
| 164 | 164 |
OBJS-$(CONFIG_NUT_MUXER) += nutenc.o nut.o riff.o |
| 165 | 165 |
OBJS-$(CONFIG_NUV_DEMUXER) += nuv.o riff.o |
| 166 | 166 |
OBJS-$(CONFIG_OGG_DEMUXER) += oggdec.o \ |
| 167 |
+ oggparsecelt.o \ |
|
| 167 | 168 |
oggparsedirac.o \ |
| 168 | 169 |
oggparseflac.o \ |
| 169 | 170 |
oggparseogm.o \ |
| ... | ... |
@@ -98,6 +98,7 @@ struct ogg {
|
| 98 | 98 |
#define OGG_FLAG_BOS 2 |
| 99 | 99 |
#define OGG_FLAG_EOS 4 |
| 100 | 100 |
|
| 101 |
+extern const struct ogg_codec ff_celt_codec; |
|
| 101 | 102 |
extern const struct ogg_codec ff_dirac_codec; |
| 102 | 103 |
extern const struct ogg_codec ff_flac_codec; |
| 103 | 104 |
extern const struct ogg_codec ff_ogm_audio_codec; |
| 104 | 105 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,99 @@ |
| 0 |
+/* |
|
| 1 |
+ * Xiph CELT / Opus parser for Ogg |
|
| 2 |
+ * Copyright (c) 2011 Nicolas George |
|
| 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 <string.h> |
|
| 22 |
+#include "avformat.h" |
|
| 23 |
+#include "oggdec.h" |
|
| 24 |
+#include "libavutil/intreadwrite.h" |
|
| 25 |
+ |
|
| 26 |
+struct oggcelt_private {
|
|
| 27 |
+ int extra_headers_left; |
|
| 28 |
+}; |
|
| 29 |
+ |
|
| 30 |
+static int celt_header(AVFormatContext *s, int idx) |
|
| 31 |
+{
|
|
| 32 |
+ struct ogg *ogg = s->priv_data; |
|
| 33 |
+ struct ogg_stream *os = ogg->streams + idx; |
|
| 34 |
+ AVStream *st = s->streams[idx]; |
|
| 35 |
+ struct oggcelt_private *priv = os->private; |
|
| 36 |
+ uint8_t *p = os->buf + os->pstart; |
|
| 37 |
+ |
|
| 38 |
+ if (os->psize == 60 && |
|
| 39 |
+ !memcmp(p, ff_celt_codec.magic, ff_celt_codec.magicsize)) {
|
|
| 40 |
+ |
|
| 41 |
+ /* Main header */ |
|
| 42 |
+ |
|
| 43 |
+ uint32_t version, header_size, sample_rate, nb_channels, frame_size; |
|
| 44 |
+ uint32_t overlap, bytes_per_packet, extra_headers; |
|
| 45 |
+ uint8_t *extradata; |
|
| 46 |
+ |
|
| 47 |
+ extradata = av_malloc(2 * sizeof(uint32_t) + |
|
| 48 |
+ FF_INPUT_BUFFER_PADDING_SIZE); |
|
| 49 |
+ priv = av_malloc(sizeof(struct oggcelt_private)); |
|
| 50 |
+ if (!extradata || !priv) {
|
|
| 51 |
+ av_free(extradata); |
|
| 52 |
+ av_free(priv); |
|
| 53 |
+ return AVERROR(ENOMEM); |
|
| 54 |
+ } |
|
| 55 |
+ version = AV_RL32(p + 28); |
|
| 56 |
+ header_size = AV_RL32(p + 32); /* unused */ |
|
| 57 |
+ sample_rate = AV_RL32(p + 36); |
|
| 58 |
+ nb_channels = AV_RL32(p + 40); |
|
| 59 |
+ frame_size = AV_RL32(p + 44); |
|
| 60 |
+ overlap = AV_RL32(p + 48); |
|
| 61 |
+ bytes_per_packet = AV_RL32(p + 52); /* unused */ |
|
| 62 |
+ extra_headers = AV_RL32(p + 56); |
|
| 63 |
+ av_free(os->private); |
|
| 64 |
+ av_free(st->codec->extradata); |
|
| 65 |
+ st->codec->codec_type = AVMEDIA_TYPE_AUDIO; |
|
| 66 |
+ st->codec->codec_id = CODEC_ID_CELT; |
|
| 67 |
+ st->codec->sample_rate = sample_rate; |
|
| 68 |
+ st->codec->channels = nb_channels; |
|
| 69 |
+ st->codec->frame_size = frame_size; |
|
| 70 |
+ st->codec->sample_fmt = AV_SAMPLE_FMT_S16; |
|
| 71 |
+ st->codec->extradata = extradata; |
|
| 72 |
+ st->codec->extradata_size = 2 * sizeof(uint32_t); |
|
| 73 |
+ if (sample_rate) |
|
| 74 |
+ av_set_pts_info(st, 64, 1, sample_rate); |
|
| 75 |
+ priv->extra_headers_left = 1 + extra_headers; |
|
| 76 |
+ os->private = priv; |
|
| 77 |
+ AV_WL32(extradata + 0, overlap); |
|
| 78 |
+ AV_WL32(extradata + 4, version); |
|
| 79 |
+ return 1; |
|
| 80 |
+ |
|
| 81 |
+ } else if(priv && priv->extra_headers_left) {
|
|
| 82 |
+ |
|
| 83 |
+ /* Extra headers (vorbiscomment) */ |
|
| 84 |
+ |
|
| 85 |
+ ff_vorbis_comment(s, &st->metadata, p, os->psize); |
|
| 86 |
+ priv->extra_headers_left--; |
|
| 87 |
+ return 1; |
|
| 88 |
+ |
|
| 89 |
+ } else {
|
|
| 90 |
+ return 0; |
|
| 91 |
+ } |
|
| 92 |
+} |
|
| 93 |
+ |
|
| 94 |
+const struct ogg_codec ff_celt_codec = {
|
|
| 95 |
+ .magic = "CELT ", |
|
| 96 |
+ .magicsize = 8, |
|
| 97 |
+ .header = celt_header, |
|
| 98 |
+}; |
| ... | ... |
@@ -2084,7 +2084,8 @@ static int has_codec_parameters(AVCodecContext *enc) |
| 2084 | 2084 |
enc->codec_id == CODEC_ID_MP1 || |
| 2085 | 2085 |
enc->codec_id == CODEC_ID_MP2 || |
| 2086 | 2086 |
enc->codec_id == CODEC_ID_MP3 || |
| 2087 |
- enc->codec_id == CODEC_ID_SPEEX)) |
|
| 2087 |
+ enc->codec_id == CODEC_ID_SPEEX || |
|
| 2088 |
+ enc->codec_id == CODEC_ID_CELT)) |
|
| 2088 | 2089 |
return 0; |
| 2089 | 2090 |
break; |
| 2090 | 2091 |
case AVMEDIA_TYPE_VIDEO: |