Exemple #1
0
static GstStateChangeReturn
gst_trm_change_state (GstElement * element, GstStateChange transition)
{
  GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
  GstTRM *trm;

  trm = GST_TRM (element);

  switch (transition) {
    case GST_STATE_CHANGE_READY_TO_PAUSED:
      trm->trm = trm_New ();
      break;
    default:
      break;
  }

  ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
  if (ret != GST_STATE_CHANGE_SUCCESS)
    return ret;

  switch (transition) {
    case GST_STATE_CHANGE_PAUSED_TO_READY:
      trm_Delete (trm->trm);
      trm->trm = NULL;
      trm->data_available = FALSE;
      trm->signature_available = FALSE;
      break;
    default:
      break;
  }

  return ret;
}
Exemple #2
0
static void
gst_trm_get_property (GObject * object, guint prop_id, GValue * value,
    GParamSpec * pspec)
{
  GstTRM *trm;

  trm = GST_TRM (object);

  GST_OBJECT_LOCK (trm);

  switch (prop_id) {
    case ARG_PROXY_ADDRESS:{
      g_value_set_string (value, trm->proxy_address);
      break;
    }
    case ARG_PROXY_PORT:{
      g_value_set_uint (value, trm->proxy_port);
      break;
    }
    default:{
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
  }

  GST_OBJECT_UNLOCK (trm);
}
Exemple #3
0
static GstFlowReturn
gst_trm_chain (GstPad * pad, GstBuffer * buf)
{
  GstTRM *trm = GST_TRM (GST_PAD_PARENT (pad));

  if (!trm->data_available) {
    GstFormat tformat = GST_FORMAT_TIME;
    gint64 total_duration;

    /* FIXME: maybe we should only query this once we have as much data as
     * we need (30secs or so), to get a better estimation of the length in
     * the case of VBR files? */
    if (gst_pad_query_peer_duration (pad, &tformat, &total_duration)) {
      total_duration /= GST_SECOND;
      trm_SetSongLength (trm->trm, total_duration);
      trm->data_available = TRUE;
    }
  }

  if (!trm->signature_available
      && trm_GenerateSignature (trm->trm, (char *) GST_BUFFER_DATA (buf),
          GST_BUFFER_SIZE (buf))) {
    GST_DEBUG ("Signature");

    GST_OBJECT_LOCK (trm);
    if (trm->proxy_address != NULL) {
      if (!trm_SetProxy (trm->trm, trm->proxy_address, trm->proxy_port)) {
        GST_OBJECT_UNLOCK (trm);
        goto proxy_setup_error;
      }
    }
    GST_OBJECT_UNLOCK (trm);

    gst_trm_emit_signature (trm);
  }

  return gst_pad_push (trm->srcpad, buf);

/* ERRORS */
proxy_setup_error:
  {
    GST_ELEMENT_ERROR (trm, RESOURCE, SETTINGS, (NULL),
        ("Unable to set proxy server for trm lookup"));
    return GST_FLOW_ERROR;
  }
}
Exemple #4
0
static gboolean
gst_trm_setcaps (GstPad * pad, GstCaps * caps)
{
  GstTRM *trm;
  GstStructure *structure;
  const gchar *mimetype;
  gint width;

  trm = GST_TRM (gst_pad_get_parent (pad));

  if (!gst_pad_set_caps (trm->srcpad, caps))
    return FALSE;

  structure = gst_caps_get_structure (caps, 0);
  mimetype = gst_structure_get_name (structure);

  if (!gst_structure_get_int (structure, "depth", &trm->depth) ||
      !gst_structure_get_int (structure, "width", &width) ||
      !gst_structure_get_int (structure, "channels", &trm->channels) ||
      !gst_structure_get_int (structure, "rate", &trm->rate)) {
    GST_DEBUG_OBJECT (trm, "failed to extract depth, width, channels or rate");
    goto failure;
  }

  if (trm->depth != width) {
    GST_DEBUG_OBJECT (trm, "depth != width (%d != %d)", trm->depth, width);
    goto failure;
  }

  trm_SetPCMDataInfo (trm->trm, trm->rate, trm->channels, trm->depth);

  gst_object_unref (trm);
  return TRUE;

/* ERRORS */
failure:
  {
    GST_WARNING_OBJECT (trm, "FAILED with caps %" GST_PTR_FORMAT, caps);
    gst_object_unref (trm);
    return FALSE;
  }
}