static gboolean missing_structure_get_caps_detail (const GstStructure * s, GstCaps ** p_caps) { const GstCaps *caps; const GValue *val; GType detail_type; *p_caps = NULL; detail_type = gst_structure_get_field_type (s, "detail"); if (!g_type_is_a (detail_type, GST_TYPE_CAPS)) { GST_WARNING ("expected 'detail' field to be of GST_TYPE_CAPS"); return FALSE; } val = gst_structure_get_value (s, "detail"); caps = gst_value_get_caps (val); if (gst_caps_is_empty (caps) || gst_caps_is_any (caps)) { GST_WARNING ("EMPTY or ANY caps not allowed"); return FALSE; } *p_caps = gst_caps_copy (caps); return TRUE; }
/** * pk_gst_structure_to_provide: **/ static gchar * pk_gst_structure_to_provide (GstStructure *s) { GString *string; guint i, num_fields; GList *l; _cleanup_list_free_ GList *fields = NULL; num_fields = gst_structure_n_fields (s); fields = NULL; for (i = 0; i < num_fields; i++) { const gchar *field_name; field_name = gst_structure_nth_field_name (s, i); if (pk_gst_field_get_type (field_name) < 0) { g_message ("PackageKit: ignoring field named %s", field_name); continue; } fields = g_list_insert_sorted (fields, g_strdup (field_name), (GCompareFunc) pk_gst_fields_type_compare); } string = g_string_new(""); for (l = fields; l != NULL; l = l->next) { gchar *field_name; GType type; field_name = l->data; type = gst_structure_get_field_type (s, field_name); g_message ("PackageKit: field is: %s, type: %s", field_name, g_type_name (type)); if (type == G_TYPE_INT) { int value; gst_structure_get_int (s, field_name, &value); g_string_append_printf (string, "(%s=%d)", field_name, value); } else if (type == G_TYPE_BOOLEAN) { int value; gst_structure_get_boolean (s, field_name, &value); g_string_append_printf (string, "(%s=%s)", field_name, value ? "true" : "false"); } else if (type == G_TYPE_STRING) { const gchar *value; value = gst_structure_get_string (s, field_name); g_string_append_printf (string, "(%s=%s)", field_name, value); } else { g_warning ("PackageKit: unhandled type! %s", g_type_name (type)); } g_free (field_name); } return g_string_free (string, FALSE); }
std::vector<std::string> index_caps_formats (GstCaps* caps) { // todo missing jpeg std::vector<std::string> ret; for (guint i = 0; i < gst_caps_get_size(caps); ++i) { GstStructure* struc = gst_caps_get_structure(caps, i); if (gst_structure_get_field_type(struc, "format") == GST_TYPE_LIST) { auto vec = gst_list_to_vector(gst_structure_get_value(struc, "format")); for (const auto& v : vec) { std::string str = gst_structure_get_name(struc); str += ",format="; str += v; ret.push_back(str); } } else if (gst_structure_get_field_type(struc, "format") == G_TYPE_STRING) { std::string str = gst_structure_get_name(struc); str += ",format="; str += gst_structure_get_string(struc, "format"); ret.push_back(str); } } // make all entries unique if (ret.size() > 1) { std::sort(ret.begin(), ret.end()); ret.erase(std::unique(ret.begin(), ret.end()), ret.end()); } return std::move(ret); }
static gboolean extract_resolution (GstTcamWhitebalance* self) { GstPad* pad = GST_BASE_TRANSFORM_SINK_PAD(self); GstCaps* caps = gst_pad_get_current_caps(pad); GstStructure *structure = gst_caps_get_structure (caps, 0); g_return_val_if_fail(gst_structure_get_int(structure, "width", &self->image_size.width), FALSE); g_return_val_if_fail(gst_structure_get_int(structure, "height", &self->image_size.height), FALSE); guint fourcc; if (gst_structure_get_field_type(structure, "format") == G_TYPE_STRING) { const char *string; string = gst_structure_get_string (structure, "format"); fourcc = GST_STR_FOURCC (string); } if (fourcc == MAKE_FOURCC ('g','r','b','g')) { self->pattern = GR; } else if (fourcc == MAKE_FOURCC ('r', 'g', 'g', 'b')) { self->pattern = RG; } else if (fourcc == MAKE_FOURCC ('g', 'b', 'r', 'g')) { self->pattern = GB; } else if (fourcc == MAKE_FOURCC ('b', 'g', 'g', 'r')) { self->pattern = BG; } else { GST_ERROR("Unable to determine bayer pattern."); return FALSE; } // we only handle bayer 8 bit -> 1 byte int bytes_per_pixel = 1; self->expected_buffer_size = self->image_size.height * self->image_size.width * bytes_per_pixel; self->res = find_source(GST_ELEMENT(self)); return TRUE; }
static gboolean missing_structure_get_string_detail (const GstStructure * s, gchar ** p_detail) { const gchar *detail; GType detail_type; *p_detail = NULL; detail_type = gst_structure_get_field_type (s, "detail"); if (!g_type_is_a (detail_type, G_TYPE_STRING)) { GST_WARNING ("expected 'detail' field to be of G_TYPE_STRING"); return FALSE; } detail = gst_structure_get_string (s, "detail"); if (detail == NULL || *detail == '\0') { GST_WARNING ("empty 'detail' field"); return FALSE; } *p_detail = g_strdup (detail); return TRUE; }
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 gboolean gst_aravis_set_caps (GstBaseSrc *src, GstCaps *caps) { GstAravis* gst_aravis = GST_ARAVIS(src); GstStructure *structure; ArvPixelFormat pixel_format; int height, width; int bpp, depth; const GValue *frame_rate; const char *caps_string; unsigned int i; guint32 fourcc; GST_LOG_OBJECT (gst_aravis, "Requested caps = %" GST_PTR_FORMAT, caps); arv_camera_stop_acquisition (gst_aravis->camera); if (gst_aravis->stream != NULL) g_object_unref (gst_aravis->stream); structure = gst_caps_get_structure (caps, 0); gst_structure_get_int (structure, "width", &width); gst_structure_get_int (structure, "height", &height); frame_rate = gst_structure_get_value (structure, "framerate"); gst_structure_get_int (structure, "bpp", &bpp); gst_structure_get_int (structure, "depth", &depth); if (gst_structure_get_field_type (structure, "format") == G_TYPE_STRING) { const char *string; string = gst_structure_get_string (structure, "format"); fourcc = GST_STR_FOURCC (string); } else if (gst_structure_get_field_type (structure, "format") == GST_TYPE_FOURCC) { gst_structure_get_fourcc (structure, "format", &fourcc); } else fourcc = 0; pixel_format = arv_pixel_format_from_gst_0_10_caps (gst_structure_get_name (structure), bpp, depth, fourcc); arv_camera_set_region (gst_aravis->camera, gst_aravis->offset_x, gst_aravis->offset_y, width, height); arv_camera_set_binning (gst_aravis->camera, gst_aravis->h_binning, gst_aravis->v_binning); arv_camera_set_pixel_format (gst_aravis->camera, pixel_format); if (frame_rate != NULL) { double dbl_frame_rate; dbl_frame_rate = (double) gst_value_get_fraction_numerator (frame_rate) / (double) gst_value_get_fraction_denominator (frame_rate); GST_DEBUG_OBJECT (gst_aravis, "Frame rate = %g Hz", dbl_frame_rate); arv_camera_set_frame_rate (gst_aravis->camera, dbl_frame_rate); if (dbl_frame_rate > 0.0) gst_aravis->buffer_timeout_us = MAX (GST_ARAVIS_BUFFER_TIMEOUT_DEFAULT, 3e6 / dbl_frame_rate); else gst_aravis->buffer_timeout_us = GST_ARAVIS_BUFFER_TIMEOUT_DEFAULT; } else gst_aravis->buffer_timeout_us = GST_ARAVIS_BUFFER_TIMEOUT_DEFAULT; GST_DEBUG_OBJECT (gst_aravis, "Buffer timeout = %" G_GUINT64_FORMAT " µs", gst_aravis->buffer_timeout_us); GST_DEBUG_OBJECT (gst_aravis, "Actual frame rate = %g Hz", arv_camera_get_frame_rate (gst_aravis->camera)); if(gst_aravis->gain_auto) { arv_camera_set_gain_auto (gst_aravis->camera, ARV_AUTO_CONTINUOUS); GST_DEBUG_OBJECT (gst_aravis, "Auto Gain = continuous"); } else { if (gst_aravis->gain >= 0) { GST_DEBUG_OBJECT (gst_aravis, "Gain = %g", gst_aravis->gain); arv_camera_set_gain_auto (gst_aravis->camera, ARV_AUTO_OFF); arv_camera_set_gain (gst_aravis->camera, gst_aravis->gain); } GST_DEBUG_OBJECT (gst_aravis, "Actual gain = %g", arv_camera_get_gain (gst_aravis->camera)); } if(gst_aravis->exposure_auto) { arv_camera_set_exposure_time_auto (gst_aravis->camera, ARV_AUTO_CONTINUOUS); GST_DEBUG_OBJECT (gst_aravis, "Auto Exposure = continuous"); } else { if (gst_aravis->exposure_time_us > 0.0) { GST_DEBUG_OBJECT (gst_aravis, "Exposure = %g µs", gst_aravis->exposure_time_us); arv_camera_set_exposure_time_auto (gst_aravis->camera, ARV_AUTO_OFF); arv_camera_set_exposure_time (gst_aravis->camera, gst_aravis->exposure_time_us); } GST_DEBUG_OBJECT (gst_aravis, "Actual exposure = %g µs", arv_camera_get_exposure_time (gst_aravis->camera)); } if (gst_aravis->fixed_caps != NULL) gst_caps_unref (gst_aravis->fixed_caps); caps_string = arv_pixel_format_to_gst_0_10_caps_string (pixel_format); if (caps_string != NULL) { GstStructure *structure; GstCaps *caps; caps = gst_caps_new_empty (); structure = gst_structure_from_string (caps_string, NULL); gst_structure_set (structure, "width", G_TYPE_INT, width, "height", G_TYPE_INT, height, NULL); if (frame_rate != NULL) gst_structure_set_value (structure, "framerate", frame_rate); gst_caps_append_structure (caps, structure); gst_aravis->fixed_caps = caps; } else gst_aravis->fixed_caps = NULL; gst_aravis->payload = arv_camera_get_payload (gst_aravis->camera); gst_aravis->stream = arv_camera_create_stream (gst_aravis->camera, NULL, NULL); if (ARV_IS_GV_STREAM (gst_aravis->stream) && gst_aravis->packet_resend) g_object_set (gst_aravis->stream, "packet-resend", ARV_GV_STREAM_PACKET_RESEND_ALWAYS, NULL); else g_object_set (gst_aravis->stream, "packet-resend", ARV_GV_STREAM_PACKET_RESEND_NEVER, NULL); for (i = 0; i < GST_ARAVIS_N_BUFFERS; i++) arv_stream_push_buffer (gst_aravis->stream, arv_buffer_new (gst_aravis->payload, NULL)); GST_LOG_OBJECT (gst_aravis, "Start acquisition"); arv_camera_start_acquisition (gst_aravis->camera); gst_aravis->timestamp_offset = 0; gst_aravis->last_timestamp = 0; return TRUE; }
static void gst_tiswhitebalance_fixate_caps (GstBaseTransform* base, GstPadDirection direction, GstCaps* incoming, GstCaps* outgoing) { GstTisWhiteBalance* self = GST_TISWHITEBALANCE(base); GstStructure* ins; GstStructure* outs; gint width, height; g_return_if_fail (gst_caps_is_fixed (incoming)); GST_DEBUG_OBJECT (base, "trying to fixate outgoing caps %" GST_PTR_FORMAT " based on caps %" GST_PTR_FORMAT, outgoing, incoming); ins = gst_caps_get_structure (incoming, 0); outs = gst_caps_get_structure (outgoing, 0); if (gst_structure_get_int (ins, "width", &width)) { if (gst_structure_has_field (outs, "width")) { gst_structure_fixate_field_nearest_int (outs, "width", width); } self->width = width; } if (gst_structure_get_int (ins, "height", &height)) { if (gst_structure_has_field (outs, "height")) { gst_structure_fixate_field_nearest_int (outs, "height", height); } self->height = height; } const char* p = gst_structure_get_name (ins); guint fourcc; if (g_strcmp0(p, "video/x-raw-bayer") == 0) { if (gst_structure_get_field_type (ins, "format") == G_TYPE_STRING) { const char *string; string = gst_structure_get_string (ins, "format"); fourcc = GST_STR_FOURCC (string); } else if (gst_structure_get_field_type (ins, "format") == GST_TYPE_FOURCC) { gst_structure_get_fourcc (ins, "format", &fourcc); } else fourcc = 0; if (fourcc == 0) { gst_debug_log (gst_tiswhitebalance_debug_category, GST_LEVEL_ERROR, "gst_tiswhitebalance", "gst_tiswhitebalance_fixate_caps", 0, NULL, "Unable to determine video format."); return; } if (fourcc == MAKE_FOURCC ('g','r','b','g')) { self->pattern = GR; } else if (fourcc == MAKE_FOURCC ('r', 'g', 'g', 'b')) { self->pattern = RG; } else if (fourcc == MAKE_FOURCC ('g', 'b', 'r', 'g')) { self->pattern = GB; } else if (fourcc == MAKE_FOURCC ('b', 'g', 'g', 'r')) { self->pattern = BG; } else { gst_debug_log (gst_tiswhitebalance_debug_category, GST_LEVEL_ERROR, "gst_tiswhitebalance", "gst_tiswhitebalance_fixate_caps", 0, NULL, "Unable to determine bayer pattern."); return; } gst_debug_log (gst_tiswhitebalance_debug_category, GST_LEVEL_INFO, "gst_tiswhitebalance", "gst_tiswhitebalance_fixate_caps", 0, NULL, "Using bayer format %s for whitebalancing.", bayer_to_string(self->pattern)); } else { gst_debug_log (gst_tiswhitebalance_debug_category, GST_LEVEL_INFO, "gst_tiswhitebalance", "gst_tiswhitebalance_fixate_caps", 0, NULL, "Not a bayer format. White balance will be disabled."); } }
static GstCaps * gst_alsa_detect_channels (GstObject * obj, snd_pcm_hw_params_t * hw_params, GstCaps * in_caps) { GstCaps *caps; guint min, max; gint min_chans, max_chans; gint err, i; GST_LOG_OBJECT (obj, "probing channels ..."); if ((err = snd_pcm_hw_params_get_channels_min (hw_params, &min)) < 0) goto min_chan_error; if ((err = snd_pcm_hw_params_get_channels_max (hw_params, &max)) < 0) goto max_chan_error; /* note: the above functions may return (guint) -1 */ min_chans = min; max_chans = max; if (min_chans < 0) { min_chans = 1; max_chans = GST_ALSA_MAX_CHANNELS; } else if (max_chans < 0) { max_chans = GST_ALSA_MAX_CHANNELS; } if (min_chans > max_chans) { gint temp; GST_WARNING_OBJECT (obj, "minimum channels > maximum channels (%d > %d), " "please fix your soundcard drivers", min, max); temp = min_chans; min_chans = max_chans; max_chans = temp; } /* pro cards seem to return large numbers for min_channels */ if (min_chans > GST_ALSA_MAX_CHANNELS) { GST_DEBUG_OBJECT (obj, "min_chans = %u, looks like a pro card", min_chans); if (max_chans < min_chans) { max_chans = min_chans; } else { /* only support [max_chans; max_chans] for these cards for now * to avoid inflating the source caps with loads of structures ... */ min_chans = max_chans; } } else { min_chans = MAX (min_chans, 1); max_chans = MIN (GST_ALSA_MAX_CHANNELS, max_chans); } GST_DEBUG_OBJECT (obj, "Min. channels = %d (%d)", min_chans, min); GST_DEBUG_OBJECT (obj, "Max. channels = %d (%d)", max_chans, max); caps = gst_caps_new_empty (); for (i = 0; i < gst_caps_get_size (in_caps); ++i) { GstStructure *s; GType field_type; gint c_min = min_chans; gint c_max = max_chans; s = gst_caps_get_structure (in_caps, i); /* the template caps might limit the number of channels (like alsasrc), * in which case we don't want to return a superset, so hack around this * for the two common cases where the channels are either a fixed number * or a min/max range). Example: alsasrc template has channels = [1,2] and * the detection will claim to support 8 channels for device 'plughw:0' */ field_type = gst_structure_get_field_type (s, "channels"); if (field_type == G_TYPE_INT) { gst_structure_get_int (s, "channels", &c_min); gst_structure_get_int (s, "channels", &c_max); } else if (field_type == GST_TYPE_INT_RANGE) { const GValue *val; val = gst_structure_get_value (s, "channels"); c_min = CLAMP (gst_value_get_int_range_min (val), min_chans, max_chans); c_max = CLAMP (gst_value_get_int_range_max (val), min_chans, max_chans); } else { c_min = min_chans; c_max = max_chans; } caps_add_channel_configuration (caps, s, c_min, c_max); } gst_caps_unref (in_caps); return caps; /* ERRORS */ min_chan_error: { GST_ERROR_OBJECT (obj, "failed to query minimum channel count: %s", snd_strerror (err)); return NULL; } max_chan_error: { GST_ERROR_OBJECT (obj, "failed to query maximum channel count: %s", snd_strerror (err)); return NULL; } }
bool tcam_gst_raw_only_has_mono (const GstCaps* caps) { if (caps == nullptr) { return false; } auto correct_format = [] (const char* str) { if (str == nullptr) { return false; } const static std::vector<std::string> formats = {"GRAY8", "GRAY16_LE", "GRAY16_BE"}; if (std::find(formats.begin(), formats.end(), str) == formats.end()) { return false; } return true; }; for (unsigned int i = 0; i < gst_caps_get_size(caps); ++i) { GstStructure* struc = gst_caps_get_structure(caps, i); if (strcmp("video/x-raw", gst_structure_get_name(struc)) == 0) { if (gst_structure_has_field(struc, "format")) { if (gst_structure_get_field_type(struc, "format") == G_TYPE_STRING) { if (!correct_format(gst_structure_get_string(struc, "format"))) { return false; } } else if (gst_structure_get_field_type(struc, "format") == GST_TYPE_LIST) { auto vec = gst_list_to_vector(gst_structure_get_value(struc, "format")); for (const auto& fmt : vec) { if (!correct_format(fmt.c_str())) { return false; } } } else { tcam_error("Cannot handle format type in GstStructure."); } } else { // since raw can be anything // do not assume it is gray but color return false; } } else { return false; } } return true; }
/** * Helper function to get a list of all available fourccs in caps */ std::vector<uint32_t> index_format_fourccs (const GstCaps* caps) { std::vector<uint32_t> ret; /* gst_caps_is_empty acts erratic, thus we work arround the issue with gst_caps_to_string: -------- (gdb) print (char*)gst_caps_to_string (caps) $4 = 0x555555a8f120 "EMPTY" (gdb) print (int)gst_caps_is_empty (caps) (process:5873): GStreamer-CRITICAL (recursed) **: gst_caps_is_empty: assertion 'GST_IS_CAPS (caps)' failed -------- */ if (!caps || (!g_strcmp0(gst_caps_to_string(caps), "EMPTY")) || gst_caps_is_any(caps)) { return ret; } for (guint i = 0; i < gst_caps_get_size(caps); ++i) { GstStructure* struc = gst_caps_get_structure(caps, i); std::string format_string; std::vector<std::string> vec; if (gst_structure_get_field_type(struc, "format") == GST_TYPE_LIST) { vec = gst_list_to_vector(gst_structure_get_value(struc, "format")); } else if (gst_structure_get_field_type(struc, "format") == G_TYPE_STRING) { vec.push_back(gst_structure_get_string(struc, "format")); } // code in helper func is needed weither vec is empty or not // prevents code duplication auto helper_func = [&ret] (const char* name, const char* fmt) { uint32_t fourcc = tcam_fourcc_from_gst_1_0_caps_string(name, fmt); if (fourcc != 0) { ret.push_back(fourcc); } }; const char* name = gst_structure_get_name(struc); if (!vec.empty()) { for (const auto& fmt : vec) { helper_func(name, fmt.c_str()); } } else { // this will be the case for things like image/jpeg // such caps will have no format field and thus vec.empty() == helper_func(name, ""); } } // remove duplicate entries // probably never enough entries to make switch to std::set a good alternative sort( ret.begin(), ret.end() ); ret.erase( unique( ret.begin(), ret.end() ), ret.end() ); return ret; }
static GstBusSyncReply bus_sync_handler (GstBus * bus, GstMessage * message, GstPipeline * pipeline) { const GstStructure *structure; gint64 position, length; GstFormat format = GST_FORMAT_TIME; const GValue *x_value, *y_value; gint x, i, y; /* select msg */ if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT || !gst_structure_has_name (gst_message_get_structure (message), "hand-gesture")) return GST_BUS_PASS; /* parse msg structure */ structure = gst_message_get_structure (message); /* if PALM gesture detected */ if (structure && strcmp (gst_structure_get_name (structure), "hand-gesture") == 0 && strcmp (gst_structure_get_string (structure, "gesture"), "palm") == 0) { /* media operation - closed palm to stop media play */ gst_element_set_state (playbin, GST_STATE_PAUSED); } /* if FIST gesture detected */ if (structure && strcmp (gst_structure_get_name (structure), "hand-gesture") == 0 && strcmp (gst_structure_get_string (structure, "gesture"), "fist") == 0) { /* print message type and structure name */ g_print ("%s{{%s}}\n", gst_message_type_get_name (message->type), gst_structure_get_name (structure)); /* print msg structure names&values */ 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); const GValue *value = gst_structure_get_value (structure, name); type == G_TYPE_STRING ? g_print ("-%s[%s]{%s}\n", name, g_type_name (type), g_value_get_string (value)) : g_print ("-%s[%s]{%d}\n", name, g_type_name (type), g_value_get_uint (value)); } g_print ("\n"); /* get X,Y positions in frame */ x_value = gst_structure_get_value (structure, "x"); x = g_value_get_uint (x_value); y_value = gst_structure_get_value (structure, "y"); y = g_value_get_uint (y_value); /* set object volumes [0-10] based on Y */ g_object_set (G_OBJECT (playbin), "volume", (gdouble) (10 - y / 24), NULL); /* seek playback positions */ gst_element_query_duration (playbin, format, &length); /* Width = 320 is specified in caps */ position = (gint64) length *x / 320; gst_element_set_state (playbin, GST_STATE_PAUSED); gst_element_seek (GST_ELEMENT (playbin), 1.0, format, GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET, position, GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE); gst_element_set_state (GST_ELEMENT (playbin), GST_STATE_PLAYING); } gst_message_unref (message); return GST_BUS_DROP; }
// possible values in GstCaps are: // width // height // format // framerate bool ExtractImageParams(GstCaps *caps, int & width, int & height, PixelFormat & pixelFormat) { width = height = 0; pixelFormat = PF__UNKNOWN; char text[4000]; text[0] = 0; strcat_s(text, "\r\n\r\n"); for (unsigned int j = 0; j < gst_caps_get_size(caps); ++j) { GstStructure * structure = gst_caps_get_structure(caps, j); for (int i = 0; i < gst_structure_n_fields(structure); ++i) { const char * name = gst_structure_nth_field_name(structure, i); GType type = gst_structure_get_field_type(structure, name); const GValue * value = gst_structure_get_value(structure, name); if (strcmp("width", name) == 0) { width = value->data->v_int; } if (strcmp("height", name) == 0) { height = value->data->v_int; } if (strcmp("format", name) == 0) { const gchar * format = g_value_get_string(value); if (strcmp(format, "RGB") == 0) pixelFormat = PF__RGB; else if (strcmp(format, "BGR") == 0) pixelFormat = PF__BGR; else if (strcmp(format, "I420") == 0) pixelFormat = PF__I420; } strcat_s(text, name); strcat_s(text, "["); strcat_s(text, g_type_name(type)); strcat_s(text, ":"); if (g_type_is_a(type, G_TYPE_STRING)) strcat_s(text, g_value_get_string(value)); else if (GST_VALUE_HOLDS_FRACTION(&type)) { char size[100]; sprintf_s(size, "%d/%d", value->data[0].v_int, value->data[1].v_int); strcat_s(text, size); } else { char size[100]; sprintf_s(size, "%d", value->data->v_int); strcat_s(text, size); } strcat(text ,"]\r\n"); } printf(text); } return width > 0 && height > 0 && pixelFormat != PF__UNKNOWN; }