2 * Copyright (C) 2010 Mark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>
3 * Copyright (C) 2010 Nokia Corporation. All rights reserved.
4 * Contact: Stefan Kost <stefan.kost@nokia.com>
6 * Tremor modifications <2006>:
7 * Chris Lord, OpenedHand Ltd. <chris@openedhand.com>, http://www.o-hand.com/
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
25 #ifndef __GST_VORBIS_DEC_LIB_H__
26 #define __GST_VORBIS_DEC_LIB_H__
29 #include <gst/audio/audio.h>
33 #include <vorbis/codec.h>
35 typedef float vorbis_sample_t;
36 typedef ogg_packet ogg_packet_wrapper;
38 #define GST_VORBIS_DEC_DESCRIPTION "decode raw vorbis streams to float audio"
40 #define GST_VORBIS_AUDIO_FORMAT GST_AUDIO_FORMAT_F32
41 #define GST_VORBIS_AUDIO_FORMAT_STR GST_AUDIO_NE (F32)
43 #define GST_VORBIS_DEC_SRC_CAPS \
44 GST_STATIC_CAPS ("audio/x-raw, " \
45 "format = (string)" GST_VORBIS_AUDIO_FORMAT_STR ", " \
46 "rate = (int) [ 1, MAX ], " \
47 "channels = (int) [ 1, 256 ]")
49 #define GST_VORBIS_DEC_DEFAULT_SAMPLE_WIDTH (32)
51 #define GST_VORBIS_DEC_GLIB_TYPE_NAME GstVorbisDec
53 static inline guint8 *
54 gst_ogg_packet_data (ogg_packet * p)
56 return (guint8 *) p->packet;
60 gst_ogg_packet_size (ogg_packet * p)
66 gst_ogg_packet_wrapper_map (ogg_packet * packet, GstBuffer * buffer, GstMapInfo *map)
68 gst_buffer_ref (buffer);
69 gst_buffer_map (buffer, map, GST_MAP_READ);
70 packet->packet = map->data;
71 packet->bytes = map->size;
75 gst_ogg_packet_wrapper_unmap (ogg_packet * packet, GstBuffer * buffer, GstMapInfo *map)
77 gst_buffer_unmap (buffer, map);
78 gst_buffer_unref (buffer);
81 static inline ogg_packet *
82 gst_ogg_packet_from_wrapper (ogg_packet_wrapper * packet)
90 #include <Tremolo/ivorbiscodec.h>
91 #include <Tremolo/codec_internal.h>
92 typedef ogg_int16_t vorbis_sample_t;
94 #include <tremor/ivorbiscodec.h>
95 typedef ogg_int32_t vorbis_sample_t;
98 typedef struct _ogg_packet_wrapper ogg_packet_wrapper;
100 struct _ogg_packet_wrapper {
106 #define GST_VORBIS_DEC_DESCRIPTION "decode raw vorbis streams to integer audio"
108 #define GST_VORBIS_AUDIO_FORMAT GST_AUDIO_FORMAT_S16
109 #define GST_VORBIS_AUDIO_FORMAT_STR GST_AUDIO_NE (S16)
111 #define GST_VORBIS_DEC_SRC_CAPS \
112 GST_STATIC_CAPS ("audio/x-raw, " \
113 "format = (string) " GST_VORBIS_AUDIO_FORMAT_STR ", " \
114 "rate = (int) [ 1, MAX ], " \
115 "channels = (int) [ 1, 6 ]")
117 /* we need a different type name here */
118 #define GST_VORBIS_DEC_GLIB_TYPE_NAME GstIVorbisDec
120 /* and still have it compile */
121 typedef struct _GstVorbisDec GstIVorbisDec;
122 typedef struct _GstVorbisDecClass GstIVorbisDecClass;
124 /* compensate minor variation */
125 #define vorbis_synthesis(a, b) vorbis_synthesis (a, b, 1)
127 static inline guint8 *
128 gst_ogg_packet_data (ogg_packet * p)
130 return (guint8 *) p->packet->buffer->data;
134 gst_ogg_packet_size (ogg_packet * p)
136 return p->packet->buffer->size;
140 gst_ogg_packet_wrapper_map (ogg_packet_wrapper * packet,
141 GstBuffer * buffer, GstMapInfo * map)
144 ogg_reference *ref = &packet->ref;
145 ogg_buffer *buf = &packet->buf;
148 gst_buffer_ref (buffer);
149 gst_buffer_map (buffer, map, GST_MAP_READ);
150 buf->data = map->data;
151 buf->size = map->size;
153 buf->ptr.owner = NULL;
154 buf->ptr.next = NULL;
158 ref->length = buf->size;
161 packet->packet.packet = ref;
162 packet->packet.bytes = ref->length;
166 gst_ogg_packet_wrapper_unmap (ogg_packet_wrapper * packet,
167 GstBuffer * buffer, GstMapInfo * map)
169 ogg_reference *ref = &packet->ref;
170 ogg_buffer *buf = &packet->buf;
172 gst_buffer_unmap (buffer, map);
173 gst_buffer_unref (buffer);
176 static inline ogg_packet *
177 gst_ogg_packet_from_wrapper (ogg_packet_wrapper * packet)
179 return &(packet->packet);
184 typedef void (*CopySampleFunc)(vorbis_sample_t *out, vorbis_sample_t **in,
185 guint samples, gint channels);
187 CopySampleFunc get_copy_sample_func (gint channels);
189 #endif /* __GST_VORBIS_DEC_LIB_H__ */