gboolean message_handler (GstBus * bus, GstMessage * message, gpointer data) { if (message->type == GST_MESSAGE_ELEMENT) { const GstStructure *s = gst_message_get_structure (message); const gchar *name = gst_structure_get_name (s); if (strcmp (name, "level") == 0) { gint channels; GstClockTime endtime; gdouble rms_dB, peak_dB, decay_dB; gdouble rms; const GValue *list; const GValue *value; gint i; if (!gst_structure_get_clock_time (s, "endtime", &endtime)) g_warning ("Could not parse endtime"); /* we can get the number of channels as the length of any of the value * lists */ list = gst_structure_get_value (s, "rms"); channels = gst_value_list_get_size (list); g_print ("endtime: %" GST_TIME_FORMAT ", channels: %d\n", GST_TIME_ARGS (endtime), channels); for (i = 0; i < channels; ++i) { g_print ("channel %d\n", i); list = gst_structure_get_value (s, "rms"); value = gst_value_list_get_value (list, i); rms_dB = g_value_get_double (value); list = gst_structure_get_value (s, "peak"); value = gst_value_list_get_value (list, i); peak_dB = g_value_get_double (value); list = gst_structure_get_value (s, "decay"); value = gst_value_list_get_value (list, i); decay_dB = g_value_get_double (value); g_print (" RMS: %f dB, peak: %f dB, decay: %f dB\n", rms_dB, peak_dB, decay_dB); /* converting from dB to normal gives us a value between 0.0 and 1.0 */ rms = pow (10, rms_dB / 20); g_print (" normalized rms value: %f\n", rms); } } } /* we handled the message we want, and ignored the ones we didn't want. * so the core can unref the message for us */ return TRUE; }
static VALUE value_list_gvalue2rvalue(const GValue *value) { guint i, len; VALUE result; len = gst_value_list_get_size(value); result = rb_ary_new2(len); for (i = 0; i < len; i++) { rb_ary_push(result, GVAL2RVAL(gst_value_list_get_value(value, i))); } return result; }
static void check_pad_template (GstPadTemplate * tmpl) { const GValue *list_val, *fmt_val; GstStructure *s; gboolean *formats_supported; GstCaps *caps; guint i, num_formats; num_formats = get_num_formats (); formats_supported = g_new0 (gboolean, num_formats); caps = gst_pad_template_get_caps (tmpl); /* If this fails, we need to update this unit test */ fail_unless_equals_int (gst_caps_get_size (caps), 1); s = gst_caps_get_structure (caps, 0); fail_unless (gst_structure_has_name (s, "video/x-raw")); list_val = gst_structure_get_value (s, "format"); fail_unless (list_val != NULL); /* If this fails, we need to update this unit test */ fail_unless (GST_VALUE_HOLDS_LIST (list_val)); for (i = 0; i < gst_value_list_get_size (list_val); ++i) { GstVideoFormat fmt; const gchar *fmt_str; fmt_val = gst_value_list_get_value (list_val, i); fail_unless (G_VALUE_HOLDS_STRING (fmt_val)); fmt_str = g_value_get_string (fmt_val); GST_LOG ("format string: '%s'", fmt_str); fmt = gst_video_format_from_string (fmt_str); fail_unless (fmt != GST_VIDEO_FORMAT_UNKNOWN); formats_supported[(guint) fmt] = TRUE; } gst_caps_unref (caps); for (i = 2; i < num_formats; ++i) { if (!formats_supported[i]) { g_error ("videoconvert doesn't support format '%s'", gst_video_format_to_string ((GstVideoFormat) i)); } } g_free (formats_supported); }
static void dvb_base_bin_pat_info_cb (DvbBaseBin * dvbbasebin, const GstStructure * pat_info) { DvbBaseBinProgram *program; DvbBaseBinStream *stream; const GValue *value; GstStructure *program_info; guint program_number; guint pid; guint old_pmt_pid; gint i; gboolean rebuild_filter = FALSE; const GValue *programs; programs = gst_structure_get_value (pat_info, "programs"); for (i = 0; i < gst_value_list_get_size (programs); ++i) { value = gst_value_list_get_value (programs, i); program_info = g_value_get_boxed (value); gst_structure_get_uint (program_info, "program-number", &program_number); gst_structure_get_uint (program_info, "pid", &pid); program = dvb_base_bin_get_program (dvbbasebin, program_number); if (program == NULL) program = dvb_base_bin_add_program (dvbbasebin, program_number); old_pmt_pid = program->pmt_pid; program->pmt_pid = pid; if (program->selected) { /* PAT update */ if (old_pmt_pid != G_MAXUINT16 && old_pmt_pid != program->pmt_pid) dvb_base_bin_get_stream (dvbbasebin, old_pmt_pid)->usecount -= 1; stream = dvb_base_bin_get_stream (dvbbasebin, program->pmt_pid); if (stream == NULL) stream = dvb_base_bin_add_stream (dvbbasebin, program->pmt_pid); stream->usecount += 1; rebuild_filter = TRUE; } } if (rebuild_filter) dvb_base_bin_rebuild_filter (dvbbasebin); }
static void get_supported_framerates (ofGstVideoFormat &video_format, GstStructure &structure) { const GValue *framerates; ofGstFramerate framerate; framerates = gst_structure_get_value (&structure, "framerate"); if (GST_VALUE_HOLDS_FRACTION (framerates)){ framerate.numerator = gst_value_get_fraction_numerator (framerates); framerate.denominator = gst_value_get_fraction_denominator (framerates); video_format.framerates.push_back(framerate); ofLog(OF_LOG_NOTICE,"%d/%d ", framerate.numerator, framerate.denominator); }else if (GST_VALUE_HOLDS_LIST (framerates)){ int num_framerates = gst_value_list_get_size (framerates); for (int i = 0; i < num_framerates; i++){ const GValue *value = gst_value_list_get_value (framerates, i); framerate.numerator = gst_value_get_fraction_numerator (value); framerate.denominator = gst_value_get_fraction_denominator (value); video_format.framerates.push_back(framerate); ofLog(OF_LOG_NOTICE,"%d/%d ", framerate.numerator, framerate.denominator); } }else if (GST_VALUE_HOLDS_FRACTION_RANGE (framerates)){ int numerator_min, denominator_min, numerator_max, denominator_max; const GValue *fraction_range_min; const GValue *fraction_range_max; fraction_range_min = gst_value_get_fraction_range_min (framerates); numerator_min = gst_value_get_fraction_numerator (fraction_range_min); denominator_min = gst_value_get_fraction_denominator (fraction_range_min); fraction_range_max = gst_value_get_fraction_range_max (framerates); numerator_max = gst_value_get_fraction_numerator (fraction_range_max); denominator_max = gst_value_get_fraction_denominator (fraction_range_max); ofLog(OF_LOG_NOTICE,"from %d/%d to %d/%d", numerator_min, denominator_max, numerator_max, denominator_min); for (int i = numerator_min; i <= numerator_max; i++){ for (int j = denominator_min; j <= denominator_max; j++){ framerate.numerator = i; framerate.denominator = j; video_format.framerates.push_back(framerate); } } }else{ ofLog (OF_LOG_WARNING,"unknown GValue type %s for framerates", G_VALUE_TYPE_NAME (framerates)); } }
static GstCaps * gst_real_video_dec_getcaps (GstPad * pad) { GstRealVideoDec *dec = GST_REAL_VIDEO_DEC (GST_PAD_PARENT (pad)); GstCaps *res; if (dec->checked_modules) { GValue versions = { 0 }; GValue version = { 0 }; GST_LOG_OBJECT (dec, "constructing caps"); res = gst_caps_new_empty (); g_value_init (&versions, GST_TYPE_LIST); g_value_init (&version, G_TYPE_INT); if (dec->valid_rv20) { g_value_set_int (&version, GST_REAL_VIDEO_DEC_VERSION_2); gst_value_list_append_value (&versions, &version); } if (dec->valid_rv30) { g_value_set_int (&version, GST_REAL_VIDEO_DEC_VERSION_3); gst_value_list_append_value (&versions, &version); } if (dec->valid_rv40) { g_value_set_int (&version, GST_REAL_VIDEO_DEC_VERSION_4); gst_value_list_append_value (&versions, &version); } if (gst_value_list_get_size (&versions) > 0) { res = gst_caps_new_simple ("video/x-pn-realvideo", NULL); gst_structure_set_value (gst_caps_get_structure (res, 0), "rmversion", &versions); } else { res = gst_caps_new_empty (); } g_value_unset (&versions); g_value_unset (&version); } else { GST_LOG_OBJECT (dec, "returning padtemplate caps"); res = gst_caps_copy (gst_pad_get_pad_template_caps (pad)); } GST_LOG_OBJECT (dec, "returning caps %" GST_PTR_FORMAT, res); return res; }
static GstVideoFormat gst_vaapi_find_preferred_format (const GValue * format_list, GstVideoFormat native_format) { const GValue *frmt; GstVideoFormat out_format; guint i; /* if one format, that is the one */ if (G_VALUE_HOLDS_STRING (format_list)) return gst_video_format_from_string (g_value_get_string (format_list)); if (!GST_VALUE_HOLDS_LIST (format_list)) { GST_ERROR ("negotiated caps do not have a valid format"); return GST_VIDEO_FORMAT_UNKNOWN; } if (native_format == GST_VIDEO_FORMAT_UNKNOWN || native_format == GST_VIDEO_FORMAT_ENCODED) { native_format = GST_VIDEO_FORMAT_NV12; /* default VA format */ } /* search our native format in the list */ for (i = 0; i < gst_value_list_get_size (format_list); i++) { frmt = gst_value_list_get_value (format_list, i); out_format = gst_video_format_from_string (g_value_get_string (frmt)); /* GStreamer do not handle encoded formats nicely. Try the next * one. */ if (out_format == GST_VIDEO_FORMAT_ENCODED) continue; if (native_format == out_format) return out_format; } /* just pick the first valid format in the list */ i = 0; do { frmt = gst_value_list_get_value (format_list, i++); out_format = gst_video_format_from_string (g_value_get_string (frmt)); } while (out_format == GST_VIDEO_FORMAT_ENCODED); return out_format; }
EXPORT_C #endif guint gst_tag_list_get_tag_size (const GstTagList * list, const gchar * tag) { const GValue *value; g_return_val_if_fail (GST_IS_TAG_LIST (list), 0); value = gst_structure_get_value ((GstStructure *) list, tag); if (value == NULL) return 0; if (G_VALUE_TYPE (value) != GST_TYPE_LIST) return 1; return gst_value_list_get_size (value); }
/** * gst_query_parse_formats_length: * @query: a #GstQuery * @n_formats: the number of formats in this query. * * Parse the number of formats in the formats @query. * * Since: 0.10.4 */ void gst_query_parse_formats_length (GstQuery * query, guint * n_formats) { GstStructure *structure; g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS); if (n_formats) { const GValue *list; structure = gst_query_get_structure (query); list = gst_structure_get_value (structure, "formats"); if (list == NULL) *n_formats = 0; else *n_formats = gst_value_list_get_size (list); } }
/** * gst_navigation_query_parse_commands_length: * @query: a #GstQuery * @n_cmds: the number of commands in this query. * * Parse the number of commands in the #GstNavigation commands @query. * * Returns: %TRUE if the query could be successfully parsed. %FALSE if not. * Since: 0.10.23 */ gboolean gst_navigation_query_parse_commands_length (GstQuery * query, guint * n_cmds) { GstStructure *structure; const GValue *list; g_return_val_if_fail (GST_NAVIGATION_QUERY_HAS_TYPE (query, COMMANDS), FALSE); if (n_cmds == NULL) return TRUE; structure = gst_query_get_structure (query); list = gst_structure_get_value (structure, "commands"); if (list == NULL) *n_cmds = 0; else *n_cmds = gst_value_list_get_size (list); return TRUE; }
/** * gst_query_parse_formats_nth: * @query: a #GstQuery * @nth: the nth format to retrieve. * @format: a pointer to store the nth format * * Parse the format query and retrieve the @nth format from it into * @format. If the list contains less elements than @nth, @format will be * set to GST_FORMAT_UNDEFINED. * * Since: 0.10.4 */ void gst_query_parse_formats_nth (GstQuery * query, guint nth, GstFormat * format) { GstStructure *structure; g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS); if (format) { const GValue *list; structure = gst_query_get_structure (query); list = gst_structure_get_value (structure, "formats"); if (list == NULL) { *format = GST_FORMAT_UNDEFINED; } else { if (nth < gst_value_list_get_size (list)) { *format = g_value_get_enum (gst_value_list_get_value (list, nth)); } else *format = GST_FORMAT_UNDEFINED; } } }
static void lgm_device_parse_structure (GstStructure * s, GHashTable * table) { gint width, height; const GValue *val; gchar *struct_str; struct_str = gst_structure_to_string (s); GST_DEBUG ("Parsing structure: %s\n", struct_str); g_free (struct_str); width = lgm_device_fixate_int_value (gst_structure_get_value (s, "width")); height = lgm_device_fixate_int_value (gst_structure_get_value (s, "height")); val = gst_structure_get_value (s, "framerate"); if (G_VALUE_TYPE (val) == GST_TYPE_FRACTION) { lgm_device_add_format_from_fps_val (table, width, height, val); } else if (G_VALUE_TYPE (val) == GST_TYPE_FRACTION_RANGE) { /* For sources returning template caps or ranges set framerate to 0/0 */ lgm_device_add_format (table, width, height, 0, 0); } else if (G_VALUE_TYPE (val) == GST_TYPE_ARRAY) { guint n, len; len = gst_value_array_get_size (val); for (n = 0; n < len; n++) { const GValue *kid = gst_value_array_get_value (val, n); lgm_device_add_format_from_fps_val (table, width, height, kid); } } else if (G_VALUE_TYPE (val) == GST_TYPE_LIST) { guint n, len; len = gst_value_list_get_size (val); for (n = 0; n < len; n++) { const GValue *kid = gst_value_list_get_value (val, n); lgm_device_add_format_from_fps_val (table, width, height, kid); } } }
EXPORT_C #endif void gst_tag_merge_strings_with_comma (GValue * dest, const GValue * src) { GString *str; gint i, count; count = gst_value_list_get_size (src); str = g_string_new (g_value_get_string (gst_value_list_get_value (src, 0))); for (i = 1; i < count; i++) { /* seperator between two string */ str = g_string_append (str, _(", ")); str = g_string_append (str, g_value_get_string (gst_value_list_get_value (src, 1))); } g_value_init (dest, G_TYPE_STRING); g_value_set_string_take_ownership (dest, str->str); g_string_free (str, FALSE); }
/* * Selects one mode from the ones on the list */ const gchar *gst_sbc_get_mode_from_list(const GValue *list, gint channels) { unsigned int i; const GValue *value; const gchar *aux; gboolean joint, stereo, dual, mono; guint size = gst_value_list_get_size(list); joint = stereo = dual = mono = FALSE; for (i = 0; i < size; i++) { value = gst_value_list_get_value(list, i); aux = g_value_get_string(value); if (strcmp("joint", aux) == 0) joint = TRUE; else if (strcmp("stereo", aux) == 0) stereo = TRUE; else if (strcmp("dual", aux) == 0) dual = TRUE; else if (strcmp("mono", aux) == 0) mono = TRUE; } if (channels == 1 && mono) return "mono"; else if (channels == 2) { if (joint) return "joint"; else if (stereo) return "stereo"; else if (dual) return "dual"; } return NULL; }
static GstCaps * gst_smpte_alpha_transform_caps (GstBaseTransform * trans, GstPadDirection direction, GstCaps * from, GstCaps * filter) { GstCaps *result, *tmp_caps, *tmpl_caps = NULL; gint i, j; tmp_caps = gst_caps_new_empty (); for (i = 0; i < gst_caps_get_size (from); i++) { GstStructure *structure; const GValue *val, *lval; GValue list = { 0, }; GValue aval = { 0, }; const gchar *str; structure = gst_structure_copy (gst_caps_get_structure (from, i)); /* we can transform I420 to AYUV, * so need to locate and substitute AYUV for the both of them */ val = gst_structure_get_value (structure, "format"); if (val && GST_VALUE_HOLDS_LIST (val)) { gboolean seen_ayuv = FALSE, seen_i420 = FALSE; g_value_init (&list, GST_TYPE_LIST); for (j = 0; j < gst_value_list_get_size (val); j++) { lval = gst_value_list_get_value (val, j); if ((str = g_value_get_string (lval))) { if (strcmp (str, "AYUV") == 0) { seen_ayuv = TRUE; } else if (strcmp (str, "I420") == 0) { seen_i420 = TRUE; } } } if (seen_ayuv && !seen_i420) { str = "I420"; } else if (seen_i420 && !seen_ayuv) { str = "AYUV"; } else str = NULL; if (str) { g_value_copy (val, &list); g_value_init (&aval, G_TYPE_STRING); g_value_set_string (&aval, str); gst_value_list_append_value (&list, &aval); g_value_reset (&aval); gst_structure_set_value (structure, "format", &list); g_value_unset (&list); } } else if (val && G_VALUE_HOLDS_STRING (val)) { if ((str = g_value_get_string (val)) && ((strcmp (str, "AYUV") == 0) || (strcmp (str, "I420") == 0))) { g_value_init (&list, GST_TYPE_LIST); g_value_init (&aval, G_TYPE_STRING); g_value_set_string (&aval, "AYUV"); gst_value_list_append_value (&list, &aval); g_value_reset (&aval); g_value_set_string (&aval, "I420"); gst_value_list_append_value (&list, &aval); g_value_reset (&aval); gst_structure_set_value (structure, "format", &list); g_value_unset (&list); } } else { gst_structure_remove_field (structure, "format"); } gst_structure_remove_field (structure, "colorimetry"); gst_structure_remove_field (structure, "chroma-site"); gst_caps_append_structure (tmp_caps, structure); } /* Get the appropriate template */ if (direction == GST_PAD_SINK) { tmpl_caps = gst_static_pad_template_get_caps (&gst_smpte_alpha_src_template); } else if (direction == GST_PAD_SRC) { tmpl_caps = gst_static_pad_template_get_caps (&gst_smpte_alpha_sink_template); } else { g_assert_not_reached (); } /* Intersect with our template caps */ result = gst_caps_intersect (tmp_caps, tmpl_caps); gst_caps_unref (tmpl_caps); gst_caps_unref (tmp_caps); result = gst_caps_simplify (result); GST_LOG_OBJECT (trans, "transformed %" GST_PTR_FORMAT " to %" GST_PTR_FORMAT, from, result); if (filter) { GstCaps *intersection; GST_DEBUG_OBJECT (trans, "Using filter caps %" GST_PTR_FORMAT, filter); intersection = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST); gst_caps_unref (result); result = intersection; GST_DEBUG_OBJECT (trans, "Intersection %" GST_PTR_FORMAT, result); } return result; }
/** * Tries to guess the frame rate for a V4L2 source. */ std::string Pipeline::guess_source_caps(unsigned int framerateIndex) const { bool is_verbose = owner_->get_configuration()->get_verbose(); if (is_verbose) LOG_DEBUG("Trying to guess source FPS " << framerateIndex); std::ostringstream capsStr; GstStateChangeReturn ret = gst_element_set_state(videosrc_, GST_STATE_READY); if (ret not_eq GST_STATE_CHANGE_SUCCESS) THROW_ERROR("Could not change v4l2src state to READY"); GstPad *srcPad = gst_element_get_static_pad(videosrc_, "src"); GstCaps *caps = gst_pad_get_caps(srcPad); GstStructure *structure = gst_caps_get_structure(caps, 0); const GValue *val = gst_structure_get_value(structure, "framerate"); if (is_verbose) LOG_DEBUG("Caps structure from v4l2src srcpad: " << gst_structure_to_string(structure)); gint framerate_numerator = 1; gint framerate_denominator = 1; if (GST_VALUE_HOLDS_LIST(val)) { // trying another one if (framerateIndex >= gst_value_list_get_size(val)) THROW_ERROR("Framerate index out of range"); framerate_numerator = gst_value_get_fraction_numerator((gst_value_list_get_value(val, framerateIndex))); framerate_denominator = gst_value_get_fraction_denominator((gst_value_list_get_value(val, framerateIndex))); } else { // FIXME: this is really bad, we should be iterating over framerates and resolutions until we find a good one if (framerateIndex > 0) LOG_ERROR("Caps parameters haven't been changed and have failed before"); framerate_numerator = gst_value_get_fraction_numerator(val); framerate_denominator = gst_value_get_fraction_denominator(val); } gst_caps_unref(caps); gst_object_unref(srcPad); // use default from gst std::string capsSuffix = boost::lexical_cast<std::string>(framerate_numerator); capsSuffix += "/"; capsSuffix += boost::lexical_cast<std::string>(framerate_denominator); // TODO: handle interlaced video capture stream if (v4l2util::isInterlaced(owner_->get_configuration()->videoSource())) { capsSuffix +=", interlaced=true"; } // TODO: handle aspect ratio // capsSuffix += ", pixel-aspect-ratio=1/1"; //capsSuffix += config_.pixelAspectRatio(); //capsSuffix += "4:3"; Configuration *config = owner_->get_configuration(); capsStr << "video/x-raw-yuv, width=" << config->get_capture_width() << ", height=" << config->get_capture_height() << ", framerate=" << capsSuffix; if (is_verbose) LOG_DEBUG("Video source caps are " << capsStr.str()); ret = gst_element_set_state(videosrc_, GST_STATE_NULL); if (ret not_eq GST_STATE_CHANGE_SUCCESS) THROW_ERROR("Could not change v4l2src state to NULL"); return capsStr.str(); }
static gboolean gst_video_crop_transform_dimension_value (const GValue * src_val, gint delta, GValue * dest_val, GstPadDirection direction, gboolean dynamic) { gboolean ret = TRUE; if (G_VALUE_HOLDS_INT (src_val)) { gint ival = g_value_get_int (src_val); ival = gst_video_crop_transform_dimension (ival, delta); if (dynamic) { if (direction == GST_PAD_SRC) { if (ival == G_MAXINT) { g_value_init (dest_val, G_TYPE_INT); g_value_set_int (dest_val, ival); } else { g_value_init (dest_val, GST_TYPE_INT_RANGE); gst_value_set_int_range (dest_val, ival, G_MAXINT); } } else { if (ival == 1) { g_value_init (dest_val, G_TYPE_INT); g_value_set_int (dest_val, ival); } else { g_value_init (dest_val, GST_TYPE_INT_RANGE); gst_value_set_int_range (dest_val, 1, ival); } } } else { g_value_init (dest_val, G_TYPE_INT); g_value_set_int (dest_val, ival); } } else if (GST_VALUE_HOLDS_INT_RANGE (src_val)) { gint min = gst_value_get_int_range_min (src_val); gint max = gst_value_get_int_range_max (src_val); min = gst_video_crop_transform_dimension (min, delta); max = gst_video_crop_transform_dimension (max, delta); if (dynamic) { if (direction == GST_PAD_SRC) max = G_MAXINT; else min = 1; } if (min == max) { g_value_init (dest_val, G_TYPE_INT); g_value_set_int (dest_val, min); } else { g_value_init (dest_val, GST_TYPE_INT_RANGE); gst_value_set_int_range (dest_val, min, max); } } else if (GST_VALUE_HOLDS_LIST (src_val)) { gint i; g_value_init (dest_val, GST_TYPE_LIST); for (i = 0; i < gst_value_list_get_size (src_val); ++i) { const GValue *list_val; GValue newval = { 0, }; list_val = gst_value_list_get_value (src_val, i); if (gst_video_crop_transform_dimension_value (list_val, delta, &newval, direction, dynamic)) gst_value_list_append_value (dest_val, &newval); g_value_unset (&newval); } if (gst_value_list_get_size (dest_val) == 0) { g_value_unset (dest_val); ret = FALSE; } } else { ret = FALSE; } return ret; }
/* * Selects one number of subbands from a list * TODO - use a better approach to this (it is selecting the last element) */ gint gst_sbc_select_subbands_from_list(const GValue *value) { guint size = gst_value_list_get_size(value); return g_value_get_int(gst_value_list_get_value(value, size-1)); }
static void check_pad_template (GstPadTemplate * tmpl) { const GValue *list_val, *fmt_val; GstStructure *s; gboolean *formats_supported; GstCaps *caps; guint i, num_formats; num_formats = get_num_formats (); formats_supported = g_new0 (gboolean, num_formats); caps = gst_pad_template_get_caps (tmpl); /* If this fails, we need to update this unit test */ fail_unless_equals_int (gst_caps_get_size (caps), 2); /* Remove the ANY caps features structure */ caps = gst_caps_truncate (caps); s = gst_caps_get_structure (caps, 0); fail_unless (gst_structure_has_name (s, "video/x-raw")); list_val = gst_structure_get_value (s, "format"); fail_unless (list_val != NULL); /* If this fails, we need to update this unit test */ fail_unless (GST_VALUE_HOLDS_LIST (list_val)); for (i = 0; i < gst_value_list_get_size (list_val); ++i) { GstVideoFormat fmt; const gchar *fmt_str; fmt_val = gst_value_list_get_value (list_val, i); fail_unless (G_VALUE_HOLDS_STRING (fmt_val)); fmt_str = g_value_get_string (fmt_val); GST_LOG ("format string: '%s'", fmt_str); fmt = gst_video_format_from_string (fmt_str); if (fmt == GST_VIDEO_FORMAT_UNKNOWN) g_error ("Unknown raw format '%s' in pad template caps", fmt_str); formats_supported[(guint) fmt] = TRUE; } gst_caps_unref (caps); for (i = 2; i < num_formats; ++i) { if (!formats_supported[i]) { const gchar *fmt_str = gst_video_format_to_string ((GstVideoFormat) i); switch (i) { case GST_VIDEO_FORMAT_v210: case GST_VIDEO_FORMAT_v216: case GST_VIDEO_FORMAT_NV12: case GST_VIDEO_FORMAT_NV16: case GST_VIDEO_FORMAT_NV21: case GST_VIDEO_FORMAT_NV24: case GST_VIDEO_FORMAT_UYVP: case GST_VIDEO_FORMAT_A420: case GST_VIDEO_FORMAT_YUV9: case GST_VIDEO_FORMAT_YVU9: case GST_VIDEO_FORMAT_IYU1: case GST_VIDEO_FORMAT_r210:{ static gboolean shown_fixme[100] = { FALSE, }; if (!shown_fixme[i]) { GST_FIXME ("FIXME: add %s support to videoscale", fmt_str); shown_fixme[i] = TRUE; } break; } case GST_VIDEO_FORMAT_BGR16: case GST_VIDEO_FORMAT_BGR15: case GST_VIDEO_FORMAT_RGB8P: case GST_VIDEO_FORMAT_I420_10BE: case GST_VIDEO_FORMAT_I420_10LE: case GST_VIDEO_FORMAT_I422_10BE: case GST_VIDEO_FORMAT_I422_10LE: case GST_VIDEO_FORMAT_Y444_10BE: case GST_VIDEO_FORMAT_Y444_10LE: case GST_VIDEO_FORMAT_GBR: case GST_VIDEO_FORMAT_GBR_10BE: case GST_VIDEO_FORMAT_GBR_10LE: GST_LOG ("Ignoring lack of support for format %s", fmt_str); break; default: g_error ("videoscale doesn't support format '%s'", fmt_str); break; } } } g_free (formats_supported); }
/* * Selects one allocation mode from the ones on the list * TODO - use a better approach */ const gchar *gst_sbc_get_allocation_from_list(const GValue *value) { guint size = gst_value_list_get_size(value); return g_value_get_string(gst_value_list_get_value(value, size-1)); }
void test_simplify() { GstStructure *s1, *s2; gboolean did_simplify; GstCaps *caps; caps = gst_caps_from_string (non_simple_caps_string); fail_unless (caps != NULL, "gst_caps_from_string (non_simple_caps_string) failed"); did_simplify = gst_caps_do_simplify (caps); fail_unless (did_simplify == TRUE, "gst_caps_do_simplify() should have worked"); /* check simplified caps, should be: * * video/x-raw-rgb, bpp=(int)8, depth=(int)8, endianness=(int)1234, * framerate=(fraction)[ 1/100, 100 ], width=(int)[ 16, 4096 ], * height=(int)[ 16, 4096 ]; * video/x-raw-yuv, format=(fourcc){ YV12, YUY2, I420 }, * width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], * framerate=(fraction)[ 1/100, 100 ] */ fail_unless (gst_caps_get_size (caps) == 2); s1 = gst_caps_get_structure (caps, 0); s2 = gst_caps_get_structure (caps, 1); fail_unless (s1 != NULL); fail_unless (s2 != NULL); if (!gst_structure_has_name (s1, "video/x-raw-rgb")) { GstStructure *tmp; tmp = s1; s1 = s2; s2 = tmp; } fail_unless (gst_structure_has_name (s1, "video/x-raw-rgb")); { const GValue *framerate_value; const GValue *width_value; const GValue *height_value; const GValue *val_fps; GValue test_fps = { 0, }; gint bpp, depth, endianness; gint min_width, max_width; gint min_height, max_height; fail_unless (gst_structure_get_int (s1, "bpp", &bpp)); fail_unless (bpp == 8); fail_unless (gst_structure_get_int (s1, "depth", &depth)); fail_unless (depth == 8); fail_unless (gst_structure_get_int (s1, "endianness", &endianness)); fail_unless (endianness == G_LITTLE_ENDIAN); g_value_init (&test_fps, GST_TYPE_FRACTION); framerate_value = gst_structure_get_value (s1, "framerate"); fail_unless (framerate_value != NULL); fail_unless (GST_VALUE_HOLDS_FRACTION_RANGE (framerate_value)); val_fps = gst_value_get_fraction_range_min (framerate_value); gst_value_set_fraction (&test_fps, 1, 100); fail_unless (gst_value_compare (&test_fps, val_fps) == GST_VALUE_EQUAL); val_fps = gst_value_get_fraction_range_max (framerate_value); gst_value_set_fraction (&test_fps, 100, 1); fail_unless (gst_value_compare (&test_fps, val_fps) == GST_VALUE_EQUAL); g_value_unset (&test_fps); width_value = gst_structure_get_value (s1, "width"); fail_unless (width_value != NULL); fail_unless (GST_VALUE_HOLDS_INT_RANGE (width_value)); min_width = gst_value_get_int_range_min (width_value); max_width = gst_value_get_int_range_max (width_value); fail_unless (min_width == 16 && max_width == 4096); height_value = gst_structure_get_value (s1, "height"); fail_unless (height_value != NULL); fail_unless (GST_VALUE_HOLDS_INT_RANGE (height_value)); min_height = gst_value_get_int_range_min (height_value); max_height = gst_value_get_int_range_max (height_value); fail_unless (min_height == 16 && max_height == 4096); } fail_unless (gst_structure_has_name (s2, "video/x-raw-yuv")); { const GValue *framerate_value; const GValue *format_value; const GValue *width_value; const GValue *height_value; const GValue *val_fps; GValue test_fps = { 0, }; gint min_width, max_width; gint min_height, max_height; format_value = gst_structure_get_value (s2, "format"); fail_unless (format_value != NULL); fail_unless (GST_VALUE_HOLDS_LIST (format_value)); fail_unless (gst_value_list_get_size (format_value) == 3); fail_unless (check_fourcc_list (format_value) == TRUE); g_value_init (&test_fps, GST_TYPE_FRACTION); framerate_value = gst_structure_get_value (s2, "framerate"); fail_unless (framerate_value != NULL); fail_unless (GST_VALUE_HOLDS_FRACTION_RANGE (framerate_value)); val_fps = gst_value_get_fraction_range_min (framerate_value); gst_value_set_fraction (&test_fps, 1, 100); fail_unless (gst_value_compare (&test_fps, val_fps) == GST_VALUE_EQUAL); val_fps = gst_value_get_fraction_range_max (framerate_value); gst_value_set_fraction (&test_fps, 100, 1); fail_unless (gst_value_compare (&test_fps, val_fps) == GST_VALUE_EQUAL); g_value_unset (&test_fps); width_value = gst_structure_get_value (s2, "width"); fail_unless (width_value != NULL); fail_unless (GST_VALUE_HOLDS_INT_RANGE (width_value)); min_width = gst_value_get_int_range_min (width_value); max_width = gst_value_get_int_range_max (width_value); fail_unless (min_width == 16 && max_width == 4096); height_value = gst_structure_get_value (s2, "height"); fail_unless (height_value != NULL); fail_unless (GST_VALUE_HOLDS_INT_RANGE (height_value)); min_height = gst_value_get_int_range_min (height_value); max_height = gst_value_get_int_range_max (height_value); fail_unless (min_height == 16 && max_height == 4096); } gst_caps_unref (caps); }
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 empathy_audio_src_handle_message (GstBin *bin, GstMessage *message) { EmpathyGstAudioSrc *self = EMPATHY_GST_AUDIO_SRC (bin); EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self); if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ELEMENT && GST_MESSAGE_SRC (message) == GST_OBJECT (priv->level)) { const GstStructure *s; const gchar *name; const GValue *list; guint i, len; gdouble peak = -G_MAXDOUBLE; gdouble rms = -G_MAXDOUBLE; s = gst_message_get_structure (message); name = gst_structure_get_name (s); if (g_strcmp0 ("level", name) != 0) goto out; list = gst_structure_get_value (s, "peak"); len = gst_value_list_get_size (list); for (i =0 ; i < len; i++) { const GValue *value; gdouble db; value = gst_value_list_get_value (list, i); db = g_value_get_double (value); peak = MAX (db, peak); } list = gst_structure_get_value (s, "rms"); len = gst_value_list_get_size (list); for (i =0 ; i < len; i++) { const GValue *value; gdouble db; value = gst_value_list_get_value (list, i); db = g_value_get_double (value); rms = MAX (db, rms); } g_mutex_lock (priv->lock); priv->peak_level = peak; priv->rms_level = rms; if (priv->idle_id == 0) priv->idle_id = g_idle_add (empathy_audio_src_levels_updated, self); g_mutex_unlock (priv->lock); } out: GST_BIN_CLASS (empathy_audio_src_parent_class)->handle_message (bin, message); }
/* 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; }
/* * cheese_camera_device_get_highest_framerate: * @framerate: a #GValue holding a framerate cap * @numerator: destination to store the numerator of the highest rate * @denominator: destination to store the denominator of the highest rate * * Get the numerator and denominator for the highest framerate stored in * a framerate cap. * * Note this function does not handle framerate ranges, if @framerate * contains a range it will return 0/0 as framerate */ static void cheese_camera_device_get_highest_framerate (const GValue *framerate, gint *numerator, gint *denominator) { *numerator = 0; *denominator = 0; if (GST_VALUE_HOLDS_FRACTION (framerate)) { *numerator = gst_value_get_fraction_numerator (framerate); *denominator = gst_value_get_fraction_denominator (framerate); } else if (GST_VALUE_HOLDS_ARRAY (framerate)) { float curr, highest = 0; guint i, size = gst_value_array_get_size (framerate); for (i = 0; i < size; i++) { const GValue *val = gst_value_array_get_value (framerate, i); if (!GST_VALUE_HOLDS_FRACTION (val) || gst_value_get_fraction_denominator (val) == 0) { continue; } curr = (float)gst_value_get_fraction_numerator (val) / (float)gst_value_get_fraction_denominator (val); if (curr > highest && curr <= CHEESE_MAXIMUM_RATE) { highest = curr; *numerator = gst_value_get_fraction_numerator (val); *denominator = gst_value_get_fraction_denominator (val); } } } else if (GST_VALUE_HOLDS_LIST (framerate)) { float curr, highest = 0; guint i, size = gst_value_list_get_size (framerate); for (i = 0; i < size; i++) { const GValue *val = gst_value_list_get_value(framerate, i); if (!GST_VALUE_HOLDS_FRACTION (val) || gst_value_get_fraction_denominator (val) == 0) { continue; } curr = (float)gst_value_get_fraction_numerator (val) / (float)gst_value_get_fraction_denominator (val); if (curr > highest && curr <= CHEESE_MAXIMUM_RATE) { highest = curr; *numerator = gst_value_get_fraction_numerator (val); *denominator = gst_value_get_fraction_denominator (val); } } } }
static GstCaps * gst_deinterlace2_getcaps (GstPad * pad) { GstCaps *ret; GstDeinterlace2 *self = GST_DEINTERLACE2 (gst_pad_get_parent (pad)); GstPad *otherpad; gint len; const GstCaps *ourcaps; GstCaps *peercaps; GST_OBJECT_LOCK (self); otherpad = (pad == self->srcpad) ? self->sinkpad : self->srcpad; ourcaps = gst_pad_get_pad_template_caps (pad); peercaps = gst_pad_peer_get_caps (otherpad); if (peercaps) { ret = gst_caps_intersect (ourcaps, peercaps); gst_caps_unref (peercaps); } else { ret = gst_caps_copy (ourcaps); } GST_OBJECT_UNLOCK (self); if (self->fields == GST_DEINTERLACE2_ALL) { for (len = gst_caps_get_size (ret); len > 0; len--) { GstStructure *s = gst_caps_get_structure (ret, len - 1); const GValue *val; val = gst_structure_get_value (s, "framerate"); if (!val) continue; if (G_VALUE_TYPE (val) == GST_TYPE_FRACTION) { gint n, d; n = gst_value_get_fraction_numerator (val); d = gst_value_get_fraction_denominator (val); if (!gst_fraction_double (&n, &d, pad != self->srcpad)) { goto error; } gst_structure_set (s, "framerate", GST_TYPE_FRACTION, n, d, NULL); } else if (G_VALUE_TYPE (val) == GST_TYPE_FRACTION_RANGE) { const GValue *min, *max; GValue nrange = { 0, }, nmin = { 0,}, nmax = { 0,}; gint n, d; g_value_init (&nrange, GST_TYPE_FRACTION_RANGE); g_value_init (&nmin, GST_TYPE_FRACTION); g_value_init (&nmax, GST_TYPE_FRACTION); min = gst_value_get_fraction_range_min (val); max = gst_value_get_fraction_range_max (val); n = gst_value_get_fraction_numerator (min); d = gst_value_get_fraction_denominator (min); if (!gst_fraction_double (&n, &d, pad != self->srcpad)) { g_value_unset (&nrange); g_value_unset (&nmax); g_value_unset (&nmin); goto error; } gst_value_set_fraction (&nmin, n, d); n = gst_value_get_fraction_numerator (max); d = gst_value_get_fraction_denominator (max); if (!gst_fraction_double (&n, &d, pad != self->srcpad)) { g_value_unset (&nrange); g_value_unset (&nmax); g_value_unset (&nmin); goto error; } gst_value_set_fraction (&nmax, n, d); gst_value_set_fraction_range (&nrange, &nmin, &nmax); gst_structure_set_value (s, "framerate", &nrange); g_value_unset (&nmin); g_value_unset (&nmax); g_value_unset (&nrange); } else if (G_VALUE_TYPE (val) == GST_TYPE_LIST) { const GValue *lval; GValue nlist = { 0, }; GValue nval = { 0, }; gint i; g_value_init (&nlist, GST_TYPE_LIST); for (i = gst_value_list_get_size (val); i > 0; i--) { gint n, d; lval = gst_value_list_get_value (val, i); if (G_VALUE_TYPE (lval) != GST_TYPE_FRACTION) continue; n = gst_value_get_fraction_numerator (lval); d = gst_value_get_fraction_denominator (lval); /* Double/Half the framerate but if this fails simply * skip this value from the list */ if (!gst_fraction_double (&n, &d, pad != self->srcpad)) { continue; } g_value_init (&nval, GST_TYPE_FRACTION); gst_value_set_fraction (&nval, n, d); gst_value_list_append_value (&nlist, &nval); g_value_unset (&nval); } gst_structure_set_value (s, "framerate", &nlist); g_value_unset (&nlist); } } } GST_DEBUG_OBJECT (pad, "Returning caps %" GST_PTR_FORMAT, ret); return ret; error: GST_ERROR_OBJECT (pad, "Unable to transform peer caps"); gst_caps_unref (ret); return NULL; }
void Player::messageReceived(GstMessage *message) { switch (GST_MESSAGE_TYPE (message)) { case GST_STATE_CHANGE_FAILURE: { qDebug() << Q_FUNC_INFO <<": Gstreamer error:"<< p->error; } case GST_MESSAGE_ERROR: { if ( p->error == "") { GError *err; gchar *debug; gst_message_parse_error (message, &err, &debug); p->error = "Error #"+QString::number(err->code)+" in module "+QString::number(err->domain)+"\n"+QString::fromUtf8(err->message); if(err->domain != GST_STREAM_ERROR && err->code != GST_STREAM_ERROR_FAILED) { p->error += "\nMay be you should install more of gstreamer plugins"; lastError = QString::fromUtf8(err->message); } qDebug() << Q_FUNC_INFO <<": Gstreamer error:"<< p->error; g_error_free (err); g_free (debug); Q_EMIT error(); } break; } case GST_MESSAGE_EOS:{ qDebug() << Q_FUNC_INFO <<":"<<parentWidget()->objectName()<<" End of track reached"; Q_EMIT finish(); break; } case GST_MESSAGE_STATE_CHANGED: { GstState old_state, new_state; gst_message_parse_state_changed (message, &old_state, &new_state, NULL); switch(new_state){ case GST_STATE_PAUSED: case GST_STATE_NULL: rms_l=rms_r=0; rmsout_l=rmsout_r=0; default: break; } break; } case GST_MESSAGE_ELEMENT:{ const GstStructure *s = gst_message_get_structure (message); const gchar *src_name=GST_MESSAGE_SRC_NAME (message); if (strcmp (src_name, "levelintern") == 0) { gint channels; gdouble peak_dB; gdouble rms; gint i; #ifdef GST_API_VERSION_1 const GValue *array_val; GValueArray *peak_arr; array_val = gst_structure_get_value (s, "peak"); peak_arr = (GValueArray *) g_value_get_boxed (array_val); channels = peak_arr->n_values; for (i = 0; i < channels; ++i) { peak_dB = g_value_get_double (peak_arr->values+i); #else const GValue *list; const GValue *value; list = gst_structure_get_value (s, "peak"); channels = gst_value_list_get_size (list); for (i = 0; i < channels; ++i) { list = gst_structure_get_value (s, "peak"); value = gst_value_list_get_value (list, i); peak_dB = g_value_get_double (value); #endif /* converting from dB to normal gives us a value between 0.0 and 1.0 */ rms = pow (10, peak_dB / 20); if (i==0) rms_l=rms; else rms_r=rms; } } if (strcmp (src_name, "levelout") == 0) { gint channels; gdouble peak_dB; gdouble rms; gint i; #ifdef GST_API_VERSION_1 const GValue *array_val; GValueArray *peak_arr; array_val = gst_structure_get_value (s, "peak"); peak_arr = (GValueArray *) g_value_get_boxed (array_val); channels = peak_arr->n_values; for (i = 0; i < channels; ++i) { peak_dB = g_value_get_double (peak_arr->values+i); #else const GValue *list; const GValue *value; list = gst_structure_get_value (s, "peak"); channels = gst_value_list_get_size (list); for (i = 0; i < channels; ++i) { list = gst_structure_get_value (s, "peak"); value = gst_value_list_get_value (list, i); peak_dB = g_value_get_double (value); #endif /* converting from dB to normal gives us a value between 0.0 and 1.0 */ rms = pow (10, peak_dB / 20); if (i==0) rmsout_l=rms; else rmsout_r=rms; } } } break; default: break; } }
int main (int argc, char *argv[]) { /* Initialisation */ gst_init (&argc, &argv); GList *element_list = gst_element_factory_list_get_elements (GST_ELEMENT_FACTORY_TYPE_DEPAYLOADER, GST_RANK_NONE); GList *iter = element_list; while (iter != NULL) { g_print ("+++++\n"); g_print ("%s -- ", gst_element_factory_get_longname ((GstElementFactory *)iter->data)); g_print ("%s\n", gst_plugin_feature_get_name ((GstPluginFeature *)iter->data)); const GList *static_pads = gst_element_factory_get_static_pad_templates ((GstElementFactory *)iter->data); while (NULL != static_pads) { GstStaticPadTemplate *pad = (GstStaticPadTemplate *)static_pads->data; //the following is EMPTY gchar *caps_str = gst_caps_to_string (&pad->static_caps.caps); //g_free (caps_str); /* g_print ("string: %s\n", */ /* pad->static_caps.string); */ GstCaps *caps = gst_caps_from_string (pad->static_caps.string); guint caps_size = gst_caps_get_size (caps); if (! gst_caps_is_any (caps)) for (guint i = caps_size; i > 0; i--) { GstStructure *caps_struct = gst_caps_get_structure (caps, i-1); if (gst_structure_has_name (caps_struct,"application/x-rtp")) { g_print ("string: %s\n", gst_structure_to_string (caps_struct)); {//payload const GValue *val = gst_structure_get_value (caps_struct, "payload"); if (NULL != val) { //g_print ("payload struct type %s\n", G_VALUE_TYPE_NAME (val)); if(GST_VALUE_HOLDS_INT_RANGE(val)) { g_print ("payload min %d\n", gst_value_get_int_range_min (val)); } if (GST_VALUE_HOLDS_LIST(val)) { for (guint i = 0; i < gst_value_list_get_size (val); i++) { const GValue *item_val = gst_value_list_get_value (val, i); g_print ("payload list %d\n", g_value_get_int (item_val)); } } if (G_VALUE_HOLDS_INT (val)) { g_print ("payload int %d\n", g_value_get_int (val)); } } } { //encodeing-name const GValue *val = gst_structure_get_value (caps_struct, "encoding-name"); if (NULL != val) { //g_print ("encoding-name struct type %s\n", G_VALUE_TYPE_NAME (val)); if (GST_VALUE_HOLDS_LIST(val)) { for (guint i = 0; i < gst_value_list_get_size (val); i++) { const GValue *item_val = gst_value_list_get_value (val, i); g_print ("encoding-name list %s\n", g_value_get_string (item_val)); } } if (G_VALUE_HOLDS_STRING (val)) { g_print ("encoding-name string %s\n", g_value_get_string (val)); } } } {//media const GValue *val = gst_structure_get_value (caps_struct, "media"); if (NULL != val) { if (GST_VALUE_HOLDS_LIST(val)) { for (guint i = 0; i < gst_value_list_get_size (val); i++) { const GValue *item_val = gst_value_list_get_value (val, i); g_print ("media list %s\n", g_value_get_string (item_val)); } } if (G_VALUE_HOLDS_STRING (val)) { g_print ("media string %s\n", g_value_get_string (val)); } } } {//clock rate const GValue *val = gst_structure_get_value (caps_struct, "clock-rate"); if (NULL != val) { //g_print ("payload struct type %s\n", G_VALUE_TYPE_NAME (val)); if(GST_VALUE_HOLDS_INT_RANGE(val)) { g_print ("clock-rate min %d\n", gst_value_get_int_range_min (val)); } if (GST_VALUE_HOLDS_LIST(val)) { for (guint i = 0; i < gst_value_list_get_size (val); i++) { const GValue *item_val = gst_value_list_get_value (val, i); g_print ("clock-rate list %d\n", g_value_get_int (item_val)); } } if (G_VALUE_HOLDS_INT (val)) { g_print ("clock-rate int %d\n", g_value_get_int (val)); } } } /* g_print ("\nencoding-name %s\n", */ /* gst_structure_get_string (caps_struct, */ /* "encoding-name")); */ } } static_pads = g_list_next (static_pads); gst_caps_unref (caps); } iter = g_list_next (iter); } gst_plugin_feature_list_free (element_list); return 0; }