summaryrefslogtreecommitdiffstats
path: root/gst-libs/gst
diff options
context:
space:
mode:
authorThomas Vander Stichele <thomas@apestaart.org>2001-12-22 23:43:34 +0000
committerThomas Vander Stichele <thomas@apestaart.org>2001-12-22 23:43:34 +0000
commit41585b7e7836988c2e6ca136f8a85733ff2dc3cc (patch)
tree46e41cabc8389bcc1525a4c9dd2dbbac25d6b0bb /gst-libs/gst
parent0e758d6292d8c330db3c0abcaa0a9a359a27cf10 (diff)
downloadgst-plugins-bad-41585b7e7836988c2e6ca136f8a85733ff2dc3cc.tar.gz
gst-plugins-bad-41585b7e7836988c2e6ca136f8a85733ff2dc3cc.tar.bz2
gst-plugins-bad-41585b7e7836988c2e6ca136f8a85733ff2dc3cc.zip
moving and renaming we put the libs in the source in gst-libs/gst/(dir) the headers get installed in prefix/include/g...
Original commit message from CVS: moving and renaming we put the libs in the source in gst-libs/gst/(dir) the headers get installed in prefix/include/gst/(dir) the libs are installed in prefix/lib/gst with a libgst prefix the sources should be without the gst prefix as per irc agreement please comment if this sounds like a bad idea ;)
Diffstat (limited to 'gst-libs/gst')
-rw-r--r--gst-libs/gst/audio/Makefile.am11
-rw-r--r--gst-libs/gst/audio/audio.c152
-rw-r--r--gst-libs/gst/audio/audio.h109
3 files changed, 272 insertions, 0 deletions
diff --git a/gst-libs/gst/audio/Makefile.am b/gst-libs/gst/audio/Makefile.am
new file mode 100644
index 00000000..433c4fd0
--- /dev/null
+++ b/gst-libs/gst/audio/Makefile.am
@@ -0,0 +1,11 @@
+## libdir = $(libdir)/gst
+
+lib_LTLIBRARIES = libgstaudio.la
+
+libgstaudio_la_SOURCES = audio.c
+
+libgstaudioincludedir = $(includedir)/gst/audio
+libgstaudioinclude_HEADERS = audio.h
+
+libgstaudio_la_LIBADD = $(GST_LIBS)
+libgstaudio_la_CFLAGS = $(GST_CFLAGS) -finline-functions -ffast-math
diff --git a/gst-libs/gst/audio/audio.c b/gst-libs/gst/audio/audio.c
new file mode 100644
index 00000000..31b9ed89
--- /dev/null
+++ b/gst-libs/gst/audio/audio.c
@@ -0,0 +1,152 @@
+/* Gnome-Streamer
+ * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <gst/audio/audio.h>
+
+int
+gst_audio_frame_byte_size (GstPad* pad)
+{
+/* calculate byte size of an audio frame
+ * this should be moved closer to the gstreamer core
+ * and be implemented for every mime type IMO
+ * returns 0 if there's an error, or the byte size if everything's ok
+ */
+
+ int width = 0;
+ int channels = 0;
+
+ GstCaps *caps = NULL;
+
+ /* get caps of pad */
+ caps = GST_PAD_CAPS (pad);
+
+ if (caps == NULL)
+ /* ERROR: could not get caps of pad */
+ return 0;
+
+ width = gst_caps_get_int (caps, "width");
+ channels = gst_caps_get_int (caps, "channels");
+ return (width / 8) * channels;
+}
+
+long
+gst_audio_frame_length (GstPad* pad, GstBuffer* buf)
+/* calculate length of buffer in frames
+ * this should be moved closer to the gstreamer core
+ * and be implemented for every mime type IMO
+ * returns 0 if there's an error, or the number of frames if everything's ok
+ */
+{
+ int frame_byte_size = 0;
+
+ frame_byte_size = gst_audio_frame_byte_size (pad);
+ if (frame_byte_size == 0)
+ /* error */
+ return 0;
+ /* FIXME: this function assumes the buffer size to be a whole multiple
+ * of the frame byte size
+ */
+ return GST_BUFFER_SIZE (buf) / frame_byte_size;
+}
+
+long
+gst_audio_frame_rate (GstPad *pad)
+/*
+ * calculate frame rate (based on caps of pad)
+ * returns 0 if failed, rate if success
+ */
+{
+ GstCaps *caps = NULL;
+
+ /* get caps of pad */
+ caps = GST_PAD_CAPS (pad);
+
+ if (caps == NULL)
+ /* ERROR: could not get caps of pad */
+ return 0;
+ else
+ return gst_caps_get_int (caps, "rate");
+}
+
+double
+gst_audio_length (GstPad* pad, GstBuffer* buf)
+{
+/* calculate length in seconds
+ * of audio buffer buf
+ * based on capabilities of pad
+ */
+
+ long bytes = 0;
+ int width = 0;
+ int channels = 0;
+ long rate = 0L;
+
+ double length;
+
+ GstCaps *caps = NULL;
+
+ /* get caps of pad */
+ caps = GST_PAD_CAPS (pad);
+ if (caps == NULL)
+ {
+ /* ERROR: could not get caps of pad */
+ length = 0.0;
+ }
+ else
+ {
+ bytes = GST_BUFFER_SIZE (buf);
+ width = gst_caps_get_int (caps, "width");
+ channels = gst_caps_get_int (caps, "channels");
+ rate = gst_caps_get_int (caps, "rate");
+
+ length = (bytes * 8.0) / (double) (rate * channels * width);
+ }
+ return length;
+}
+
+long
+gst_audio_highest_sample_value (GstPad* pad)
+/* calculate highest possible sample value
+ * based on capabilities of pad
+ */
+{
+ gboolean is_signed = FALSE;
+ gint width = 0;
+ GstCaps *caps = NULL;
+
+ caps = GST_PAD_CAPS (pad);
+ // FIXME : Please change this to a better warning method !
+ if (caps == NULL)
+ printf ("WARNING: gstaudio: could not get caps of pad !\n");
+ width = gst_caps_get_int (caps, "width");
+ is_signed = gst_caps_get_boolean (caps, "signed");
+ if (is_signed) --width;
+ /* example : 16 bit, signed : samples between -32768 and 32767 */
+ return ((long) (1 << width));
+}
+
+gboolean
+gst_audio_is_buffer_framed (GstPad* pad, GstBuffer* buf)
+/* check if the buffer size is a whole multiple of the frame size */
+{
+ if (GST_BUFFER_SIZE (buf) % gst_audio_frame_byte_size (pad) == 0)
+ return TRUE;
+ else
+ return FALSE;
+}
diff --git a/gst-libs/gst/audio/audio.h b/gst-libs/gst/audio/audio.h
new file mode 100644
index 00000000..09ef3ec7
--- /dev/null
+++ b/gst-libs/gst/audio/audio.h
@@ -0,0 +1,109 @@
+/* Gnome-Streamer
+ * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
+ * Library <2001> Thomas Vander Stichele <thomas@apestaart.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <gst/gst.h>
+
+/* for people that are looking at this source: the purpose of these defines is
+ * to make GstCaps a bit easier, in that you don't have to know all of the
+ * properties that need to be defined. you can just use these macros. currently
+ * (8/01) the only plugins that use these are the passthrough, speed, volume,
+ * and [de]interleave plugins. so. these are for convenience only, and do not
+ * specify the 'limits' of gstreamer. you might also use these definitions as a
+ * base for making your own caps, if need be.
+ *
+ * for example, to make a source pad that can output mono streams of either
+ * float or int:
+
+ template = gst_padtemplate_new
+ ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+ gst_caps_append(gst_caps_new ("sink_int", "audio/raw",
+ GST_AUDIO_INT_PAD_TEMPLATE_PROPS),
+ gst_caps_new ("sink_float", "audio/raw",
+ GST_AUDIO_FLOAT_MONO_PAD_TEMPLATE_PROPS)),
+ NULL);
+
+ srcpad = gst_pad_new_from_template(template,"src");
+
+ * Andy Wingo, 18 August 2001 */
+
+#define GST_AUDIO_INT_PAD_TEMPLATE_PROPS \
+ gst_props_new (\
+ "format", GST_PROPS_STRING ("int"),\
+ "law", GST_PROPS_INT (0),\
+ "endianness", GST_PROPS_INT (G_BYTE_ORDER),\
+ "signed", GST_PROPS_LIST (\
+ GST_PROPS_BOOLEAN (TRUE),\
+ GST_PROPS_BOOLEAN(FALSE)\
+ ),\
+ "width", GST_PROPS_LIST (GST_PROPS_INT(8), GST_PROPS_INT(16)),\
+ "depth", GST_PROPS_LIST (GST_PROPS_INT(8), GST_PROPS_INT(16)),\
+ "rate", GST_PROPS_INT_RANGE (4000, 96000),\
+ "channels", GST_PROPS_INT_RANGE (1, G_MAXINT),\
+ NULL)
+
+#define GST_AUDIO_INT_MONO_PAD_TEMPLATE_PROPS \
+ gst_props_new (\
+ "format", GST_PROPS_STRING ("int"),\
+ "law", GST_PROPS_INT (0),\
+ "endianness", GST_PROPS_INT (G_BYTE_ORDER),\
+ "signed", GST_PROPS_LIST (\
+ GST_PROPS_BOOLEAN (TRUE),\
+ GST_PROPS_BOOLEAN(FALSE)\
+ ),\
+ "width", GST_PROPS_LIST (GST_PROPS_INT(8), GST_PROPS_INT(16)),\
+ "depth", GST_PROPS_LIST (GST_PROPS_INT(8), GST_PROPS_INT(16)),\
+ "rate", GST_PROPS_INT_RANGE (4000, 96000),\
+ "channels", GST_PROPS_INT (1),\
+ NULL)
+
+#define GST_AUDIO_FLOAT_MONO_PAD_TEMPLATE_PROPS \
+ gst_props_new (\
+ "format", GST_PROPS_STRING ("float"),\
+ "layout", GST_PROPS_STRING ("gfloat"),\
+ "intercept", GST_PROPS_FLOAT (0.0),\
+ "slope", GST_PROPS_FLOAT (1.0),\
+ "rate", GST_PROPS_INT_RANGE (4000, 96000),\
+ "channels", GST_PROPS_INT (1),\
+ NULL)
+
+/*
+ * this library defines and implements some helper functions for audio
+ * handling
+ */
+
+/* get byte size of audio frame (based on caps of pad */
+int gst_audio_frame_byte_size (GstPad* pad);
+
+/* get length in frames of buffer */
+long gst_audio_frame_length (GstPad* pad, GstBuffer* buf);
+
+/* get frame rate based on caps */
+long gst_audio_frame_rate (GstPad *pad);
+
+/* calculate length in seconds of audio buffer buf based on caps of pad */
+double gst_audio_length (GstPad* pad, GstBuffer* buf);
+
+/* calculate highest possible sample value based on capabilities of pad */
+long gst_audio_highest_sample_value (GstPad* pad);
+
+/* check if the buffer size is a whole multiple of the frame size */
+gboolean gst_audio_is_buffer_framed (GstPad* pad, GstBuffer* buf);
+
+