mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-24 01:00:37 +00:00
Remove dead audiofile plugin
This was never even ported to 0.10.
This commit is contained in:
parent
914291808a
commit
0b4a3a4dbd
11 changed files with 0 additions and 1807 deletions
|
@ -16,12 +16,6 @@ else
|
|||
APEXSINK_DIR =
|
||||
endif
|
||||
|
||||
# if USE_AUDIOFILE
|
||||
# AUDIOFILE_DIR=audiofile
|
||||
# else
|
||||
AUDIOFILE_DIR=
|
||||
# endif
|
||||
|
||||
if USE_BS2B
|
||||
BS2B_DIR=bs2b
|
||||
else
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
|
||||
plugin_LTLIBRARIES = libgstaudiofile.la
|
||||
|
||||
libgstaudiofile_la_SOURCES = gstaf.c gstafsink.c gstafsrc.c gstafparse.c
|
||||
libgstaudiofile_la_CFLAGS = $(GST_PLUGINS_BAD_CFLAGS) $(GST_CFLAGS) $(AUDIOFILE_CFLAGS)
|
||||
libgstaudiofile_la_LIBADD = $(AUDIOFILE_LIBS)
|
||||
libgstaudiofile_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
|
||||
libgstaudiofile_la_LIBTOOLFLAGS = $(GST_PLUGIN_LIBTOOLFLAGS)
|
||||
|
||||
noinst_HEADERS = gstafsink.h gstafsrc.h gstafparse.h
|
|
@ -1,39 +0,0 @@
|
|||
This plugin wraps the SGI Audiofile
|
||||
(http://oss.sgi.com/projects/audiofile/) library into a src and sink
|
||||
element.
|
||||
|
||||
You can read from and write to the supported formats (WAVE, AIFF, AIFFC,
|
||||
NEXTSND).
|
||||
|
||||
What is supported :
|
||||
* all the file formats
|
||||
* integer sample data, both 2's complement and unsigned
|
||||
* 8 or 16 bit width & depth (haven't tested others)
|
||||
* sample rate
|
||||
* some sort of endianness control
|
||||
|
||||
What isn't supported yet :
|
||||
* float data
|
||||
|
||||
What you can do :
|
||||
* src element only accepts location argument
|
||||
* sink element accepts location, endianness and type
|
||||
- location : file on the system to output
|
||||
- endianness : at this time endianness is still a bit shady
|
||||
you can either set 1234 or 4321;
|
||||
setting it to 4321 will byteswap the buffer data
|
||||
you might want to keep it at 1234 for now
|
||||
- type : one of the file types
|
||||
|
||||
Use gstreamer-inspect on afsink and afsrc to see all of the supported
|
||||
options.
|
||||
|
||||
Examples :
|
||||
|
||||
* tools/gstreamer-launch afsrc location=/opt/media/wav/dark-480-16-m.wav ! afsink type=2 location=/opt/media/wav/dark-480-16-m.aiff
|
||||
|
||||
Future plans :
|
||||
|
||||
* add float support
|
||||
* wrap up afsink and afsrc with pipe and fork to act like data convertors,
|
||||
allowing arbitrary choice of sink and src element
|
|
@ -1,47 +0,0 @@
|
|||
/* GStreamer
|
||||
* 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., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "gstafsrc.h"
|
||||
#include "gstafsink.h"
|
||||
#include "gstafparse.h"
|
||||
|
||||
gboolean gst_aftypes_plugin_init (GstPlugin * plugin);
|
||||
|
||||
static gboolean
|
||||
plugin_init (GstPlugin * plugin)
|
||||
{
|
||||
if (!gst_library_load ("gstbytestream"))
|
||||
return FALSE;
|
||||
|
||||
gst_afsink_plugin_init (plugin);
|
||||
gst_afsrc_plugin_init (plugin);
|
||||
gst_afparse_plugin_init (plugin);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
||||
GST_VERSION_MINOR,
|
||||
audiofile,
|
||||
"Audiofile plugin", plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME,
|
||||
GST_PACKAGE_ORIGIN)
|
|
@ -1,515 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
||||
* 2000 Wim Taymans <wtay@chello.be>
|
||||
*
|
||||
* gstafparse.c:
|
||||
*
|
||||
* 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., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
#include <gst/gst.h>
|
||||
#include <gst/audio/audio.h>
|
||||
#include <string.h>
|
||||
#include "gstafparse.h"
|
||||
|
||||
/* AFParse signals and args */
|
||||
enum
|
||||
{
|
||||
/* FILL ME */
|
||||
SIGNAL_HANDOFF,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
ARG_0
|
||||
};
|
||||
|
||||
/* added a src factory function to force audio/raw MIME type */
|
||||
static GstStaticPadTemplate afparse_src_factory =
|
||||
GST_STATIC_PAD_TEMPLATE ("src",
|
||||
GST_PAD_SRC,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS ("audio/x-raw-int, "
|
||||
"rate = (int) [ 1, MAX ], "
|
||||
"channels = (int) [ 1, MAX ], "
|
||||
"endianness = (int) BYTE_ORDER, "
|
||||
"width = (int) { 8, 16 }, "
|
||||
"depth = (int) { 8, 16 }, " "signed = (boolean) { true, false }")
|
||||
);
|
||||
|
||||
static GstStaticPadTemplate afparse_sink_factory =
|
||||
GST_STATIC_PAD_TEMPLATE ("sink",
|
||||
GST_PAD_SINK,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS ("audio/x-aiff; " "audio/x-wav; " "audio/x-au")
|
||||
);
|
||||
|
||||
static void gst_afparse_base_init (gpointer g_class);
|
||||
static void gst_afparse_class_init (GstAFParseClass * klass);
|
||||
static void gst_afparse_init (GstAFParse * afparse);
|
||||
|
||||
static gboolean gst_afparse_open_file (GstAFParse * afparse);
|
||||
static void gst_afparse_close_file (GstAFParse * afparse);
|
||||
|
||||
static void gst_afparse_loop (GstElement * element);
|
||||
static void gst_afparse_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec);
|
||||
static void gst_afparse_get_property (GObject * object, guint prop_id,
|
||||
GValue * value, GParamSpec * pspec);
|
||||
static ssize_t gst_afparse_vf_read (AFvirtualfile * vfile, void *data,
|
||||
size_t nbytes);
|
||||
static long gst_afparse_vf_length (AFvirtualfile * vfile);
|
||||
static ssize_t gst_afparse_vf_write (AFvirtualfile * vfile, const void *data,
|
||||
size_t nbytes);
|
||||
static void gst_afparse_vf_destroy (AFvirtualfile * vfile);
|
||||
static long gst_afparse_vf_seek (AFvirtualfile * vfile, long offset,
|
||||
int is_relative);
|
||||
static long gst_afparse_vf_tell (AFvirtualfile * vfile);
|
||||
|
||||
GType
|
||||
gst_afparse_get_type (void)
|
||||
{
|
||||
static GType afparse_type = 0;
|
||||
|
||||
if (!afparse_type) {
|
||||
static const GTypeInfo afparse_info = {
|
||||
sizeof (GstAFParseClass),
|
||||
gst_afparse_base_init,
|
||||
NULL,
|
||||
(GClassInitFunc) gst_afparse_class_init,
|
||||
NULL,
|
||||
NULL,
|
||||
sizeof (GstAFParse),
|
||||
0,
|
||||
(GInstanceInitFunc) gst_afparse_init,
|
||||
};
|
||||
|
||||
afparse_type =
|
||||
g_type_register_static (GST_TYPE_ELEMENT, "GstAFParse", &afparse_info,
|
||||
0);
|
||||
}
|
||||
return afparse_type;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_afparse_base_init (gpointer g_class)
|
||||
{
|
||||
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
||||
|
||||
gst_element_class_add_pad_template (element_class,
|
||||
gst_static_pad_template_get (&afparse_src_factory));
|
||||
gst_element_class_add_pad_template (element_class,
|
||||
gst_static_pad_template_get (&afparse_sink_factory));
|
||||
|
||||
gst_element_class_set_static_metadata (element_class, "Audiofile demuxer",
|
||||
"Codec/Demuxer/Audio",
|
||||
"Audiofile parser for audio/raw",
|
||||
"Steve Baker <stevebaker_org@yahoo.co.uk>");
|
||||
}
|
||||
|
||||
static void
|
||||
gst_afparse_class_init (GstAFParseClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class;
|
||||
GstElementClass *gstelement_class;
|
||||
|
||||
gobject_class = (GObjectClass *) klass;
|
||||
gstelement_class = (GstElementClass *) klass;
|
||||
|
||||
gobject_class->set_property = gst_afparse_set_property;
|
||||
gobject_class->get_property = gst_afparse_get_property;
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
gst_afparse_init (GstAFParse * afparse)
|
||||
{
|
||||
afparse->srcpad =
|
||||
gst_pad_new_from_template (gst_element_get_pad_template (GST_ELEMENT
|
||||
(afparse), "src"), "src");
|
||||
gst_pad_use_explicit_caps (afparse->srcpad);
|
||||
gst_element_add_pad (GST_ELEMENT (afparse), afparse->srcpad);
|
||||
|
||||
afparse->sinkpad =
|
||||
gst_pad_new_from_template (gst_element_get_pad_template (GST_ELEMENT
|
||||
(afparse), "sink"), "sink");
|
||||
gst_element_add_pad (GST_ELEMENT (afparse), afparse->sinkpad);
|
||||
|
||||
gst_element_set_loop_function (GST_ELEMENT (afparse), gst_afparse_loop);
|
||||
|
||||
afparse->vfile = af_virtual_file_new ();
|
||||
afparse->vfile->closure = NULL;
|
||||
afparse->vfile->read = gst_afparse_vf_read;
|
||||
afparse->vfile->length = gst_afparse_vf_length;
|
||||
afparse->vfile->write = gst_afparse_vf_write;
|
||||
afparse->vfile->destroy = gst_afparse_vf_destroy;
|
||||
afparse->vfile->seek = gst_afparse_vf_seek;
|
||||
afparse->vfile->tell = gst_afparse_vf_tell;
|
||||
|
||||
afparse->frames_per_read = 1024;
|
||||
afparse->curoffset = 0;
|
||||
afparse->seq = 0;
|
||||
|
||||
afparse->file = NULL;
|
||||
/* default values, should never be needed */
|
||||
afparse->channels = 2;
|
||||
afparse->width = 16;
|
||||
afparse->rate = 44100;
|
||||
afparse->type = AF_FILE_WAVE;
|
||||
afparse->endianness_data = 1234;
|
||||
afparse->endianness_wanted = 1234;
|
||||
afparse->timestamp = 0LL;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_afparse_loop (GstElement * element)
|
||||
{
|
||||
GstAFParse *afparse;
|
||||
GstBuffer *buf;
|
||||
gint numframes = 0, frames_to_bytes, frames_per_read, bytes_per_read;
|
||||
guint8 *data;
|
||||
gboolean bypass_afread = TRUE;
|
||||
GstByteStream *bs;
|
||||
int s_format, v_format, s_width, v_width;
|
||||
|
||||
afparse = GST_AFPARSE (element);
|
||||
|
||||
afparse->vfile->closure = bs = gst_bytestream_new (afparse->sinkpad);
|
||||
|
||||
/* just stop if we cannot open the file */
|
||||
if (!gst_afparse_open_file (afparse)) {
|
||||
gst_bytestream_destroy ((GstByteStream *) afparse->vfile->closure);
|
||||
gst_pad_push (afparse->srcpad, GST_DATA (gst_event_new (GST_EVENT_EOS)));
|
||||
gst_element_set_eos (GST_ELEMENT (afparse));
|
||||
return;
|
||||
}
|
||||
|
||||
/* if audiofile changes the data in any way, we have to access
|
||||
* the audio data via afReadFrames. Otherwise we can just access
|
||||
* the data directly. */
|
||||
afGetSampleFormat (afparse->file, AF_DEFAULT_TRACK, &s_format, &s_width);
|
||||
afGetVirtualSampleFormat (afparse->file, AF_DEFAULT_TRACK, &v_format,
|
||||
&v_width);
|
||||
if (afGetCompression != AF_COMPRESSION_NONE
|
||||
|| afGetByteOrder (afparse->file,
|
||||
AF_DEFAULT_TRACK) != afGetVirtualByteOrder (afparse->file,
|
||||
AF_DEFAULT_TRACK) || s_format != v_format || s_width != v_width) {
|
||||
bypass_afread = FALSE;
|
||||
}
|
||||
|
||||
if (bypass_afread) {
|
||||
GST_DEBUG ("will bypass afReadFrames\n");
|
||||
}
|
||||
|
||||
frames_to_bytes = afparse->channels * afparse->width / 8;
|
||||
frames_per_read = afparse->frames_per_read;
|
||||
bytes_per_read = frames_per_read * frames_to_bytes;
|
||||
|
||||
afSeekFrame (afparse->file, AF_DEFAULT_TRACK, 0);
|
||||
|
||||
if (bypass_afread) {
|
||||
GstEvent *event = NULL;
|
||||
guint32 waiting;
|
||||
guint32 got_bytes;
|
||||
|
||||
do {
|
||||
|
||||
got_bytes = gst_bytestream_read (bs, &buf, bytes_per_read);
|
||||
if (got_bytes == 0) {
|
||||
/* we need to check for an event. */
|
||||
gst_bytestream_get_status (bs, &waiting, &event);
|
||||
if (event && GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
|
||||
gst_pad_push (afparse->srcpad,
|
||||
GST_DATA (gst_event_new (GST_EVENT_EOS)));
|
||||
gst_element_set_eos (GST_ELEMENT (afparse));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
GST_BUFFER_TIMESTAMP (buf) = afparse->timestamp;
|
||||
gst_pad_push (afparse->srcpad, GST_DATA (buf));
|
||||
if (got_bytes != bytes_per_read) {
|
||||
/* this shouldn't happen very often */
|
||||
/* FIXME calculate the timestamps based on the fewer bytes received */
|
||||
|
||||
} else {
|
||||
afparse->timestamp += frames_per_read * 1E9 / afparse->rate;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (TRUE);
|
||||
|
||||
} else {
|
||||
do {
|
||||
buf = gst_buffer_new_and_alloc (bytes_per_read);
|
||||
GST_BUFFER_TIMESTAMP (buf) = afparse->timestamp;
|
||||
data = GST_BUFFER_DATA (buf);
|
||||
numframes =
|
||||
afReadFrames (afparse->file, AF_DEFAULT_TRACK, data, frames_per_read);
|
||||
|
||||
/* events are handled in gst_afparse_vf_read so if there are no
|
||||
* frames it must be EOS */
|
||||
if (numframes < 1) {
|
||||
gst_buffer_unref (buf);
|
||||
|
||||
gst_pad_push (afparse->srcpad,
|
||||
GST_DATA (gst_event_new (GST_EVENT_EOS)));
|
||||
gst_element_set_eos (GST_ELEMENT (afparse));
|
||||
break;
|
||||
}
|
||||
GST_BUFFER_SIZE (buf) = numframes * frames_to_bytes;
|
||||
gst_pad_push (afparse->srcpad, GST_DATA (buf));
|
||||
afparse->timestamp += numframes * 1E9 / afparse->rate;
|
||||
}
|
||||
while (TRUE);
|
||||
}
|
||||
gst_afparse_close_file (afparse);
|
||||
|
||||
gst_bytestream_destroy ((GstByteStream *) afparse->vfile->closure);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
gst_afparse_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstAFParse *afparse;
|
||||
|
||||
afparse = GST_AFPARSE (object);
|
||||
|
||||
switch (prop_id) {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_afparse_get_property (GObject * object, guint prop_id,
|
||||
GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstAFParse *afparse;
|
||||
|
||||
g_return_if_fail (GST_IS_AFPARSE (object));
|
||||
|
||||
afparse = GST_AFPARSE (object);
|
||||
|
||||
switch (prop_id) {
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_afparse_plugin_init (GstPlugin * plugin)
|
||||
{
|
||||
/* load audio support library */
|
||||
if (!gst_library_load ("gstaudio"))
|
||||
return FALSE;
|
||||
|
||||
if (!gst_element_register (plugin, "afparse", GST_RANK_NONE,
|
||||
GST_TYPE_AFPARSE))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* this is where we open the audiofile */
|
||||
static gboolean
|
||||
gst_afparse_open_file (GstAFParse * afparse)
|
||||
{
|
||||
g_return_val_if_fail (!GST_OBJECT_FLAG_IS_SET (afparse, GST_AFPARSE_OPEN),
|
||||
FALSE);
|
||||
|
||||
|
||||
/* open the file */
|
||||
GST_DEBUG ("opening vfile %p\n", afparse->vfile);
|
||||
afparse->file = afOpenVirtualFile (afparse->vfile, "r", AF_NULL_FILESETUP);
|
||||
if (afparse->file == AF_NULL_FILEHANDLE) {
|
||||
/* this should never happen */
|
||||
g_warning ("ERROR: gstafparse: Could not open virtual file for reading\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
GST_DEBUG ("vfile opened\n");
|
||||
/* get the audiofile audio parameters */
|
||||
{
|
||||
int sampleFormat, sampleWidth;
|
||||
|
||||
afparse->channels = afGetChannels (afparse->file, AF_DEFAULT_TRACK);
|
||||
afGetSampleFormat (afparse->file, AF_DEFAULT_TRACK,
|
||||
&sampleFormat, &sampleWidth);
|
||||
switch (sampleFormat) {
|
||||
case AF_SAMPFMT_TWOSCOMP:
|
||||
afparse->is_signed = TRUE;
|
||||
break;
|
||||
case AF_SAMPFMT_UNSIGNED:
|
||||
afparse->is_signed = FALSE;
|
||||
break;
|
||||
case AF_SAMPFMT_FLOAT:
|
||||
case AF_SAMPFMT_DOUBLE:
|
||||
GST_DEBUG ("ERROR: float data not supported yet !\n");
|
||||
}
|
||||
afparse->rate = (guint) afGetRate (afparse->file, AF_DEFAULT_TRACK);
|
||||
afparse->width = sampleWidth;
|
||||
GST_DEBUG ("input file: %d channels, %d width, %d rate, signed %s\n",
|
||||
afparse->channels, afparse->width, afparse->rate,
|
||||
afparse->is_signed ? "yes" : "no");
|
||||
}
|
||||
|
||||
/* set caps on src */
|
||||
/*FIXME: add all the possible formats, especially float ! */
|
||||
gst_pad_set_explicit_caps (afparse->srcpad,
|
||||
gst_caps_new_simple ("audio/x-raw-int",
|
||||
"endianness", G_TYPE_INT, G_BYTE_ORDER,
|
||||
"signed", G_TYPE_BOOLEAN, afparse->is_signed,
|
||||
"width", G_TYPE_INT, afparse->width,
|
||||
"depth", G_TYPE_INT, afparse->width,
|
||||
"rate", G_TYPE_INT, afparse->rate,
|
||||
"channels", G_TYPE_INT, afparse->channels, NULL));
|
||||
|
||||
GST_OBJECT_FLAG_SET (afparse, GST_AFPARSE_OPEN);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_afparse_close_file (GstAFParse * afparse)
|
||||
{
|
||||
g_return_if_fail (GST_OBJECT_FLAG_IS_SET (afparse, GST_AFPARSE_OPEN));
|
||||
if (afCloseFile (afparse->file) != 0) {
|
||||
g_warning ("afparse: oops, error closing !\n");
|
||||
} else {
|
||||
GST_OBJECT_FLAG_UNSET (afparse, GST_AFPARSE_OPEN);
|
||||
}
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
gst_afparse_vf_read (AFvirtualfile * vfile, void *data, size_t nbytes)
|
||||
{
|
||||
GstByteStream *bs = (GstByteStream *) vfile->closure;
|
||||
guint8 *bytes = NULL;
|
||||
GstEvent *event = NULL;
|
||||
guint32 waiting;
|
||||
guint32 got_bytes;
|
||||
|
||||
/*gchar *debug_str; */
|
||||
|
||||
got_bytes = gst_bytestream_peek_bytes (bs, &bytes, nbytes);
|
||||
|
||||
while (got_bytes != nbytes) {
|
||||
/* handle events */
|
||||
gst_bytestream_get_status (bs, &waiting, &event);
|
||||
|
||||
/* FIXME this event handling isn't right yet */
|
||||
if (!event) {
|
||||
/*g_print("no event found with %u bytes\n", got_bytes); */
|
||||
return 0;
|
||||
}
|
||||
switch (GST_EVENT_TYPE (event)) {
|
||||
case GST_EVENT_EOS:
|
||||
return 0;
|
||||
case GST_EVENT_FLUSH:
|
||||
GST_DEBUG ("flush");
|
||||
break;
|
||||
case GST_EVENT_DISCONTINUOUS:
|
||||
GST_DEBUG ("seek done");
|
||||
got_bytes = gst_bytestream_peek_bytes (bs, &bytes, nbytes);
|
||||
break;
|
||||
default:
|
||||
g_warning ("unknown event %d", GST_EVENT_TYPE (event));
|
||||
got_bytes = gst_bytestream_peek_bytes (bs, &bytes, nbytes);
|
||||
}
|
||||
}
|
||||
|
||||
memcpy (data, bytes, got_bytes);
|
||||
gst_bytestream_flush_fast (bs, got_bytes);
|
||||
|
||||
/* debug_str = g_strndup((gchar*)bytes, got_bytes);
|
||||
g_print("read %u bytes: %s\n", got_bytes, debug_str);
|
||||
*/
|
||||
return got_bytes;
|
||||
}
|
||||
|
||||
static long
|
||||
gst_afparse_vf_seek (AFvirtualfile * vfile, long offset, int is_relative)
|
||||
{
|
||||
GstByteStream *bs = (GstByteStream *) vfile->closure;
|
||||
GstSeekType method;
|
||||
guint64 current_offset = gst_bytestream_tell (bs);
|
||||
|
||||
if (!is_relative) {
|
||||
if ((guint64) offset == current_offset) {
|
||||
/* this seems to happen before every read - bad audiofile */
|
||||
return offset;
|
||||
}
|
||||
|
||||
method = GST_SEEK_METHOD_SET;
|
||||
} else {
|
||||
if (offset == 0)
|
||||
return current_offset;
|
||||
method = GST_SEEK_METHOD_CUR;
|
||||
}
|
||||
|
||||
if (gst_bytestream_seek (bs, (gint64) offset, method)) {
|
||||
GST_DEBUG ("doing seek to %d", (gint) offset);
|
||||
return offset;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static long
|
||||
gst_afparse_vf_length (AFvirtualfile * vfile)
|
||||
{
|
||||
GstByteStream *bs = (GstByteStream *) vfile->closure;
|
||||
guint64 length;
|
||||
|
||||
length = gst_bytestream_length (bs);
|
||||
GST_DEBUG ("doing length: %" G_GUINT64_FORMAT, length);
|
||||
return length;
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
gst_afparse_vf_write (AFvirtualfile * vfile, const void *data, size_t nbytes)
|
||||
{
|
||||
/* GstByteStream *bs = (GstByteStream*)vfile->closure; */
|
||||
g_warning ("shouldn't write to a readonly pad");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_afparse_vf_destroy (AFvirtualfile * vfile)
|
||||
{
|
||||
/* GstByteStream *bs = (GstByteStream*)vfile->closure; */
|
||||
|
||||
GST_DEBUG ("doing destroy");
|
||||
}
|
||||
|
||||
static long
|
||||
gst_afparse_vf_tell (AFvirtualfile * vfile)
|
||||
{
|
||||
GstByteStream *bs = (GstByteStream *) vfile->closure;
|
||||
guint64 offset;
|
||||
|
||||
offset = gst_bytestream_tell (bs);
|
||||
GST_DEBUG ("doing tell: %" G_GUINT64_FORMAT, offset);
|
||||
return offset;
|
||||
}
|
|
@ -1,101 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
||||
* 2000 Wim Taymans <wtay@chello.be>
|
||||
*
|
||||
* gstafparse.h:
|
||||
*
|
||||
* 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., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __GST_AFPARSE_H__
|
||||
#define __GST_AFPARSE_H__
|
||||
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/bytestream/bytestream.h>
|
||||
#include <audiofile.h> /* what else are we to do */
|
||||
#include <af_vfs.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
#define GST_TYPE_AFPARSE \
|
||||
(gst_afparse_get_type())
|
||||
#define GST_AFPARSE(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AFPARSE,GstAFParse))
|
||||
#define GST_AFPARSE_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AFPARSE,GstAFParseClass))
|
||||
#define GST_IS_AFPARSE(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AFPARSE))
|
||||
#define GST_IS_AFPARSE_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AFPARSE))
|
||||
|
||||
typedef struct _GstAFParse GstAFParse;
|
||||
typedef struct _GstAFParseClass GstAFParseClass;
|
||||
|
||||
typedef enum {
|
||||
GST_AFPARSE_OPEN = (GST_ELEMENT_FLAG_LAST << 0),
|
||||
|
||||
GST_AFPARSE_FLAG_LAST = (GST_ELEMENT_FLAG_LAST << 2),
|
||||
} GstAFParseFlags;
|
||||
|
||||
struct _GstAFParse {
|
||||
GstElement element;
|
||||
GstPad *srcpad;
|
||||
GstPad *sinkpad;
|
||||
|
||||
AFvirtualfile *vfile;
|
||||
AFfilehandle file;
|
||||
int format;
|
||||
int channels;
|
||||
int width;
|
||||
unsigned int rate;
|
||||
gboolean is_signed;
|
||||
int type; /* type of output, compare to audiofile.h
|
||||
* RAW, AIFF, AIFFC, NEXTSND, WAVE
|
||||
*/
|
||||
/* blocking */
|
||||
gulong curoffset;
|
||||
gulong bytes_per_read;
|
||||
gint frames_per_read;
|
||||
|
||||
gulong seq;
|
||||
gint64 timestamp;
|
||||
/* FIXME : endianness is a little cryptic at this point */
|
||||
int endianness_data; /* 4321 or 1234 */
|
||||
int endianness_wanted; /* same thing, but what the output format wants */
|
||||
int endianness_output; /* what the output endianness will be */
|
||||
};
|
||||
|
||||
struct _GstAFParseClass {
|
||||
GstElementClass parent_class;
|
||||
|
||||
/* signals */
|
||||
void (*handoff) (GstElement *element,GstPad *pad);
|
||||
};
|
||||
|
||||
gboolean gst_afparse_plugin_init (GstPlugin *plugin);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
#endif /* __GST_AFPARSE_H__ */
|
|
@ -1,490 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
||||
* 2000 Wim Taymans <wtay@chello.be>
|
||||
*
|
||||
* gstafsink.c:
|
||||
*
|
||||
* 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., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "gst/gst-i18n-plugin.h"
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "gstafsink.h"
|
||||
|
||||
/* AFSink signals and args */
|
||||
enum
|
||||
{
|
||||
/* FILL ME */
|
||||
SIGNAL_HANDOFF,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
ARG_0,
|
||||
ARG_TYPE,
|
||||
ARG_OUTPUT_ENDIANNESS,
|
||||
ARG_LOCATION
|
||||
};
|
||||
|
||||
/* added a sink factory function to force audio/raw MIME type */
|
||||
/* I think the caps can be broader, we need to change that somehow */
|
||||
static GstStaticPadTemplate afsink_sink_factory =
|
||||
GST_STATIC_PAD_TEMPLATE ("sink",
|
||||
GST_PAD_SINK,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS ("audio/x-raw-int, "
|
||||
"rate = (int) [ 1, MAX ], "
|
||||
"channels = (int) [ 1, 2 ], "
|
||||
"endianness = (int) BYTE_ORDER, "
|
||||
"width = (int) { 8, 16 }, "
|
||||
"depth = (int) { 8, 16 }, " "signed = (boolean) { true, false }")
|
||||
);
|
||||
|
||||
/* we use an enum for the output type arg */
|
||||
|
||||
#define GST_TYPE_AFSINK_TYPES (gst_afsink_types_get_type())
|
||||
/* FIXME: fix the string ints to be string-converted from the audiofile.h types */
|
||||
static GType
|
||||
gst_afsink_types_get_type (void)
|
||||
{
|
||||
static GType afsink_types_type = 0;
|
||||
static const GEnumValue afsink_types[] = {
|
||||
{AF_FILE_RAWDATA, "0", "raw PCM"},
|
||||
{AF_FILE_AIFFC, "1", "AIFFC"},
|
||||
{AF_FILE_AIFF, "2", "AIFF"},
|
||||
{AF_FILE_NEXTSND, "3", "Next/SND"},
|
||||
{AF_FILE_WAVE, "4", "Wave"},
|
||||
{0, NULL, NULL},
|
||||
};
|
||||
|
||||
if (!afsink_types_type) {
|
||||
afsink_types_type =
|
||||
g_enum_register_static ("GstAudiosinkTypes", afsink_types);
|
||||
}
|
||||
return afsink_types_type;
|
||||
}
|
||||
|
||||
static void gst_afsink_base_init (gpointer g_class);
|
||||
static void gst_afsink_class_init (GstAFSinkClass * klass);
|
||||
static void gst_afsink_init (GstAFSink * afsink);
|
||||
|
||||
static gboolean gst_afsink_open_file (GstAFSink * sink);
|
||||
static void gst_afsink_close_file (GstAFSink * sink);
|
||||
|
||||
static void gst_afsink_chain (GstPad * pad, GstData * _data);
|
||||
|
||||
static void gst_afsink_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec);
|
||||
static void gst_afsink_get_property (GObject * object, guint prop_id,
|
||||
GValue * value, GParamSpec * pspec);
|
||||
|
||||
static gboolean gst_afsink_handle_event (GstPad * pad, GstEvent * event);
|
||||
|
||||
static GstStateChangeReturn gst_afsink_change_state (GstElement * element,
|
||||
GstStateChange transition);
|
||||
|
||||
static GstElementClass *parent_class = NULL;
|
||||
static guint gst_afsink_signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
GType
|
||||
gst_afsink_get_type (void)
|
||||
{
|
||||
static GType afsink_type = 0;
|
||||
|
||||
if (!afsink_type) {
|
||||
static const GTypeInfo afsink_info = {
|
||||
sizeof (GstAFSinkClass),
|
||||
gst_afsink_base_init,
|
||||
NULL,
|
||||
(GClassInitFunc) gst_afsink_class_init,
|
||||
NULL,
|
||||
NULL,
|
||||
sizeof (GstAFSink),
|
||||
0,
|
||||
(GInstanceInitFunc) gst_afsink_init,
|
||||
};
|
||||
|
||||
afsink_type =
|
||||
g_type_register_static (GST_TYPE_ELEMENT, "GstAFSink", &afsink_info, 0);
|
||||
}
|
||||
return afsink_type;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_afsink_base_init (gpointer g_class)
|
||||
{
|
||||
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
||||
|
||||
gst_element_class_add_pad_template (element_class,
|
||||
gst_static_pad_template_get (&afsink_sink_factory));
|
||||
gst_element_class_set_static_metadata (element_class, "Audiofile sink",
|
||||
"Sink/Audio",
|
||||
"Write audio streams to disk using libaudiofile",
|
||||
"Thomas Vander Stichele <thomas@apestaart.org>");
|
||||
}
|
||||
|
||||
static void
|
||||
gst_afsink_class_init (GstAFSinkClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class;
|
||||
GstElementClass *gstelement_class;
|
||||
|
||||
gobject_class = (GObjectClass *) klass;
|
||||
gstelement_class = (GstElementClass *) klass;
|
||||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
gst_element_class_install_std_props (GST_ELEMENT_CLASS (klass),
|
||||
"location", ARG_LOCATION, G_PARAM_READWRITE, NULL);
|
||||
|
||||
/* FIXME: add long property descriptions */
|
||||
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_TYPE,
|
||||
g_param_spec_enum ("type", "type", "type", GST_TYPE_AFSINK_TYPES, 0,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property (G_OBJECT_CLASS (klass),
|
||||
ARG_OUTPUT_ENDIANNESS, g_param_spec_int ("endianness", "endianness",
|
||||
"endianness", G_MININT, G_MAXINT, 0,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
gst_afsink_signals[SIGNAL_HANDOFF] =
|
||||
g_signal_new ("handoff", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (GstAFSinkClass, handoff), NULL, NULL,
|
||||
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
|
||||
|
||||
|
||||
gobject_class->set_property = gst_afsink_set_property;
|
||||
gobject_class->get_property = gst_afsink_get_property;
|
||||
|
||||
gstelement_class->change_state = gst_afsink_change_state;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_afsink_init (GstAFSink * afsink)
|
||||
{
|
||||
/* GstPad *pad; this is now done in the struct */
|
||||
|
||||
afsink->sinkpad =
|
||||
gst_pad_new_from_template (gst_element_get_pad_template (GST_ELEMENT
|
||||
(afsink), "sink"), "sink");
|
||||
gst_element_add_pad (GST_ELEMENT (afsink), afsink->sinkpad);
|
||||
|
||||
gst_pad_set_chain_function (afsink->sinkpad, gst_afsink_chain);
|
||||
|
||||
afsink->filename = NULL;
|
||||
afsink->file = NULL;
|
||||
/* default values, should never be needed */
|
||||
afsink->channels = 2;
|
||||
afsink->width = 16;
|
||||
afsink->rate = 44100;
|
||||
afsink->type = AF_FILE_WAVE;
|
||||
afsink->endianness_data = 1234;
|
||||
afsink->endianness_wanted = 1234;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_afsink_set_property (GObject * object, guint prop_id, const GValue * value,
|
||||
GParamSpec * pspec)
|
||||
{
|
||||
GstAFSink *sink;
|
||||
|
||||
sink = GST_AFSINK (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case ARG_LOCATION:
|
||||
/* the element must be stopped or paused in order to do this */
|
||||
g_return_if_fail ((GST_STATE (sink) < GST_STATE_PLAYING)
|
||||
|| (GST_STATE (sink) == GST_STATE_PAUSED));
|
||||
g_free (sink->filename);
|
||||
sink->filename = g_strdup (g_value_get_string (value));
|
||||
if ((GST_STATE (sink) == GST_STATE_PAUSED)
|
||||
&& (sink->filename != NULL)) {
|
||||
gst_afsink_close_file (sink);
|
||||
gst_afsink_open_file (sink);
|
||||
}
|
||||
|
||||
break;
|
||||
case ARG_TYPE:
|
||||
sink->type = g_value_get_enum (value);
|
||||
break;
|
||||
case ARG_OUTPUT_ENDIANNESS:
|
||||
{
|
||||
int end = g_value_get_int (value);
|
||||
|
||||
if (end == 1234 || end == 4321)
|
||||
sink->endianness_output = end;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_afsink_get_property (GObject * object, guint prop_id, GValue * value,
|
||||
GParamSpec * pspec)
|
||||
{
|
||||
GstAFSink *sink;
|
||||
|
||||
g_return_if_fail (GST_IS_AFSINK (object));
|
||||
|
||||
sink = GST_AFSINK (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case ARG_LOCATION:
|
||||
g_value_set_string (value, sink->filename);
|
||||
break;
|
||||
case ARG_TYPE:
|
||||
g_value_set_enum (value, sink->type);
|
||||
break;
|
||||
case ARG_OUTPUT_ENDIANNESS:
|
||||
g_value_set_int (value, sink->endianness_output);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_afsink_plugin_init (GstPlugin * plugin)
|
||||
{
|
||||
if (!gst_element_register (plugin, "afsink", GST_RANK_NONE, GST_TYPE_AFSINK))
|
||||
return FALSE;
|
||||
#ifdef ENABLE_NLS
|
||||
setlocale (LC_ALL, "");
|
||||
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
|
||||
#endif /* ENABLE_NLS */
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* this is where we open the audiofile */
|
||||
static gboolean
|
||||
gst_afsink_open_file (GstAFSink * sink)
|
||||
{
|
||||
AFfilesetup outfilesetup;
|
||||
const GstCaps *caps;
|
||||
GstStructure *structure;
|
||||
int sample_format; /* audiofile's sample format, look in audiofile.h */
|
||||
int byte_order = 0; /* audiofile's byte order defines */
|
||||
|
||||
g_return_val_if_fail (!GST_OBJECT_FLAG_IS_SET (sink, GST_AFSINK_OPEN), FALSE);
|
||||
|
||||
/* get the audio parameters */
|
||||
g_return_val_if_fail (GST_IS_PAD (sink->sinkpad), FALSE);
|
||||
caps = GST_PAD_CAPS (sink->sinkpad);
|
||||
|
||||
if (caps == NULL) {
|
||||
g_critical ("gstafsink chain : Could not get caps of pad !\n");
|
||||
} else {
|
||||
structure = gst_caps_get_structure (caps, 0);
|
||||
gst_structure_get_int (structure, "channels", &sink->channels);
|
||||
gst_structure_get_int (structure, "width", &sink->width);
|
||||
gst_structure_get_int (structure, "rate", &sink->rate);
|
||||
gst_structure_get_boolean (structure, "signed", &sink->is_signed);
|
||||
gst_structure_get_int (structure, "endianness", &sink->endianness_data);
|
||||
}
|
||||
GST_DEBUG ("channels %d, width %d, rate %d, signed %s",
|
||||
sink->channels, sink->width, sink->rate, sink->is_signed ? "yes" : "no");
|
||||
GST_DEBUG ("endianness: data %d, output %d",
|
||||
sink->endianness_data, sink->endianness_output);
|
||||
/* setup the output file */
|
||||
if (sink->is_signed)
|
||||
sample_format = AF_SAMPFMT_TWOSCOMP;
|
||||
else
|
||||
sample_format = AF_SAMPFMT_UNSIGNED;
|
||||
/* FIXME : this check didn't seem to work, so let the output endianness be set */
|
||||
/*
|
||||
if (sink->endianness_data == sink->endianness_wanted)
|
||||
byte_order = AF_BYTEORDER_LITTLEENDIAN;
|
||||
else
|
||||
byte_order = AF_BYTEORDER_BIGENDIAN;
|
||||
*/
|
||||
if (sink->endianness_output == 1234)
|
||||
byte_order = AF_BYTEORDER_LITTLEENDIAN;
|
||||
else
|
||||
byte_order = AF_BYTEORDER_BIGENDIAN;
|
||||
|
||||
outfilesetup = afNewFileSetup ();
|
||||
afInitFileFormat (outfilesetup, sink->type);
|
||||
afInitChannels (outfilesetup, AF_DEFAULT_TRACK, sink->channels);
|
||||
afInitRate (outfilesetup, AF_DEFAULT_TRACK, sink->rate);
|
||||
afInitSampleFormat (outfilesetup, AF_DEFAULT_TRACK,
|
||||
sample_format, sink->width);
|
||||
|
||||
/* open it */
|
||||
sink->file = afOpenFile (sink->filename, "w", outfilesetup);
|
||||
if (sink->file == AF_NULL_FILEHANDLE) {
|
||||
GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE,
|
||||
(_("Could not open file \"%s\" for writing."), sink->filename),
|
||||
("system error: %s", strerror (errno)));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
afFreeFileSetup (outfilesetup);
|
||||
/* afSetVirtualByteOrder (sink->file, AF_DEFAULT_TRACK, byte_order); */
|
||||
|
||||
GST_OBJECT_FLAG_SET (sink, GST_AFSINK_OPEN);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_afsink_close_file (GstAFSink * sink)
|
||||
{
|
||||
/* g_print ("DEBUG: closing sinkfile...\n"); */
|
||||
g_return_if_fail (GST_OBJECT_FLAG_IS_SET (sink, GST_AFSINK_OPEN));
|
||||
/* g_print ("DEBUG: past flag test\n"); */
|
||||
/* if (fclose (sink->file) != 0) */
|
||||
if (afCloseFile (sink->file) != 0) {
|
||||
GST_ELEMENT_ERROR (sink, RESOURCE, CLOSE,
|
||||
(_("Error closing file \"%s\"."), sink->filename), GST_ERROR_SYSTEM);
|
||||
} else {
|
||||
GST_OBJECT_FLAG_UNSET (sink, GST_AFSINK_OPEN);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_afsink_chain:
|
||||
* @pad: the pad this afsink is connected to
|
||||
* @buf: the buffer that has to be absorbed
|
||||
*
|
||||
* take the buffer from the pad and write to file if it's open
|
||||
*/
|
||||
static void
|
||||
gst_afsink_chain (GstPad * pad, GstData * _data)
|
||||
{
|
||||
GstBuffer *buf;
|
||||
GstAFSink *afsink;
|
||||
int ret = 0;
|
||||
|
||||
g_return_if_fail (pad != NULL);
|
||||
g_return_if_fail (GST_IS_PAD (pad));
|
||||
|
||||
if (GST_IS_EVENT (_data)) {
|
||||
gst_afsink_handle_event (pad, GST_EVENT (_data));
|
||||
return;
|
||||
}
|
||||
|
||||
buf = GST_BUFFER (_data);
|
||||
afsink = GST_AFSINK (gst_pad_get_parent (pad));
|
||||
/* we use audiofile now
|
||||
if (GST_OBJECT_FLAG_IS_SET (afsink, GST_AFSINK_OPEN))
|
||||
{
|
||||
bytes_written = fwrite (GST_BUFFER_DATA (buf), 1, GST_BUFFER_SIZE (buf), afsink->file);
|
||||
if (bytes_written < GST_BUFFER_SIZE (buf))
|
||||
{
|
||||
printf ("afsink : Warning : %d bytes should be written, only %d bytes written\n",
|
||||
GST_BUFFER_SIZE (buf), bytes_written);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if (!GST_OBJECT_FLAG_IS_SET (afsink, GST_AFSINK_OPEN)) {
|
||||
/* it's not open yet, open it */
|
||||
if (!gst_afsink_open_file (afsink))
|
||||
g_print ("WARNING: gstafsink: can't open file !\n");
|
||||
/* return FALSE; Can't return value */
|
||||
}
|
||||
|
||||
if (GST_OBJECT_FLAG_IS_SET (afsink, GST_AFSINK_OPEN)) {
|
||||
int frameCount = 0;
|
||||
|
||||
frameCount =
|
||||
GST_BUFFER_SIZE (buf) / ((afsink->width / 8) * afsink->channels);
|
||||
/* g_print ("DEBUG: writing %d frames ", frameCount); */
|
||||
ret = afWriteFrames (afsink->file, AF_DEFAULT_TRACK,
|
||||
GST_BUFFER_DATA (buf), frameCount);
|
||||
if (ret == AF_BAD_WRITE || ret == AF_BAD_LSEEK) {
|
||||
printf ("afsink : Warning : afWriteFrames returned an error (%d)\n", ret);
|
||||
}
|
||||
}
|
||||
|
||||
gst_buffer_unref (buf);
|
||||
|
||||
g_signal_emit (G_OBJECT (afsink), gst_afsink_signals[SIGNAL_HANDOFF], 0);
|
||||
}
|
||||
|
||||
static GstStateChangeReturn
|
||||
gst_afsink_change_state (GstElement * element, GstStateChange transition)
|
||||
{
|
||||
g_return_val_if_fail (GST_IS_AFSINK (element), GST_STATE_CHANGE_FAILURE);
|
||||
|
||||
/* if going to NULL? then close the file */
|
||||
if (GST_STATE_PENDING (element) == GST_STATE_NULL) {
|
||||
/* printf ("DEBUG: afsink state change: null pending\n"); */
|
||||
if (GST_OBJECT_FLAG_IS_SET (element, GST_AFSINK_OPEN)) {
|
||||
/* g_print ("DEBUG: trying to close the sink file\n"); */
|
||||
gst_afsink_close_file (GST_AFSINK (element));
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
||||
else
|
||||
this has been moved to the chain function, since it's only then that
|
||||
the caps are set and can be known
|
||||
{
|
||||
g_print ("DEBUG: it's not going to null\n");
|
||||
if (!GST_OBJECT_FLAG_IS_SET (element, GST_AFSINK_OPEN))
|
||||
{
|
||||
g_print ("DEBUG: GST_AFSINK_OPEN not set\n");
|
||||
if (!gst_afsink_open_file (GST_AFSINK (element)))
|
||||
{
|
||||
g_print ("DEBUG: element tries to open file\n");
|
||||
return GST_STATE_CHANGE_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
||||
return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
||||
|
||||
return GST_STATE_CHANGE_SUCCESS;
|
||||
}
|
||||
|
||||
/* this function was copied from sinesrc */
|
||||
|
||||
static gboolean
|
||||
gst_afsink_handle_event (GstPad * pad, GstEvent * event)
|
||||
{
|
||||
GstAFSink *afsink;
|
||||
|
||||
afsink = GST_AFSINK (gst_pad_get_parent (pad));
|
||||
GST_DEBUG ("DEBUG: afsink: got event");
|
||||
|
||||
switch (GST_EVENT_TYPE (event)) {
|
||||
case GST_EVENT_EOS:
|
||||
gst_afsink_close_file (afsink);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
gst_pad_event_default (pad, event);
|
||||
|
||||
return TRUE;
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
||||
* 2000 Wim Taymans <wtay@chello.be>
|
||||
*
|
||||
* gstafsink.h:
|
||||
*
|
||||
* 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., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __GST_AFSINK_H__
|
||||
#define __GST_AFSINK_H__
|
||||
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <audiofile.h> /* what else are we to do */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
#define GST_TYPE_AFSINK \
|
||||
(gst_afsink_get_type())
|
||||
#define GST_AFSINK(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AFSINK,GstAFSink))
|
||||
#define GST_AFSINK_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AFSINK,GstAFSinkClass))
|
||||
#define GST_IS_AFSINK(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AFSINK))
|
||||
#define GST_IS_AFSINK_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AFSINK))
|
||||
|
||||
typedef struct _GstAFSink GstAFSink;
|
||||
typedef struct _GstAFSinkClass GstAFSinkClass;
|
||||
|
||||
typedef enum {
|
||||
GST_AFSINK_OPEN = (GST_ELEMENT_FLAG_LAST << 0),
|
||||
|
||||
GST_AFSINK_FLAG_LAST = (GST_ELEMENT_FLAG_LAST << 2),
|
||||
} GstAFSinkFlags;
|
||||
|
||||
struct _GstAFSink {
|
||||
GstElement element;
|
||||
GstPad *sinkpad;
|
||||
|
||||
gchar *filename;
|
||||
/* FILE *file; */
|
||||
|
||||
/* AFfilesetup outfilesetup; */
|
||||
AFfilehandle file;
|
||||
int format;
|
||||
int channels;
|
||||
int width;
|
||||
unsigned int rate;
|
||||
gboolean is_signed;
|
||||
int type; /* type of output, compare to audiofile.h
|
||||
* RAW, AIFF, AIFFC, NEXTSND, WAVE
|
||||
*/
|
||||
/* FIXME : endianness is a little cryptic at this point */
|
||||
int endianness_data; /* 4321 or 1234 */
|
||||
int endianness_wanted; /* same thing, but what the output format wants */
|
||||
int endianness_output; /* what the output endianness will be */
|
||||
};
|
||||
|
||||
struct _GstAFSinkClass {
|
||||
GstElementClass parent_class;
|
||||
|
||||
/* signals */
|
||||
void (*handoff) (GstElement *element,GstPad *pad);
|
||||
};
|
||||
|
||||
GType gst_afsink_get_type (void);
|
||||
gboolean gst_afsink_plugin_init (GstPlugin *plugin);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
#endif /* __GST_AFSINK_H__ */
|
|
@ -1,396 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
||||
* 2000 Wim Taymans <wtay@chello.be>
|
||||
*
|
||||
* gstafsrc.c:
|
||||
*
|
||||
* 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., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "gst/gst-i18n-plugin.h"
|
||||
#include <gst/gst.h>
|
||||
#include <gst/audio/audio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "gstafsrc.h"
|
||||
|
||||
/* AFSrc signals and args */
|
||||
enum
|
||||
{
|
||||
/* FILL ME */
|
||||
SIGNAL_HANDOFF,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
ARG_0,
|
||||
ARG_LOCATION
|
||||
};
|
||||
|
||||
/* added a src factory function to force audio/raw MIME type */
|
||||
/* I think the caps can be broader, we need to change that somehow */
|
||||
static GstStaticPadTemplate afsrc_src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
||||
GST_PAD_SRC,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS ("audio/x-raw-int, "
|
||||
"rate = (int) [ 1, MAX ], "
|
||||
"channels = (int) [ 1, MAX ], "
|
||||
"endianness = (int) BYTE_ORDER, "
|
||||
"width = (int) { 8, 16 }, "
|
||||
"depth = (int) { 8, 16 }, " "signed = (boolean) { true, false }")
|
||||
);
|
||||
|
||||
/* we use an enum for the output type arg */
|
||||
|
||||
#define GST_TYPE_AFSRC_TYPES (gst_afsrc_types_get_type())
|
||||
|
||||
/* FIXME: fix the string ints to be string-converted from the audiofile.h types */
|
||||
/* defined but not used
|
||||
static GType
|
||||
gst_afsrc_types_get_type (void)
|
||||
{
|
||||
static GType afsrc_types_type = 0;
|
||||
static const GEnumValue afsrc_types[] = {
|
||||
{AF_FILE_RAWDATA, "0", "raw PCM"},
|
||||
{AF_FILE_AIFFC, "1", "AIFFC"},
|
||||
{AF_FILE_AIFF, "2", "AIFF"},
|
||||
{AF_FILE_NEXTSND, "3", "Next/SND"},
|
||||
{AF_FILE_WAVE, "4", "Wave"},
|
||||
{0, NULL, NULL},
|
||||
};
|
||||
|
||||
if (!afsrc_types_type)
|
||||
{
|
||||
afsrc_types_type = g_enum_register_static ("GstAudiosrcTypes", afsrc_types);
|
||||
}
|
||||
return afsrc_types_type;
|
||||
}
|
||||
*/
|
||||
static void gst_afsrc_base_init (gpointer g_class);
|
||||
static void gst_afsrc_class_init (GstAFSrcClass * klass);
|
||||
static void gst_afsrc_init (GstAFSrc * afsrc);
|
||||
|
||||
static gboolean gst_afsrc_open_file (GstAFSrc * src);
|
||||
static void gst_afsrc_close_file (GstAFSrc * src);
|
||||
|
||||
static GstData *gst_afsrc_get (GstPad * pad);
|
||||
|
||||
static void gst_afsrc_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec);
|
||||
static void gst_afsrc_get_property (GObject * object, guint prop_id,
|
||||
GValue * value, GParamSpec * pspec);
|
||||
|
||||
static GstStateChangeReturn gst_afsrc_change_state (GstElement * element,
|
||||
GstStateChange transition);
|
||||
|
||||
static GstElementClass *parent_class = NULL;
|
||||
static guint gst_afsrc_signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
GType
|
||||
gst_afsrc_get_type (void)
|
||||
{
|
||||
static GType afsrc_type = 0;
|
||||
|
||||
if (!afsrc_type) {
|
||||
static const GTypeInfo afsrc_info = {
|
||||
sizeof (GstAFSrcClass),
|
||||
gst_afsrc_base_init,
|
||||
NULL,
|
||||
(GClassInitFunc) gst_afsrc_class_init,
|
||||
NULL,
|
||||
NULL,
|
||||
sizeof (GstAFSrc),
|
||||
0,
|
||||
(GInstanceInitFunc) gst_afsrc_init,
|
||||
};
|
||||
|
||||
afsrc_type =
|
||||
g_type_register_static (GST_TYPE_ELEMENT, "GstAFSrc", &afsrc_info, 0);
|
||||
}
|
||||
return afsrc_type;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_afsrc_base_init (gpointer g_class)
|
||||
{
|
||||
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
||||
|
||||
gst_element_class_add_pad_template (element_class,
|
||||
gst_static_pad_template_get (&afsrc_src_factory));
|
||||
gst_element_class_set_static_metadata (element_class, "Audiofile source",
|
||||
"Source/Audio",
|
||||
"Read audio files from disk using libaudiofile",
|
||||
"Thomas <thomas@apestaart.org>");
|
||||
}
|
||||
|
||||
static void
|
||||
gst_afsrc_class_init (GstAFSrcClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class;
|
||||
GstElementClass *gstelement_class;
|
||||
|
||||
gobject_class = (GObjectClass *) klass;
|
||||
gstelement_class = (GstElementClass *) klass;
|
||||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
gst_element_class_install_std_props (GST_ELEMENT_CLASS (klass),
|
||||
"location", ARG_LOCATION, G_PARAM_READWRITE, NULL);
|
||||
|
||||
gst_afsrc_signals[SIGNAL_HANDOFF] =
|
||||
g_signal_new ("handoff", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (GstAFSrcClass, handoff), NULL, NULL,
|
||||
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
|
||||
|
||||
|
||||
gobject_class->set_property = gst_afsrc_set_property;
|
||||
gobject_class->get_property = gst_afsrc_get_property;
|
||||
|
||||
gstelement_class->change_state = gst_afsrc_change_state;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_afsrc_init (GstAFSrc * afsrc)
|
||||
{
|
||||
/* no need for a template, caps are set based on file, right ? */
|
||||
afsrc->srcpad =
|
||||
gst_pad_new_from_template (gst_element_get_pad_template (GST_ELEMENT
|
||||
(afsrc), "src"), "src");
|
||||
gst_element_add_pad (GST_ELEMENT (afsrc), afsrc->srcpad);
|
||||
gst_pad_use_explicit_caps (afsrc->srcpad);
|
||||
gst_pad_set_get_function (afsrc->srcpad, gst_afsrc_get);
|
||||
|
||||
afsrc->bytes_per_read = 4096;
|
||||
afsrc->curoffset = 0;
|
||||
afsrc->seq = 0;
|
||||
|
||||
afsrc->filename = NULL;
|
||||
afsrc->file = NULL;
|
||||
/* default values, should never be needed */
|
||||
afsrc->channels = 2;
|
||||
afsrc->width = 16;
|
||||
afsrc->rate = 44100;
|
||||
afsrc->type = AF_FILE_WAVE;
|
||||
afsrc->endianness_data = 1234;
|
||||
afsrc->endianness_wanted = 1234;
|
||||
afsrc->framestamp = 0;
|
||||
}
|
||||
|
||||
static GstData *
|
||||
gst_afsrc_get (GstPad * pad)
|
||||
{
|
||||
GstAFSrc *src;
|
||||
GstBuffer *buf;
|
||||
|
||||
glong readbytes, readframes;
|
||||
glong frameCount;
|
||||
|
||||
g_return_val_if_fail (pad != NULL, NULL);
|
||||
src = GST_AFSRC (gst_pad_get_parent (pad));
|
||||
|
||||
buf = gst_buffer_new ();
|
||||
g_return_val_if_fail (buf, NULL);
|
||||
|
||||
GST_BUFFER_DATA (buf) = (gpointer) g_malloc (src->bytes_per_read);
|
||||
|
||||
/* calculate frameCount to read based on file info */
|
||||
|
||||
frameCount = src->bytes_per_read / (src->channels * src->width / 8);
|
||||
/* g_print ("DEBUG: gstafsrc: going to read %ld frames\n", frameCount); */
|
||||
readframes = afReadFrames (src->file, AF_DEFAULT_TRACK, GST_BUFFER_DATA (buf),
|
||||
frameCount);
|
||||
readbytes = readframes * (src->channels * src->width / 8);
|
||||
if (readbytes == 0) {
|
||||
gst_element_set_eos (GST_ELEMENT (src));
|
||||
return GST_DATA (gst_event_new (GST_EVENT_EOS));
|
||||
}
|
||||
|
||||
GST_BUFFER_SIZE (buf) = readbytes;
|
||||
GST_BUFFER_OFFSET (buf) = src->curoffset;
|
||||
|
||||
src->curoffset += readbytes;
|
||||
|
||||
src->framestamp += gst_audio_frame_length (src->srcpad, buf);
|
||||
GST_BUFFER_TIMESTAMP (buf) = src->framestamp * 1E9
|
||||
/ gst_audio_frame_rate (src->srcpad);
|
||||
/* printf ("DEBUG: afsrc: timestamp set on output buffer: %f sec\n",
|
||||
GST_BUFFER_TIMESTAMP (buf) / 1E9); */
|
||||
|
||||
/* g_print("DEBUG: gstafsrc: pushed buffer of %ld bytes\n", readbytes); */
|
||||
return GST_DATA (buf);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_afsrc_set_property (GObject * object, guint prop_id, const GValue * value,
|
||||
GParamSpec * pspec)
|
||||
{
|
||||
GstAFSrc *src;
|
||||
|
||||
src = GST_AFSRC (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case ARG_LOCATION:
|
||||
g_free (src->filename);
|
||||
src->filename = g_strdup (g_value_get_string (value));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_afsrc_get_property (GObject * object, guint prop_id, GValue * value,
|
||||
GParamSpec * pspec)
|
||||
{
|
||||
GstAFSrc *src;
|
||||
|
||||
g_return_if_fail (GST_IS_AFSRC (object));
|
||||
|
||||
src = GST_AFSRC (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case ARG_LOCATION:
|
||||
g_value_set_string (value, src->filename);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_afsrc_plugin_init (GstPlugin * plugin)
|
||||
{
|
||||
/* load audio support library */
|
||||
if (!gst_library_load ("gstaudio"))
|
||||
return FALSE;
|
||||
|
||||
if (!gst_element_register (plugin, "afsrc", GST_RANK_NONE, GST_TYPE_AFSRC))
|
||||
return FALSE;
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
setlocale (LC_ALL, "");
|
||||
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
|
||||
#endif /* ENABLE_NLS */
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/* this is where we open the audiofile */
|
||||
static gboolean
|
||||
gst_afsrc_open_file (GstAFSrc * src)
|
||||
{
|
||||
g_return_val_if_fail (!GST_OBJECT_FLAG_IS_SET (src, GST_AFSRC_OPEN), FALSE);
|
||||
|
||||
/* open the file */
|
||||
src->file = afOpenFile (src->filename, "r", AF_NULL_FILESETUP);
|
||||
if (src->file == AF_NULL_FILEHANDLE) {
|
||||
GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
|
||||
(_("Could not open file \"%s\" for reading."), src->filename),
|
||||
("system error: %s", strerror (errno)));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* get the audiofile audio parameters */
|
||||
{
|
||||
int sampleFormat, sampleWidth;
|
||||
|
||||
src->channels = afGetChannels (src->file, AF_DEFAULT_TRACK);
|
||||
afGetSampleFormat (src->file, AF_DEFAULT_TRACK,
|
||||
&sampleFormat, &sampleWidth);
|
||||
switch (sampleFormat) {
|
||||
case AF_SAMPFMT_TWOSCOMP:
|
||||
src->is_signed = TRUE;
|
||||
break;
|
||||
case AF_SAMPFMT_UNSIGNED:
|
||||
src->is_signed = FALSE;
|
||||
break;
|
||||
case AF_SAMPFMT_FLOAT:
|
||||
case AF_SAMPFMT_DOUBLE:
|
||||
GST_DEBUG ("ERROR: float data not supported yet !\n");
|
||||
}
|
||||
src->rate = (guint) afGetRate (src->file, AF_DEFAULT_TRACK);
|
||||
src->width = sampleWidth;
|
||||
GST_DEBUG ("input file: %d channels, %d width, %d rate, signed %s\n",
|
||||
src->channels, src->width, src->rate, src->is_signed ? "yes" : "no");
|
||||
}
|
||||
|
||||
/* set caps on src */
|
||||
gst_pad_set_explicit_caps (src->srcpad,
|
||||
gst_caps_new_simple ("audio/x-raw-int",
|
||||
"endianness", G_TYPE_INT, G_BYTE_ORDER,
|
||||
"signed", G_TYPE_BOOLEAN, src->is_signed,
|
||||
"width", G_TYPE_INT, src->width,
|
||||
"depth", G_TYPE_INT, src->width,
|
||||
"rate", G_TYPE_INT, src->rate,
|
||||
"channels", G_TYPE_INT, src->channels, NULL));
|
||||
|
||||
GST_OBJECT_FLAG_SET (src, GST_AFSRC_OPEN);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_afsrc_close_file (GstAFSrc * src)
|
||||
{
|
||||
/* g_print ("DEBUG: closing srcfile...\n"); */
|
||||
g_return_if_fail (GST_OBJECT_FLAG_IS_SET (src, GST_AFSRC_OPEN));
|
||||
/* g_print ("DEBUG: past flag test\n"); */
|
||||
/* if (fclose (src->file) != 0) */
|
||||
if (afCloseFile (src->file) != 0) {
|
||||
GST_ELEMENT_ERROR (src, RESOURCE, CLOSE,
|
||||
(_("Error closing file \"%s\"."), src->filename), GST_ERROR_SYSTEM);
|
||||
} else {
|
||||
GST_OBJECT_FLAG_UNSET (src, GST_AFSRC_OPEN);
|
||||
}
|
||||
}
|
||||
|
||||
static GstStateChangeReturn
|
||||
gst_afsrc_change_state (GstElement * element, GstStateChange transition)
|
||||
{
|
||||
g_return_val_if_fail (GST_IS_AFSRC (element), GST_STATE_CHANGE_FAILURE);
|
||||
|
||||
/* if going to NULL then close the file */
|
||||
if (GST_STATE_PENDING (element) == GST_STATE_NULL) {
|
||||
/* printf ("DEBUG: afsrc state change: null pending\n"); */
|
||||
if (GST_OBJECT_FLAG_IS_SET (element, GST_AFSRC_OPEN)) {
|
||||
/* g_print ("DEBUG: trying to close the src file\n"); */
|
||||
gst_afsrc_close_file (GST_AFSRC (element));
|
||||
}
|
||||
} else if (GST_STATE_PENDING (element) == GST_STATE_READY) {
|
||||
/* g_print ("DEBUG: afsrc: ready state pending. This shouldn't happen at the *end* of a stream\n"); */
|
||||
if (!GST_OBJECT_FLAG_IS_SET (element, GST_AFSRC_OPEN)) {
|
||||
/* g_print ("DEBUG: GST_AFSRC_OPEN not set\n"); */
|
||||
if (!gst_afsrc_open_file (GST_AFSRC (element))) {
|
||||
/* g_print ("DEBUG: element tries to open file\n"); */
|
||||
return GST_STATE_CHANGE_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
||||
return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
||||
|
||||
return GST_STATE_CHANGE_SUCCESS;
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
||||
* 2000 Wim Taymans <wtay@chello.be>
|
||||
*
|
||||
* gstafsrc.h:
|
||||
*
|
||||
* 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., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __GST_AFSRC_H__
|
||||
#define __GST_AFSRC_H__
|
||||
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <audiofile.h> /* what else are we to do */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
#define GST_TYPE_AFSRC \
|
||||
(gst_afsrc_get_type())
|
||||
#define GST_AFSRC(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AFSRC,GstAFSrc))
|
||||
#define GST_AFSRC_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AFSRC,GstAFSrcClass))
|
||||
#define GST_IS_AFSRC(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AFSRC))
|
||||
#define GST_IS_AFSRC_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AFSRC))
|
||||
|
||||
typedef struct _GstAFSrc GstAFSrc;
|
||||
typedef struct _GstAFSrcClass GstAFSrcClass;
|
||||
|
||||
typedef enum {
|
||||
GST_AFSRC_OPEN = (GST_ELEMENT_FLAG_LAST << 0),
|
||||
|
||||
GST_AFSRC_FLAG_LAST = (GST_ELEMENT_FLAG_LAST << 2),
|
||||
} GstAFSrcFlags;
|
||||
|
||||
struct _GstAFSrc {
|
||||
GstElement element;
|
||||
GstPad *srcpad;
|
||||
|
||||
gchar *filename;
|
||||
/* FILE *file; */
|
||||
|
||||
/* AFfilesetup outfilesetup; */
|
||||
AFfilehandle file;
|
||||
int format;
|
||||
int channels;
|
||||
int width;
|
||||
unsigned int rate;
|
||||
gboolean is_signed;
|
||||
int type; /* type of output, compare to audiofile.h
|
||||
* RAW, AIFF, AIFFC, NEXTSND, WAVE
|
||||
*/
|
||||
/* blocking */
|
||||
gulong curoffset;
|
||||
gulong bytes_per_read;
|
||||
|
||||
gulong seq;
|
||||
guint64 framestamp;
|
||||
/* FIXME : endianness is a little cryptic at this point */
|
||||
int endianness_data; /* 4321 or 1234 */
|
||||
int endianness_wanted; /* same thing, but what the output format wants */
|
||||
int endianness_output; /* what the output endianness will be */
|
||||
};
|
||||
|
||||
struct _GstAFSrcClass {
|
||||
GstElementClass parent_class;
|
||||
|
||||
/* signals */
|
||||
void (*handoff) (GstElement *element,GstPad *pad);
|
||||
};
|
||||
|
||||
GType gst_afsrc_get_type (void);
|
||||
gboolean gst_afsrc_plugin_init (GstPlugin *plugin);
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
#endif /* __GST_AFSRC_H__ */
|
|
@ -1,5 +1,3 @@
|
|||
ext/audiofile/gstafsink.c
|
||||
ext/audiofile/gstafsrc.c
|
||||
ext/sndfile/gstsfsink.c
|
||||
ext/sndfile/gstsfsrc.c
|
||||
sys/dxr3/dxr3audiosink.c
|
||||
|
|
Loading…
Reference in a new issue