mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-18 07:47:17 +00:00
tests: clean up eventloop in examples
Don't leak the bus. Don't parse messages with the method for errors (triggers gobject warning).
This commit is contained in:
parent
dbe8e5d1ad
commit
461fd8d82d
7 changed files with 121 additions and 45 deletions
|
@ -32,35 +32,46 @@ event_loop (GstElement * pipe)
|
|||
{
|
||||
GstBus *bus;
|
||||
GstMessage *message = NULL;
|
||||
gboolean running = TRUE;
|
||||
|
||||
bus = gst_element_get_bus (GST_ELEMENT (pipe));
|
||||
|
||||
while (TRUE) {
|
||||
while (running) {
|
||||
message = gst_bus_poll (bus, GST_MESSAGE_ANY, -1);
|
||||
|
||||
g_assert (message != NULL);
|
||||
|
||||
switch (message->type) {
|
||||
case GST_MESSAGE_EOS:
|
||||
gst_message_unref (message);
|
||||
return;
|
||||
case GST_MESSAGE_WARNING:
|
||||
running = FALSE;
|
||||
break;
|
||||
case GST_MESSAGE_WARNING:{
|
||||
GError *gerror;
|
||||
gchar *debug;
|
||||
|
||||
gst_message_parse_warning (message, &gerror, &debug);
|
||||
gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
|
||||
g_error_free (gerror);
|
||||
g_free (debug);
|
||||
break;
|
||||
}
|
||||
case GST_MESSAGE_ERROR:{
|
||||
GError *gerror;
|
||||
gchar *debug;
|
||||
|
||||
gst_message_parse_error (message, &gerror, &debug);
|
||||
gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
|
||||
gst_message_unref (message);
|
||||
g_error_free (gerror);
|
||||
g_free (debug);
|
||||
return;
|
||||
running = FALSE;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
gst_message_unref (message);
|
||||
break;
|
||||
}
|
||||
gst_message_unref (message);
|
||||
}
|
||||
gst_object_unref (bus);
|
||||
}
|
||||
|
||||
gint
|
||||
|
|
|
@ -6,35 +6,46 @@ event_loop (GstElement * pipe)
|
|||
{
|
||||
GstBus *bus;
|
||||
GstMessage *message = NULL;
|
||||
gboolean running = TRUE;
|
||||
|
||||
bus = gst_element_get_bus (GST_ELEMENT (pipe));
|
||||
|
||||
while (TRUE) {
|
||||
while (running) {
|
||||
message = gst_bus_poll (bus, GST_MESSAGE_ANY, -1);
|
||||
|
||||
g_assert (message != NULL);
|
||||
|
||||
switch (message->type) {
|
||||
case GST_MESSAGE_EOS:
|
||||
gst_message_unref (message);
|
||||
return;
|
||||
case GST_MESSAGE_WARNING:
|
||||
running = FALSE;
|
||||
break;
|
||||
case GST_MESSAGE_WARNING:{
|
||||
GError *gerror;
|
||||
gchar *debug;
|
||||
|
||||
gst_message_parse_warning (message, &gerror, &debug);
|
||||
gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
|
||||
g_error_free (gerror);
|
||||
g_free (debug);
|
||||
break;
|
||||
}
|
||||
case GST_MESSAGE_ERROR:{
|
||||
GError *gerror;
|
||||
gchar *debug;
|
||||
|
||||
gst_message_parse_error (message, &gerror, &debug);
|
||||
gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
|
||||
gst_message_unref (message);
|
||||
g_error_free (gerror);
|
||||
g_free (debug);
|
||||
return;
|
||||
running = FALSE;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
gst_message_unref (message);
|
||||
break;
|
||||
}
|
||||
gst_message_unref (message);
|
||||
}
|
||||
gst_object_unref (bus);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -7,35 +7,46 @@ event_loop (GstElement * pipe)
|
|||
{
|
||||
GstBus *bus;
|
||||
GstMessage *message = NULL;
|
||||
gboolean running = TRUE;
|
||||
|
||||
bus = gst_element_get_bus (GST_ELEMENT (pipe));
|
||||
|
||||
while (TRUE) {
|
||||
while (running) {
|
||||
message = gst_bus_poll (bus, GST_MESSAGE_ANY, -1);
|
||||
|
||||
g_assert (message != NULL);
|
||||
|
||||
switch (message->type) {
|
||||
case GST_MESSAGE_EOS:
|
||||
gst_message_unref (message);
|
||||
return;
|
||||
case GST_MESSAGE_WARNING:
|
||||
running = FALSE;
|
||||
break;
|
||||
case GST_MESSAGE_WARNING:{
|
||||
GError *gerror;
|
||||
gchar *debug;
|
||||
|
||||
gst_message_parse_warning (message, &gerror, &debug);
|
||||
gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
|
||||
g_error_free (gerror);
|
||||
g_free (debug);
|
||||
break;
|
||||
}
|
||||
case GST_MESSAGE_ERROR:{
|
||||
GError *gerror;
|
||||
gchar *debug;
|
||||
|
||||
gst_message_parse_error (message, &gerror, &debug);
|
||||
gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
|
||||
gst_message_unref (message);
|
||||
g_error_free (gerror);
|
||||
g_free (debug);
|
||||
return;
|
||||
running = FALSE;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
gst_message_unref (message);
|
||||
break;
|
||||
}
|
||||
gst_message_unref (message);
|
||||
}
|
||||
gst_object_unref (bus);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -14,34 +14,46 @@ event_loop (GstElement * pipe)
|
|||
{
|
||||
GstBus *bus;
|
||||
GstMessage *message = NULL;
|
||||
gboolean running = TRUE;
|
||||
|
||||
bus = gst_element_get_bus (GST_ELEMENT (pipe));
|
||||
|
||||
while (TRUE) {
|
||||
while (running) {
|
||||
message = gst_bus_poll (bus, GST_MESSAGE_ANY, -1);
|
||||
|
||||
g_assert (message != NULL);
|
||||
|
||||
switch (message->type) {
|
||||
case GST_MESSAGE_EOS:
|
||||
gst_message_unref (message);
|
||||
return;
|
||||
case GST_MESSAGE_WARNING:
|
||||
running = FALSE;
|
||||
break;
|
||||
case GST_MESSAGE_WARNING:{
|
||||
GError *gerror;
|
||||
gchar *debug;
|
||||
|
||||
gst_message_parse_warning (message, &gerror, &debug);
|
||||
gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
|
||||
g_error_free (gerror);
|
||||
g_free (debug);
|
||||
break;
|
||||
}
|
||||
case GST_MESSAGE_ERROR:{
|
||||
GError *gerror;
|
||||
gchar *debug;
|
||||
|
||||
gst_message_parse_error (message, &gerror, &debug);
|
||||
gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
|
||||
gst_message_unref (message);
|
||||
g_error_free (gerror);
|
||||
g_free (debug);
|
||||
return;
|
||||
running = FALSE;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
gst_message_unref (message);
|
||||
break;
|
||||
}
|
||||
gst_message_unref (message);
|
||||
}
|
||||
gst_object_unref (bus);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -6,10 +6,11 @@ event_loop (GstElement * pipe)
|
|||
{
|
||||
GstBus *bus;
|
||||
GstMessage *message = NULL;
|
||||
gboolean running = TRUE;
|
||||
|
||||
bus = gst_element_get_bus (GST_ELEMENT (pipe));
|
||||
|
||||
while (TRUE) {
|
||||
while (running) {
|
||||
message = gst_bus_timed_pop_filtered (bus, GST_MESSAGE_ANY, -1);
|
||||
|
||||
g_assert (message != NULL);
|
||||
|
@ -17,9 +18,18 @@ event_loop (GstElement * pipe)
|
|||
switch (message->type) {
|
||||
case GST_MESSAGE_EOS:
|
||||
g_message ("got EOS");
|
||||
gst_message_unref (message);
|
||||
return;
|
||||
case GST_MESSAGE_WARNING:
|
||||
running = FALSE;
|
||||
break;
|
||||
case GST_MESSAGE_WARNING:{
|
||||
GError *gerror;
|
||||
gchar *debug;
|
||||
|
||||
gst_message_parse_warning (message, &gerror, &debug);
|
||||
gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
|
||||
g_error_free (gerror);
|
||||
g_free (debug);
|
||||
break;
|
||||
}
|
||||
case GST_MESSAGE_ERROR:
|
||||
{
|
||||
GError *gerror;
|
||||
|
@ -27,10 +37,10 @@ event_loop (GstElement * pipe)
|
|||
|
||||
gst_message_parse_error (message, &gerror, &debug);
|
||||
gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
|
||||
gst_message_unref (message);
|
||||
g_error_free (gerror);
|
||||
g_free (debug);
|
||||
return;
|
||||
running = FALSE;
|
||||
break;
|
||||
}
|
||||
case GST_MESSAGE_STEP_DONE:
|
||||
{
|
||||
|
@ -51,14 +61,14 @@ event_loop (GstElement * pipe)
|
|||
g_message ("step done: %" GST_TIME_FORMAT " skipped",
|
||||
GST_TIME_ARGS (duration));
|
||||
}
|
||||
|
||||
return;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
gst_message_unref (message);
|
||||
break;
|
||||
}
|
||||
gst_message_unref (message);
|
||||
}
|
||||
gst_object_unref (bus);
|
||||
}
|
||||
|
||||
/* signalled when a new preroll buffer is available */
|
||||
|
|
|
@ -16,7 +16,17 @@ event_loop (GstBus * bus, GstElement * pipe)
|
|||
g_message ("received EOS");
|
||||
gst_message_unref (message);
|
||||
return;
|
||||
case GST_MESSAGE_WARNING:
|
||||
case GST_MESSAGE_WARNING:{
|
||||
GError *gerror;
|
||||
gchar *debug;
|
||||
|
||||
gst_message_parse_warning (message, &gerror, &debug);
|
||||
gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
|
||||
gst_message_unref (message);
|
||||
g_error_free (gerror);
|
||||
g_free (debug);
|
||||
break;
|
||||
}
|
||||
case GST_MESSAGE_ERROR:{
|
||||
GError *gerror;
|
||||
gchar *debug;
|
||||
|
|
|
@ -42,35 +42,46 @@ event_loop (GstElement * pipe)
|
|||
{
|
||||
GstBus *bus;
|
||||
GstMessage *message = NULL;
|
||||
gboolean running = TRUE;
|
||||
|
||||
bus = gst_element_get_bus (GST_ELEMENT (pipe));
|
||||
|
||||
while (TRUE) {
|
||||
while (running) {
|
||||
message = gst_bus_poll (bus, GST_MESSAGE_ANY, -1);
|
||||
|
||||
g_assert (message != NULL);
|
||||
|
||||
switch (message->type) {
|
||||
case GST_MESSAGE_EOS:
|
||||
gst_message_unref (message);
|
||||
return;
|
||||
case GST_MESSAGE_WARNING:
|
||||
running = FALSE;
|
||||
break;
|
||||
case GST_MESSAGE_WARNING:{
|
||||
GError *gerror;
|
||||
gchar *debug;
|
||||
|
||||
gst_message_parse_warning (message, &gerror, &debug);
|
||||
gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
|
||||
g_error_free (gerror);
|
||||
g_free (debug);
|
||||
break;
|
||||
}
|
||||
case GST_MESSAGE_ERROR:{
|
||||
GError *gerror;
|
||||
gchar *debug;
|
||||
|
||||
gst_message_parse_error (message, &gerror, &debug);
|
||||
gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
|
||||
gst_message_unref (message);
|
||||
g_error_free (gerror);
|
||||
g_free (debug);
|
||||
return;
|
||||
running = FALSE;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
gst_message_unref (message);
|
||||
break;
|
||||
}
|
||||
gst_message_unref (message);
|
||||
}
|
||||
gst_object_unref (bus);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
Loading…
Reference in a new issue