#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]);
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);
}
/* 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);
}
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 {
/* 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);
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);
int *sp;
int *top_sp;
int *pc;
- sigjmp_buf jmp;
+ jmp_buf jmp;
};
struct _cothread_context {
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)
/* 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)) {
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);
}
}
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;
_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);
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);
}
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);
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);
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);
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;
* 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",
widget->allocation.width-width-20, 15, status_area->playtime);
}
}
+
return FALSE;
}
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)
/* 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)) {
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);
}
}
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;
#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]);
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);
}
/* 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);
}