static gboolean insert_field (GQuark field_id, const GValue * val, gpointer user_data) { GtkTreeIter *parent_iter = user_data; GtkTreeIter iter; const gchar *f = g_quark_to_string (field_id); gtk_tree_store_append (treestore, &iter, parent_iter); if (G_VALUE_TYPE (val) == GST_TYPE_ARRAY) { guint n = gst_value_array_get_size (val); guint i; GtkTreeIter child_iter; gtk_tree_store_set (treestore, &iter, 0, f, -1); for (i = 0; i < n; i++) { const GValue *ve = gst_value_array_get_value (val, i); gtk_tree_store_append (treestore, &child_iter, &iter); if (G_VALUE_TYPE (ve) == GST_TYPE_STRUCTURE) { const GstStructure *s = gst_value_get_structure (ve); gtk_tree_store_set (treestore, &child_iter, 0, gst_structure_get_name (s), -1); gst_structure_foreach (s, insert_field, &child_iter); } else { gchar *v = g_value_to_string (ve); gtk_tree_store_set (treestore, &child_iter, 0, v, -1); g_free (v); } } } else if (G_VALUE_TYPE (val) == GST_TYPE_STRUCTURE) { const GstStructure *s = gst_value_get_structure (val); gchar *entry = g_strdup_printf ("%s: %s", f, gst_structure_get_name (s)); gtk_tree_store_set (treestore, &iter, 0, entry, -1); g_free (entry); gst_structure_foreach (s, insert_field, &iter); } else { gchar *v = g_value_to_string (val); gchar *entry = g_strdup_printf ("%s: %s", f, v); gtk_tree_store_set (treestore, &iter, 0, entry, -1); g_free (v); g_free (entry); } return TRUE; }
GstStructure * kms_stats_get_element_stats (GstStructure * stats) { GstStructure *element_stats; const GValue *value; if (!gst_structure_has_field (stats, KMS_MEDIA_ELEMENT_FIELD)) { return NULL; } value = gst_structure_get_value (stats, KMS_MEDIA_ELEMENT_FIELD); if (!GST_VALUE_HOLDS_STRUCTURE (value)) { return NULL; } element_stats = (GstStructure *) gst_value_get_structure (value); if (g_strcmp0 (KMS_ELEMENT_STATS_STRUCT_NAME, gst_structure_get_name (element_stats)) != 0) { return NULL; } return element_stats; }
static void kms_connection_attr_ext_add_ips (KmsISdpMediaExtension * ext, GstSDPMedia * media, GArray * ips) { gint i; for (i = 0; i < ips->len; i++) { gchar *nettype, *addrtype, *address; guint ttl, addr_number; const GstStructure *addr; GValue *val; val = &g_array_index (ips, GValue, i); if (!GST_VALUE_HOLDS_STRUCTURE (val)) { GST_WARNING_OBJECT (ext, "Inavalid address provided"); continue; } addr = gst_value_get_structure (val); nettype = addrtype = address = NULL; if (gst_structure_get (addr, "nettype", G_TYPE_STRING, &nettype, "addrtype", G_TYPE_STRING, &addrtype, "address", G_TYPE_STRING, &address, "ttl", G_TYPE_UINT, &ttl, "addrnumber", G_TYPE_UINT, &addr_number, NULL)) { gst_sdp_media_add_connection (media, nettype, addrtype, address, ttl, addr_number); } g_free (nettype); g_free (addrtype); g_free (address); } }
gint httpstreaming_start (HTTPStreaming *httpstreaming, gint maxthreads) { GValue *value; GstStructure *structure; gchar *p, **pp; gint port; /* get streaming listen port */ value = (GValue *)gst_structure_get_value (httpstreaming->itvencoder->configure->data, "server"); structure = (GstStructure *)gst_value_get_structure (value); value = (GValue *)gst_structure_get_value (structure, "httpstreaming"); p = (gchar *)g_value_get_string (value); pp = g_strsplit (p, ":", 0); port = atoi (pp[1]); g_strfreev (pp); /* start http streaming */ httpstreaming->httpserver = httpserver_new ("maxthreads", maxthreads, "port", port, NULL); if (httpserver_start (httpstreaming->httpserver, httpstreaming_dispatcher, httpstreaming) != 0) { GST_ERROR ("Start streaming httpserver error!"); exit (0); } return 0; }
static void gst_pulsesrc_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { GstPulseSrc *pulsesrc = GST_PULSESRC_CAST (object); switch (prop_id) { case PROP_SERVER: g_free (pulsesrc->server); pulsesrc->server = g_value_dup_string (value); if (pulsesrc->probe) gst_pulseprobe_set_server (pulsesrc->probe, pulsesrc->server); break; case PROP_DEVICE: g_free (pulsesrc->device); pulsesrc->device = g_value_dup_string (value); break; case PROP_STREAM_PROPERTIES: if (pulsesrc->properties) gst_structure_free (pulsesrc->properties); pulsesrc->properties = gst_structure_copy (gst_value_get_structure (value)); if (pulsesrc->proplist) pa_proplist_free (pulsesrc->proplist); pulsesrc->proplist = gst_pulse_make_proplist (pulsesrc->properties); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static JsonNode * snra_json_value_to_node (const GValue *value) { JsonNode *n = NULL; if (GST_VALUE_HOLDS_STRUCTURE (value)) { const GstStructure *s = gst_value_get_structure (value); n = snra_json_from_gst_structure (s); } else if (GST_VALUE_HOLDS_ARRAY (value)) { guint count = gst_value_array_get_size (value); guint i; JsonArray *arr = json_array_sized_new (count); for (i = 0; i < count; i++) { const GValue *sub_val = gst_value_array_get_value (value, i); JsonNode *tmp = snra_json_value_to_node (sub_val); if (tmp) json_array_add_element (arr, tmp); } n = json_node_new (JSON_NODE_ARRAY); json_node_take_array (n, arr); } else { n = json_node_new (JSON_NODE_VALUE); json_node_set_value (n, value); } return n; }
static const GstStructure * get_structure_from_value (const GValue * val) { if (!GST_VALUE_HOLDS_STRUCTURE (val)) { return NULL; } return gst_value_get_structure (val); }
static void gst_face_overlay_message_handler (GstBin * bin, GstMessage * message) { if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ELEMENT && strcmp (gst_structure_get_name (message->structure), "facedetect") == 0) { GstFaceOverlay *filter = GST_FACEOVERLAY (bin); /* optionally draw the image once every two messages for better performance * filter->process_message = !filter->process_message; * if(!filter->process_message) * return; */ guint x, y, width, height; int delta_x, delta_y, svg_x, svg_y, svg_width, svg_height; const GstStructure *face; int face_count; face_count = gst_value_list_get_size (gst_structure_get_value (message->structure, "faces")); /* The last face in the list seems to be the right one, objects mistakenly * detected as faces for a couple of frames seem to be in the list * beginning. TODO: needs confirmation. */ face = gst_value_get_structure (gst_value_list_get_value (gst_structure_get_value (message->structure, "faces"), face_count - 1)); gst_structure_get_uint (face, "x", &x); gst_structure_get_uint (face, "y", &y); gst_structure_get_uint (face, "width", &width); gst_structure_get_uint (face, "height", &height); /* Apply x and y offsets relative to face position and size. * Set image width and height as a fraction of face width and height. * Cast to int since face position and size will never be bigger than * G_MAX_INT and we may have negative values as svg_x or svg_y */ delta_x = (int) (filter->x * (int) width); svg_x = (int) x + delta_x; delta_y = (int) (filter->y * (int) height); svg_y = (int) y + delta_y; svg_width = (int) width *filter->w; svg_height = (int) height *filter->h; g_object_set (filter->svg_overlay, "location", filter->location, "x", svg_x, "y", svg_y, "width", svg_width, "height", svg_height, NULL); } GST_BIN_CLASS (parent_class)->handle_message (bin, message); }
static gboolean bus_callback (GstBus * bus, GstMessage * message, gpointer data) { switch (GST_MESSAGE_TYPE (message)) { case GST_MESSAGE_WARNING:{ GError *err; gchar *debug; gst_message_parse_warning (message, &err, &debug); g_print ("Warning: %s\n", err->message); g_error_free (err); g_free (debug); break; } case GST_MESSAGE_ERROR:{ GError *err; gchar *debug = NULL; gst_message_parse_error (message, &err, &debug); g_print ("Error: %s : %s\n", err->message, debug); g_error_free (err); g_free (debug); gtk_main_quit (); break; } case GST_MESSAGE_TAG:{ GstTagList *tags; GValue v = { 0, }; g_print ("Got tags\n"); gst_message_parse_tag (message, &tags); if (gst_tag_list_copy_value (&v, tags, "mxf-structure")) { const GstStructure *s; GtkTreeIter iter; s = gst_value_get_structure (&v); gtk_tree_store_append (treestore, &iter, NULL); insert_structure (s, &iter); gtk_widget_show_all (window); g_value_unset (&v); } gst_tag_list_unref (tags); break; } default: break; } return TRUE; }
static void gst_pulsesrc_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { GstPulseSrc *pulsesrc = GST_PULSESRC_CAST (object); switch (prop_id) { case PROP_SERVER: g_free (pulsesrc->server); pulsesrc->server = g_value_dup_string (value); if (pulsesrc->probe) gst_pulseprobe_set_server (pulsesrc->probe, pulsesrc->server); break; case PROP_DEVICE: g_free (pulsesrc->device); pulsesrc->device = g_value_dup_string (value); break; case PROP_CLIENT_NAME: g_free (pulsesrc->client_name); if (!g_value_get_string (value)) { GST_WARNING_OBJECT (pulsesrc, "Empty PulseAudio client name not allowed. Resetting to default value"); pulsesrc->client_name = gst_pulse_client_name (); } else pulsesrc->client_name = g_value_dup_string (value); break; case PROP_STREAM_PROPERTIES: if (pulsesrc->properties) gst_structure_free (pulsesrc->properties); pulsesrc->properties = gst_structure_copy (gst_value_get_structure (value)); if (pulsesrc->proplist) pa_proplist_free (pulsesrc->proplist); pulsesrc->proplist = gst_pulse_make_proplist (pulsesrc->properties); break; case PROP_VOLUME: gst_pulsesrc_set_stream_volume (pulsesrc, g_value_get_double (value)); break; case PROP_MUTE: gst_pulsesrc_set_stream_mute (pulsesrc, g_value_get_boolean (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static void gst_test_http_src_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { GstTestHTTPSrc *src = GST_TEST_HTTP_SRC (object); switch (prop_id) { case PROP_USER_AGENT: g_free (src->user_agent); src->user_agent = g_value_dup_string (value); break; case PROP_EXTRA_HEADERS:{ const GstStructure *s = gst_value_get_structure (value); if (src->extra_headers) gst_structure_free (src->extra_headers); src->extra_headers = s ? gst_structure_copy (s) : NULL; break; } case PROP_COMPRESS: src->compress = g_value_get_boolean (value); GST_DEBUG ("Set compress=%s", src->compress ? "TRUE" : "FALSE"); break; case PROP_KEEP_ALIVE: src->keep_alive = g_value_get_boolean (value); break; case PROP_METHOD: g_free (src->http_method_name); src->http_method_name = g_value_dup_string (value); src->http_method = METHOD_INVALID; for (guint i = 0; gst_test_http_src_methods[i].name; ++i) { if (strcmp (gst_test_http_src_methods[i].name, src->http_method_name) == 0) { src->http_method = gst_test_http_src_methods[i].method; break; } } /* we don't cause an error for an invalid method at this point, as GstSoupHTTPSrc does not use the http_method_name string until trying to open a connection. */ break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static void set_program (GstObject * elem, GstStructure * prog) { const GstStructure *s; GstControlSource *cs; GstClockTime ts, dur; gdouble v; const GValue *frame; GHashTable *css; gint i, j; const gchar *name; css = g_hash_table_new (g_str_hash, g_str_equal); ts = 0; dur = gst_util_uint64_scale_int (GST_SECOND, 1, 15); /* loop over each image in prog */ for (i = 0; i < gst_structure_n_fields (prog); i++) { GST_DEBUG ("ctrl on %" GST_TIME_FORMAT, GST_TIME_ARGS (ts)); frame = gst_structure_get_value (prog, gst_structure_nth_field_name (prog, i)); s = gst_value_get_structure (frame); for (j = 0; j < gst_structure_n_fields (s); j++) { name = gst_structure_nth_field_name (s, j); cs = g_hash_table_lookup (css, name); if (!cs) { cs = gst_interpolation_control_source_new (); gst_object_add_control_binding (elem, gst_direct_control_binding_new (elem, name, cs)); g_object_set (cs, "mode", GST_INTERPOLATION_MODE_NONE, NULL); g_hash_table_insert (css, (gpointer) name, cs); gst_object_unref (cs); } gst_structure_get_double (s, name, &v); gst_timed_value_control_source_set ((GstTimedValueControlSource *) cs, ts, v); GST_DEBUG (" %s = %lf", name, v); } ts += dur; } g_hash_table_unref (css); }
static void gst_mpegtsmux_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { MpegTsMux *mux = GST_MPEG_TSMUX (object); GSList *walk; switch (prop_id) { case ARG_M2TS_MODE: /*set incase if the output stream need to be of 192 bytes */ mux->m2ts_mode = g_value_get_boolean (value); break; case ARG_PROG_MAP: { const GstStructure *s = gst_value_get_structure (value); if (mux->prog_map) { gst_structure_free (mux->prog_map); } if (s) mux->prog_map = gst_structure_copy (s); else mux->prog_map = NULL; break; } case ARG_PAT_INTERVAL: mux->pat_interval = g_value_get_uint (value); if (mux->tsmux) tsmux_set_pat_interval (mux->tsmux, mux->pat_interval); break; case ARG_PMT_INTERVAL: walk = mux->collect->data; mux->pmt_interval = g_value_get_uint (value); while (walk) { MpegTsPadData *ts_data = (MpegTsPadData *) walk->data; tsmux_set_pmt_interval (ts_data->prog, mux->pmt_interval); walk = g_slist_next (walk); } break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static void collectRTCDataChannelStats (std::map <std::string, std::shared_ptr<Stats>> &statsReport, double timestamp, const GstStructure *stats) { gint i, n; n = gst_structure_n_fields (stats); for (i = 0; i < n; i++) { std::shared_ptr<RTCDataChannelStats> rtcDataStats; const GValue *value; const gchar *name; name = gst_structure_nth_field_name (stats, i); if (!g_str_has_prefix (name, "data-channel-") ) { continue; } value = gst_structure_get_value (stats, name); if (!GST_VALUE_HOLDS_STRUCTURE (value) ) { gchar *str_val; str_val = g_strdup_value_contents (value); GST_WARNING ("Unexpected field type (%s) = %s", name, str_val); g_free (str_val); continue; } rtcDataStats = createtRTCDataChannelStats (gst_value_get_structure (value) ); rtcDataStats->setTimestamp (timestamp); statsReport[rtcDataStats->getId ()] = rtcDataStats; } std::shared_ptr<RTCPeerConnectionStats> peerConnStats = createtRTCPeerConnectionStats (stats); peerConnStats->setTimestamp (timestamp); statsReport[peerConnStats->getId ()] = peerConnStats; }
static void remove_not_supported_codecs_from_array (GstElement *element, GArray *codecs) { guint i; if (codecs == NULL) { return; } for (i = 0; i < codecs->len; i++) { GValue *v = &g_array_index (codecs, GValue, i); const GstStructure *s; const gchar *codec_name; gboolean supported = FALSE; if (!GST_VALUE_HOLDS_STRUCTURE (v) ) { GST_WARNING_OBJECT (element, "Value into array is not a GstStructure"); continue; } s = gst_value_get_structure (v); codec_name = gst_structure_get_name (s); for (std::vector<std::string>::iterator it = supported_codecs.begin(); it != supported_codecs.end(); ++it) { if (g_str_has_prefix (codec_name, (*it).c_str() ) ) { supported = TRUE; break; } } if (!supported) { GST_INFO_OBJECT (element, "Removing not supported codec '%s'", codec_name); g_array_remove_index (codecs, i); i--; } } }
const GstStructure * kms_utils_get_structure_by_name (const GstStructure * str, const gchar * name) { const GValue *value; value = gst_structure_get_value (str, name); if (value == NULL) { return NULL; } if (!GST_VALUE_HOLDS_STRUCTURE (value)) { gchar *str_val; str_val = g_strdup_value_contents (value); GST_WARNING ("Unexpected field type (%s) = %s", name, str_val); g_free (str_val); return NULL; } return gst_value_get_structure (value); }
static gboolean build_field_template (GQuark field_id, const GValue * value, gpointer user_data) { GString *s = (GString *) user_data; const GstStructure *sub; GValue template_value = { 0, }; GType type = G_TYPE_INVALID; GstTracerValueFlags flags = GST_TRACER_VALUE_FLAGS_NONE; gboolean res; if (G_VALUE_TYPE (value) != GST_TYPE_STRUCTURE) { GST_WARNING ("expected field of type GstStructure, but %s is %s", g_quark_to_string (field_id), G_VALUE_TYPE_NAME (value)); return FALSE; } sub = gst_value_get_structure (value); gst_structure_get (sub, "type", G_TYPE_GTYPE, &type, "flags", GST_TYPE_TRACER_VALUE_FLAGS, &flags, NULL); if (flags & GST_TRACER_VALUE_FLAGS_OPTIONAL) { gchar *opt_name = g_strconcat ("have-", g_quark_to_string (field_id), NULL); /* add a boolean field, that indicates the presence of the next field */ g_value_init (&template_value, G_TYPE_BOOLEAN); priv__gst_structure_append_template_to_gstring (g_quark_from_string (opt_name), &template_value, s); g_value_unset (&template_value); g_free (opt_name); } g_value_init (&template_value, type); res = priv__gst_structure_append_template_to_gstring (field_id, &template_value, s); g_value_unset (&template_value); return res; }
static void on_message (GstBus * bus, GstMessage * message, gpointer data) { switch (GST_MESSAGE_TYPE (message)) { case GST_MESSAGE_WARNING: case GST_MESSAGE_ERROR: g_error ("Got error"); gtk_main_quit (); break; case GST_MESSAGE_TAG:{ GstTagList *tags; GValue v = { 0, }; g_print ("Got tags\n"); gst_message_parse_tag (message, &tags); if (gst_tag_list_copy_value (&v, tags, "mxf-structure")) { const GstStructure *s; GtkTreeIter iter; s = gst_value_get_structure (&v); gtk_tree_store_append (treestore, &iter, NULL); insert_structure (s, &iter); gtk_widget_show_all (window); g_value_unset (&v); } gst_tag_list_free (tags); break; } default: break; } }
static void gst_soup_http_src_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (object); switch (prop_id) { case PROP_LOCATION: { const gchar *location; location = g_value_get_string (value); if (location == NULL) { GST_WARNING ("location property cannot be NULL"); goto done; } if (!gst_soup_http_src_set_location (src, location)) { GST_WARNING ("badly formatted location"); goto done; } break; } case PROP_USER_AGENT: if (src->user_agent) g_free (src->user_agent); src->user_agent = g_value_dup_string (value); break; case PROP_IRADIO_MODE: src->iradio_mode = g_value_get_boolean (value); break; case PROP_AUTOMATIC_REDIRECT: src->automatic_redirect = g_value_get_boolean (value); break; case PROP_PROXY: { const gchar *proxy; proxy = g_value_get_string (value); if (proxy == NULL) { GST_WARNING ("proxy property cannot be NULL"); goto done; } if (!gst_soup_http_src_set_proxy (src, proxy)) { GST_WARNING ("badly formatted proxy URI"); goto done; } break; } case PROP_COOKIES: g_strfreev (src->cookies); src->cookies = g_strdupv (g_value_get_boxed (value)); break; case PROP_IS_LIVE: gst_base_src_set_live (GST_BASE_SRC (src), g_value_get_boolean (value)); break; case PROP_USER_ID: if (src->user_id) g_free (src->user_id); src->user_id = g_value_dup_string (value); break; case PROP_USER_PW: if (src->user_pw) g_free (src->user_pw); src->user_pw = g_value_dup_string (value); break; case PROP_PROXY_ID: if (src->proxy_id) g_free (src->proxy_id); src->proxy_id = g_value_dup_string (value); break; case PROP_PROXY_PW: if (src->proxy_pw) g_free (src->proxy_pw); src->proxy_pw = g_value_dup_string (value); break; case PROP_TIMEOUT: src->timeout = g_value_get_uint (value); break; case PROP_EXTRA_HEADERS:{ const GstStructure *s = gst_value_get_structure (value); if (src->extra_headers) gst_structure_free (src->extra_headers); src->extra_headers = s ? gst_structure_copy (s) : NULL; break; } default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } done: return; }
static gboolean kms_sdp_sdes_ext_add_offer_crypto_attrs (KmsISdpMediaExtension * ext, GstSDPMedia * offer, GArray * keys, GError ** error) { gboolean ret = TRUE; guint i; for (i = 0; i < keys->len; i++) { const GstStructure *str; SrtpCryptoSuite crypto; gchar *key, *lifetime; guint tag, *mki, *len; GValue *val; key = lifetime = NULL; mki = len = NULL; val = &g_array_index (keys, GValue, i); if (!GST_VALUE_HOLDS_STRUCTURE (val)) { g_set_error (error, KMS_SDP_AGENT_ERROR, SDP_AGENT_INVALID_PARAMETER, "Can not add crypto attribute for key %u", i); return FALSE; } str = gst_value_get_structure (val); if (!gst_structure_get (str, KMS_SDES_TAG_FIELD, G_TYPE_UINT, &tag, KMS_SDES_KEY_FIELD, G_TYPE_STRING, &key, KMS_SDES_CRYPTO, G_TYPE_UINT, &crypto, NULL)) { g_set_error (error, KMS_SDP_AGENT_ERROR, SDP_AGENT_INVALID_PARAMETER, "Can not add crypto attribute for key %u", i); ret = FALSE; } if (ret) { guint m, l; /* get optional parameters */ gst_structure_get (str, KMS_SDES_LIFETIME, G_TYPE_STRING, &lifetime, NULL); if (gst_structure_get (str, KMS_SDES_MKI, G_TYPE_UINT, &m, KMS_SDES_LENGTH, G_TYPE_UINT, &l, NULL)) { mki = &m; len = &l; } ret = kms_sdp_sdes_ext_add_crypto_attr (ext, offer, tag, key, crypto, lifetime, mki, len, error); } g_free (key); g_free (lifetime); if (!ret) { /* Something went wrong */ break; } } return ret; }
/* If a parent is non-NULL, collected stream information will be appended to it * (and where the information exists, it will be overriden) */ static GstDiscovererStreamInfo * parse_stream_topology (GstDiscoverer * dc, const GstStructure * topology, GstDiscovererStreamInfo * parent) { GstDiscovererStreamInfo *res = NULL; GstCaps *caps = NULL; const GValue *nval = NULL; GST_DEBUG ("parsing: %" GST_PTR_FORMAT, topology); nval = gst_structure_get_value (topology, "next"); if (nval == NULL || GST_VALUE_HOLDS_STRUCTURE (nval)) { GstStructure *st = find_stream_for_node (dc, topology); gboolean add_to_list = TRUE; if (st) { res = collect_information (dc, st, parent); gst_structure_free (st); } else { /* Didn't find a stream structure, so let's just use the caps we have */ res = collect_information (dc, topology, parent); } if (nval == NULL) { /* FIXME : aggregate with information from main streams */ GST_DEBUG ("Coudn't find 'next' ! might be the last entry"); } else { GstCaps *caps; const GstStructure *st; st = gst_value_get_structure (nval); GST_DEBUG ("next is a structure %" GST_PTR_FORMAT, st); if (!parent) parent = res; if (gst_structure_id_get (st, _CAPS_QUARK, GST_TYPE_CAPS, &caps, NULL)) { if (gst_caps_can_intersect (parent->caps, caps)) { /* We sometimes get an extra sub-stream from the parser. If this is * the case, we just replace the parent caps with this stream's caps * since they might contain more information */ gst_caps_unref (parent->caps); parent->caps = caps; parse_stream_topology (dc, st, parent); add_to_list = FALSE; } else if (child_is_raw_stream (parent->caps, caps)) { /* This is the "raw" stream corresponding to the parent. This * contains more information than the parent, tags etc. */ parse_stream_topology (dc, st, parent); add_to_list = FALSE; gst_caps_unref (caps); } else { GstDiscovererStreamInfo *next = parse_stream_topology (dc, st, NULL); res->next = next; next->previous = res; } } } if (add_to_list) { dc->priv->current_info->stream_list = g_list_append (dc->priv->current_info->stream_list, res); } } else if (GST_VALUE_HOLDS_LIST (nval)) { guint i, len; GstDiscovererContainerInfo *cont; GstTagList *tags; if (!gst_structure_id_get (topology, _CAPS_QUARK, GST_TYPE_CAPS, &caps, NULL)) GST_WARNING ("Couldn't find caps !"); len = gst_value_list_get_size (nval); GST_DEBUG ("next is a list of %d entries", len); cont = (GstDiscovererContainerInfo *) gst_mini_object_new (GST_TYPE_DISCOVERER_CONTAINER_INFO); cont->parent.caps = caps; res = (GstDiscovererStreamInfo *) cont; if (gst_structure_id_has_field (topology, _TAGS_QUARK)) { GstTagList *tmp; gst_structure_id_get (topology, _TAGS_QUARK, GST_TYPE_STRUCTURE, &tags, NULL); GST_DEBUG ("Merge tags %" GST_PTR_FORMAT, tags); tmp = gst_tag_list_merge (cont->parent.tags, (GstTagList *) tags, GST_TAG_MERGE_APPEND); gst_tag_list_free (tags); if (cont->parent.tags) gst_tag_list_free (cont->parent.tags); cont->parent.tags = tmp; GST_DEBUG ("Container info tags %" GST_PTR_FORMAT, tmp); } for (i = 0; i < len; i++) { const GValue *subv = gst_value_list_get_value (nval, i); const GstStructure *subst = gst_value_get_structure (subv); GstDiscovererStreamInfo *substream; GST_DEBUG ("%d %" GST_PTR_FORMAT, i, subst); substream = parse_stream_topology (dc, subst, NULL); substream->previous = res; cont->streams = g_list_append (cont->streams, gst_discoverer_stream_info_ref (substream)); } } return res; }
static GstBusSyncReply bus_sync_handler (GstBus * bus, GstMessage * message, GstPipeline * pipeline) { const GstStructure *structure; const GValue *value; gchar *contents; gint i; guint size = 0; /* select msg */ if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT || !gst_structure_has_name (gst_message_get_structure (message), "facedetect")) return GST_BUS_PASS; /* parse msg structure */ structure = gst_message_get_structure (message); /* if facedetect is into buffer */ if (structure && strcmp (gst_structure_get_name (structure), "facedetect") == 0) { if (!silent) { /* print message type and structure name */ g_print ("Type message, name message: %s{{%s}}\n", gst_message_type_get_name (message->type), gst_structure_get_name (structure)); /* print msg structure names and type */ for (i = 0; i < gst_structure_n_fields (structure); i++) { const gchar *name = gst_structure_nth_field_name (structure, i); GType type = gst_structure_get_field_type (structure, name); g_print ("-Name field, type: %s[%s]\n", name, g_type_name (type)); } } /* get structure of faces */ value = gst_structure_get_value (structure, "faces"); /* obtain the contents into the structure */ contents = g_strdup_value_contents (value); if (!silent) g_print ("Detected objects: %s\n\n", *(&contents)); /* list size */ size = gst_value_list_get_size (value); /* if face is detected, obtain the values X and Y of mouth and of nose. */ if (size != 0) { GstState state; /* if paused, set to playing */ gst_element_get_state (GST_ELEMENT (playbin), &state, NULL, GST_CLOCK_TIME_NONE); if (state != GST_STATE_PLAYING) { gst_element_set_state (GST_ELEMENT (playbin), GST_STATE_PLAYING); } if (ctrlvol) { gdouble volume; const GValue *faces_value = gst_value_list_get_value (value, 0); const GstStructure *faces_structure = gst_value_get_structure (faces_value); gboolean have_mouth_y = gst_structure_has_field (faces_structure, "mouth->y"); gboolean have_mouth_x = gst_structure_has_field (faces_structure, "mouth->x"); gboolean have_nose_y = gst_structure_has_field (faces_structure, "nose->y"); gboolean have_nose_x = gst_structure_has_field (faces_structure, "nose->x"); /* get the volume value */ g_object_get (G_OBJECT (playbin), "volume", &volume, NULL); /* media operation - hide your mouth for down the volume of the video */ if (have_mouth_y == 0 && have_mouth_x == 0) { volume = volume - 0.5; if (volume <= 0.5) volume = 0.0; g_object_set (G_OBJECT (playbin), "volume", volume, NULL); } /* media operation - hide your nose for up the volume of the video */ if (have_nose_y == 0 && have_nose_x == 0) { volume = volume + 0.5; if (volume >= 9.5) volume = 10.0; g_object_set (G_OBJECT (playbin), "volume", volume, NULL); } } /* if face is not detected */ } else { /* media operation - hide your face to stop media play */ gst_element_set_state (playbin, GST_STATE_PAUSED); } } gst_message_unref (message); return GST_BUS_DROP; }
static void handle_player_info (G_GNUC_UNUSED SoupSession *session, SoupMessage *msg, SnraClient *client) { SoupBuffer *buffer; if (msg->status_code < 200 || msg->status_code >= 300) return; buffer = soup_message_body_flatten (msg->response_body); if (json_parser_load_from_data (client->json, buffer->data, buffer->length, NULL)) { const GValue *v1; GArray *player_info = NULL; gsize i; JsonNode *root = json_parser_get_root (client->json); GstStructure *s1 = snra_json_to_gst_structure (root); if (s1 == NULL) return; /* Invalid chunk */ v1 = gst_structure_get_value (s1, "player-clients"); if (!GST_VALUE_HOLDS_ARRAY (v1)) goto failed; player_info = g_array_sized_new (TRUE, TRUE, sizeof (SnraPlayerInfo), gst_value_array_get_size (v1)); for (i = 0; i < gst_value_array_get_size (v1); i++) { SnraPlayerInfo info; const GValue *v2 = gst_value_array_get_value (v1, i); const GstStructure *s2; gint64 client_id; if (!GST_VALUE_HOLDS_STRUCTURE (v2)) goto failed; s2 = gst_value_get_structure (v2); if (!snra_json_structure_get_int64 (s2, "client-id", &client_id)) goto failed; info.id = client_id; if (!snra_json_structure_get_boolean (s2, "enabled", &info.enabled)) goto failed; if (!snra_json_structure_get_double (s2, "volume", &info.volume)) goto failed; if (!(info.host = g_strdup (gst_structure_get_string (s2, "host")))) goto failed; g_array_append_val (player_info, info); } free_player_info (client->player_info); client->player_info = player_info; player_info = NULL; g_signal_emit (client, signals[SIGNAL_PLAYER_INFO_CHANGED], 0); failed: if (player_info) free_player_info (player_info); gst_structure_free (s1); } }
static void print_element_properties_info (GstElement * element) { GParamSpec **property_specs; guint num_properties, i; gboolean readable; gboolean first_flag; property_specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (element), &num_properties); n_print ("\n"); n_print ("Element Properties:\n"); for (i = 0; i < num_properties; i++) { GValue value = { 0, }; GParamSpec *param = property_specs[i]; readable = FALSE; g_value_init (&value, param->value_type); n_print (" %-20s: %s\n", g_param_spec_get_name (param), g_param_spec_get_blurb (param)); first_flag = TRUE; n_print ("%-23.23s flags: ", ""); if (param->flags & G_PARAM_READABLE) { g_object_get_property (G_OBJECT (element), param->name, &value); readable = TRUE; g_print ("%s%s", (first_flag) ? "" : ", ", _("readable")); first_flag = FALSE; } else { /* if we can't read the property value, assume it's set to the default * (which might not be entirely true for sub-classes, but that's an * unlikely corner-case anyway) */ g_param_value_set_default (param, &value); } if (param->flags & G_PARAM_WRITABLE) { g_print ("%s%s", (first_flag) ? "" : ", ", _("writable")); first_flag = FALSE; } if (param->flags & G_PARAM_DEPRECATED) { g_print ("%s%s", (first_flag) ? "" : ", ", _("deprecated")); first_flag = FALSE; } if (param->flags & GST_PARAM_CONTROLLABLE) { g_print (", %s", _("controllable")); first_flag = FALSE; } if (param->flags & GST_PARAM_MUTABLE_PLAYING) { g_print (", %s", _("changeable in NULL, READY, PAUSED or PLAYING state")); } else if (param->flags & GST_PARAM_MUTABLE_PAUSED) { g_print (", %s", _("changeable only in NULL, READY or PAUSED state")); } else if (param->flags & GST_PARAM_MUTABLE_READY) { g_print (", %s", _("changeable only in NULL or READY state")); } if (param->flags & ~KNOWN_PARAM_FLAGS) { g_print ("%s0x%0x", (first_flag) ? "" : ", ", param->flags & ~KNOWN_PARAM_FLAGS); } n_print ("\n"); switch (G_VALUE_TYPE (&value)) { case G_TYPE_STRING: { const char *string_val = g_value_get_string (&value); n_print ("%-23.23s String. ", ""); if (string_val == NULL) g_print ("Default: null"); else g_print ("Default: \"%s\"", string_val); break; } case G_TYPE_BOOLEAN: { gboolean bool_val = g_value_get_boolean (&value); n_print ("%-23.23s Boolean. ", ""); g_print ("Default: %s", bool_val ? "true" : "false"); break; } case G_TYPE_ULONG: { GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param); n_print ("%-23.23s Unsigned Long. ", ""); g_print ("Range: %lu - %lu Default: %lu ", pulong->minimum, pulong->maximum, g_value_get_ulong (&value)); GST_ERROR ("%s: property '%s' of type ulong: consider changing to " "uint/uint64", GST_OBJECT_NAME (element), g_param_spec_get_name (param)); break; } case G_TYPE_LONG: { GParamSpecLong *plong = G_PARAM_SPEC_LONG (param); n_print ("%-23.23s Long. ", ""); g_print ("Range: %ld - %ld Default: %ld ", plong->minimum, plong->maximum, g_value_get_long (&value)); GST_ERROR ("%s: property '%s' of type long: consider changing to " "int/int64", GST_OBJECT_NAME (element), g_param_spec_get_name (param)); break; } case G_TYPE_UINT: { GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param); n_print ("%-23.23s Unsigned Integer. ", ""); g_print ("Range: %u - %u Default: %u ", puint->minimum, puint->maximum, g_value_get_uint (&value)); break; } case G_TYPE_INT: { GParamSpecInt *pint = G_PARAM_SPEC_INT (param); n_print ("%-23.23s Integer. ", ""); g_print ("Range: %d - %d Default: %d ", pint->minimum, pint->maximum, g_value_get_int (&value)); break; } case G_TYPE_UINT64: { GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param); n_print ("%-23.23s Unsigned Integer64. ", ""); g_print ("Range: %" G_GUINT64_FORMAT " - %" G_GUINT64_FORMAT " Default: %" G_GUINT64_FORMAT " ", puint64->minimum, puint64->maximum, g_value_get_uint64 (&value)); break; } case G_TYPE_INT64: { GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param); n_print ("%-23.23s Integer64. ", ""); g_print ("Range: %" G_GINT64_FORMAT " - %" G_GINT64_FORMAT " Default: %" G_GINT64_FORMAT " ", pint64->minimum, pint64->maximum, g_value_get_int64 (&value)); break; } case G_TYPE_FLOAT: { GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param); n_print ("%-23.23s Float. ", ""); g_print ("Range: %15.7g - %15.7g Default: %15.7g ", pfloat->minimum, pfloat->maximum, g_value_get_float (&value)); break; } case G_TYPE_DOUBLE: { GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param); n_print ("%-23.23s Double. ", ""); g_print ("Range: %15.7g - %15.7g Default: %15.7g ", pdouble->minimum, pdouble->maximum, g_value_get_double (&value)); break; } case G_TYPE_CHAR: case G_TYPE_UCHAR: GST_ERROR ("%s: property '%s' of type char: consider changing to " "int/string", GST_OBJECT_NAME (element), g_param_spec_get_name (param)); /* fall through */ default: if (param->value_type == GST_TYPE_CAPS) { const GstCaps *caps = gst_value_get_caps (&value); if (!caps) n_print ("%-23.23s Caps (NULL)", ""); else { print_caps (caps, " "); } } else if (G_IS_PARAM_SPEC_ENUM (param)) { GEnumValue *values; guint j = 0; gint enum_value; const gchar *value_nick = ""; values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values; enum_value = g_value_get_enum (&value); while (values[j].value_name) { if (values[j].value == enum_value) value_nick = values[j].value_nick; j++; } n_print ("%-23.23s Enum \"%s\" Default: %d, \"%s\"", "", g_type_name (G_VALUE_TYPE (&value)), enum_value, value_nick); j = 0; while (values[j].value_name) { g_print ("\n"); if (_name) g_print ("%s", _name); g_print ("%-23.23s (%d): %-16s - %s", "", values[j].value, values[j].value_nick, values[j].value_name); j++; } /* g_type_class_unref (ec); */ } else if (G_IS_PARAM_SPEC_FLAGS (param)) { GParamSpecFlags *pflags = G_PARAM_SPEC_FLAGS (param); GFlagsValue *vals; gchar *cur; vals = pflags->flags_class->values; cur = flags_to_string (vals, g_value_get_flags (&value)); n_print ("%-23.23s Flags \"%s\" Default: 0x%08x, \"%s\"", "", g_type_name (G_VALUE_TYPE (&value)), g_value_get_flags (&value), cur); while (vals[0].value_name) { g_print ("\n"); if (_name) g_print ("%s", _name); g_print ("%-23.23s (0x%08x): %-16s - %s", "", vals[0].value, vals[0].value_nick, vals[0].value_name); ++vals; } g_free (cur); } else if (G_IS_PARAM_SPEC_OBJECT (param)) { n_print ("%-23.23s Object of type \"%s\"", "", g_type_name (param->value_type)); } else if (G_IS_PARAM_SPEC_BOXED (param)) { n_print ("%-23.23s Boxed pointer of type \"%s\"", "", g_type_name (param->value_type)); if (param->value_type == GST_TYPE_STRUCTURE) { const GstStructure *s = gst_value_get_structure (&value); if (s) gst_structure_foreach (s, print_field, (gpointer) " "); } } else if (G_IS_PARAM_SPEC_POINTER (param)) { if (param->value_type != G_TYPE_POINTER) { n_print ("%-23.23s Pointer of type \"%s\".", "", g_type_name (param->value_type)); } else { n_print ("%-23.23s Pointer.", ""); } } else if (param->value_type == G_TYPE_VALUE_ARRAY) { GParamSpecValueArray *pvarray = G_PARAM_SPEC_VALUE_ARRAY (param); if (pvarray->element_spec) { n_print ("%-23.23s Array of GValues of type \"%s\"", "", g_type_name (pvarray->element_spec->value_type)); } else { n_print ("%-23.23s Array of GValues", ""); } } else if (GST_IS_PARAM_SPEC_FRACTION (param)) { GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION (param); n_print ("%-23.23s Fraction. ", ""); g_print ("Range: %d/%d - %d/%d Default: %d/%d ", pfraction->min_num, pfraction->min_den, pfraction->max_num, pfraction->max_den, gst_value_get_fraction_numerator (&value), gst_value_get_fraction_denominator (&value)); } else { n_print ("%-23.23s Unknown type %ld \"%s\"", "", (glong) param->value_type, g_type_name (param->value_type)); } break; } if (!readable) g_print (" Write only\n"); else g_print ("\n"); g_value_reset (&value); } if (num_properties == 0) n_print (" none\n"); g_free (property_specs); }