2004-01-18 20:17:05 +00:00
|
|
|
/* GStreamer trm plugin
|
|
|
|
* Copyright (C) 2004 Jeremy Simon <jsimon13@yahoo.fr>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
#include "gsttrm.h"
|
|
|
|
|
|
|
|
/* musicbrainz signals and args */
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2004-01-18 20:17:05 +00:00
|
|
|
SIGNAL_SIGNATURE_AVAILABLE,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2004-01-18 20:17:05 +00:00
|
|
|
ARG_0,
|
|
|
|
ARG_SIGNATURE,
|
|
|
|
ARG_ASCII_SIGNATURE
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("audio/x-raw-int, "
|
2004-03-15 19:32:27 +00:00
|
|
|
"endianness = (int) BYTE_ORDER, "
|
|
|
|
"signed = (bool) TRUE, "
|
|
|
|
"width = (int) { 8, 16 }, "
|
|
|
|
"depth = (int) { 8, 16 }, "
|
|
|
|
"rate = (int) [ 8000, 96000 ], " "channels = (int) [ 1, 2 ]")
|
2004-03-14 22:34:33 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("audio/x-raw-int, "
|
2004-03-15 19:32:27 +00:00
|
|
|
"endianness = (int) BYTE_ORDER, "
|
|
|
|
"signed = (bool) TRUE, "
|
|
|
|
"width = (int) { 8, 16 }, "
|
|
|
|
"depth = (int) { 8, 16 }, "
|
|
|
|
"rate = (int) [ 8000, 96000 ], " "channels = (int) [ 1, 2 ]")
|
2004-03-14 22:34:33 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
static void gst_musicbrainz_class_init (GstMusicBrainzClass * klass);
|
|
|
|
static void gst_musicbrainz_base_init (GstMusicBrainzClass * klass);
|
|
|
|
static void gst_musicbrainz_init (GstMusicBrainz * musicbrainz);
|
|
|
|
|
|
|
|
static void gst_musicbrainz_chain (GstPad * pad, GstData * data);
|
|
|
|
|
|
|
|
static void gst_musicbrainz_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_musicbrainz_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
|
|
|
|
static GstElementStateReturn
|
|
|
|
gst_musicbrainz_change_state (GstElement * element);
|
2004-01-18 20:17:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
|
|
|
static guint gst_musicbrainz_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
|
|
|
|
GType
|
|
|
|
gst_musicbrainz_get_type (void)
|
|
|
|
{
|
|
|
|
static GType musicbrainz_type = 0;
|
|
|
|
|
|
|
|
if (!musicbrainz_type) {
|
|
|
|
static const GTypeInfo musicbrainz_info = {
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstMusicBrainzClass),
|
2004-01-18 20:17:05 +00:00
|
|
|
(GBaseInitFunc) gst_musicbrainz_base_init,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) gst_musicbrainz_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstMusicBrainz),
|
2004-01-18 20:17:05 +00:00
|
|
|
0,
|
2004-03-14 22:34:33 +00:00
|
|
|
(GInstanceInitFunc) gst_musicbrainz_init,
|
2004-01-18 20:17:05 +00:00
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
musicbrainz_type = g_type_register_static (GST_TYPE_ELEMENT,
|
2004-03-15 19:32:27 +00:00
|
|
|
"GstMusicBrainz", &musicbrainz_info, 0);
|
2004-01-18 20:17:05 +00:00
|
|
|
}
|
|
|
|
return musicbrainz_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_musicbrainz_base_init (GstMusicBrainzClass * klass)
|
2004-01-18 20:17:05 +00:00
|
|
|
{
|
|
|
|
GstElementDetails gst_musicbrainz_details = {
|
|
|
|
"Compute TRM Id",
|
2004-05-09 14:37:16 +00:00
|
|
|
"Filter/Analyzer/Audio",
|
2004-01-24 12:04:39 +00:00
|
|
|
"Compute TRM Id from muscibrainz",
|
2004-01-18 20:17:05 +00:00
|
|
|
"Jeremy Simon <jsimon13@yahoo.fr>",
|
|
|
|
};
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_static_pad_template_get (&src_template));
|
2004-01-18 20:17:05 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_static_pad_template_get (&sink_template));
|
2004-01-18 20:17:05 +00:00
|
|
|
|
|
|
|
gst_element_class_set_details (element_class, &gst_musicbrainz_details);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_musicbrainz_class_init (GstMusicBrainzClass * klass)
|
2004-01-18 20:17:05 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2004-01-18 20:17:05 +00:00
|
|
|
|
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SIGNATURE,
|
|
|
|
g_param_spec_string ("signature", "signature", "signature",
|
2004-03-15 19:32:27 +00:00
|
|
|
NULL, G_PARAM_READABLE));
|
2004-03-14 22:34:33 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ASCII_SIGNATURE,
|
|
|
|
g_param_spec_string ("ascii_signature", "ascii_signature",
|
2004-03-15 19:32:27 +00:00
|
|
|
"ascii_signature", NULL, G_PARAM_READABLE));
|
2004-01-18 20:17:05 +00:00
|
|
|
|
|
|
|
gobject_class->set_property = gst_musicbrainz_set_property;
|
|
|
|
gobject_class->get_property = gst_musicbrainz_get_property;
|
|
|
|
|
|
|
|
gst_musicbrainz_signals[SIGNAL_SIGNATURE_AVAILABLE] =
|
2004-03-14 22:34:33 +00:00
|
|
|
g_signal_new ("signature-available", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstMusicBrainzClass,
|
2004-03-15 19:32:27 +00:00
|
|
|
signature_available), NULL, NULL, g_cclosure_marshal_VOID__VOID,
|
2004-03-14 22:34:33 +00:00
|
|
|
G_TYPE_NONE, 0);
|
2004-01-18 20:17:05 +00:00
|
|
|
|
|
|
|
gstelement_class->change_state = gst_musicbrainz_change_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstPadLinkReturn
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_musicbrainz_sinkconnect (GstPad * pad, const GstCaps * caps)
|
2004-01-18 20:17:05 +00:00
|
|
|
{
|
|
|
|
GstMusicBrainz *musicbrainz;
|
|
|
|
GstStructure *structure;
|
|
|
|
const gchar *mimetype;
|
|
|
|
gint width;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
musicbrainz = GST_MUSICBRAINZ (gst_pad_get_parent (pad));
|
|
|
|
|
2004-01-18 20:17:05 +00:00
|
|
|
musicbrainz->caps = caps;
|
|
|
|
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
mimetype = gst_structure_get_name (structure);
|
|
|
|
|
|
|
|
if (!gst_structure_get_int (structure, "depth", &musicbrainz->depth) ||
|
|
|
|
!gst_structure_get_int (structure, "width", &width))
|
2004-03-14 22:34:33 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2004-01-18 20:17:05 +00:00
|
|
|
|
|
|
|
if (musicbrainz->depth != width)
|
2004-03-14 22:34:33 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2004-01-18 20:17:05 +00:00
|
|
|
|
|
|
|
if (!gst_structure_get_int (structure, "channels", &musicbrainz->channels))
|
2004-03-14 22:34:33 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2004-01-18 20:17:05 +00:00
|
|
|
|
|
|
|
if (!gst_structure_get_int (structure, "rate", &musicbrainz->rate))
|
2004-03-14 22:34:33 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2004-01-18 20:17:05 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
trm_SetPCMDataInfo (musicbrainz->trm, musicbrainz->rate,
|
|
|
|
musicbrainz->channels, musicbrainz->depth);
|
|
|
|
musicbrainz->linked = TRUE;
|
2004-01-18 20:17:05 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
return GST_PAD_LINK_OK;
|
2004-01-18 20:17:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_musicbrainz_init (GstMusicBrainz * musicbrainz)
|
2004-01-18 20:17:05 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
musicbrainz->sinkpad =
|
|
|
|
gst_pad_new_from_template (gst_static_pad_template_get (&sink_template),
|
|
|
|
"sink");
|
2004-01-18 20:17:05 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (musicbrainz), musicbrainz->sinkpad);
|
|
|
|
gst_pad_set_chain_function (musicbrainz->sinkpad, gst_musicbrainz_chain);
|
|
|
|
gst_pad_set_link_function (musicbrainz->sinkpad, gst_musicbrainz_sinkconnect);
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
musicbrainz->srcpad =
|
|
|
|
gst_pad_new_from_template (gst_static_pad_template_get (&src_template),
|
|
|
|
"src");
|
2004-01-18 20:17:05 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (musicbrainz), musicbrainz->srcpad);
|
|
|
|
|
|
|
|
musicbrainz->trm = NULL;
|
|
|
|
musicbrainz->linked = FALSE;
|
|
|
|
musicbrainz->data_available = FALSE;
|
|
|
|
musicbrainz->total_time = 0;
|
|
|
|
musicbrainz->signature_available = FALSE;
|
|
|
|
|
|
|
|
GST_FLAG_SET (musicbrainz, GST_ELEMENT_EVENT_AWARE);
|
2004-03-14 22:34:33 +00:00
|
|
|
/*GST_FLAG_SET(musicbrainz, GST_ELEMENT_THREAD_SUGGESTED); */
|
2004-01-18 20:17:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_trm_handle_event (GstPad * pad, GstData * data)
|
2004-01-18 20:17:05 +00:00
|
|
|
{
|
|
|
|
GstEvent *event = GST_EVENT (data);
|
|
|
|
|
|
|
|
gst_pad_event_default (pad, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_musicbrainz_chain (GstPad * pad, GstData * data)
|
2004-01-18 20:17:05 +00:00
|
|
|
{
|
|
|
|
GstMusicBrainz *musicbrainz;
|
|
|
|
GstBuffer *buf;
|
|
|
|
static GstFormat format = GST_FORMAT_TIME;
|
|
|
|
gint64 nanos;
|
|
|
|
|
|
|
|
g_return_if_fail (pad != NULL);
|
|
|
|
g_return_if_fail (GST_IS_PAD (pad));
|
|
|
|
|
|
|
|
musicbrainz = GST_MUSICBRAINZ (gst_pad_get_parent (pad));
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (GST_IS_EVENT (data)) {
|
2004-01-18 20:17:05 +00:00
|
|
|
gst_trm_handle_event (pad, data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf = GST_BUFFER (data);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-01-18 20:17:05 +00:00
|
|
|
if (musicbrainz->linked && !musicbrainz->data_available)
|
2004-03-14 22:34:33 +00:00
|
|
|
if (gst_pad_query (gst_pad_get_peer (pad), GST_QUERY_TOTAL, &format,
|
2004-03-15 19:32:27 +00:00
|
|
|
&nanos)) {
|
2004-01-18 20:17:05 +00:00
|
|
|
musicbrainz->total_time = nanos / GST_SECOND;
|
2004-03-14 22:34:33 +00:00
|
|
|
trm_SetSongLength (musicbrainz->trm, musicbrainz->total_time);
|
2004-01-18 20:17:05 +00:00
|
|
|
musicbrainz->data_available = TRUE;
|
|
|
|
|
|
|
|
gst_pad_try_set_caps (musicbrainz->srcpad, musicbrainz->caps);
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (!musicbrainz->signature_available
|
|
|
|
&& trm_GenerateSignature (musicbrainz->trm, GST_BUFFER_DATA (buf),
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_BUFFER_SIZE (buf))) {
|
2004-01-18 20:17:05 +00:00
|
|
|
GST_DEBUG ("Signature");
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
trm_FinalizeSignature (musicbrainz->trm, musicbrainz->signature, NULL);
|
|
|
|
trm_ConvertSigToASCII (musicbrainz->trm, musicbrainz->signature,
|
2004-03-15 19:32:27 +00:00
|
|
|
musicbrainz->ascii_signature);
|
2004-01-18 20:17:05 +00:00
|
|
|
musicbrainz->signature_available = TRUE;
|
2004-03-14 22:34:33 +00:00
|
|
|
g_signal_emit (G_OBJECT (musicbrainz),
|
2004-03-15 19:32:27 +00:00
|
|
|
gst_musicbrainz_signals[SIGNAL_SIGNATURE_AVAILABLE], 0);
|
2004-01-18 20:17:05 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("Signature : %s", musicbrainz->ascii_signature);
|
|
|
|
|
|
|
|
musicbrainz->signature_available = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_pad_push (musicbrainz->srcpad, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_musicbrainz_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
2004-01-18 20:17:05 +00:00
|
|
|
{
|
|
|
|
GstMusicBrainz *musicbrainz;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail (GST_IS_MUSICBRAINZ (object));
|
|
|
|
|
|
|
|
musicbrainz = GST_MUSICBRAINZ (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_SIGNATURE:
|
|
|
|
case ARG_ASCII_SIGNATURE:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_musicbrainz_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2004-01-18 20:17:05 +00:00
|
|
|
{
|
|
|
|
GstMusicBrainz *musicbrainz;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2004-03-14 22:34:33 +00:00
|
|
|
musicbrainz = GST_MUSICBRAINZ (object);
|
2004-01-18 20:17:05 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2004-03-14 22:34:33 +00:00
|
|
|
case ARG_SIGNATURE:{
|
2004-01-18 20:17:05 +00:00
|
|
|
g_value_set_string (value, musicbrainz->signature);
|
|
|
|
break;
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
case ARG_ASCII_SIGNATURE:{
|
2004-01-18 20:17:05 +00:00
|
|
|
g_value_set_string (value, musicbrainz->ascii_signature);
|
|
|
|
break;
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
default:{
|
2004-01-18 20:17:05 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static GstElementStateReturn
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_musicbrainz_change_state (GstElement * element)
|
2004-01-18 20:17:05 +00:00
|
|
|
{
|
|
|
|
GstMusicBrainz *musicbrainz;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_MUSICBRAINZ (element), GST_STATE_FAILURE);
|
|
|
|
|
|
|
|
musicbrainz = GST_MUSICBRAINZ (element);
|
|
|
|
|
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
|
|
|
musicbrainz->trm = trm_New ();
|
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
|
|
|
trm_Delete (musicbrainz->trm);
|
|
|
|
musicbrainz->trm = NULL;
|
|
|
|
musicbrainz->linked = FALSE;
|
|
|
|
musicbrainz->data_available = FALSE;
|
|
|
|
musicbrainz->total_time = 0;
|
|
|
|
musicbrainz->signature_available = FALSE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
|
|
|
|
|
|
|
return GST_STATE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
plugin_init (GstPlugin * plugin)
|
2004-01-18 20:17:05 +00:00
|
|
|
{
|
|
|
|
return gst_element_register (plugin, "trm",
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_RANK_NONE, GST_TYPE_MUSICBRAINZ);
|
2004-01-18 20:17:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"trm",
|
|
|
|
"A trm signature producer",
|
|
|
|
plugin_init, VERSION, "GPL", GST_PACKAGE, GST_ORIGIN)
|