From 5e8b1667f98f05e89a3e11df410a29b403fd4c40 Mon Sep 17 00:00:00 2001 From: Taeho Oh Date: Sat, 23 Jan 2016 20:18:23 +0900 Subject: [PATCH] If EOS, finish scan. --- omvs_gst.c | 22 ++++++++++++++++++++++ omvs_gst.h | 1 + omvs_main.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/omvs_gst.c b/omvs_gst.c index 538d20b..9d623dd 100644 --- a/omvs_gst.c +++ b/omvs_gst.c @@ -23,6 +23,7 @@ typedef struct _OMVSGstImpl { GstElement *play; + GstBus *bus; } OMVSGstImpl; OMVSGst omvs_gst_open(const gchar *uri, const gchar *filename) { @@ -55,11 +56,32 @@ OMVSGst omvs_gst_open(const gchar *uri, const gchar *filename) { g_object_set(play, "video-sink", convpngfile, NULL); g_object_set(play, "mute", TRUE, NULL); + gst_impl->bus = gst_element_get_bus(play); + gst_object_unref(GST_OBJECT(gst_impl->bus)); + gst_element_set_state(play, GST_STATE_PLAYING); return (OMVSGst)gst_impl; } +gboolean omvs_gst_is_finished(OMVSGst gst) { + OMVSGstImpl *gst_impl; + GstMessage *msg; + + g_assert(gst); + + gst_impl = (OMVSGstImpl *)gst; + + msg = gst_bus_pop_filtered(gst_impl->bus, GST_MESSAGE_EOS); + if (!msg) { + return FALSE; + } + + gst_message_unref(msg); + + return TRUE; +} + gint omvs_gst_close(OMVSGst gst) { OMVSGstImpl *gst_impl; diff --git a/omvs_gst.h b/omvs_gst.h index 633879d..6252990 100644 --- a/omvs_gst.h +++ b/omvs_gst.h @@ -26,6 +26,7 @@ typedef void *OMVSGst; extern OMVSGst omvs_gst_open(const gchar *uri, const gchar *filename); +extern gboolean omvs_gst_is_finished(OMVSGst gst); extern gint omvs_gst_close(OMVSGst gst); #endif /* _OMVS_GST_H_ */ diff --git a/omvs_main.c b/omvs_main.c index d2a4e92..a4ccb69 100644 --- a/omvs_main.c +++ b/omvs_main.c @@ -226,6 +226,8 @@ static gpointer _omvs_start_scan_job(gpointer data) { guint ip_hdr_len; gint udp_port; gboolean is_udp_port_found; + gboolean is_gst_finished; + gboolean is_all_gst_finished; ret = pcap_next_ex(pcap, &header, &packet); @@ -306,6 +308,32 @@ static gpointer _omvs_start_scan_job(gpointer data) { o_ipaddr->ports[o_ipaddr->num_ports] = udp_port; o_ipaddr->num_ports++; } + + is_gst_finished = FALSE; + for (j = 0; j < o_ipaddr->num_ports; j++) { + if (o_ipaddr->gsts[j]) { + if (omvs_gst_is_finished(o_ipaddr->gsts[j])) { + omvs_gst_close(o_ipaddr->gsts[j]); + o_ipaddr->gsts[j] = NULL; + is_gst_finished = TRUE; + } + } + } + + is_all_gst_finished = FALSE; + if (is_gst_finished) { + is_all_gst_finished = TRUE; + for (j = 0; j < o_ipaddr->num_ports; j++) { + if (o_ipaddr->gsts[j]) { + is_all_gst_finished = FALSE; + break; + } + } + } + + if (is_all_gst_finished) { + break; + } } for (j = 0; j < o_ipaddr->num_ports; j++) {