oggparsecelt.c
Go to the documentation of this file.
1 /*
2  * Xiph CELT parser for Ogg
3  * Copyright (c) 2011 Nicolas George
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg 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  * FFmpeg 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 FFmpeg; 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 
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);
68  st->codec->channels = nb_channels;
70  av_free(st->codec->extradata);
71  st->codec->extradata = extradata;
72  st->codec->extradata_size = 2 * sizeof(uint32_t);
73  if (sample_rate)
74  avpriv_set_pts_info(st, 64, 1, sample_rate);
75  priv->extra_headers_left = 1 + extra_headers;
76  av_free(os->private);
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  .nb_header = 2,
97 };
const char * s
Definition: avisynth_c.h:668
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 time base and wrapping info for a given stream.
static int celt_header(AVFormatContext *s, int idx)
Definition: oggparsecelt.c:33
int version
Definition: avisynth_c.h:666
Format I/O context.
Definition: avformat.h:944
unsigned int psize
Definition: oggdec.h:66
#define AV_WL32(p, darg)
Definition: intreadwrite.h:282
uint8_t
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVStream ** streams
Definition: avformat.h:992
int ff_vorbis_comment(AVFormatContext *ms, AVDictionary **m, const uint8_t *buf, int size)
static const uint8_t frame_size[4]
Definition: g723_1_data.h:58
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:183
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:662
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
unsigned int pstart
Definition: oggdec.h:65
struct ogg_stream * streams
Definition: oggdec.h:99
#define AV_RL32
AVDictionary * metadata
Definition: avformat.h:711
const struct ogg_codec ff_celt_codec
Definition: oggparsecelt.c:92
Stream structure.
Definition: avformat.h:643
int frame_size
Number of samples per channel in an audio frame.
sample_rate
enum AVMediaType codec_type
enum AVCodecID codec_id
int sample_rate
samples per second
void * private
Definition: oggdec.h:87
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:73
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
const int8_t * magic
Definition: oggdec.h:32
uint8_t * buf
Definition: oggdec.h:62
Main libavformat public API header.
Definition: oggdec.h:98
int channels
number of audio channels
void * priv_data
Format private data.
Definition: avformat.h:964
uint8_t magicsize
Definition: oggdec.h:33
int nb_channels