[Goodies-commits] r5905 - xfburn/trunk/xfburn
David Mohr
squisher at xfce.org
Sun Nov 2 06:32:29 CET 2008
Author: squisher
Date: 2008-11-02 05:32:28 +0000 (Sun, 02 Nov 2008)
New Revision: 5905
Modified:
xfburn/trunk/xfburn/xfburn-audio-composition.c
xfburn/trunk/xfburn/xfburn-burn-audio-cd-composition-dialog.c
xfburn/trunk/xfburn/xfburn-perform-burn.c
xfburn/trunk/xfburn/xfburn-transcoder-gst.c
Log:
Restructuring passing of info from gst to xfburn, better control over debugging output
Modified: xfburn/trunk/xfburn/xfburn-audio-composition.c
===================================================================
--- xfburn/trunk/xfburn/xfburn-audio-composition.c 2008-11-01 23:11:13 UTC (rev 5904)
+++ xfburn/trunk/xfburn/xfburn-audio-composition.c 2008-11-02 05:32:28 UTC (rev 5905)
@@ -1190,8 +1190,7 @@
gtk_tree_store_append (GTK_TREE_STORE (model), iter, NULL);
gdk_threads_leave ();
- /* (filesize - header_size) / bytes_per_seconds */
- DBG ("length = %d", atrack->length);
+ //DBG ("length = %d", atrack->length);
secs = atrack->length;
humanlength = g_strdup_printf ("%2d:%2d", secs / 60, secs % 60);
Modified: xfburn/trunk/xfburn/xfburn-burn-audio-cd-composition-dialog.c
===================================================================
--- xfburn/trunk/xfburn/xfburn-burn-audio-cd-composition-dialog.c 2008-11-01 23:11:13 UTC (rev 5904)
+++ xfburn/trunk/xfburn/xfburn-burn-audio-cd-composition-dialog.c 2008-11-02 05:32:28 UTC (rev 5905)
@@ -454,9 +454,9 @@
return;
}
- DBG ("Adding %d tracks to the session", n_tracks);
+ //DBG ("Adding %d tracks to the session", n_tracks);
for (i=0; i<n_tracks; i++) {
- DBG ("Track %d has %d sectors", i, track_sectors[i]);
+ //DBG ("Track %d has %d sectors", i, track_sectors[i]);
burn_session_add_track (session, tracks[i], BURN_POS_END);
}
Modified: xfburn/trunk/xfburn/xfburn-perform-burn.c
===================================================================
--- xfburn/trunk/xfburn/xfburn-perform-burn.c 2008-11-01 23:11:13 UTC (rev 5904)
+++ xfburn/trunk/xfburn/xfburn-perform-burn.c 2008-11-02 05:32:28 UTC (rev 5905)
@@ -160,9 +160,9 @@
//percent = 1.0 + ((gdouble) progress.sector+1.0) / ((gdouble) progress.sectors) * 98.0;
percent = 1.0 + ((gdouble) progress.sector + burned_sectors + 1.0) / ((gdouble) total_sectors) * 98.0;
- //if ((dbg_no % 16) == 0) {
+ /*
+ if ((dbg_no % 16) == 0) {
DBG ("%.0f ; track = %d\tsector %d/%d", percent, progress.track, progress.sector, progress.sectors);
- /*
}
*/
xfburn_progress_dialog_set_progress_bar_fraction (XFBURN_PROGRESS_DIALOG (dialog_progress), percent / 100.0);
@@ -278,6 +278,7 @@
final_message = g_strdup_printf ("%s: %s", final_status_text, msg_text);
}
+ /* output it to console in case the program crashes */
DBG ("Final burning status: %s", final_message);
/* restore default signal handlers */
Modified: xfburn/trunk/xfburn/xfburn-transcoder-gst.c
===================================================================
--- xfburn/trunk/xfburn/xfburn-transcoder-gst.c 2008-11-01 23:11:13 UTC (rev 5904)
+++ xfburn/trunk/xfburn/xfburn-transcoder-gst.c 2008-11-02 05:32:28 UTC (rev 5905)
@@ -50,11 +50,11 @@
#include "xfburn-transcoder-gst.h"
-/* if this is set, then add in an identity element so
- that the data can get inspected in cb_handoff */
-//#define DEBUG_GST
+/* Set DEBUG_GST > 0 to be able to inspect the data just before it gets to the fd,
+ and to get a lot more gst debugging output.
+ Set DEBUG_GST > 1 to also get a lot of gst state change messages */
+//#define DEBUG_GST 1
-
/** Prototypes **/
/* class initialization */
static void xfburn_transcoder_gst_class_init (XfburnTranscoderGstClass * klass);
@@ -324,7 +324,7 @@
g_signal_connect (id, "handoff", G_CALLBACK (cb_handoff), id);
#endif
- g_signal_connect (decoder, "new-decoded-pad", G_CALLBACK (on_pad_added), conv);
+ g_signal_connect (decoder, "new-decoded-pad", G_CALLBACK (on_pad_added), trans);
}
static void
@@ -332,11 +332,14 @@
{
XfburnTranscoderGstPrivate *priv= XFBURN_TRANSCODER_GST_GET_PRIVATE (trans);
+#if DEBUG_GST > 0
DBG ("Deleting pipeline");
+#endif
if (gst_element_set_state (priv->pipeline, GST_STATE_NULL) == GST_STATE_CHANGE_FAILURE)
g_warning ("Failed to change state to null, deleting pipeline anyways");
- /* give gstreamer a chance to do something */
+ /* give gstreamer a chance to do something
+ * this might not be necessary, but shouldn't hurt */
g_thread_yield ();
g_object_unref (priv->pipeline);
@@ -349,6 +352,7 @@
create_pipeline (trans);
}
+#if DEBUG_GST > 1
static gchar *
state_to_str (GstState st)
{
@@ -366,17 +370,54 @@
}
return "invalid";
}
+#endif
static gboolean
+signal_identification_done (XfburnTranscoderGst *trans, const char *dbg_res)
+{
+ XfburnTranscoderGstPrivate *priv= XFBURN_TRANSCODER_GST_GET_PRIVATE (trans);
+
+ int i;
+
+#if DEBUG_GST > 0
+ DBG ("Trying to lock mutex (%s)", dbg_res);
+#endif
+
+ /* There is no g_mutex_lock_timed, so emulate it with a loop.
+ * I have never seen this getting hung here, but one never knows! */
+ for (i=0; i<SIGNAL_SEND_ITERATIONS; i++) {
+ if (g_mutex_trylock (priv->gst_mutex))
+ break;
+ g_usleep (SIGNAL_SEND_TIMEOUT_MICROS / SIGNAL_SEND_ITERATIONS);
+ DBG ("foo");
+ g_thread_yield ();
+ if (i==9) {
+ DBG ("Noone was there to listen to the result of the identification!");
+ /* FIXME: recreate pipeline here? This state is not the fault of gst */
+ if (gst_element_set_state (priv->pipeline, GST_STATE_NULL) == GST_STATE_CHANGE_FAILURE) {
+ DBG ("Oops, could not reset pipeline to null");
+ }
+ return FALSE;
+ }
+ }
+
+ g_cond_signal (priv->gst_cond);
+ g_mutex_unlock (priv->gst_mutex);
+
+#if DEBUG_GST > 0
+ DBG ("Releasing mutex (%s)", dbg_res);
+#endif
+
+ return TRUE;
+}
+
+
+static gboolean
bus_call (GstBus *bus, GstMessage *msg, gpointer data)
{
XfburnTranscoderGst *trans = XFBURN_TRANSCODER_GST (data);
XfburnTranscoderGstPrivate *priv= XFBURN_TRANSCODER_GST_GET_PRIVATE (trans);
- GstFormat fmt;
- guint secs;
- //gint64 frames;
-
switch (GST_MESSAGE_TYPE (msg)) {
case GST_MESSAGE_EOS: {
@@ -406,36 +447,30 @@
case GST_MESSAGE_ERROR: {
gchar *debug;
GError *error;
- int i;
gst_message_parse_error (msg, &error, &debug);
g_free (debug);
+ /* FIXME: show this all the time? */
g_warning ("Gstreamer error: %s\n", error->message);
g_error_free (error);
switch (priv->state) {
case XFBURN_TRANSCODER_GST_STATE_IDLE:
+#if DEBUG_GST > 0
DBG ("Ignoring gstreamer error while idling.");
+#endif
+ recreate_pipeline (trans);
break;
+
case XFBURN_TRANSCODER_GST_STATE_IDENTIFYING:
+ recreate_pipeline (trans);
+
priv->is_audio = FALSE;
- DBG ("Trying to lock mutex (error)");
- for (i=0; i<SIGNAL_SEND_ITERATIONS; i++) {
- if (g_mutex_trylock (priv->gst_mutex))
- break;
- g_usleep (SIGNAL_SEND_TIMEOUT_MICROS / SIGNAL_SEND_ITERATIONS);
- if (i==9) {
- recreate_pipeline (trans);
- g_warning ("Noone was there to listen to the gstreamer error: %s", error->message);
- }
- }
- g_cond_signal (priv->gst_cond);
- g_mutex_unlock (priv->gst_mutex);
- DBG ("Releasing mutex (error)");
- recreate_pipeline (trans);
+ signal_identification_done (trans, "error");
break;
+
case XFBURN_TRANSCODER_GST_STATE_TRANSCODE_START:
case XFBURN_TRANSCODER_GST_STATE_TRANSCODING:
g_error ("Gstreamer error while transcoding!");
@@ -443,79 +478,95 @@
}
break;
}
+ case GST_MESSAGE_APPLICATION: {
+ if (gst_element_set_state (priv->pipeline, GST_STATE_NULL) == GST_STATE_CHANGE_FAILURE) {
+ DBG ("Failed to reset GST state.");
+ recreate_pipeline (trans);
+ }
+ signal_identification_done (trans, "no audio");
+
+ break;
+ }
case GST_MESSAGE_STATE_CHANGED: {
- GstState state;
- GstState pending, old_state;
+ GstState state, pending, old_state;
- //if (GST_MESSAGE_SRC (msg) == GST_OBJECT (priv->sink))
- //DBG ("RIGHT SOURCE");
- //DBG ("source is %p", GST_MESSAGE_SRC (msg));
+ gst_message_parse_state_changed (msg, &old_state, &state, &pending);
- gst_message_parse_state_changed (msg, &old_state, &state, &pending);
+/* this is very verbose */
+#if DEBUG_GST > 1
if (pending != 0)
- DBG ("New state is %s, old is %s and pending is %s", state_to_str(state), state_to_str(old_state), state_to_str(pending));
+ DBG ("%-15s\tNew state is %s, old is %s and pending is %s", GST_OBJECT_NAME (GST_MESSAGE_SRC (msg)), state_to_str(state), state_to_str(old_state), state_to_str(pending));
else
- DBG ("New state is %s, old is %s", state_to_str(state), state_to_str(old_state));
+ DBG ("%-15s\tNew state is %s, old is %s", GST_OBJECT_NAME (GST_MESSAGE_SRC (msg)), state_to_str(state), state_to_str(old_state));
+#endif
switch (priv->state) {
case XFBURN_TRANSCODER_GST_STATE_IDLE:
case XFBURN_TRANSCODER_GST_STATE_TRANSCODING:
- DBG ("Not identifying, ignoring state change");
+ case XFBURN_TRANSCODER_GST_STATE_IDENTIFYING:
break;
- case XFBURN_TRANSCODER_GST_STATE_IDENTIFYING:
- if (state != GST_STATE_PAUSED)
+ case XFBURN_TRANSCODER_GST_STATE_TRANSCODE_START:
+ if (state != GST_STATE_PLAYING)
break;
+
+ if (strcmp (GST_OBJECT_NAME (GST_MESSAGE_SRC (msg)), "decoder") != 0)
+ break;
if (!g_mutex_trylock (priv->gst_mutex)) {
- DBG ("Lock held by another thread, not doing anything");
- return TRUE;
+ g_warning ("Lock held by another thread, can't signal transcoding start!");
+ break;
} else {
- DBG ("Locked mutex");
+#if DEBUG_GST > 0
+ DBG ("Locked mutex to signal transcoding start");
+#endif
}
+ g_cond_signal (priv->gst_cond);
+ g_mutex_unlock (priv->gst_mutex);
+ break;
+ } /* switch of priv->state */
+
+ break;
+ }
+ case GST_MESSAGE_DURATION: {
+ GstFormat fmt;
+ guint secs;
+
+ switch (priv->state) {
+ case XFBURN_TRANSCODER_GST_STATE_IDLE:
+ case XFBURN_TRANSCODER_GST_STATE_TRANSCODING:
+ case XFBURN_TRANSCODER_GST_STATE_TRANSCODE_START:
+ break;
+
+ case XFBURN_TRANSCODER_GST_STATE_IDENTIFYING:
fmt = GST_FORMAT_TIME;
if (!gst_element_query_duration (priv->pipeline, &fmt, &priv->duration)) {
- g_mutex_unlock (priv->gst_mutex);
+#if DEBUG_GST > 0
DBG ("Could not query stream length!");
+#endif
return TRUE;
}
secs = priv->duration / 1000000000;
- //DBG ("Length is %lldns = %ds = %lld bytes\n", priv->duration, secs, priv->duration * 176400 /1000000000);
- if (gst_element_set_state (priv->pipeline, GST_STATE_READY) == GST_STATE_CHANGE_FAILURE) {
+ if (gst_element_set_state (priv->pipeline, GST_STATE_NULL) == GST_STATE_CHANGE_FAILURE) {
DBG ("Failed to set state!");
+ recreate_pipeline (trans);
}
priv->is_audio = TRUE;
- g_cond_signal (priv->gst_cond);
- g_mutex_unlock (priv->gst_mutex);
- DBG ("Releasing mutex (success)");
priv->state = XFBURN_TRANSCODER_GST_STATE_IDLE;
- case XFBURN_TRANSCODER_GST_STATE_TRANSCODE_START:
- if (state != GST_STATE_PLAYING)
- break;
-
- if (strcmp (GST_OBJECT_NAME (GST_MESSAGE_SRC (msg)), "decoder") != 0)
- break;
-
- if (!g_mutex_trylock (priv->gst_mutex)) {
- DBG ("Lock held by another thread, can't signal transcoding start!");
- break;
- } else {
- DBG ("Locked mutex");
- }
-
- g_cond_signal (priv->gst_cond);
- g_mutex_unlock (priv->gst_mutex);
+ signal_identification_done (trans, "is audio");
break;
- }
+ } /* switch of priv->state */
break;
}
default:
+#if DEBUG_GST > 0
DBG ("bus call: %s (%d) ", GST_MESSAGE_TYPE_NAME (msg), GST_MESSAGE_TYPE (msg));
+#endif
break;
}
@@ -525,10 +576,13 @@
static void
on_pad_added (GstElement *element, GstPad *pad, gboolean last, gpointer data)
{
+ XfburnTranscoderGst *trans = XFBURN_TRANSCODER_GST (data);
+ XfburnTranscoderGstPrivate *priv= XFBURN_TRANSCODER_GST_GET_PRIVATE (trans);
+
GstCaps *caps;
GstStructure *str;
GstPad *audiopad;
- GstElement *audio = (GstElement *) data;
+ GstElement *audio = (GstElement *) priv->conv;
// only link once
audiopad = gst_element_get_static_pad (audio, "sink");
@@ -538,16 +592,36 @@
return;
}
+#if DEBUG_GST > 0
DBG ("linking pads");
+#endif
// check media type
caps = gst_pad_get_caps (pad);
str = gst_caps_get_structure (caps, 0);
if (!g_strrstr (gst_structure_get_name (str), "audio")) {
- DBG ("not audio!");
- /* FIXME: report this as an error? */
+ GstStructure *msg_struct;
+ GstMessage *msg;
+ GstBus *bus;
+
+ DBG ("File content has a decoder but is not audio");
+
gst_caps_unref (caps);
gst_object_unref (audiopad);
+
+ priv->is_audio = FALSE;
+
+ msg_struct = gst_structure_new ("no-audio-content", NULL);
+
+ msg = gst_message_new_application (GST_OBJECT (element), msg_struct);
+
+ bus = gst_element_get_bus (element);
+ if (!gst_bus_post (bus, msg)) {
+ DBG ("Could not post the message on the gst bus!");
+ g_object_unref (msg);
+ }
+ g_object_unref (bus);
+
return;
}
gst_caps_unref (caps);
@@ -590,7 +664,9 @@
off_t size;
priv->is_audio = FALSE;
- DBG ("setting filename for gstreamer");
+#if DEBUG_GST > 0
+ DBG ("Querying GST about %s", fn);
+#endif
priv->state = XFBURN_TRANSCODER_GST_STATE_IDENTIFYING;
g_object_set (G_OBJECT (priv->source), "location", fn, NULL);
@@ -602,20 +678,25 @@
return NULL;
*/
}
- DBG ("Waiting for signal");
g_get_current_time (&tv);
g_time_val_add (&tv, SIGNAL_WAIT_TIMEOUT_MICROS);
+#if DEBUG_GST > 0
+ DBG ("Now waiting for identification result");
+#endif
if (!g_cond_timed_wait (priv->gst_cond, priv->gst_mutex, &tv)) {
+ DBG ("gst identification timed out");
recreate_pipeline (tgst);
g_set_error (error, XFBURN_ERROR, XFBURN_ERROR_GST_TIMEOUT,
_("Gstreamer did not like this file (detection timed out)"));
return NULL;
}
- DBG ("Got a signal");
+#if DEBUG_GST > 0
+ DBG ("Got an identification result ");
+#endif
if (!priv->is_audio) {
g_set_error (error, XFBURN_ERROR, XFBURN_ERROR_NOT_AUDIO_FORMAT,
- _("This is not an audio file"));
+ _("%s is not an audio file"), fn);
return NULL;
}
@@ -629,7 +710,7 @@
atrack->sectors = size / AUDIO_BYTES_PER_SECTOR;
if (size % AUDIO_BYTES_PER_SECTOR > 0)
atrack->sectors++;
- DBG ("Track length = %d secs => size = %.0f bytes => %d sectors", atrack->length, (float) size, atrack->sectors);
+ DBG ("Track length = %4d secs => size = %9.0f bytes => %5d sectors", atrack->length, (float) size, atrack->sectors);
gtrack = g_new0 (XfburnAudioTrackGst, 1);
atrack->data = (gpointer) gtrack;
@@ -660,7 +741,7 @@
atrack->fd = pipe_fd[0];
- DBG ("track %d fd = %d", atrack->pos, atrack->fd);
+ //DBG ("track %d fd = %d", atrack->pos, atrack->fd);
atrack->src = burn_fd_source_new (atrack->fd, -1 , gtrack->size);
if (atrack->src == NULL) {
@@ -721,7 +802,7 @@
priv->state = XFBURN_TRANSCODER_GST_STATE_TRANSCODE_START;
ret = transcode_next_track (gst, error);
- DBG ("Waiting for start signal");
+ //DBG ("Waiting for start signal");
g_get_current_time (&tv);
g_time_val_add (&tv, SIGNAL_WAIT_TIMEOUT_MICROS);
if (!g_cond_timed_wait (priv->gst_cond, priv->gst_mutex, &tv)) {
@@ -730,15 +811,10 @@
_("Gstreamer did not want to start transcoding (timed out)"));
return FALSE;
}
- DBG ("Got the start signal");
+ //DBG ("Got the start signal");
priv->state = XFBURN_TRANSCODER_GST_STATE_TRANSCODING;
- /* give gstreamer a tiny bit of time.
- * FIXME: what's a good time here?
- * or rather, we should wait for the state change... */
- g_usleep (100000);
-
return ret;
}
@@ -760,7 +836,9 @@
g_object_set (G_OBJECT (priv->source), "location", atrack->inputfile, NULL);
g_object_set (G_OBJECT (priv->sink), "fd", gtrack->fd_in, NULL);
+#if DEBUG_GST > 0
DBG ("now transcoding %s -> %d", atrack->inputfile, gtrack->fd_in);
+#endif
if (gst_element_set_state (priv->pipeline, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
g_set_error (error, XFBURN_ERROR, XFBURN_ERROR_GST_STATE,
@@ -784,7 +862,9 @@
GstClock *clock;
GstClockTime tv;
+#if DEBUG_GST > 0
DBG ("Done transcoding");
+#endif
priv->state = XFBURN_TRANSCODER_GST_STATE_IDLE;
priv->curr_track = NULL;
@@ -801,7 +881,7 @@
}
if ((state != GST_STATE_READY) &&
- (gst_element_set_state (priv->pipeline, GST_STATE_READY) == GST_STATE_CHANGE_FAILURE)) {
+ (gst_element_set_state (priv->pipeline, GST_STATE_NULL) == GST_STATE_CHANGE_FAILURE)) {
DBG ("Could not make pipeline ready, recreating it");
recreate_pipeline (gst);
}
More information about the Goodies-commits
mailing list