MediaPipeline: Play() now takes an extra optional argument that allows not to wait for the command completion.

[GB.MEDIA]
* NEW: 'GB_MEDIA_DEBUG' is a new environmental variable that toggles warning messages.
* NEW: MediaPipeline: Play() now takes an extra optional argument that allows not to wait for the command completion.
This commit is contained in:
gambas 2020-05-21 20:37:44 +02:00
parent 7fd9766d02
commit 875fcafa51
5 changed files with 33 additions and 27 deletions

View file

@ -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,6 +162,7 @@ static GB_TYPE to_gambas_type(const GValue *value)
return GB_T_DATE;
else
{
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,6 +379,7 @@ static void return_value(const GValue *value)
#endif
else
{
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,6 +1825,7 @@ void MEDIA_stop_pipeline(CMEDIACONTROL *_object)
try++;
if (try > 25)
{
if (MAIN_debug)
fprintf(stderr, "gb.media: warning: could not catch end of stream\n");
break;
}
@ -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),

View file

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

View file

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

View file

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

View file

@ -36,6 +36,7 @@
#include "gb.image.h"
#ifndef __MAIN_C
extern bool MAIN_debug;
extern GB_INTERFACE GB;
extern IMAGE_INTERFACE IMAGE;
#endif