update for memory api changes
[platform/upstream/gst-plugins-base.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, GstMapInfo *map)
67 {
68   gst_buffer_ref (buffer);
69   gst_buffer_map (buffer, map, GST_MAP_READ);
70   packet->packet = map->data;
71   packet->bytes = map->size;
72 }
73
74 static inline void
75 gst_ogg_packet_wrapper_unmap (ogg_packet * packet, GstBuffer * buffer, GstMapInfo *map)
76 {
77   gst_buffer_unmap (buffer, map);
78   gst_buffer_unref (buffer);
79 }
80
81 static inline ogg_packet *
82 gst_ogg_packet_from_wrapper (ogg_packet_wrapper * packet)
83 {
84   return packet;
85 }
86
87 #else
88
89 #ifdef USE_TREMOLO
90   #include <Tremolo/ivorbiscodec.h>
91   #include <Tremolo/codec_internal.h>
92   typedef ogg_int16_t                    vorbis_sample_t;
93 #else
94   #include <tremor/ivorbiscodec.h>
95   typedef ogg_int32_t                    vorbis_sample_t;
96 #endif
97
98 typedef struct _ogg_packet_wrapper     ogg_packet_wrapper;
99
100 struct _ogg_packet_wrapper {
101   ogg_packet          packet;
102   ogg_reference       ref;
103   ogg_buffer          buf;
104 };
105
106 #define GST_VORBIS_DEC_DESCRIPTION "decode raw vorbis streams to integer audio"
107
108 #define GST_VORBIS_AUDIO_FORMAT GST_AUDIO_FORMAT_S16
109 #define GST_VORBIS_AUDIO_FORMAT_STR GST_AUDIO_NE (S16)
110
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 ]")
116
117 /* we need a different type name here */
118 #define GST_VORBIS_DEC_GLIB_TYPE_NAME      GstIVorbisDec
119
120 /* and still have it compile */
121 typedef struct _GstVorbisDec               GstIVorbisDec;
122 typedef struct _GstVorbisDecClass          GstIVorbisDecClass;
123
124 /* compensate minor variation */
125 #define vorbis_synthesis(a, b)             vorbis_synthesis (a, b, 1)
126
127 static inline guint8 *
128 gst_ogg_packet_data (ogg_packet * p)
129 {
130   return (guint8 *) p->packet->buffer->data;
131 }
132
133 static inline gint
134 gst_ogg_packet_size (ogg_packet * p)
135 {
136   return p->packet->buffer->size;
137 }
138
139 static inline void
140 gst_ogg_packet_wrapper_map (ogg_packet_wrapper * packet,
141     GstBuffer * buffer, GstMapInfo * map)
142 {
143   GstMapInfo info;
144   ogg_reference *ref = &packet->ref;
145   ogg_buffer *buf = &packet->buf;
146   gsize size;
147
148   gst_buffer_ref (buffer);
149   gst_buffer_map (buffer, map, GST_MAP_READ);
150   buf->data = map->data;
151   buf->size = map->size;
152   buf->refcount = 1;
153   buf->ptr.owner = NULL;
154   buf->ptr.next = NULL;
155
156   ref->buffer = buf;
157   ref->begin = 0;
158   ref->length = buf->size;
159   ref->next = NULL;
160
161   packet->packet.packet = ref;
162   packet->packet.bytes = ref->length;
163 }
164
165 static inline void
166 gst_ogg_packet_wrapper_unmap (ogg_packet_wrapper * packet,
167     GstBuffer * buffer, GstMapInfo * map)
168 {
169   ogg_reference *ref = &packet->ref;
170   ogg_buffer *buf = &packet->buf;
171
172   gst_buffer_unmap (buffer, map);
173   gst_buffer_unref (buffer);
174 }
175
176 static inline ogg_packet *
177 gst_ogg_packet_from_wrapper (ogg_packet_wrapper * packet)
178 {
179   return &(packet->packet);
180 }
181
182 #endif
183
184 typedef void (*CopySampleFunc)(vorbis_sample_t *out, vorbis_sample_t **in,
185                            guint samples, gint channels);
186
187 CopySampleFunc get_copy_sample_func (gint channels);
188
189 #endif /* __GST_VORBIS_DEC_LIB_H__ */