1 /* GStreamer
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>
5 *
6 * Tremor modifications <2006>:
7 * Chris Lord, OpenedHand Ltd. <chris@openedhand.com>, http://www.o-hand.com/
8 *
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.
13 *
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.
18 *
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., 51 Franklin St, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23 */
24
25 #ifndef __GST_VORBIS_DEC_LIB_H__
26 #define __GST_VORBIS_DEC_LIB_H__
27
28 #include <gst/gst.h>
29 #include <gst/audio/audio.h>
30
31 #ifndef TREMOR
32
33 #define GST_VORBIS_DEC_DESCRIPTION "decode raw vorbis streams to float audio"
34
35 #define GST_VORBIS_AUDIO_FORMAT GST_AUDIO_FORMAT_F32
36 #define GST_VORBIS_AUDIO_FORMAT_STR GST_AUDIO_NE (F32)
37
38 #define GST_VORBIS_DEC_SRC_CAPS \
39 GST_STATIC_CAPS ("audio/x-raw, " \
40 "format = (string)" GST_VORBIS_AUDIO_FORMAT_STR ", " \
41 "rate = (int) [ 1, MAX ], " \
42 "channels = (int) [ 1, 256 ]")
43
44 #define GST_VORBIS_DEC_DEFAULT_SAMPLE_WIDTH (32)
45
46 #else /* TREMOR */
47
48 #define GST_VORBIS_DEC_DESCRIPTION "decode raw vorbis streams to integer audio"
49
50 #define GST_VORBIS_AUDIO_FORMAT GST_AUDIO_FORMAT_S16
51 #define GST_VORBIS_AUDIO_FORMAT_STR GST_AUDIO_NE (S16)
52
53 #define GST_VORBIS_DEC_SRC_CAPS \
54 GST_STATIC_CAPS ("audio/x-raw, " \
55 "format = (string) " GST_VORBIS_AUDIO_FORMAT_STR ", " \
56 "rate = (int) [ 1, MAX ], " \
57 "channels = (int) [ 1, 6 ]")
58
59 #define GST_VORBIS_DEC_DEFAULT_SAMPLE_WIDTH (16)
60
61 /* we need a different type name here */
62 #define GstVorbisDec GstIVorbisDec
63 #define GstVorbisDecClass GstIVorbisDecClass
64 #define gst_vorbis_dec_get_type gst_ivorbis_dec_get_type
65 #define gst_vorbis_get_copy_sample_func gst_ivorbis_get_copy_sample_func
66
67 #endif /* TREMOR */
68
69 #ifndef USE_TREMOLO
70
71 #ifdef TREMOR
72 #include <tremor/ivorbiscodec.h>
73 typedef ogg_int32_t vorbis_sample_t;
74 #else
75 #include <vorbis/codec.h>
76 typedef float vorbis_sample_t;
77 #endif
78
79 typedef ogg_packet ogg_packet_wrapper;
80
81 static inline guint8 *
gst_ogg_packet_data(ogg_packet * p)82 gst_ogg_packet_data (ogg_packet * p)
83 {
84 return (guint8 *) p->packet;
85 }
86
87 static inline gint
gst_ogg_packet_size(ogg_packet * p)88 gst_ogg_packet_size (ogg_packet * p)
89 {
90 return p->bytes;
91 }
92
93 static inline void
gst_ogg_packet_wrapper_map(ogg_packet * packet,GstBuffer * buffer,GstMapInfo * map)94 gst_ogg_packet_wrapper_map (ogg_packet * packet, GstBuffer * buffer, GstMapInfo *map)
95 {
96 gst_buffer_ref (buffer);
97 gst_buffer_map (buffer, map, GST_MAP_READ);
98 packet->packet = map->data;
99 packet->bytes = map->size;
100 }
101
102 static inline void
gst_ogg_packet_wrapper_unmap(ogg_packet * packet,GstBuffer * buffer,GstMapInfo * map)103 gst_ogg_packet_wrapper_unmap (ogg_packet * packet, GstBuffer * buffer, GstMapInfo *map)
104 {
105 gst_buffer_unmap (buffer, map);
106 gst_buffer_unref (buffer);
107 }
108
109 static inline ogg_packet *
gst_ogg_packet_from_wrapper(ogg_packet_wrapper * packet)110 gst_ogg_packet_from_wrapper (ogg_packet_wrapper * packet)
111 {
112 return packet;
113 }
114
115 #else /* USE_TREMOLO */
116
117 #include <Tremolo/ivorbiscodec.h>
118 #include <Tremolo/codec_internal.h>
119 typedef ogg_int16_t vorbis_sample_t;
120 typedef struct _ogg_packet_wrapper ogg_packet_wrapper;
121
122 struct _ogg_packet_wrapper {
123 ogg_packet packet;
124 ogg_reference ref;
125 ogg_buffer buf;
126 };
127
128 /* compensate minor variation */
129 #define vorbis_synthesis(a, b) vorbis_synthesis (a, b, 1)
130
131 static inline guint8 *
gst_ogg_packet_data(ogg_packet * p)132 gst_ogg_packet_data (ogg_packet * p)
133 {
134 return (guint8 *) p->packet->buffer->data;
135 }
136
137 static inline gint
gst_ogg_packet_size(ogg_packet * p)138 gst_ogg_packet_size (ogg_packet * p)
139 {
140 return p->packet->buffer->size;
141 }
142
143 static inline void
gst_ogg_packet_wrapper_map(ogg_packet_wrapper * packet,GstBuffer * buffer,GstMapInfo * map)144 gst_ogg_packet_wrapper_map (ogg_packet_wrapper * packet,
145 GstBuffer * buffer, GstMapInfo * map)
146 {
147 GstMapInfo info;
148 ogg_reference *ref = &packet->ref;
149 ogg_buffer *buf = &packet->buf;
150 gsize size;
151
152 gst_buffer_ref (buffer);
153 gst_buffer_map (buffer, map, GST_MAP_READ);
154 buf->data = map->data;
155 buf->size = map->size;
156 buf->refcount = 1;
157 buf->ptr.owner = NULL;
158 buf->ptr.next = NULL;
159
160 ref->buffer = buf;
161 ref->begin = 0;
162 ref->length = buf->size;
163 ref->next = NULL;
164
165 packet->packet.packet = ref;
166 packet->packet.bytes = ref->length;
167 }
168
169 static inline void
gst_ogg_packet_wrapper_unmap(ogg_packet_wrapper * packet,GstBuffer * buffer,GstMapInfo * map)170 gst_ogg_packet_wrapper_unmap (ogg_packet_wrapper * packet,
171 GstBuffer * buffer, GstMapInfo * map)
172 {
173 ogg_reference *ref = &packet->ref;
174 ogg_buffer *buf = &packet->buf;
175
176 gst_buffer_unmap (buffer, map);
177 gst_buffer_unref (buffer);
178 }
179
180 static inline ogg_packet *
gst_ogg_packet_from_wrapper(ogg_packet_wrapper * packet)181 gst_ogg_packet_from_wrapper (ogg_packet_wrapper * packet)
182 {
183 return &(packet->packet);
184 }
185
186 #endif /* USE_TREMOLO */
187
188 typedef void (*CopySampleFunc)(vorbis_sample_t *out, vorbis_sample_t **in,
189 guint samples, gint channels);
190
191 CopySampleFunc gst_vorbis_get_copy_sample_func (gint channels);
192
193 #endif /* __GST_VORBIS_DEC_LIB_H__ */
194