summaryrefslogtreecommitdiffstats
path: root/ext/audiofile/gstaftypes.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/audiofile/gstaftypes.c')
-rw-r--r--ext/audiofile/gstaftypes.c73
1 files changed, 30 insertions, 43 deletions
diff --git a/ext/audiofile/gstaftypes.c b/ext/audiofile/gstaftypes.c
index 26832d76..befe141b 100644
--- a/ext/audiofile/gstaftypes.c
+++ b/ext/audiofile/gstaftypes.c
@@ -33,34 +33,33 @@ static void gst_aftypes_vf_destroy(AFvirtualfile *vfile);
static long gst_aftypes_vf_seek (AFvirtualfile *vfile, long offset, int is_relative);
static long gst_aftypes_vf_tell (AFvirtualfile *vfile);
-static GstCaps* gst_aftypes_type_find(GstBuffer *buf, gpointer private);
-
-static GstTypeDefinition aftype_definitions[] = {
- { "aftypes audio/x-aiff", "audio/x-aiff", ".aiff .aif .aifc", gst_aftypes_type_find },
- { "aftypes audio/x-wav", "audio/x-wav", ".wav", gst_aftypes_type_find },
- { "aftypes audio/basic", "audio/basic", ".au .snd", gst_aftypes_type_find },
- { NULL, NULL, NULL, NULL },
-};
+static void gst_aftypes_type_find(GstTypeFind *tf, gpointer private);
typedef struct _GstAFTypesBuffer GstAFTypesBuffer;
struct _GstAFTypesBuffer {
- GstBuffer *buffer;
+ guint8 *data;
+ int length;
long offset;
};
-static GstCaps*
-gst_aftypes_type_find(GstBuffer *buf, gpointer private)
+#define GST_AUDIOFILE_TYPE_FIND_SIZE 4096
+#define AF_CAPS(type) gst_caps_new ("audiofile_type_find", type, NULL)
+static void
+gst_aftypes_type_find(GstTypeFind *tf, gpointer private)
{
-
- GstAFTypesBuffer *buffer_wrap = g_new0(GstAFTypesBuffer, 1);
+ GstAFTypesBuffer *buffer_wrap;
+ guint8 *data;
AFvirtualfile *vfile;
AFfilehandle file;
int file_format, format_version;
gchar *type;
- GST_DEBUG("calling gst_aftypes_type_find");
+ data = gst_type_find_peek (tf, 0, GST_AUDIOFILE_TYPE_FIND_SIZE);
+ if (data == NULL) return;
- buffer_wrap->buffer = buf;
+ buffer_wrap = g_new0(GstAFTypesBuffer, 1);
+ buffer_wrap->data = data;
+ buffer_wrap->length = GST_AUDIOFILE_TYPE_FIND_SIZE;
buffer_wrap->offset = 0;
vfile = af_virtual_file_new();
@@ -76,12 +75,13 @@ gst_aftypes_type_find(GstBuffer *buf, gpointer private)
file_format = afGetFileFormat (file, &format_version);
afCloseFile (file);
- GST_DEBUG("file format: %d", file_format);
+ //GST_DEBUG("file format: %d", file_format);
/* reject raw data, just in case it is some other format */
if (file_format == AF_FILE_UNKNOWN ||
file_format == AF_FILE_RAWDATA){
- return NULL;
+ g_free (buffer_wrap);
+ return;
}
switch (file_format){
case AF_FILE_AIFF:
@@ -94,49 +94,36 @@ gst_aftypes_type_find(GstBuffer *buf, gpointer private)
case AF_FILE_NEXTSND:
type = "audio/basic";
break;
+ case AF_FILE_BICSF:
default:
type=NULL;
break;
}
if (type != NULL){
- return gst_caps_new ("audiofile_type_find", type, NULL);
+ gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, AF_CAPS(type));
}
-
- return NULL;
}
-static gboolean
-plugin_init (GModule *module, GstPlugin *plugin)
+gboolean
+gst_aftypes_plugin_init (GModule *module, GstPlugin *plugin)
{
- gint i=0;
+ static gchar * af_exts[] = { "aiff", "aif", "aifc", "wav", "au", "snd", NULL };
- while (aftype_definitions[i].name) {
- GstTypeFactory *type;
-
- type = gst_type_factory_new (&aftype_definitions[i]);
- gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (type));
- i++;
- }
-
+ gst_type_find_factory_register (plugin, "audio/x-mod",
+ GST_ELEMENT_RANK_MARGINAL, gst_aftypes_type_find, af_exts,
+ GST_CAPS_ANY, NULL);
+
return TRUE;
}
-GstPluginDesc plugin_desc = {
- GST_VERSION_MAJOR,
- GST_VERSION_MINOR,
- "aftypes",
- plugin_init
-};
-
-
static ssize_t
gst_aftypes_vf_read (AFvirtualfile *vfile, void *data, size_t nbytes)
{
GstAFTypesBuffer *bwrap = (GstAFTypesBuffer*)vfile->closure;
- long bufsize = GST_BUFFER_SIZE(bwrap->buffer);
- guchar *bytes = GST_BUFFER_DATA(bwrap->buffer);
+ long bufsize = bwrap->length;
+ guint8 *bytes = bwrap->data;
if (bwrap->offset + nbytes > bufsize){
nbytes = bufsize;
@@ -155,7 +142,7 @@ static long
gst_aftypes_vf_seek (AFvirtualfile *vfile, long offset, int is_relative)
{
GstAFTypesBuffer *bwrap = (GstAFTypesBuffer*)vfile->closure;
- long bufsize = GST_BUFFER_SIZE(bwrap->buffer);
+ long bufsize = bwrap->length;
g_print("request seek to: %ld\n", offset);
if (!is_relative){
@@ -180,7 +167,7 @@ static long
gst_aftypes_vf_length (AFvirtualfile *vfile)
{
GstAFTypesBuffer *bwrap = (GstAFTypesBuffer*)vfile->closure;
- return GST_BUFFER_SIZE(bwrap->buffer);
+ return bwrap->length;
}
static ssize_t