vorbisdec: report to 0.11
[platform/upstream/gstreamer.git] / ext / vorbis / gstvorbisdeclib.h
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., 59 Temple Place - Suite 330,
22  * Boston, MA 02111-1307, 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 #include <vorbis/codec.h>
34
35 typedef float                          vorbis_sample_t;
36 typedef ogg_packet                     ogg_packet_wrapper;
37
38 #define GST_VORBIS_DEC_DESCRIPTION "decode raw vorbis streams to float audio"
39
40 #define GST_VORBIS_AUDIO_FORMAT     GST_AUDIO_FORMAT_F32
41 #define GST_VORBIS_AUDIO_FORMAT_STR GST_AUDIO_NE (F32)
42
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 ]")
48
49 #define GST_VORBIS_DEC_DEFAULT_SAMPLE_WIDTH           (32)
50
51 #define GST_VORBIS_DEC_GLIB_TYPE_NAME      GstVorbisDec
52
53 static inline guint8 *
54 gst_ogg_packet_data (ogg_packet * p)
55 {
56   return (guint8 *) p->packet;
57 }
58
59 static inline gint
60 gst_ogg_packet_size (ogg_packet * p)
61 {
62   return p->bytes;
63 }
64
65 static inline void
66 gst_ogg_packet_wrapper_map (ogg_packet * packet, GstBuffer * buffer)
67 {
68   gsize size;
69
70   gst_buffer_ref (buffer);
71   packet->packet = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
72   packet->bytes = size;
73 }
74
75 static inline void
76 gst_ogg_packet_wrapper_unmap (ogg_packet * packet, GstBuffer * buffer)
77 {
78   gst_buffer_unmap (buffer, packet->packet, packet->bytes);
79   gst_buffer_unref (buffer);
80 }
81
82 static inline ogg_packet *
83 gst_ogg_packet_from_wrapper (ogg_packet_wrapper * packet)
84 {
85   return packet;
86 }
87
88 #else
89
90 #ifdef USE_TREMOLO
91   #include <Tremolo/ivorbiscodec.h>
92   #include <Tremolo/codec_internal.h>
93   typedef ogg_int16_t                    vorbis_sample_t;
94 #else
95   #include <tremor/ivorbiscodec.h>
96   typedef ogg_int32_t                    vorbis_sample_t;
97 #endif
98
99 typedef struct _ogg_packet_wrapper     ogg_packet_wrapper;
100
101 struct _ogg_packet_wrapper {
102   ogg_packet          packet;
103   ogg_reference       ref;
104   ogg_buffer          buf;
105 };
106
107 #define GST_VORBIS_DEC_DESCRIPTION "decode raw vorbis streams to integer audio"
108
109 #define GST_VORBIS_AUDIO_FORMAT GST_AUDIO_FORMAT_S16
110 #define GST_VORBIS_AUDIO_FORMAT_STR GST_AUDIO_NE (S16)
111
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 ]")
117
118 /* we need a different type name here */
119 #define GST_VORBIS_DEC_GLIB_TYPE_NAME      GstIVorbisDec
120
121 /* and still have it compile */
122 typedef struct _GstVorbisDec               GstIVorbisDec;
123 typedef struct _GstVorbisDecClass          GstIVorbisDecClass;
124
125 /* compensate minor variation */
126 #define vorbis_synthesis(a, b)             vorbis_synthesis (a, b, 1)
127
128 static inline guint8 *
129 gst_ogg_packet_data (ogg_packet * p)
130 {
131   return (guint8 *) p->packet->buffer->data;
132 }
133
134 static inline gint
135 gst_ogg_packet_size (ogg_packet * p)
136 {
137   return p->packet->buffer->size;
138 }
139
140 static inline void
141 gst_ogg_packet_wrapper_map (ogg_packet_wrapper * packet,
142     GstBuffer * buffer)
143 {
144   ogg_reference *ref = &packet->ref;
145   ogg_buffer *buf = &packet->buf;
146   gsize size;
147
148   gst_buffer_ref (buffer);
149   buf->data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
150   buf->size = size;
151   buf->refcount = 1;
152   buf->ptr.owner = NULL;
153   buf->ptr.next = NULL;
154
155   ref->buffer = buf;
156   ref->begin = 0;
157   ref->length = buf->size;
158   ref->next = NULL;
159
160   packet->packet.packet = ref;
161   packet->packet.bytes = ref->length;
162 }
163
164 static inline void
165 gst_ogg_packet_wrapper_unmap (ogg_packet_wrapper * packet,
166     GstBuffer * buffer)
167 {
168   ogg_reference *ref = &packet->ref;
169   ogg_buffer *buf = &packet->buf;
170
171   gst_buffer_unmap (buffer, buf->data, buf->size);
172   gst_buffer_unref (buffer);
173 }
174
175 static inline ogg_packet *
176 gst_ogg_packet_from_wrapper (ogg_packet_wrapper * packet)
177 {
178   return &(packet->packet);
179 }
180
181 #endif
182
183 typedef void (*CopySampleFunc)(vorbis_sample_t *out, vorbis_sample_t **in,
184                            guint samples, gint channels);
185
186 CopySampleFunc get_copy_sample_func (gint channels);
187
188 #endif /* __GST_VORBIS_DEC_LIB_H__ */