2002-03-20 21:45:03 +00:00
|
|
|
/* GStreamer
|
2001-12-22 23:43:34 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2003-10-31 20:03:29 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2002-04-13 00:46:23 +00:00
|
|
|
#include "audio.h"
|
Surround sound support.
Original commit message from CVS:
* ext/a52dec/gsta52dec.c: (gst_a52dec_channels), (gst_a52dec_push),
(gst_a52dec_reneg), (gst_a52dec_loop), (plugin_init):
* ext/alsa/gstalsa.c: (gst_alsa_get_caps):
* ext/alsa/gstalsaplugin.c: (plugin_init):
* ext/dts/gstdtsdec.c: (gst_dtsdec_channels),
(gst_dtsdec_renegotiate), (gst_dtsdec_loop), (plugin_init):
* ext/faad/gstfaad.c: (gst_faad_init), (gst_faad_chanpos_from_gst),
(gst_faad_chanpos_to_gst), (gst_faad_sinkconnect),
(gst_faad_srcgetcaps), (gst_faad_srcconnect), (gst_faad_chain),
(gst_faad_change_state), (plugin_init):
* ext/faad/gstfaad.h:
* ext/vorbis/vorbis.c: (plugin_init):
* ext/vorbis/vorbisdec.c: (vorbis_dec_chain):
* gst-libs/gst/audio/Makefile.am:
* gst-libs/gst/audio/audio.c: (plugin_init):
* gst-libs/gst/audio/multichannel.c:
(gst_audio_check_channel_positions),
(gst_audio_get_channel_positions),
(gst_audio_set_channel_positions),
(gst_audio_set_structure_channel_positions_list),
(add_list_to_struct), (gst_audio_set_caps_channel_positions_list),
(gst_audio_fixate_channel_positions):
* gst-libs/gst/audio/multichannel.h:
* gst-libs/gst/audio/testchannels.c: (main):
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_class_init), (gst_audio_convert_init),
(gst_audio_convert_dispose), (gst_audio_convert_getcaps),
(gst_audio_convert_parse_caps), (gst_audio_convert_link),
(gst_audio_convert_fixate), (gst_audio_convert_channels):
* gst/audioconvert/plugin.c: (plugin_init):
Surround sound support.
2004-11-25 20:36:29 +00:00
|
|
|
#include "multichannel-enumtypes.h"
|
2001-12-22 23:43:34 +00:00
|
|
|
|
2004-01-12 19:35:54 +00:00
|
|
|
#include <gst/gststructure.h>
|
|
|
|
|
2001-12-22 23:43:34 +00:00
|
|
|
int
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_audio_frame_byte_size (GstPad * pad)
|
2001-12-22 23:43:34 +00:00
|
|
|
{
|
|
|
|
/* calculate byte size of an audio frame
|
|
|
|
* this should be moved closer to the gstreamer core
|
|
|
|
* and be implemented for every mime type IMO
|
2002-07-15 11:06:33 +00:00
|
|
|
* returns -1 if there's an error (to avoid division by zero),
|
|
|
|
* or the byte size if everything's ok
|
2001-12-22 23:43:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
int width = 0;
|
|
|
|
int channels = 0;
|
2003-12-27 19:37:17 +00:00
|
|
|
const GstCaps *caps = NULL;
|
2003-12-22 01:47:09 +00:00
|
|
|
GstStructure *structure;
|
2001-12-22 23:43:34 +00:00
|
|
|
|
|
|
|
/* get caps of pad */
|
|
|
|
caps = GST_PAD_CAPS (pad);
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
if (caps == NULL) {
|
2001-12-22 23:43:34 +00:00
|
|
|
/* ERROR: could not get caps of pad */
|
2004-03-14 22:34:34 +00:00
|
|
|
g_warning ("gstaudio: could not get caps of pad %s:%s\n",
|
2004-03-15 19:32:28 +00:00
|
|
|
GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad));
|
2001-12-22 23:43:34 +00:00
|
|
|
return 0;
|
2002-07-15 11:06:33 +00:00
|
|
|
}
|
2001-12-22 23:43:34 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_structure_get_int (structure, "width", &width);
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_structure_get_int (structure, "channels", &channels);
|
2004-03-14 22:34:34 +00:00
|
|
|
return (width / 8) * channels;
|
2001-12-22 23:43:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
long
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_audio_frame_length (GstPad * pad, GstBuffer * buf)
|
2001-12-22 23:43:34 +00:00
|
|
|
/* 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
|
2004-03-14 22:34:34 +00:00
|
|
|
* of the frame byte size
|
2001-12-22 23:43:34 +00:00
|
|
|
*/
|
|
|
|
return GST_BUFFER_SIZE (buf) / frame_byte_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
long
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_audio_frame_rate (GstPad * pad)
|
2001-12-22 23:43:34 +00:00
|
|
|
/*
|
|
|
|
* calculate frame rate (based on caps of pad)
|
|
|
|
* returns 0 if failed, rate if success
|
|
|
|
*/
|
|
|
|
{
|
2003-12-27 19:37:17 +00:00
|
|
|
const GstCaps *caps = NULL;
|
2002-03-30 17:06:26 +00:00
|
|
|
gint rate;
|
2003-12-22 01:47:09 +00:00
|
|
|
GstStructure *structure;
|
2001-12-22 23:43:34 +00:00
|
|
|
|
|
|
|
/* get caps of pad */
|
|
|
|
caps = GST_PAD_CAPS (pad);
|
|
|
|
|
2002-07-15 11:17:24 +00:00
|
|
|
if (caps == NULL) {
|
2001-12-22 23:43:34 +00:00
|
|
|
/* ERROR: could not get caps of pad */
|
2004-03-14 22:34:34 +00:00
|
|
|
g_warning ("gstaudio: could not get caps of pad %s:%s\n",
|
2004-03-15 19:32:28 +00:00
|
|
|
GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad));
|
2001-12-22 23:43:34 +00:00
|
|
|
return 0;
|
2004-03-14 22:34:34 +00:00
|
|
|
} else {
|
2003-12-22 01:47:09 +00:00
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_structure_get_int (structure, "rate", &rate);
|
2002-03-30 17:06:26 +00:00
|
|
|
return rate;
|
|
|
|
}
|
2001-12-22 23:43:34 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
double
|
|
|
|
gst_audio_length (GstPad * pad, GstBuffer * buf)
|
2001-12-22 23:43:34 +00:00
|
|
|
{
|
|
|
|
/* calculate length in seconds
|
|
|
|
* of audio buffer buf
|
|
|
|
* based on capabilities of pad
|
|
|
|
*/
|
|
|
|
|
|
|
|
long bytes = 0;
|
|
|
|
int width = 0;
|
|
|
|
int channels = 0;
|
2002-03-30 17:06:26 +00:00
|
|
|
int rate = 0;
|
2001-12-22 23:43:34 +00:00
|
|
|
|
|
|
|
double length;
|
|
|
|
|
2003-12-27 19:37:17 +00:00
|
|
|
const GstCaps *caps = NULL;
|
2003-12-22 01:47:09 +00:00
|
|
|
GstStructure *structure;
|
2001-12-22 23:43:34 +00:00
|
|
|
|
2002-07-12 21:09:17 +00:00
|
|
|
g_assert (GST_IS_BUFFER (buf));
|
2001-12-22 23:43:34 +00:00
|
|
|
/* get caps of pad */
|
|
|
|
caps = GST_PAD_CAPS (pad);
|
2004-03-14 22:34:34 +00:00
|
|
|
if (caps == NULL) {
|
2001-12-22 23:43:34 +00:00
|
|
|
/* ERROR: could not get caps of pad */
|
2004-03-14 22:34:34 +00:00
|
|
|
g_warning ("gstaudio: could not get caps of pad %s:%s\n",
|
2004-03-15 19:32:28 +00:00
|
|
|
GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad));
|
2001-12-22 23:43:34 +00:00
|
|
|
length = 0.0;
|
2004-03-14 22:34:34 +00:00
|
|
|
} else {
|
2003-12-22 01:47:09 +00:00
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
2001-12-22 23:43:34 +00:00
|
|
|
bytes = GST_BUFFER_SIZE (buf);
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_structure_get_int (structure, "width", &width);
|
|
|
|
gst_structure_get_int (structure, "channels", &channels);
|
|
|
|
gst_structure_get_int (structure, "rate", &rate);
|
2001-12-22 23:43:34 +00:00
|
|
|
|
2002-07-12 21:09:17 +00:00
|
|
|
g_assert (bytes != 0);
|
|
|
|
g_assert (width != 0);
|
|
|
|
g_assert (channels != 0);
|
|
|
|
g_assert (rate != 0);
|
2001-12-22 23:43:34 +00:00
|
|
|
length = (bytes * 8.0) / (double) (rate * channels * width);
|
|
|
|
}
|
2002-07-12 21:09:17 +00:00
|
|
|
/* g_print ("DEBUG: audio: returning length of %f\n", length); */
|
2001-12-22 23:43:34 +00:00
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
long
|
|
|
|
gst_audio_highest_sample_value (GstPad * pad)
|
2001-12-22 23:43:34 +00:00
|
|
|
/* calculate highest possible sample value
|
|
|
|
* based on capabilities of pad
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
gboolean is_signed = FALSE;
|
|
|
|
gint width = 0;
|
2003-12-27 19:37:17 +00:00
|
|
|
const GstCaps *caps = NULL;
|
2003-12-22 01:47:09 +00:00
|
|
|
GstStructure *structure;
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2001-12-22 23:43:34 +00:00
|
|
|
caps = GST_PAD_CAPS (pad);
|
2004-03-14 22:34:34 +00:00
|
|
|
if (caps == NULL) {
|
|
|
|
g_warning ("gstaudio: could not get caps of pad %s:%s\n",
|
2004-03-15 19:32:28 +00:00
|
|
|
GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad));
|
2002-07-15 11:17:24 +00:00
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_structure_get_int (structure, "width", &width);
|
|
|
|
gst_structure_get_boolean (structure, "signed", &is_signed);
|
|
|
|
|
|
|
|
if (is_signed)
|
|
|
|
--width;
|
2001-12-22 23:43:34 +00:00
|
|
|
/* example : 16 bit, signed : samples between -32768 and 32767 */
|
|
|
|
return ((long) (1 << width));
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
gboolean
|
|
|
|
gst_audio_is_buffer_framed (GstPad * pad, GstBuffer * buf)
|
2001-12-22 23:43:34 +00:00
|
|
|
/* 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;
|
|
|
|
}
|
2002-03-24 20:55:44 +00:00
|
|
|
|
2004-01-12 19:35:54 +00:00
|
|
|
/* _getcaps helper functions
|
|
|
|
* sets structure fields to default for audio type
|
|
|
|
* flag determines which structure fields to set to default
|
|
|
|
* keep these functions in sync with the templates in audio.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* private helper function
|
|
|
|
* sets a list on the structure
|
|
|
|
* pass in structure, fieldname for the list, type of the list values,
|
|
|
|
* number of list values, and each of the values, terminating with NULL
|
|
|
|
*/
|
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
_gst_audio_structure_set_list (GstStructure * structure,
|
|
|
|
const gchar * fieldname, GType type, int number, ...)
|
2004-01-12 19:35:54 +00:00
|
|
|
{
|
|
|
|
va_list varargs;
|
|
|
|
GValue value = { 0 };
|
|
|
|
GArray *array;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
g_return_if_fail (structure != NULL);
|
|
|
|
|
|
|
|
g_value_init (&value, GST_TYPE_LIST);
|
|
|
|
array = g_value_peek_pointer (&value);
|
|
|
|
|
|
|
|
va_start (varargs, number);
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
for (j = 0; j < number; ++j) {
|
2004-01-12 19:35:54 +00:00
|
|
|
int i;
|
|
|
|
gboolean b;
|
|
|
|
|
|
|
|
GValue list_value = { 0 };
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
switch (type) {
|
2004-01-12 19:35:54 +00:00
|
|
|
case G_TYPE_INT:
|
2004-03-15 19:32:28 +00:00
|
|
|
i = va_arg (varargs, int);
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2004-03-15 19:32:28 +00:00
|
|
|
g_value_init (&list_value, G_TYPE_INT);
|
|
|
|
g_value_set_int (&list_value, i);
|
|
|
|
break;
|
2004-01-12 19:35:54 +00:00
|
|
|
case G_TYPE_BOOLEAN:
|
2004-03-15 19:32:28 +00:00
|
|
|
b = va_arg (varargs, gboolean);
|
|
|
|
g_value_init (&list_value, G_TYPE_BOOLEAN);
|
|
|
|
g_value_set_boolean (&list_value, b);
|
|
|
|
break;
|
2004-03-14 22:34:34 +00:00
|
|
|
default:
|
2004-03-15 19:32:28 +00:00
|
|
|
g_warning
|
|
|
|
("_gst_audio_structure_set_list: LIST of given type not implemented.");
|
2004-01-12 19:35:54 +00:00
|
|
|
}
|
|
|
|
g_array_append_val (array, list_value);
|
|
|
|
|
|
|
|
}
|
|
|
|
gst_structure_set_value (structure, fieldname, &value);
|
|
|
|
va_end (varargs);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_audio_structure_set_int (GstStructure * structure, GstAudioFieldFlag flag)
|
2004-01-12 19:35:54 +00:00
|
|
|
{
|
|
|
|
if (flag & GST_AUDIO_FIELD_RATE)
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_structure_set (structure, "rate", GST_TYPE_INT_RANGE, 1, G_MAXINT,
|
2004-03-15 19:32:28 +00:00
|
|
|
NULL);
|
2004-01-12 19:35:54 +00:00
|
|
|
if (flag & GST_AUDIO_FIELD_CHANNELS)
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_structure_set (structure, "channels", GST_TYPE_INT_RANGE, 1, G_MAXINT,
|
2004-03-15 19:32:28 +00:00
|
|
|
NULL);
|
2004-01-12 19:35:54 +00:00
|
|
|
if (flag & GST_AUDIO_FIELD_ENDIANNESS)
|
2004-03-14 22:34:34 +00:00
|
|
|
_gst_audio_structure_set_list (structure, "endianness", G_TYPE_INT, 2,
|
2004-03-15 19:32:28 +00:00
|
|
|
G_LITTLE_ENDIAN, G_BIG_ENDIAN, NULL);
|
2004-01-12 19:35:54 +00:00
|
|
|
if (flag & GST_AUDIO_FIELD_WIDTH)
|
2004-03-14 22:34:34 +00:00
|
|
|
_gst_audio_structure_set_list (structure, "width", G_TYPE_INT, 3, 8, 16, 32,
|
2004-03-15 19:32:28 +00:00
|
|
|
NULL);
|
2004-01-12 19:35:54 +00:00
|
|
|
if (flag & GST_AUDIO_FIELD_DEPTH)
|
|
|
|
gst_structure_set (structure, "depth", GST_TYPE_INT_RANGE, 1, 32, NULL);
|
|
|
|
if (flag & GST_AUDIO_FIELD_SIGNED)
|
2004-03-14 22:34:34 +00:00
|
|
|
_gst_audio_structure_set_list (structure, "signed", G_TYPE_BOOLEAN, 2, TRUE,
|
2004-03-15 19:32:28 +00:00
|
|
|
FALSE, NULL);
|
2004-01-12 19:35:54 +00:00
|
|
|
if (flag & GST_AUDIO_FIELD_BUFFER_FRAMES)
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_structure_set (structure, "buffer-frames", GST_TYPE_INT_RANGE, 1,
|
2004-03-15 19:32:28 +00:00
|
|
|
G_MAXINT, NULL);
|
2004-01-12 19:35:54 +00:00
|
|
|
}
|
|
|
|
|
2002-03-24 20:55:44 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
plugin_init (GstPlugin * plugin)
|
2002-03-24 20:55:44 +00:00
|
|
|
{
|
Surround sound support.
Original commit message from CVS:
* ext/a52dec/gsta52dec.c: (gst_a52dec_channels), (gst_a52dec_push),
(gst_a52dec_reneg), (gst_a52dec_loop), (plugin_init):
* ext/alsa/gstalsa.c: (gst_alsa_get_caps):
* ext/alsa/gstalsaplugin.c: (plugin_init):
* ext/dts/gstdtsdec.c: (gst_dtsdec_channels),
(gst_dtsdec_renegotiate), (gst_dtsdec_loop), (plugin_init):
* ext/faad/gstfaad.c: (gst_faad_init), (gst_faad_chanpos_from_gst),
(gst_faad_chanpos_to_gst), (gst_faad_sinkconnect),
(gst_faad_srcgetcaps), (gst_faad_srcconnect), (gst_faad_chain),
(gst_faad_change_state), (plugin_init):
* ext/faad/gstfaad.h:
* ext/vorbis/vorbis.c: (plugin_init):
* ext/vorbis/vorbisdec.c: (vorbis_dec_chain):
* gst-libs/gst/audio/Makefile.am:
* gst-libs/gst/audio/audio.c: (plugin_init):
* gst-libs/gst/audio/multichannel.c:
(gst_audio_check_channel_positions),
(gst_audio_get_channel_positions),
(gst_audio_set_channel_positions),
(gst_audio_set_structure_channel_positions_list),
(add_list_to_struct), (gst_audio_set_caps_channel_positions_list),
(gst_audio_fixate_channel_positions):
* gst-libs/gst/audio/multichannel.h:
* gst-libs/gst/audio/testchannels.c: (main):
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_class_init), (gst_audio_convert_init),
(gst_audio_convert_dispose), (gst_audio_convert_getcaps),
(gst_audio_convert_parse_caps), (gst_audio_convert_link),
(gst_audio_convert_fixate), (gst_audio_convert_channels):
* gst/audioconvert/plugin.c: (plugin_init):
Surround sound support.
2004-11-25 20:36:29 +00:00
|
|
|
gst_audio_channel_position_get_type ();
|
|
|
|
|
2002-03-24 20:55:44 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"gstaudio",
|
|
|
|
"Support services for audio plugins",
|
|
|
|
plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN);
|