From e8ea96d23b7c87c9fbdb381ad85282e52593db53 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 1 Nov 2000 22:11:48 +0000 Subject: [PATCH] Some code cleanup Original commit message from CVS: Some code cleanup Let the parent GstBin decide when to do a create_plan (bin inside a thread) --- examples/helloworld2/helloworld2.c | 25 ++++++++++---------- gst/cothreads.c | 8 +++---- gst/cothreads.h | 2 +- gst/elements/Makefile.am | 2 +- gst/elements/gstqueue.c | 14 +++++------ gst/gstbin.c | 15 +++++++++++- gst/gstthread.c | 8 ++++--- gstplay/gststatusarea.c | 1 + plugins/elements/Makefile.am | 2 +- plugins/elements/gstqueue.c | 14 +++++------ tests/old/examples/helloworld2/helloworld2.c | 25 ++++++++++---------- 11 files changed, 65 insertions(+), 51 deletions(-) diff --git a/examples/helloworld2/helloworld2.c b/examples/helloworld2/helloworld2.c index fab7b49138..376f700b2c 100644 --- a/examples/helloworld2/helloworld2.c +++ b/examples/helloworld2/helloworld2.c @@ -1,19 +1,17 @@ #include -static gboolean playing; - /* eos will be called when the src element has an end of stream */ void eos(GstSrc *src) { g_print("have eos, quitting\n"); - playing = FALSE; + gst_main_quit(); } int main(int argc,char *argv[]) { GstElement *disksrc, *audiosink; - GstElement *pipeline; + GstElement *pipeline, *thread; if (argc != 2) { g_print("usage: %s \n", argv[0]); @@ -22,10 +20,15 @@ int main(int argc,char *argv[]) gst_init(&argc,&argv); + thread = gst_thread_new("main_thread"); + g_assert(thread != NULL); + /* create a new bin to hold the elements */ pipeline = gst_pipeline_new("pipeline"); g_assert(pipeline != NULL); + gst_bin_add(GST_BIN(thread), pipeline); + /* create a disk reader */ disksrc = gst_elementfactory_make("disksrc", "disk_source"); g_assert(disksrc != NULL); @@ -47,20 +50,16 @@ int main(int argc,char *argv[]) } /* make it ready */ - gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_READY); + gst_element_set_state(GST_ELEMENT(thread), GST_STATE_READY); /* start playing */ - gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_PLAYING); + gst_element_set_state(GST_ELEMENT(thread), GST_STATE_PLAYING); - playing = TRUE; - - while (playing) { - gst_bin_iterate(GST_BIN(pipeline)); - } + gst_main(); /* stop the bin */ - gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_NULL); + gst_element_set_state(GST_ELEMENT(thread), GST_STATE_NULL); - gst_pipeline_destroy(pipeline); + gst_pipeline_destroy(thread); exit(0); } diff --git a/gst/cothreads.c b/gst/cothreads.c index dea05945c8..e684c9b990 100644 --- a/gst/cothreads.c +++ b/gst/cothreads.c @@ -19,8 +19,8 @@ cothread_state *cothread_create(cothread_context *ctx) { cothread_state *s; DEBUG("cothread: pthread_self() %ld\n",pthread_self()); - if (0) { - //if (pthread_self() == 0) { + //if (0) { + if (pthread_self() == 0) { s = (cothread_state *)malloc(sizeof(int) * COTHREAD_STACKSIZE); DEBUG("cothread: new stack at %p\n",s); } else { @@ -139,7 +139,7 @@ void cothread_switch(cothread_state *thread) { /* save the current stack pointer, frame pointer, and pc */ GET_SP(current->sp); - enter = sigsetjmp(current->jmp, 1); + enter = setjmp(current->jmp); if (enter != 0) { DEBUG("cothread: enter thread #%d %d %p<->%p (%d)\n",current->threadnum, enter, current->sp, current->top_sp, current->top_sp-current->sp); @@ -155,7 +155,7 @@ void cothread_switch(cothread_state *thread) { DEBUG("cothread: in thread \n"); SET_SP(thread->sp); // switch to it - siglongjmp(thread->jmp,1); + longjmp(thread->jmp,1); } else { SETUP_STACK(thread->sp); SET_SP(thread->sp); diff --git a/gst/cothreads.h b/gst/cothreads.h index 3a40dd6e6a..b8edb4f3f4 100644 --- a/gst/cothreads.h +++ b/gst/cothreads.h @@ -31,7 +31,7 @@ struct _cothread_state { int *sp; int *top_sp; int *pc; - sigjmp_buf jmp; + jmp_buf jmp; }; struct _cothread_context { diff --git a/gst/elements/Makefile.am b/gst/elements/Makefile.am index bf57b271ca..5c6a39c37b 100644 --- a/gst/elements/Makefile.am +++ b/gst/elements/Makefile.am @@ -42,7 +42,7 @@ noinst_HEADERS = \ gsttypefind.h \ gstsinesrc.h -CFLAGS += -O2 -Wall +CFLAGS += -g -O2 -Wall libgstelements_la_LIBADD = $(GLIB_LIBS) $(GTK_LIBS) $(GHTTP_LIBS) libgstelements_la_LDFLAGS = -version-info $(STREAMER_CURRENT):$(STREAMER_REVISION):$(STREAMER_AGE) diff --git a/gst/elements/gstqueue.c b/gst/elements/gstqueue.c index 0b635c6a18..4486c9e3ec 100644 --- a/gst/elements/gstqueue.c +++ b/gst/elements/gstqueue.c @@ -167,8 +167,8 @@ static void gst_queue_chain(GstPad *pad,GstBuffer *buf) { /* we have to lock the queue since we span threads */ DEBUG("queue: try have queue lock\n"); - DEBUG("queue: %s adding buffer %p %ld\n", name, buf, pthread_self()); GST_LOCK(queue); + DEBUG("queue: %s adding buffer %p %ld\n", name, buf, pthread_self()); DEBUG("queue: have queue lock\n"); if (GST_BUFFER_FLAG_IS_SET(buf, GST_BUFFER_FLUSH)) { @@ -202,11 +202,11 @@ static void gst_queue_chain(GstPad *pad,GstBuffer *buf) { GST_UNLOCK(queue); if (tosignal) { - STATUS("%s: >\n"); g_mutex_lock(queue->emptylock); + STATUS("%s: >\n"); g_cond_signal(queue->emptycond); - g_mutex_unlock(queue->emptylock); STATUS("%s: >>\n"); + g_mutex_unlock(queue->emptylock); } } @@ -220,19 +220,19 @@ static void gst_queue_push(GstConnection *connection) { name = gst_element_get_name(GST_ELEMENT(queue)); /* have to lock for thread-safety */ - DEBUG("queue: try have queue lock\n"); + DEBUG("queue: %s try have queue lock\n", name); GST_LOCK(queue); DEBUG("queue: %s push %d %ld %p\n", name, queue->level_buffers, pthread_self(), queue->emptycond); - DEBUG("queue: have queue lock\n"); + DEBUG("queue: %s have queue lock\n", name); while (!queue->level_buffers) { - STATUS("%s: U released lock\n"); + STATUS("queue: %s U released lock\n"); GST_UNLOCK(queue); g_mutex_lock(queue->emptylock); g_cond_wait(queue->emptycond,queue->emptylock); g_mutex_unlock(queue->emptylock); GST_LOCK(queue); - STATUS("%s: U- getting lock\n"); + STATUS("queue: %s U- getting lock\n"); } front = queue->queue; diff --git a/gst/gstbin.c b/gst/gstbin.c index cd537eecf6..7fea389909 100644 --- a/gst/gstbin.c +++ b/gst/gstbin.c @@ -206,7 +206,12 @@ static GstElementStateReturn gst_bin_change_state(GstElement *element) { _gst_print_statename(GST_STATE_PENDING(element))); if (GST_STATE_PENDING(element) == GST_STATE_READY) { - gst_bin_create_plan(bin); + GstObject *parent; + + parent = gst_object_get_parent(GST_OBJECT(element)); + + if (!parent || !GST_IS_BIN(parent)) + gst_bin_create_plan(bin); } // g_return_val_if_fail(bin->numchildren != 0, GST_STATE_FAILURE); @@ -491,6 +496,7 @@ static int gst_bin_loopfunc_wrapper(int argc,char *argv[]) { buf = gst_pad_pull(pad); DEBUG("** gst_bin_loopfunc_wrapper(): calling chain function of %s:%s\n", name, gst_pad_get_name(pad)); (pad->chainfunc)(pad,buf); + DEBUG("** gst_bin_loopfunc_wrapper(): calling chain function of %s:%s done\n", name, gst_pad_get_name(pad)); } pads = g_list_next(pads); } @@ -589,6 +595,10 @@ static void gst_bin_create_plan_func(GstBin *bin) { cothread_setfunc(element->threadstate,gst_bin_loopfunc_wrapper, 0,(char **)element); } + if (GST_IS_BIN(element)) { + gst_bin_create_plan( GST_BIN (element)); + } + if (GST_IS_SRC(element)) { g_print("gstbin: adding '%s' as entry point\n",gst_element_get_name(element)); bin->entries = g_list_prepend(bin->entries,element); @@ -655,6 +665,9 @@ static void gst_bin_create_plan_func(GstBin *bin) { while (elements) { element = GST_ELEMENT(elements->data); g_print("gstbin: found element \"%s\"\n", gst_element_get_name(element)); + if (GST_IS_BIN(element)) { + gst_bin_create_plan( GST_BIN (element)); + } if (GST_IS_SRC(element)) { g_print("gstbin: adding '%s' as entry point\n",gst_element_get_name(element)); bin->entries = g_list_prepend(bin->entries,element); diff --git a/gst/gstthread.c b/gst/gstthread.c index ae2ab38cca..492e49ce67 100644 --- a/gst/gstthread.c +++ b/gst/gstthread.c @@ -178,7 +178,7 @@ GstElement *gst_thread_new(guchar *name) { static GstElementStateReturn gst_thread_change_state(GstElement *element) { GstThread *thread; - gboolean stateset = TRUE; + gboolean stateset = GST_STATE_SUCCESS; gint pending; g_return_val_if_fail(GST_IS_THREAD(element), FALSE); @@ -218,7 +218,7 @@ static GstElementStateReturn gst_thread_change_state(GstElement *element) { gst_info("gstthread: NOT starting thread \"%s\"\n", gst_element_get_name(GST_ELEMENT(element))); } - return GST_STATE_SUCCESS; + return GST_STATE_ASYNC; break; case GST_STATE_PLAYING: if (!stateset) return FALSE; @@ -253,7 +253,9 @@ static GstElementStateReturn gst_thread_change_state(GstElement *element) { * The main loop of the thread. The thread will iterate * while the state is GST_THREAD_STATE_SPINNING */ -static void *gst_thread_main_loop(void *arg) { +static void * +gst_thread_main_loop (void *arg) +{ GstThread *thread = GST_THREAD(arg); gst_info("gstthread: thread \"%s\" is running with PID %d\n", diff --git a/gstplay/gststatusarea.c b/gstplay/gststatusarea.c index bab25810e0..7cd1b39175 100644 --- a/gstplay/gststatusarea.c +++ b/gstplay/gststatusarea.c @@ -167,6 +167,7 @@ gst_status_area_expose(GtkWidget *widget, widget->allocation.width-width-20, 15, status_area->playtime); } } + return FALSE; } diff --git a/plugins/elements/Makefile.am b/plugins/elements/Makefile.am index bf57b271ca..5c6a39c37b 100644 --- a/plugins/elements/Makefile.am +++ b/plugins/elements/Makefile.am @@ -42,7 +42,7 @@ noinst_HEADERS = \ gsttypefind.h \ gstsinesrc.h -CFLAGS += -O2 -Wall +CFLAGS += -g -O2 -Wall libgstelements_la_LIBADD = $(GLIB_LIBS) $(GTK_LIBS) $(GHTTP_LIBS) libgstelements_la_LDFLAGS = -version-info $(STREAMER_CURRENT):$(STREAMER_REVISION):$(STREAMER_AGE) diff --git a/plugins/elements/gstqueue.c b/plugins/elements/gstqueue.c index 0b635c6a18..4486c9e3ec 100644 --- a/plugins/elements/gstqueue.c +++ b/plugins/elements/gstqueue.c @@ -167,8 +167,8 @@ static void gst_queue_chain(GstPad *pad,GstBuffer *buf) { /* we have to lock the queue since we span threads */ DEBUG("queue: try have queue lock\n"); - DEBUG("queue: %s adding buffer %p %ld\n", name, buf, pthread_self()); GST_LOCK(queue); + DEBUG("queue: %s adding buffer %p %ld\n", name, buf, pthread_self()); DEBUG("queue: have queue lock\n"); if (GST_BUFFER_FLAG_IS_SET(buf, GST_BUFFER_FLUSH)) { @@ -202,11 +202,11 @@ static void gst_queue_chain(GstPad *pad,GstBuffer *buf) { GST_UNLOCK(queue); if (tosignal) { - STATUS("%s: >\n"); g_mutex_lock(queue->emptylock); + STATUS("%s: >\n"); g_cond_signal(queue->emptycond); - g_mutex_unlock(queue->emptylock); STATUS("%s: >>\n"); + g_mutex_unlock(queue->emptylock); } } @@ -220,19 +220,19 @@ static void gst_queue_push(GstConnection *connection) { name = gst_element_get_name(GST_ELEMENT(queue)); /* have to lock for thread-safety */ - DEBUG("queue: try have queue lock\n"); + DEBUG("queue: %s try have queue lock\n", name); GST_LOCK(queue); DEBUG("queue: %s push %d %ld %p\n", name, queue->level_buffers, pthread_self(), queue->emptycond); - DEBUG("queue: have queue lock\n"); + DEBUG("queue: %s have queue lock\n", name); while (!queue->level_buffers) { - STATUS("%s: U released lock\n"); + STATUS("queue: %s U released lock\n"); GST_UNLOCK(queue); g_mutex_lock(queue->emptylock); g_cond_wait(queue->emptycond,queue->emptylock); g_mutex_unlock(queue->emptylock); GST_LOCK(queue); - STATUS("%s: U- getting lock\n"); + STATUS("queue: %s U- getting lock\n"); } front = queue->queue; diff --git a/tests/old/examples/helloworld2/helloworld2.c b/tests/old/examples/helloworld2/helloworld2.c index fab7b49138..376f700b2c 100644 --- a/tests/old/examples/helloworld2/helloworld2.c +++ b/tests/old/examples/helloworld2/helloworld2.c @@ -1,19 +1,17 @@ #include -static gboolean playing; - /* eos will be called when the src element has an end of stream */ void eos(GstSrc *src) { g_print("have eos, quitting\n"); - playing = FALSE; + gst_main_quit(); } int main(int argc,char *argv[]) { GstElement *disksrc, *audiosink; - GstElement *pipeline; + GstElement *pipeline, *thread; if (argc != 2) { g_print("usage: %s \n", argv[0]); @@ -22,10 +20,15 @@ int main(int argc,char *argv[]) gst_init(&argc,&argv); + thread = gst_thread_new("main_thread"); + g_assert(thread != NULL); + /* create a new bin to hold the elements */ pipeline = gst_pipeline_new("pipeline"); g_assert(pipeline != NULL); + gst_bin_add(GST_BIN(thread), pipeline); + /* create a disk reader */ disksrc = gst_elementfactory_make("disksrc", "disk_source"); g_assert(disksrc != NULL); @@ -47,20 +50,16 @@ int main(int argc,char *argv[]) } /* make it ready */ - gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_READY); + gst_element_set_state(GST_ELEMENT(thread), GST_STATE_READY); /* start playing */ - gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_PLAYING); + gst_element_set_state(GST_ELEMENT(thread), GST_STATE_PLAYING); - playing = TRUE; - - while (playing) { - gst_bin_iterate(GST_BIN(pipeline)); - } + gst_main(); /* stop the bin */ - gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_NULL); + gst_element_set_state(GST_ELEMENT(thread), GST_STATE_NULL); - gst_pipeline_destroy(pipeline); + gst_pipeline_destroy(thread); exit(0); }