Exemplo n.º 1
0
gboolean
nsc_gstreamer_supports_profile (GMAudioProfile *profile)
{
	GstElement *element;
	GError     *error = NULL;
	gchar      *pipeline;

	pipeline = g_strdup_printf ("fakesrc ! %s",
				    gm_audio_profile_get_pipeline (profile));
	element = gst_parse_launch (pipeline, &error);
	g_free (pipeline);

	/*
	 * It is possible for both element and error to be non NULL,
	 * so let's check both.
	 */
	if (element) {
		gst_object_unref (GST_OBJECT (element));

		if (error) {
			g_warning ("Profile warning; %s", error->message);
			g_error_free (error);
		}

		return TRUE;
	} else {
		if (error) {
			g_warning ("Profile error: %s", error->message);
			g_error_free (error);
		}

		return FALSE;
	}
}
Exemplo n.º 2
0
static GstElement*
build_encoder (NscGStreamer *gstreamer)
{
	NscGStreamerPrivate *priv;
	GstElement          *element = NULL;
	gchar               *pipeline;

	g_return_val_if_fail (NSC_IS_GSTREAMER (gstreamer), NULL);

	priv = NSC_GSTREAMER_GET_PRIVATE (gstreamer);
	g_return_val_if_fail (priv->profile != NULL, NULL);

	pipeline = g_strdup_printf ("audioconvert ! audioresample ! %s",
				    gm_audio_profile_get_pipeline (priv->profile));
	element = gst_parse_bin_from_description (pipeline, TRUE, NULL);
	g_free (pipeline);

	return element;
}
Exemplo n.º 3
0
Recording*
recording_start(const char* filename)
{
	GMAudioProfile *profile;
	GstElement *pipeline, *oss_src, *encoder, *filesink;
	pipeline = oss_src = encoder = filesink = NULL;
	
	profile = gm_audio_profile_lookup(rec_settings.profile);
	g_assert(profile);
	
	pipeline = gst_pipeline_new("gnomeradio-record-pipeline");
	if (!pipeline) {
		show_error_message(_("Could not create GStreamer pipeline."),
		_("Check your Gstreamer installation!"));
		goto error;
	}		
	
	oss_src = gst_element_factory_make("osssrc", "oss-source");
	if (!oss_src) {
		show_error_message(_("Could not open Gstreamer OSS Source."),
		_("Verify your Gstreamer OSS subsystem installation!"));
		goto error;
	}
	
	GstBus *bus = gst_element_get_bus(pipeline);
	gst_bus_add_signal_watch(bus);
	g_signal_connect(G_OBJECT(bus), "message::error", G_CALLBACK(error_cb), pipeline);

	char* pipeline_str = g_strdup_printf("audioconvert ! %s", gm_audio_profile_get_pipeline(profile));
	encoder = my_gst_gconf_render_bin_from_description(pipeline_str);
	g_free(pipeline_str);
	if (!encoder) {
		char *caption = g_strdup_printf(_("Could not create encoder \"%s\"."), gm_audio_profile_get_name (profile));
		show_error_message(caption,
		_("Verify your Gstreamer plugins installation!"));
		g_free(caption);
		goto error;
	}
	
	/* Write to disk */
	filesink = gst_element_factory_make("filesink", "file-sink");
	if (!filesink) {	
		show_error_message(_("Could not create Gstreamer filesink."),
		_("Check your Gstreamer installation!"));
		goto error;
	}
	
	/* Add the elements to the pipeline */
	gst_bin_add_many(GST_BIN(pipeline), oss_src, encoder, filesink, NULL);
	
	/* Link it all together */
	if (!gst_element_link_many(oss_src, encoder, filesink, NULL)) {
		g_warning("Could not link elements. This is bad!\n");
		goto error;
	}
	char* path = g_strdup_printf("%s.%s", filename, gm_audio_profile_get_extension(profile));	
	g_object_set(G_OBJECT(filesink), "location", path, NULL);
	
	gst_element_set_state(pipeline, GST_STATE_PLAYING);
	
	Recording *recording = g_malloc0(sizeof(Recording));
	recording->filename = path;
	recording->pipeline = pipeline;
	
	return recording;
	
error:
	if (pipeline)
		gst_object_unref(GST_OBJECT(pipeline));
	if (oss_src)
		gst_object_unref(GST_OBJECT(oss_src));
	if (encoder)
		gst_object_unref(GST_OBJECT(encoder));
	if (filesink)
		gst_object_unref(GST_OBJECT(filesink));
	
	return NULL;
}		
static void
test_clicked_cb (GtkButton *button, GtkWidget *combo)
{
  GstStateChangeReturn ret;
  gchar *partialpipe = NULL;
  gchar *extension = NULL;
  gchar *pipeline_desc;
  GError *error = NULL;
  GMAudioProfile *profile;
  GstElement *pipeline = NULL;
  GstMessage *msg = NULL;
  GstBus *bus = NULL;

  profile = gm_audio_profile_choose_get_active (combo);
  g_return_if_fail (profile != NULL);

  gtk_widget_set_sensitive (GTK_WIDGET (button), FALSE);

  extension = g_strdup (gm_audio_profile_get_extension (profile));
  partialpipe = g_strdup (gm_audio_profile_get_pipeline (profile));

  g_print ("You chose profile with name %s and pipeline %s\n",
           gm_audio_profile_get_name (profile),
           gm_audio_profile_get_pipeline (profile));

  pipeline_desc = g_strdup_printf ("audiotestsrc wave=sine num-buffers=4096 "
                                   " ! audioconvert "
                                   " ! %s "
                                   " ! filesink location=test.%s",
                                   partialpipe, extension);

  g_print ("Going to run pipeline %s\n", pipeline_desc);

  pipeline = gst_parse_launch (pipeline_desc, &error);
  if (error)
  {
    g_warning ("Error parsing pipeline: %s", error->message);
    goto done;
  }

  bus = gst_element_get_bus (pipeline);

  gst_element_set_state (pipeline, GST_STATE_PLAYING);

  /* wait for state change to complete or to have failed */
  ret = gst_element_get_state (pipeline, NULL, NULL, -1);
  if (ret == GST_STATE_CHANGE_FAILURE) {
    /* check if an error was posted on the bus */
    if ((msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, 0))) {
      gst_message_parse_error (msg, &error, NULL);
    }

    g_warning ("Error starting pipeline: %s",
        (error) ? error->message : "UNKNOWN ERROR");

    goto done;
  }

  g_print ("Writing test sound to test.%s ...\n", extension);

  /* wait for it finish (error or EOS), but no more than 30 secs */
  msg = gst_bus_poll (bus, GST_MESSAGE_ERROR | GST_MESSAGE_EOS, 30*GST_SECOND);

  if (msg) {
    switch (GST_MESSAGE_TYPE (msg)) {
      case GST_MESSAGE_EOS:
        g_print ("Test finished successfully.\n");
        break;
      case GST_MESSAGE_ERROR:
        gst_message_parse_error (msg, &error, NULL);
        g_warning ("Error starting pipeline: %s",
            (error) ? error->message : "UNKNOWN ERROR");
        break;
      default:
        g_assert_not_reached ();
    }
  } else {
    g_warning ("Test did not finish within 30 seconds!\n");
  }

done:

  g_print ("==============================================================\n");

  if (error)
    g_error_free (error);

  if (pipeline) {
    gst_element_set_state (pipeline, GST_STATE_NULL);
    gst_object_unref (pipeline);
  }

  if (msg)
    gst_message_unref (msg);

  if (bus)
    gst_object_unref (bus);

  g_free (pipeline_desc);
  g_free (partialpipe);
  g_free (extension);

  gtk_widget_set_sensitive (GTK_WIDGET (button), TRUE);
}