oggparsecelt.c
Go to the documentation of this file.
1 /*
2  * Xiph CELT / Opus parser for Ogg
3  * Copyright (c) 2011 Nicolas George
4  *
5  * This file is part of Libav.
6  *
7  * Libav is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * Libav is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include <string.h>
23 
24 #include "libavutil/intreadwrite.h"
25 #include "avformat.h"
26 #include "internal.h"
27 #include "oggdec.h"
28 
31 };
32 
33 static int celt_header(AVFormatContext *s, int idx)
34 {
35  struct ogg *ogg = s->priv_data;
36  struct ogg_stream *os = ogg->streams + idx;
37  AVStream *st = s->streams[idx];
38  struct oggcelt_private *priv = os->private;
39  uint8_t *p = os->buf + os->pstart;
40 
41  if (os->psize == 60 &&
43  /* Main header */
44 
45  uint32_t version, sample_rate, nb_channels, frame_size;
46  uint32_t overlap, extra_headers;
47  uint8_t *extradata;
48 
49  extradata = av_malloc(2 * sizeof(uint32_t) +
51  priv = av_malloc(sizeof(struct oggcelt_private));
52  if (!extradata || !priv) {
53  av_free(extradata);
54  av_free(priv);
55  return AVERROR(ENOMEM);
56  }
57  version = AV_RL32(p + 28);
58  /* unused header size field skipped */
59  sample_rate = AV_RL32(p + 36);
60  nb_channels = AV_RL32(p + 40);
61  frame_size = AV_RL32(p + 44);
62  overlap = AV_RL32(p + 48);
63  /* unused bytes per packet field skipped */
64  extra_headers = AV_RL32(p + 56);
65  av_free(os->private);
66  av_free(st->codec->extradata);
69  st->codec->sample_rate = sample_rate;
70  st->codec->channels = nb_channels;
71  st->codec->frame_size = frame_size;
72  st->codec->extradata = extradata;
73  st->codec->extradata_size = 2 * sizeof(uint32_t);
74  if (sample_rate)
75  avpriv_set_pts_info(st, 64, 1, sample_rate);
76  priv->extra_headers_left = 1 + extra_headers;
77  os->private = priv;
78  AV_WL32(extradata + 0, overlap);
79  AV_WL32(extradata + 4, version);
80  return 1;
81  } else if (priv && priv->extra_headers_left) {
82  /* Extra headers (vorbiscomment) */
83 
84  ff_vorbis_comment(s, &st->metadata, p, os->psize);
85  priv->extra_headers_left--;
86  return 1;
87  } else {
88  return 0;
89  }
90 }
91 
92 const struct ogg_codec ff_celt_codec = {
93  .magic = "CELT ",
94  .magicsize = 8,
95  .header = celt_header,
96 };
Copyright (C) 2005 Michael Ahlberg, Måns Rullgård.
Definition: oggdec.h:31
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the pts for a given stream.
Definition: utils.c:3828
static int celt_header(AVFormatContext *s, int idx)
Definition: oggparsecelt.c:33
Format I/O context.
Definition: avformat.h:863
unsigned int psize
Definition: oggdec.h:66
#define AV_WL32(p, d)
Definition: intreadwrite.h:255
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1387
AVStream ** streams
Definition: avformat.h:908
int ff_vorbis_comment(AVFormatContext *ms, AVDictionary **m, const uint8_t *buf, int size)
int nb_channels
Definition: audioconvert.c:62
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:137
#define AVERROR(e)
Definition: error.h:43
AV_RL32
Definition: bytestream.h:89
AVCodecContext * codec
codec context
Definition: avformat.h:623
unsigned int pstart
Definition: oggdec.h:65
struct ogg_stream * streams
Definition: oggdec.h:95
AVDictionary * metadata
Definition: avformat.h:718
const struct ogg_codec ff_celt_codec
Definition: oggparsecelt.c:92
version
Definition: libspeexenc.c:304
Stream structure.
Definition: avformat.h:620
int frame_size
Samples per packet, initialized when calling 'init'.
Definition: avcodec.h:1470
enum AVMediaType codec_type
Definition: avcodec.h:1574
int sample_rate
samples per second
Definition: avcodec.h:1456
int extradata_size
Definition: avcodec.h:1388
void * private
Definition: oggdec.h:83
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:64
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:497
const int8_t * magic
Definition: oggdec.h:32
uint8_t * buf
Definition: oggdec.h:62
Main libavformat public API header.
Definition: oggdec.h:94
int channels
number of audio channels
Definition: avcodec.h:1457
void * priv_data
Format private data.
Definition: avformat.h:883
uint8_t magicsize
Definition: oggdec.h:33
enum CodecID codec_id
Definition: avcodec.h:1575