static PyObject * create_print(PyObject *self, PyObject *args) { PyObject *buffer; int samples, sample_rate, stereo; void *data; const char *fingerprint; if (!PyArg_ParseTuple(args, "Oiii", &buffer, &samples, &sample_rate, &stereo)) return NULL; data = PyCObject_AsVoidPtr(buffer); Py_BEGIN_ALLOW_THREADS #ifdef __BIG_ENDIAN__ fingerprint = ofa_create_print(data, OFA_BIG_ENDIAN, samples, sample_rate, stereo); #else fingerprint = ofa_create_print(data, OFA_LITTLE_ENDIAN, samples, sample_rate, stereo); #endif Py_END_ALLOW_THREADS if (fingerprint) return PyString_FromString(fingerprint); else Py_RETURN_NONE; }
static void create_fingerprint (GstOFA * ofa) { GstBuffer *buf; gint rate = GST_AUDIO_FILTER (ofa)->format.rate; gint channels = GST_AUDIO_FILTER (ofa)->format.channels; gint endianness = (GST_AUDIO_FILTER (ofa)->format. bigend) ? OFA_BIG_ENDIAN : OFA_LITTLE_ENDIAN; GstTagList *tags; GST_DEBUG ("Generating fingerprint"); buf = gst_adapter_take_buffer (ofa->adapter, gst_adapter_available (ofa->adapter)); ofa->fingerprint = g_strdup (ofa_create_print (GST_BUFFER_DATA (buf), endianness, GST_BUFFER_SIZE (buf) / 2, rate, (channels == 2) ? 1 : 0)); GST_DEBUG ("Generated fingerprint"); gst_buffer_unref (buf); tags = gst_tag_list_new (); gst_tag_list_add (tags, GST_TAG_MERGE_REPLACE, GST_TAG_OFA_FINGERPRINT, ofa->fingerprint, NULL); gst_element_found_tags (GST_ELEMENT (ofa), tags); ofa->record = FALSE; }
static void create_fingerprint (GstOFA * ofa) { GstBuffer *buf; GstAudioFilter *ofa_filter = GST_AUDIO_FILTER (ofa); gint rate = ofa_filter->format.rate; gint channels = ofa_filter->format.channels; gint endianness = ofa_filter->format.bigend ? OFA_BIG_ENDIAN : OFA_LITTLE_ENDIAN; GstTagList *tags; guint available; available = gst_adapter_available (ofa->adapter); if (available == 0) { GST_WARNING_OBJECT (ofa, "No data to take fingerprint from"); ofa->record = FALSE; return; } if (GST_AUDIO_FILTER (ofa)->format.bigend) endianness = OFA_BIG_ENDIAN; else endianness = OFA_LITTLE_ENDIAN; GST_DEBUG_OBJECT (ofa, "Generating fingerprint for %u samples", available / 2); buf = gst_adapter_take_buffer (ofa->adapter, available); ofa->fingerprint = g_strdup (ofa_create_print (GST_BUFFER_DATA (buf), endianness, GST_BUFFER_SIZE (buf) / 2, rate, (channels == 2) ? 1 : 0)); if (ofa->fingerprint) { GST_INFO_OBJECT (ofa, "Generated fingerprint: %s", ofa->fingerprint); } else { GST_WARNING_OBJECT (ofa, "Failed to generate fingerprint"); } gst_buffer_unref (buf); if (ofa->fingerprint) { tags = gst_tag_list_new (); gst_tag_list_add (tags, GST_TAG_MERGE_REPLACE, GST_TAG_OFA_FINGERPRINT, ofa->fingerprint, NULL); gst_element_found_tags (GST_ELEMENT (ofa), tags); g_object_notify (G_OBJECT (ofa), "fingerprint"); } ofa->record = FALSE; }
static gpointer xmms_ofa_thread (gpointer arg) { xmms_ofa_data_t *data = (xmms_ofa_data_t *)arg; const char *fp; g_mutex_lock (&data->mutex); while (data->thread_state == XMMS_OFA_WAIT) { g_cond_wait (&data->cond, &data->mutex); } if (data->thread_state == XMMS_OFA_ABORT) { g_mutex_unlock (&data->mutex); return NULL; } g_mutex_unlock (&data->mutex); XMMS_DBG ("Calculating fingerprint... (will consume CPU)"); fp = ofa_create_print (data->buf, #if G_BYTE_ORDER == G_BIG_ENDIAN OFA_BIG_ENDIAN, #else OFA_LITTLE_ENDIAN, #endif data->bytes_to_read/2, 44100, 1); g_mutex_lock (&data->mutex); data->thread_state = XMMS_OFA_DONE; data->fp = g_strdup (fp); g_mutex_unlock (&data->mutex); XMMS_DBG ("Fingerprint calculated: %s", fp); return NULL; }