diff --git a/gb.media/src/c_media.c b/gb.media/src/c_media.c index 86a9c594b..b2f833523 100644 --- a/gb.media/src/c_media.c +++ b/gb.media/src/c_media.c @@ -40,6 +40,8 @@ static void *_from_element = NULL; +static int cb_message(CMEDIAPIPELINE *_object); + void MEDIA_raise_event(void *_object, int event) { gst_element_post_message(ELEMENT, gst_message_new_application(GST_OBJECT(ELEMENT), gst_structure_new("SendEvent", "event", G_TYPE_INT, event, NULL))); @@ -99,11 +101,13 @@ CMEDIACONTROL *MEDIA_get_control_from_element(void *element, bool create) return ctrl; } -bool MEDIA_set_state(void *_object, int state, bool error) +bool MEDIA_set_state(void *_object, int state, bool error, bool async) { GstStateChangeReturn status; status = gst_element_set_state(ELEMENT, state); + if (async) + return FALSE; if (status == GST_STATE_CHANGE_ASYNC) status = gst_element_get_state(ELEMENT, NULL, NULL, GST_SECOND); @@ -114,6 +118,7 @@ bool MEDIA_set_state(void *_object, int state, bool error) return TRUE; } + cb_message(THIS_PIPELINE); return FALSE; } @@ -157,7 +162,8 @@ static GB_TYPE to_gambas_type(const GValue *value) return GB_T_DATE; else { - fprintf(stderr, "gb.media: warning: unsupported data type: %s\n", G_VALUE_TYPE_NAME(value)); + if (MAIN_debug) + fprintf(stderr, "gb.media: warning: unsupported data type: %s\n", G_VALUE_TYPE_NAME(value)); //GB.Error("Unsupported property datatype"); return GB_T_NULL; } @@ -373,7 +379,8 @@ static void return_value(const GValue *value) #endif else { - fprintf(stderr, "gb.media: warning: unsupported datatype: %s\n", G_VALUE_TYPE_NAME(value)); + if (MAIN_debug) + fprintf(stderr, "gb.media: warning: unsupported datatype: %s\n", G_VALUE_TYPE_NAME(value)); GB.ReturnNull(); } } @@ -1199,7 +1206,7 @@ BEGIN_PROPERTY(MediaControl_State) } else { - MEDIA_set_state(THIS, VPROP(GB_INTEGER), TRUE); + MEDIA_set_state(THIS, VPROP(GB_INTEGER), TRUE, FALSE); } END_PROPERTY @@ -1818,7 +1825,8 @@ void MEDIA_stop_pipeline(CMEDIACONTROL *_object) try++; if (try > 25) { - fprintf(stderr, "gb.media: warning: could not catch end of stream\n"); + if (MAIN_debug) + fprintf(stderr, "gb.media: warning: could not catch end of stream\n"); break; } cb_message(THIS_PIPELINE); @@ -1826,8 +1834,7 @@ void MEDIA_stop_pipeline(CMEDIACONTROL *_object) } } - MEDIA_set_state(THIS, GST_STATE_READY, TRUE); - cb_message(THIS_PIPELINE); + MEDIA_set_state(THIS, GST_STATE_READY, TRUE, FALSE); } @@ -1863,11 +1870,10 @@ BEGIN_METHOD_VOID(MediaPipeline_free) END_METHOD -BEGIN_METHOD_VOID(MediaPipeline_Play) +BEGIN_METHOD(MediaPipeline_Play, GB_BOOLEAN async) THIS->eos = FALSE; - MEDIA_set_state(THIS, GST_STATE_PLAYING, TRUE); - cb_message(THIS_PIPELINE); + MEDIA_set_state(THIS, GST_STATE_PLAYING, TRUE, VARGOPT(async, FALSE)); set_pipeline_rate(THIS); END_METHOD @@ -1880,8 +1886,7 @@ END_METHOD BEGIN_METHOD_VOID(MediaPipeline_Close) - MEDIA_set_state(THIS, GST_STATE_NULL, TRUE); - cb_message(THIS_PIPELINE); + MEDIA_set_state(THIS, GST_STATE_NULL, TRUE, FALSE); END_METHOD @@ -1890,8 +1895,7 @@ BEGIN_METHOD_VOID(MediaPipeline_Pause) if (THIS->state != GST_STATE_PLAYING) return; - MEDIA_set_state(THIS, GST_STATE_PAUSED, TRUE); - cb_message(THIS_PIPELINE); + MEDIA_set_state(THIS, GST_STATE_PAUSED, TRUE, FALSE); END_METHOD @@ -2180,7 +2184,7 @@ GB_DESC MediaPipelineDesc[] = GB_PROPERTY("Pos", "f", MediaPipeline_Position), GB_PROPERTY_READ("Length", "f", MediaPipeline_Duration), - GB_METHOD("Play", NULL, MediaPipeline_Play, NULL), + GB_METHOD("Play", NULL, MediaPipeline_Play, "[(Async)b]"), GB_METHOD("Stop", NULL, MediaPipeline_Stop, NULL), GB_METHOD("Pause", NULL, MediaPipeline_Pause, NULL), GB_METHOD("Close", NULL, MediaPipeline_Close, NULL), diff --git a/gb.media/src/c_media.h b/gb.media/src/c_media.h index 459a26e18..1e8b46688 100644 --- a/gb.media/src/c_media.h +++ b/gb.media/src/c_media.h @@ -124,7 +124,7 @@ typedef void MEDIA_raise_event(void *_object, int event); CMEDIACONTROL *MEDIA_get_control_from_element(void *element, bool create); -bool MEDIA_set_state(void *_object, int state, bool error); +bool MEDIA_set_state(void *_object, int state, bool error, bool async); bool MEDIA_get_flag(void *element, char *property, int flag); void MEDIA_set_flag(void *element, char *property, int flag, bool value); diff --git a/gb.media/src/c_mediaplayer.c b/gb.media/src/c_mediaplayer.c index e2a12f60c..f906f32fa 100644 --- a/gb.media/src/c_mediaplayer.c +++ b/gb.media/src/c_mediaplayer.c @@ -296,7 +296,7 @@ BEGIN_PROPERTY(MediaPlayerVideo_Visualisation) playing = THIS_CONTROL->state == GST_STATE_PLAYING; if (playing) - MEDIA_set_state(THIS, GST_STATE_PAUSED, FALSE); + MEDIA_set_state(THIS, GST_STATE_PAUSED, FALSE, FALSE); //set_control(THIS, "vis-plugin", NULL); //if (vis) @@ -305,7 +305,7 @@ BEGIN_PROPERTY(MediaPlayerVideo_Visualisation) set_flag(THIS, GST_PLAY_FLAG_VIS, TRUE); if (playing) - MEDIA_set_state(THIS, GST_STATE_PLAYING, FALSE); + MEDIA_set_state(THIS, GST_STATE_PLAYING, FALSE, FALSE); } END_PROPERTY diff --git a/gb.media/src/main.c b/gb.media/src/main.c index 75d03199f..2e40e9851 100644 --- a/gb.media/src/main.c +++ b/gb.media/src/main.c @@ -29,6 +29,8 @@ #include "c_media.h" #include "c_mediaplayer.h" +bool MAIN_debug = FALSE; + GB_INTERFACE GB EXPORT; IMAGE_INTERFACE IMAGE EXPORT; @@ -70,17 +72,16 @@ int MAIN_get_x11_handle(void *control) return (*get_handle)(control); } -static void *_old_hook_main; - -static void hook_main(int *argc, char ***argv) -{ - gst_init(argc, argv); - CALL_HOOK_MAIN(_old_hook_main, argc, argv); -} - int EXPORT GB_INIT() { - _old_hook_main = GB.Hook(GB_HOOK_MAIN, (void *)hook_main); + char *env; + + gst_init(NULL, NULL); + + env = getenv("GB_MEDIA_DEBUG"); + if (env && atoi(env)) + MAIN_debug = TRUE; + GB.GetInterface("gb.image", IMAGE_INTERFACE_VERSION, &IMAGE); return 0; } diff --git a/gb.media/src/main.h b/gb.media/src/main.h index 48be7ab42..1ed8b8ccd 100644 --- a/gb.media/src/main.h +++ b/gb.media/src/main.h @@ -36,6 +36,7 @@ #include "gb.image.h" #ifndef __MAIN_C +extern bool MAIN_debug; extern GB_INTERFACE GB; extern IMAGE_INTERFACE IMAGE; #endif