[gst-devel] Problem with ogg encoder
José Sánchez Moreno
jose at oxigenow.com
Sat Dec 20 02:16:02 CET 2003
Hi, i am doing a whatever to ogg encoder..
But i have a problem that i don't know how to solve.
When i delete the vorbisenc and sink is esdsink, play all files without
crashing, but when i put that elements i receive a segment violation
error...
Thanks in advance..
Sorry for my english..
Here is the code
-- CALLBACKS.C
#include <gst/gst.h>
// Timeout para actualizar el progress
guint timeout_id;
gboolean encoding = FALSE;
GtkTreeView *treeFileSel;
GtkWidget *progressBar;
GtkWidget *progressDialog;
gboolean
update_gui_info(gpointer data)
{
gint pos,len;
if(encoding == FALSE) return FALSE;
// Si ha terminado la cancion terminar el timeout
if(encoder_get_state(encoder) != ENCODER_PLAY) return FALSE;
pos = encoder_tell(encoder);
len = encoder_length(encoder);
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progressBar),
(double)pos / (double)len);
return TRUE;
}
static void
eos(GstElement *a, gpointer data)
{
encoding = FALSE;
//encoder_set_state(encoder, ENCODER_STOP);
//if(encoder_get_state(encoder) == ENCODER_PLAY)
encoder_set_state(encoder, ENCODER_PAUSE);
tree_remove(treeFileSel, 0);
//encoder_set_state(data, ENCODER_STOP);
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progressBar), 0);
on_button_progress_cancel_clicked(NULL, NULL);
on_button_accept_clicked(NULL, NULL);
}
void
on_button_progress_cancel_clicked(GtkWidget * widget, gpointer data)
{
encoding = FALSE;
// if(timeout_id) gtk_timeout_remove(timeout_id);
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progressBar), 0);
gtk_widget_hide(progressDialog);
if(encoder_get_state(encoder) != ENCODER_PLAY) return;
encoder_set_state(encoder, ENCODER_PAUSE);
}
static void on_button_accept_clicked(GtkWidget * widget, gpointer data)
{
gchar *file;
gchar * ogg;
//if(encoder) encoder_unref(encoder);
if(file = tree_get_file(treeFileSel))
{
gtk_widget_show(progressDialog);
encoding = TRUE;
ogg = g_strdup_printf("%s.ogg", file);
encoder_encode(encoder, file, ogg);
g_idle_add ((GSourceFunc)gst_bin_iterate, encoder->pipeline);
timeout_id = gtk_timeout_add(200, update_gui_info, NULL);
}
g_free(file);
g_free(ogg);
}
-- ENCODER.C
Encoder * encoder_new(void)
{
Encoder *tmp;
tmp = (Encoder *) g_malloc(sizeof(Encoder));
//tmp = g_new(Encoder, 1);
tmp->pipeline = gst_pipeline_new("pipeline");
tmp->filesrc = gst_element_factory_make ("gnomevfssrc", "src");
tmp->decoder = gst_element_factory_make ("spider", "decoder");
tmp->encoder = gst_element_factory_make("vorbisenc", "encoder");
tmp->fileout = gst_element_factory_make("gnomevfssink", "sink");
gst_bin_add(GST_BIN (tmp->pipeline), tmp->filesrc);
gst_bin_add(GST_BIN (tmp->pipeline), tmp->decoder);
gst_bin_add(GST_BIN (tmp->pipeline), tmp->encoder);
gst_bin_add(GST_BIN (tmp->pipeline), tmp->fileout);
gst_element_link_many(tmp->filesrc, tmp->decoder, tmp->encoder,
tmp->fileout, NULL);
return tmp;
}
void
encoder_encode(Encoder *p, gchar *filein, gchar *fileout)
{
encoder_set_state(p, ENCODER_STOP);
gst_element_unlink(p->filesrc, p->decoder);
gst_element_unlink(p->decoder, p->encoder);
//gst_element_unlink(p->encoder, p->fileout);
gst_bin_remove(GST_BIN(p->pipeline), p->decoder);
//gst_bin_remove( GST_BIN(p->pipeline), p->fileout);
p->decoder= gst_element_factory_make ("spider", "decoder");
//p->fileout= gst_element_factory_make ("gnomevfssink", "sink");
g_object_set(G_OBJECT(p->filesrc), "location", filein, NULL);
g_object_set(G_OBJECT(p->fileout), "location", fileout, NULL);
gst_bin_add( GST_BIN(p->pipeline), p->decoder);
//gst_bin_add( GST_BIN(p->pipeline), p->fileout);
gst_element_link(p->filesrc, p->decoder);
gst_element_link(p->decoder, p->encoder);
//gst_element_link(p->encoder, p->fileout);
g_print("PLAY\n");
encoder_set_state(p, ENCODER_PLAY);
}
EncoderState encoder_get_state(Encoder *p)
{
return gst_element_get_state(p->pipeline);
}
....
--
More information about the gstreamer-devel
mailing list