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)
This commit is contained in:
Wim Taymans 2000-11-01 22:11:48 +00:00
parent 9500bd2128
commit e8ea96d23b
11 changed files with 65 additions and 51 deletions

View file

@ -1,19 +1,17 @@
#include <gst/gst.h>
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 <filename>\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);
}

View file

@ -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);

View file

@ -31,7 +31,7 @@ struct _cothread_state {
int *sp;
int *top_sp;
int *pc;
sigjmp_buf jmp;
jmp_buf jmp;
};
struct _cothread_context {

View file

@ -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)

View file

@ -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;

View file

@ -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);

View file

@ -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",

View file

@ -167,6 +167,7 @@ gst_status_area_expose(GtkWidget *widget,
widget->allocation.width-width-20, 15, status_area->playtime);
}
}
return FALSE;
}

View file

@ -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)

View file

@ -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;

View file

@ -1,19 +1,17 @@
#include <gst/gst.h>
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 <filename>\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);
}