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)
70 gst_buffer_ref (buffer);
71 packet->packet = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
76 gst_ogg_packet_wrapper_unmap (ogg_packet * packet, GstBuffer * buffer)
78 gst_buffer_unmap (buffer, packet->packet, packet->bytes);
79 gst_buffer_unref (buffer);
82 static inline ogg_packet *
83 gst_ogg_packet_from_wrapper (ogg_packet_wrapper * packet)
91 #include <Tremolo/ivorbiscodec.h>
92 #include <Tremolo/codec_internal.h>
93 typedef ogg_int16_t vorbis_sample_t;
95 #include <tremor/ivorbiscodec.h>
96 typedef ogg_int32_t vorbis_sample_t;
99 typedef struct _ogg_packet_wrapper ogg_packet_wrapper;
101 struct _ogg_packet_wrapper {
107 #define GST_VORBIS_DEC_DESCRIPTION "decode raw vorbis streams to integer audio"
109 #define GST_VORBIS_AUDIO_FORMAT GST_AUDIO_FORMAT_S16
110 #define GST_VORBIS_AUDIO_FORMAT_STR GST_AUDIO_NE (S16)
112 #define GST_VORBIS_DEC_SRC_CAPS \
113 GST_STATIC_CAPS ("audio/x-raw, " \
114 "format = (string) " GST_VORBIS_AUDIO_FORMAT_STR ", " \
115 "rate = (int) [ 1, MAX ], " \
116 "channels = (int) [ 1, 6 ]")
118 /* we need a different type name here */
119 #define GST_VORBIS_DEC_GLIB_TYPE_NAME GstIVorbisDec
121 /* and still have it compile */
122 typedef struct _GstVorbisDec GstIVorbisDec;
123 typedef struct _GstVorbisDecClass GstIVorbisDecClass;
125 /* compensate minor variation */
126 #define vorbis_synthesis(a, b) vorbis_synthesis (a, b, 1)
128 static inline guint8 *
129 gst_ogg_packet_data (ogg_packet * p)
131 return (guint8 *) p->packet->buffer->data;
135 gst_ogg_packet_size (ogg_packet * p)
137 return p->packet->buffer->size;
141 gst_ogg_packet_wrapper_map (ogg_packet_wrapper * packet,
144 ogg_reference *ref = &packet->ref;
145 ogg_buffer *buf = &packet->buf;
148 gst_buffer_ref (buffer);
149 buf->data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
152 buf->ptr.owner = NULL;
153 buf->ptr.next = NULL;
157 ref->length = buf->size;
160 packet->packet.packet = ref;
161 packet->packet.bytes = ref->length;
165 gst_ogg_packet_wrapper_unmap (ogg_packet_wrapper * packet,
168 ogg_reference *ref = &packet->ref;
169 ogg_buffer *buf = &packet->buf;
171 gst_buffer_unmap (buffer, buf->data, buf->size);
172 gst_buffer_unref (buffer);
175 static inline ogg_packet *
176 gst_ogg_packet_from_wrapper (ogg_packet_wrapper * packet)
178 return &(packet->packet);
183 typedef void (*CopySampleFunc)(vorbis_sample_t *out, vorbis_sample_t **in,
184 guint samples, gint channels);
186 CopySampleFunc get_copy_sample_func (gint channels);
188 #endif /* __GST_VORBIS_DEC_LIB_H__ */