Blame gst/gststructure.c

Packit f546b1
/* GStreamer
Packit f546b1
 * Copyright (C) 2003 David A. Schleef <ds@schleef.org>
Packit f546b1
 *
Packit f546b1
 * gststructure.c: lists of { GQuark, GValue } tuples
Packit f546b1
 *
Packit f546b1
 * This library is free software; you can redistribute it and/or
Packit f546b1
 * modify it under the terms of the GNU Library General Public
Packit f546b1
 * License as published by the Free Software Foundation; either
Packit f546b1
 * version 2 of the License, or (at your option) any later version.
Packit f546b1
 *
Packit f546b1
 * This library is distributed in the hope that it will be useful,
Packit f546b1
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit f546b1
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit f546b1
 * Library General Public License for more details.
Packit f546b1
 *
Packit f546b1
 * You should have received a copy of the GNU Library General Public
Packit f546b1
 * License along with this library; if not, write to the
Packit f546b1
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit f546b1
 * Boston, MA 02110-1301, USA.
Packit f546b1
 */
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * SECTION:gststructure
Packit f546b1
 * @title: GstStructure
Packit f546b1
 * @short_description: Generic structure containing fields of names and values
Packit f546b1
 * @see_also: #GstCaps, #GstMessage, #GstEvent, #GstQuery
Packit f546b1
 *
Packit f546b1
 * A #GstStructure is a collection of key/value pairs. The keys are expressed
Packit f546b1
 * as GQuarks and the values can be of any GType.
Packit f546b1
 *
Packit f546b1
 * In addition to the key/value pairs, a #GstStructure also has a name. The name
Packit f546b1
 * starts with a letter and can be filled by letters, numbers and any of "/-_.:".
Packit f546b1
 *
Packit f546b1
 * #GstStructure is used by various GStreamer subsystems to store information
Packit f546b1
 * in a flexible and extensible way. A #GstStructure does not have a refcount
Packit f546b1
 * because it usually is part of a higher level object such as #GstCaps,
Packit f546b1
 * #GstMessage, #GstEvent, #GstQuery. It provides a means to enforce mutability
Packit f546b1
 * using the refcount of the parent with the gst_structure_set_parent_refcount()
Packit f546b1
 * method.
Packit f546b1
 *
Packit f546b1
 * A #GstStructure can be created with gst_structure_new_empty() or
Packit f546b1
 * gst_structure_new(), which both take a name and an optional set of
Packit f546b1
 * key/value pairs along with the types of the values.
Packit f546b1
 *
Packit f546b1
 * Field values can be changed with gst_structure_set_value() or
Packit f546b1
 * gst_structure_set().
Packit f546b1
 *
Packit f546b1
 * Field values can be retrieved with gst_structure_get_value() or the more
Packit f546b1
 * convenient gst_structure_get_*() functions.
Packit f546b1
 *
Packit f546b1
 * Fields can be removed with gst_structure_remove_field() or
Packit f546b1
 * gst_structure_remove_fields().
Packit f546b1
 *
Packit f546b1
 * Strings in structures must be ASCII or UTF-8 encoded. Other encodings are
Packit f546b1
 * not allowed. Strings may be %NULL however.
Packit f546b1
 *
Packit f546b1
 * Be aware that the current #GstCaps / #GstStructure serialization into string
Packit f546b1
 * has limited support for nested #GstCaps / #GstStructure fields. It can only
Packit f546b1
 * support one level of nesting. Using more levels will lead to unexpected
Packit f546b1
 * behavior when using serialization features, such as gst_caps_to_string() or
Packit f546b1
 * gst_value_serialize() and their counterparts.
Packit f546b1
 */
Packit f546b1
Packit f546b1
#ifdef HAVE_CONFIG_H
Packit f546b1
#include "config.h"
Packit f546b1
#endif
Packit f546b1
Packit f546b1
/* FIXME 2.0: suppress warnings for deprecated API such as GValueArray
Packit f546b1
 * with newer GLib versions (>= 2.31.0) */
Packit f546b1
#define GLIB_DISABLE_DEPRECATION_WARNINGS
Packit f546b1
Packit f546b1
#include <string.h>
Packit f546b1
Packit f546b1
#include "gst_private.h"
Packit f546b1
#include "gstquark.h"
Packit f546b1
#include <gst/gst.h>
Packit f546b1
#include <gobject/gvaluecollector.h>
Packit f546b1
Packit f546b1
GST_DEBUG_CATEGORY_STATIC (gst_structure_debug);
Packit f546b1
#define GST_CAT_DEFAULT gst_structure_debug
Packit f546b1
Packit f546b1
typedef struct _GstStructureField GstStructureField;
Packit f546b1
Packit f546b1
struct _GstStructureField
Packit f546b1
{
Packit f546b1
  GQuark name;
Packit f546b1
  GValue value;
Packit f546b1
};
Packit f546b1
Packit f546b1
typedef struct
Packit f546b1
{
Packit f546b1
  GstStructure s;
Packit f546b1
Packit f546b1
  /* owned by parent structure, NULL if no parent */
Packit f546b1
  gint *parent_refcount;
Packit f546b1
Packit f546b1
  GArray *fields;
Packit f546b1
} GstStructureImpl;
Packit f546b1
Packit f546b1
#define GST_STRUCTURE_REFCOUNT(s) (((GstStructureImpl*)(s))->parent_refcount)
Packit f546b1
#define GST_STRUCTURE_FIELDS(s) (((GstStructureImpl*)(s))->fields)
Packit f546b1
Packit f546b1
#define GST_STRUCTURE_FIELD(structure, index) \
Packit f546b1
    &g_array_index(GST_STRUCTURE_FIELDS(structure), GstStructureField, (index))
Packit f546b1
Packit f546b1
#define IS_MUTABLE(structure) \
Packit f546b1
    (!GST_STRUCTURE_REFCOUNT(structure) || \
Packit f546b1
     g_atomic_int_get (GST_STRUCTURE_REFCOUNT(structure)) == 1)
Packit f546b1
Packit f546b1
#define IS_TAGLIST(structure) \
Packit f546b1
    (structure->name == GST_QUARK (TAGLIST))
Packit f546b1
Packit f546b1
static void gst_structure_set_field (GstStructure * structure,
Packit f546b1
    GstStructureField * field);
Packit f546b1
static GstStructureField *gst_structure_get_field (const GstStructure *
Packit f546b1
    structure, const gchar * fieldname);
Packit f546b1
static GstStructureField *gst_structure_id_get_field (const GstStructure *
Packit f546b1
    structure, GQuark field);
Packit f546b1
static void gst_structure_transform_to_string (const GValue * src_value,
Packit f546b1
    GValue * dest_value);
Packit f546b1
static GstStructure *gst_structure_copy_conditional (const GstStructure *
Packit f546b1
    structure);
Packit f546b1
Packit f546b1
GType _gst_structure_type = 0;
Packit f546b1
Packit f546b1
Packit f546b1
G_DEFINE_BOXED_TYPE (GstStructure, gst_structure,
Packit f546b1
    gst_structure_copy_conditional, gst_structure_free);
Packit f546b1
Packit f546b1
void
Packit f546b1
_priv_gst_structure_initialize (void)
Packit f546b1
{
Packit f546b1
  _gst_structure_type = gst_structure_get_type ();
Packit f546b1
Packit f546b1
  g_value_register_transform_func (_gst_structure_type, G_TYPE_STRING,
Packit f546b1
      gst_structure_transform_to_string);
Packit f546b1
Packit f546b1
  GST_DEBUG_CATEGORY_INIT (gst_structure_debug, "structure", 0,
Packit f546b1
      "GstStructure debug");
Packit f546b1
}
Packit f546b1
Packit f546b1
static GstStructure *
Packit f546b1
gst_structure_new_id_empty_with_size (GQuark quark, guint prealloc)
Packit f546b1
{
Packit f546b1
  GstStructureImpl *structure;
Packit f546b1
Packit f546b1
  structure = g_slice_new (GstStructureImpl);
Packit f546b1
  ((GstStructure *) structure)->type = _gst_structure_type;
Packit f546b1
  ((GstStructure *) structure)->name = quark;
Packit f546b1
  GST_STRUCTURE_REFCOUNT (structure) = NULL;
Packit f546b1
  GST_STRUCTURE_FIELDS (structure) =
Packit f546b1
      g_array_sized_new (FALSE, FALSE, sizeof (GstStructureField), prealloc);
Packit f546b1
Packit f546b1
  GST_TRACE ("created structure %p", structure);
Packit f546b1
Packit f546b1
  return GST_STRUCTURE_CAST (structure);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_new_id_empty:
Packit f546b1
 * @quark: name of new structure
Packit f546b1
 *
Packit f546b1
 * Creates a new, empty #GstStructure with the given name as a GQuark.
Packit f546b1
 *
Packit f546b1
 * Free-function: gst_structure_free
Packit f546b1
 *
Packit f546b1
 * Returns: (transfer full): a new, empty #GstStructure
Packit f546b1
 */
Packit f546b1
GstStructure *
Packit f546b1
gst_structure_new_id_empty (GQuark quark)
Packit f546b1
{
Packit f546b1
  g_return_val_if_fail (quark != 0, NULL);
Packit f546b1
Packit f546b1
  return gst_structure_new_id_empty_with_size (quark, 0);
Packit f546b1
}
Packit f546b1
Packit f546b1
#ifndef G_DISABLE_CHECKS
Packit f546b1
static gboolean
Packit f546b1
gst_structure_validate_name (const gchar * name)
Packit f546b1
{
Packit f546b1
  const gchar *s;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (name != NULL, FALSE);
Packit f546b1
Packit f546b1
  if (G_UNLIKELY (!g_ascii_isalpha (*name))) {
Packit f546b1
    GST_WARNING ("Invalid character '%c' at offset 0 in structure name: %s",
Packit f546b1
        *name, name);
Packit f546b1
    return FALSE;
Packit f546b1
  }
Packit f546b1
Packit f546b1
  /* FIXME: test name string more */
Packit f546b1
  s = &name[1];
Packit f546b1
  while (*s && (g_ascii_isalnum (*s) || strchr ("/-_.:+", *s) != NULL))
Packit f546b1
    s++;
Packit f546b1
  if (G_UNLIKELY (*s != '\0')) {
Packit f546b1
    GST_WARNING ("Invalid character '%c' at offset %" G_GUINTPTR_FORMAT " in"
Packit f546b1
        " structure name: %s", *s, ((guintptr) s - (guintptr) name), name);
Packit f546b1
    return FALSE;
Packit f546b1
  }
Packit f546b1
Packit f546b1
  if (strncmp (name, "video/x-raw-", 12) == 0) {
Packit f546b1
    g_warning ("0.10-style raw video caps are being created. Should be "
Packit f546b1
        "video/x-raw,format=(string).. now.");
Packit f546b1
  } else if (strncmp (name, "audio/x-raw-", 12) == 0) {
Packit f546b1
    g_warning ("0.10-style raw audio caps are being created. Should be "
Packit f546b1
        "audio/x-raw,format=(string).. now.");
Packit f546b1
  }
Packit f546b1
Packit f546b1
  return TRUE;
Packit f546b1
}
Packit f546b1
#endif
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_new_empty:
Packit f546b1
 * @name: name of new structure
Packit f546b1
 *
Packit f546b1
 * Creates a new, empty #GstStructure with the given @name.
Packit f546b1
 *
Packit f546b1
 * See gst_structure_set_name() for constraints on the @name parameter.
Packit f546b1
 *
Packit f546b1
 * Free-function: gst_structure_free
Packit f546b1
 *
Packit f546b1
 * Returns: (transfer full): a new, empty #GstStructure
Packit f546b1
 */
Packit f546b1
GstStructure *
Packit f546b1
gst_structure_new_empty (const gchar * name)
Packit f546b1
{
Packit f546b1
  g_return_val_if_fail (gst_structure_validate_name (name), NULL);
Packit f546b1
Packit f546b1
  return gst_structure_new_id_empty_with_size (g_quark_from_string (name), 0);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_new:
Packit f546b1
 * @name: name of new structure
Packit f546b1
 * @firstfield: name of first field to set
Packit f546b1
 * @...: additional arguments
Packit f546b1
 *
Packit f546b1
 * Creates a new #GstStructure with the given name.  Parses the
Packit f546b1
 * list of variable arguments and sets fields to the values listed.
Packit f546b1
 * Variable arguments should be passed as field name, field type,
Packit f546b1
 * and value.  Last variable argument should be %NULL.
Packit f546b1
 *
Packit f546b1
 * Free-function: gst_structure_free
Packit f546b1
 *
Packit f546b1
 * Returns: (transfer full): a new #GstStructure
Packit f546b1
 */
Packit f546b1
GstStructure *
Packit f546b1
gst_structure_new (const gchar * name, const gchar * firstfield, ...)
Packit f546b1
{
Packit f546b1
  GstStructure *structure;
Packit f546b1
  va_list varargs;
Packit f546b1
Packit f546b1
  va_start (varargs, firstfield);
Packit f546b1
  structure = gst_structure_new_valist (name, firstfield, varargs);
Packit f546b1
  va_end (varargs);
Packit f546b1
Packit f546b1
  return structure;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_new_valist:
Packit f546b1
 * @name: name of new structure
Packit f546b1
 * @firstfield: name of first field to set
Packit f546b1
 * @varargs: variable argument list
Packit f546b1
 *
Packit f546b1
 * Creates a new #GstStructure with the given @name.  Structure fields
Packit f546b1
 * are set according to the varargs in a manner similar to
Packit f546b1
 * gst_structure_new().
Packit f546b1
 *
Packit f546b1
 * See gst_structure_set_name() for constraints on the @name parameter.
Packit f546b1
 *
Packit f546b1
 * Free-function: gst_structure_free
Packit f546b1
 *
Packit f546b1
 * Returns: (transfer full): a new #GstStructure
Packit f546b1
 */
Packit f546b1
GstStructure *
Packit f546b1
gst_structure_new_valist (const gchar * name,
Packit f546b1
    const gchar * firstfield, va_list varargs)
Packit f546b1
{
Packit f546b1
  GstStructure *structure;
Packit f546b1
Packit f546b1
  structure = gst_structure_new_empty (name);
Packit f546b1
Packit f546b1
  if (structure)
Packit f546b1
    gst_structure_set_valist (structure, firstfield, varargs);
Packit f546b1
Packit f546b1
  return structure;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_set_parent_refcount:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @refcount: (in): a pointer to the parent's refcount
Packit f546b1
 *
Packit f546b1
 * Sets the parent_refcount field of #GstStructure. This field is used to
Packit f546b1
 * determine whether a structure is mutable or not. This function should only be
Packit f546b1
 * called by code implementing parent objects of #GstStructure, as described in
Packit f546b1
 * the MT Refcounting section of the design documents.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the parent refcount could be set.
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_set_parent_refcount (GstStructure * structure, gint * refcount)
Packit f546b1
{
Packit f546b1
  g_return_val_if_fail (structure != NULL, FALSE);
Packit f546b1
Packit f546b1
  /* if we have a parent_refcount already, we can only clear
Packit f546b1
   * if with a NULL refcount */
Packit f546b1
  if (GST_STRUCTURE_REFCOUNT (structure)) {
Packit f546b1
    if (refcount != NULL) {
Packit f546b1
      g_return_val_if_fail (refcount == NULL, FALSE);
Packit f546b1
      return FALSE;
Packit f546b1
    }
Packit f546b1
  } else {
Packit f546b1
    if (refcount == NULL) {
Packit f546b1
      g_return_val_if_fail (refcount != NULL, FALSE);
Packit f546b1
      return FALSE;
Packit f546b1
    }
Packit f546b1
  }
Packit f546b1
Packit f546b1
  GST_STRUCTURE_REFCOUNT (structure) = refcount;
Packit f546b1
Packit f546b1
  return TRUE;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_copy:
Packit f546b1
 * @structure: a #GstStructure to duplicate
Packit f546b1
 *
Packit f546b1
 * Duplicates a #GstStructure and all its fields and values.
Packit f546b1
 *
Packit f546b1
 * Free-function: gst_structure_free
Packit f546b1
 *
Packit f546b1
 * Returns: (transfer full): a new #GstStructure.
Packit f546b1
 */
Packit f546b1
GstStructure *
Packit f546b1
gst_structure_copy (const GstStructure * structure)
Packit f546b1
{
Packit f546b1
  GstStructure *new_structure;
Packit f546b1
  GstStructureField *field;
Packit f546b1
  guint i, len;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (structure != NULL, NULL);
Packit f546b1
Packit f546b1
  len = GST_STRUCTURE_FIELDS (structure)->len;
Packit f546b1
  new_structure = gst_structure_new_id_empty_with_size (structure->name, len);
Packit f546b1
Packit f546b1
  for (i = 0; i < len; i++) {
Packit f546b1
    GstStructureField new_field = { 0 };
Packit f546b1
Packit f546b1
    field = GST_STRUCTURE_FIELD (structure, i);
Packit f546b1
Packit f546b1
    new_field.name = field->name;
Packit f546b1
    gst_value_init_and_copy (&new_field.value, &field->value);
Packit f546b1
    g_array_append_val (GST_STRUCTURE_FIELDS (new_structure), new_field);
Packit f546b1
  }
Packit f546b1
  GST_CAT_TRACE (GST_CAT_PERFORMANCE, "doing copy %p -> %p",
Packit f546b1
      structure, new_structure);
Packit f546b1
Packit f546b1
  return new_structure;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_free:
Packit f546b1
 * @structure: (in) (transfer full): the #GstStructure to free
Packit f546b1
 *
Packit f546b1
 * Frees a #GstStructure and all its fields and values. The structure must not
Packit f546b1
 * have a parent when this function is called.
Packit f546b1
 */
Packit f546b1
void
Packit f546b1
gst_structure_free (GstStructure * structure)
Packit f546b1
{
Packit f546b1
  GstStructureField *field;
Packit f546b1
  guint i, len;
Packit f546b1
Packit f546b1
  g_return_if_fail (structure != NULL);
Packit f546b1
  g_return_if_fail (GST_STRUCTURE_REFCOUNT (structure) == NULL);
Packit f546b1
Packit f546b1
  len = GST_STRUCTURE_FIELDS (structure)->len;
Packit f546b1
  for (i = 0; i < len; i++) {
Packit f546b1
    field = GST_STRUCTURE_FIELD (structure, i);
Packit f546b1
Packit f546b1
    if (G_IS_VALUE (&field->value)) {
Packit f546b1
      g_value_unset (&field->value);
Packit f546b1
    }
Packit f546b1
  }
Packit f546b1
  g_array_free (GST_STRUCTURE_FIELDS (structure), TRUE);
Packit f546b1
#ifdef USE_POISONING
Packit f546b1
  memset (structure, 0xff, sizeof (GstStructure));
Packit f546b1
#endif
Packit f546b1
  GST_TRACE ("free structure %p", structure);
Packit f546b1
Packit f546b1
  g_slice_free1 (sizeof (GstStructureImpl), structure);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_get_name:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 *
Packit f546b1
 * Get the name of @structure as a string.
Packit f546b1
 *
Packit f546b1
 * Returns: the name of the structure.
Packit f546b1
 */
Packit f546b1
const gchar *
Packit f546b1
gst_structure_get_name (const GstStructure * structure)
Packit f546b1
{
Packit f546b1
  g_return_val_if_fail (structure != NULL, NULL);
Packit f546b1
Packit f546b1
  return g_quark_to_string (structure->name);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_has_name:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @name: structure name to check for
Packit f546b1
 *
Packit f546b1
 * Checks if the structure has the given name
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if @name matches the name of the structure.
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_has_name (const GstStructure * structure, const gchar * name)
Packit f546b1
{
Packit f546b1
  const gchar *structure_name;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (structure != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (name != NULL, FALSE);
Packit f546b1
Packit f546b1
  /* getting the string is cheap and comparing short strings is too
Packit f546b1
   * should be faster than getting the quark for name and comparing the quarks
Packit f546b1
   */
Packit f546b1
  structure_name = g_quark_to_string (structure->name);
Packit f546b1
Packit f546b1
  return (structure_name && strcmp (structure_name, name) == 0);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_get_name_id:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 *
Packit f546b1
 * Get the name of @structure as a GQuark.
Packit f546b1
 *
Packit f546b1
 * Returns: the quark representing the name of the structure.
Packit f546b1
 */
Packit f546b1
GQuark
Packit f546b1
gst_structure_get_name_id (const GstStructure * structure)
Packit f546b1
{
Packit f546b1
  g_return_val_if_fail (structure != NULL, 0);
Packit f546b1
Packit f546b1
  return structure->name;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_set_name:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @name: the new name of the structure
Packit f546b1
 *
Packit f546b1
 * Sets the name of the structure to the given @name.  The string
Packit f546b1
 * provided is copied before being used. It must not be empty, start with a
Packit f546b1
 * letter and can be followed by letters, numbers and any of "/-_.:".
Packit f546b1
 */
Packit f546b1
void
Packit f546b1
gst_structure_set_name (GstStructure * structure, const gchar * name)
Packit f546b1
{
Packit f546b1
  g_return_if_fail (structure != NULL);
Packit f546b1
  g_return_if_fail (IS_MUTABLE (structure));
Packit f546b1
  g_return_if_fail (gst_structure_validate_name (name));
Packit f546b1
Packit f546b1
  structure->name = g_quark_from_string (name);
Packit f546b1
}
Packit f546b1
Packit f546b1
static inline void
Packit f546b1
gst_structure_id_set_value_internal (GstStructure * structure, GQuark field,
Packit f546b1
    const GValue * value)
Packit f546b1
{
Packit f546b1
  GstStructureField gsfield = { 0, {0,} };
Packit f546b1
Packit f546b1
  gsfield.name = field;
Packit f546b1
  gst_value_init_and_copy (&gsfield.value, value);
Packit f546b1
Packit f546b1
  gst_structure_set_field (structure, &gsfield);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_id_set_value:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @field: a #GQuark representing a field
Packit f546b1
 * @value: the new value of the field
Packit f546b1
 *
Packit f546b1
 * Sets the field with the given GQuark @field to @value.  If the field
Packit f546b1
 * does not exist, it is created.  If the field exists, the previous
Packit f546b1
 * value is replaced and freed.
Packit f546b1
 */
Packit f546b1
void
Packit f546b1
gst_structure_id_set_value (GstStructure * structure,
Packit f546b1
    GQuark field, const GValue * value)
Packit f546b1
{
Packit f546b1
Packit f546b1
  g_return_if_fail (structure != NULL);
Packit f546b1
  g_return_if_fail (G_IS_VALUE (value));
Packit f546b1
  g_return_if_fail (IS_MUTABLE (structure));
Packit f546b1
Packit f546b1
  gst_structure_id_set_value_internal (structure, field, value);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_set_value:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of the field to set
Packit f546b1
 * @value: the new value of the field
Packit f546b1
 *
Packit f546b1
 * Sets the field with the given name @field to @value.  If the field
Packit f546b1
 * does not exist, it is created.  If the field exists, the previous
Packit f546b1
 * value is replaced and freed.
Packit f546b1
 */
Packit f546b1
void
Packit f546b1
gst_structure_set_value (GstStructure * structure,
Packit f546b1
    const gchar * fieldname, const GValue * value)
Packit f546b1
{
Packit f546b1
  g_return_if_fail (structure != NULL);
Packit f546b1
  g_return_if_fail (fieldname != NULL);
Packit f546b1
  g_return_if_fail (G_IS_VALUE (value));
Packit f546b1
  g_return_if_fail (IS_MUTABLE (structure));
Packit f546b1
Packit f546b1
  gst_structure_id_set_value_internal (structure,
Packit f546b1
      g_quark_from_string (fieldname), value);
Packit f546b1
}
Packit f546b1
Packit f546b1
static inline void
Packit f546b1
gst_structure_id_take_value_internal (GstStructure * structure, GQuark field,
Packit f546b1
    GValue * value)
Packit f546b1
{
Packit f546b1
  GstStructureField gsfield = { 0, {0,} };
Packit f546b1
Packit f546b1
  gsfield.name = field;
Packit f546b1
  gsfield.value = *value;
Packit f546b1
Packit f546b1
  gst_structure_set_field (structure, &gsfield);
Packit f546b1
Packit f546b1
  /* we took ownership */
Packit f546b1
#ifdef USE_POISONING
Packit f546b1
  memset (value, 0, sizeof (GValue));
Packit f546b1
#else
Packit f546b1
  value->g_type = G_TYPE_INVALID;
Packit f546b1
#endif
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_id_take_value:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @field: a #GQuark representing a field
Packit f546b1
 * @value: (transfer full): the new value of the field
Packit f546b1
 *
Packit f546b1
 * Sets the field with the given GQuark @field to @value.  If the field
Packit f546b1
 * does not exist, it is created.  If the field exists, the previous
Packit f546b1
 * value is replaced and freed.
Packit f546b1
 */
Packit f546b1
void
Packit f546b1
gst_structure_id_take_value (GstStructure * structure, GQuark field,
Packit f546b1
    GValue * value)
Packit f546b1
{
Packit f546b1
  g_return_if_fail (structure != NULL);
Packit f546b1
  g_return_if_fail (G_IS_VALUE (value));
Packit f546b1
  g_return_if_fail (IS_MUTABLE (structure));
Packit f546b1
Packit f546b1
  gst_structure_id_take_value_internal (structure, field, value);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_take_value:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of the field to set
Packit f546b1
 * @value: (transfer full): the new value of the field
Packit f546b1
 *
Packit f546b1
 * Sets the field with the given name @field to @value.  If the field
Packit f546b1
 * does not exist, it is created.  If the field exists, the previous
Packit f546b1
 * value is replaced and freed. The function will take ownership of @value.
Packit f546b1
 */
Packit f546b1
void
Packit f546b1
gst_structure_take_value (GstStructure * structure, const gchar * fieldname,
Packit f546b1
    GValue * value)
Packit f546b1
{
Packit f546b1
  g_return_if_fail (structure != NULL);
Packit f546b1
  g_return_if_fail (fieldname != NULL);
Packit f546b1
  g_return_if_fail (G_IS_VALUE (value));
Packit f546b1
  g_return_if_fail (IS_MUTABLE (structure));
Packit f546b1
Packit f546b1
  gst_structure_id_take_value_internal (structure,
Packit f546b1
      g_quark_from_string (fieldname), value);
Packit f546b1
}
Packit f546b1
Packit f546b1
static void
Packit f546b1
gst_structure_set_valist_internal (GstStructure * structure,
Packit f546b1
    const gchar * fieldname, va_list varargs)
Packit f546b1
{
Packit f546b1
  gchar *err = NULL;
Packit f546b1
  GType type;
Packit f546b1
Packit f546b1
  while (fieldname) {
Packit f546b1
    GstStructureField field = { 0 };
Packit f546b1
Packit f546b1
    field.name = g_quark_from_string (fieldname);
Packit f546b1
Packit f546b1
    type = va_arg (varargs, GType);
Packit f546b1
Packit f546b1
    G_VALUE_COLLECT_INIT (&field.value, type, varargs, 0, &err;;
Packit f546b1
    if (G_UNLIKELY (err)) {
Packit f546b1
      g_critical ("%s", err);
Packit f546b1
      return;
Packit f546b1
    }
Packit f546b1
    gst_structure_set_field (structure, &field);
Packit f546b1
Packit f546b1
    fieldname = va_arg (varargs, gchar *);
Packit f546b1
  }
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_set:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of the field to set
Packit f546b1
 * @...: variable arguments
Packit f546b1
 *
Packit f546b1
 * Parses the variable arguments and sets fields accordingly. Fields that
Packit f546b1
 * weren't already part of the structure are added as needed.
Packit f546b1
 * Variable arguments should be in the form field name, field type
Packit f546b1
 * (as a GType), value(s).  The last variable argument should be %NULL.
Packit f546b1
 */
Packit f546b1
void
Packit f546b1
gst_structure_set (GstStructure * structure, const gchar * field, ...)
Packit f546b1
{
Packit f546b1
  va_list varargs;
Packit f546b1
Packit f546b1
  g_return_if_fail (structure != NULL);
Packit f546b1
  g_return_if_fail (IS_MUTABLE (structure) || field == NULL);
Packit f546b1
Packit f546b1
  va_start (varargs, field);
Packit f546b1
  gst_structure_set_valist_internal (structure, field, varargs);
Packit f546b1
  va_end (varargs);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_set_valist:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of the field to set
Packit f546b1
 * @varargs: variable arguments
Packit f546b1
 *
Packit f546b1
 * va_list form of gst_structure_set().
Packit f546b1
 */
Packit f546b1
void
Packit f546b1
gst_structure_set_valist (GstStructure * structure,
Packit f546b1
    const gchar * fieldname, va_list varargs)
Packit f546b1
{
Packit f546b1
  g_return_if_fail (structure != NULL);
Packit f546b1
  g_return_if_fail (IS_MUTABLE (structure));
Packit f546b1
Packit f546b1
  gst_structure_set_valist_internal (structure, fieldname, varargs);
Packit f546b1
}
Packit f546b1
Packit f546b1
static void
Packit f546b1
gst_structure_id_set_valist_internal (GstStructure * structure,
Packit f546b1
    GQuark fieldname, va_list varargs)
Packit f546b1
{
Packit f546b1
  gchar *err = NULL;
Packit f546b1
  GType type;
Packit f546b1
Packit f546b1
  while (fieldname) {
Packit f546b1
    GstStructureField field = { 0 };
Packit f546b1
Packit f546b1
    field.name = fieldname;
Packit f546b1
    type = va_arg (varargs, GType);
Packit f546b1
Packit f546b1
    G_VALUE_COLLECT_INIT (&field.value, type, varargs, 0, &err;;
Packit f546b1
    if (G_UNLIKELY (err)) {
Packit f546b1
      g_critical ("%s", err);
Packit f546b1
      return;
Packit f546b1
    }
Packit f546b1
    gst_structure_set_field (structure, &field);
Packit f546b1
Packit f546b1
    fieldname = va_arg (varargs, GQuark);
Packit f546b1
  }
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_id_set:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the GQuark for the name of the field to set
Packit f546b1
 * @...: variable arguments
Packit f546b1
 *
Packit f546b1
 * Identical to gst_structure_set, except that field names are
Packit f546b1
 * passed using the GQuark for the field name. This allows more efficient
Packit f546b1
 * setting of the structure if the caller already knows the associated
Packit f546b1
 * quark values.
Packit f546b1
 * The last variable argument must be %NULL.
Packit f546b1
 */
Packit f546b1
void
Packit f546b1
gst_structure_id_set (GstStructure * structure, GQuark field, ...)
Packit f546b1
{
Packit f546b1
  va_list varargs;
Packit f546b1
Packit f546b1
  g_return_if_fail (structure != NULL);
Packit f546b1
Packit f546b1
  va_start (varargs, field);
Packit f546b1
  gst_structure_id_set_valist_internal (structure, field, varargs);
Packit f546b1
  va_end (varargs);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_id_set_valist:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of the field to set
Packit f546b1
 * @varargs: variable arguments
Packit f546b1
 *
Packit f546b1
 * va_list form of gst_structure_id_set().
Packit f546b1
 */
Packit f546b1
void
Packit f546b1
gst_structure_id_set_valist (GstStructure * structure,
Packit f546b1
    GQuark fieldname, va_list varargs)
Packit f546b1
{
Packit f546b1
  g_return_if_fail (structure != NULL);
Packit f546b1
  g_return_if_fail (IS_MUTABLE (structure));
Packit f546b1
Packit f546b1
  gst_structure_id_set_valist_internal (structure, fieldname, varargs);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_new_id:
Packit f546b1
 * @name_quark: name of new structure
Packit f546b1
 * @field_quark: the GQuark for the name of the field to set
Packit f546b1
 * @...: variable arguments
Packit f546b1
 *
Packit f546b1
 * Creates a new #GstStructure with the given name as a GQuark, followed by
Packit f546b1
 * fieldname quark, GType, argument(s) "triplets" in the same format as
Packit f546b1
 * gst_structure_id_set(). Basically a convenience wrapper around
Packit f546b1
 * gst_structure_new_id_empty() and gst_structure_id_set().
Packit f546b1
 *
Packit f546b1
 * The last variable argument must be %NULL (or 0).
Packit f546b1
 *
Packit f546b1
 * Free-function: gst_structure_free
Packit f546b1
 *
Packit f546b1
 * Returns: (transfer full): a new #GstStructure
Packit f546b1
 */
Packit f546b1
GstStructure *
Packit f546b1
gst_structure_new_id (GQuark name_quark, GQuark field_quark, ...)
Packit f546b1
{
Packit f546b1
  GstStructure *s;
Packit f546b1
  va_list varargs;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (name_quark != 0, NULL);
Packit f546b1
  g_return_val_if_fail (field_quark != 0, NULL);
Packit f546b1
Packit f546b1
  s = gst_structure_new_id_empty (name_quark);
Packit f546b1
Packit f546b1
  va_start (varargs, field_quark);
Packit f546b1
  gst_structure_id_set_valist_internal (s, field_quark, varargs);
Packit f546b1
  va_end (varargs);
Packit f546b1
Packit f546b1
  return s;
Packit f546b1
}
Packit f546b1
Packit f546b1
#if GST_VERSION_NANO == 1
Packit f546b1
#define GIT_G_WARNING g_warning
Packit f546b1
#else
Packit f546b1
#define GIT_G_WARNING GST_WARNING
Packit f546b1
#endif
Packit f546b1
Packit f546b1
/* If the structure currently contains a field with the same name, it is
Packit f546b1
 * replaced with the provided field. Otherwise, the field is added to the
Packit f546b1
 * structure. The field's value is not deeply copied.
Packit f546b1
 */
Packit f546b1
static void
Packit f546b1
gst_structure_set_field (GstStructure * structure, GstStructureField * field)
Packit f546b1
{
Packit f546b1
  GstStructureField *f;
Packit f546b1
  GType field_value_type;
Packit f546b1
  guint i, len;
Packit f546b1
Packit f546b1
  len = GST_STRUCTURE_FIELDS (structure)->len;
Packit f546b1
Packit f546b1
  field_value_type = G_VALUE_TYPE (&field->value);
Packit f546b1
  if (field_value_type == G_TYPE_STRING) {
Packit f546b1
    const gchar *s;
Packit f546b1
Packit f546b1
    s = g_value_get_string (&field->value);
Packit f546b1
    /* only check for NULL strings in taglists, as they are allowed in message
Packit f546b1
     * structs, e.g. error message debug strings */
Packit f546b1
    if (G_UNLIKELY (IS_TAGLIST (structure) && (s == NULL || *s == '\0'))) {
Packit f546b1
      if (s == NULL) {
Packit f546b1
        GIT_G_WARNING ("Trying to set NULL string on field '%s' on taglist. "
Packit f546b1
            "Please file a bug.", g_quark_to_string (field->name));
Packit f546b1
        g_value_unset (&field->value);
Packit f546b1
        return;
Packit f546b1
      } else {
Packit f546b1
        /* empty strings never make sense */
Packit f546b1
        GIT_G_WARNING ("Trying to set empty string on taglist field '%s'. "
Packit f546b1
            "Please file a bug.", g_quark_to_string (field->name));
Packit f546b1
        g_value_unset (&field->value);
Packit f546b1
        return;
Packit f546b1
      }
Packit f546b1
    } else if (G_UNLIKELY (s != NULL && !g_utf8_validate (s, -1, NULL))) {
Packit f546b1
      g_warning ("Trying to set string on %s field '%s', but string is not "
Packit f546b1
          "valid UTF-8. Please file a bug.",
Packit f546b1
          IS_TAGLIST (structure) ? "taglist" : "structure",
Packit f546b1
          g_quark_to_string (field->name));
Packit f546b1
      g_value_unset (&field->value);
Packit f546b1
      return;
Packit f546b1
    }
Packit f546b1
  } else if (G_UNLIKELY (field_value_type == G_TYPE_DATE)) {
Packit f546b1
    const GDate *d;
Packit f546b1
Packit f546b1
    d = g_value_get_boxed (&field->value);
Packit f546b1
    /* only check for NULL GDates in taglists, as they might make sense
Packit f546b1
     * in other, generic structs */
Packit f546b1
    if (G_UNLIKELY ((IS_TAGLIST (structure) && d == NULL))) {
Packit f546b1
      GIT_G_WARNING ("Trying to set NULL GDate on field '%s' on taglist. "
Packit f546b1
          "Please file a bug.", g_quark_to_string (field->name));
Packit f546b1
      g_value_unset (&field->value);
Packit f546b1
      return;
Packit f546b1
    } else if (G_UNLIKELY (d != NULL && !g_date_valid (d))) {
Packit f546b1
      g_warning
Packit f546b1
          ("Trying to set invalid GDate on %s field '%s'. Please file a bug.",
Packit f546b1
          IS_TAGLIST (structure) ? "taglist" : "structure",
Packit f546b1
          g_quark_to_string (field->name));
Packit f546b1
      g_value_unset (&field->value);
Packit f546b1
      return;
Packit f546b1
    }
Packit f546b1
  }
Packit f546b1
Packit f546b1
  for (i = 0; i < len; i++) {
Packit f546b1
    f = GST_STRUCTURE_FIELD (structure, i);
Packit f546b1
Packit f546b1
    if (G_UNLIKELY (f->name == field->name)) {
Packit f546b1
      g_value_unset (&f->value);
Packit f546b1
      memcpy (f, field, sizeof (GstStructureField));
Packit f546b1
      return;
Packit f546b1
    }
Packit f546b1
  }
Packit f546b1
Packit f546b1
  g_array_append_val (GST_STRUCTURE_FIELDS (structure), *field);
Packit f546b1
}
Packit f546b1
Packit f546b1
/* If there is no field with the given ID, NULL is returned.
Packit f546b1
 */
Packit f546b1
static GstStructureField *
Packit f546b1
gst_structure_id_get_field (const GstStructure * structure, GQuark field_id)
Packit f546b1
{
Packit f546b1
  GstStructureField *field;
Packit f546b1
  guint i, len;
Packit f546b1
Packit f546b1
  len = GST_STRUCTURE_FIELDS (structure)->len;
Packit f546b1
Packit f546b1
  for (i = 0; i < len; i++) {
Packit f546b1
    field = GST_STRUCTURE_FIELD (structure, i);
Packit f546b1
Packit f546b1
    if (G_UNLIKELY (field->name == field_id))
Packit f546b1
      return field;
Packit f546b1
  }
Packit f546b1
Packit f546b1
  return NULL;
Packit f546b1
}
Packit f546b1
Packit f546b1
/* If there is no field with the given ID, NULL is returned.
Packit f546b1
 */
Packit f546b1
static GstStructureField *
Packit f546b1
gst_structure_get_field (const GstStructure * structure,
Packit f546b1
    const gchar * fieldname)
Packit f546b1
{
Packit f546b1
  g_return_val_if_fail (structure != NULL, NULL);
Packit f546b1
  g_return_val_if_fail (fieldname != NULL, NULL);
Packit f546b1
Packit f546b1
  return gst_structure_id_get_field (structure,
Packit f546b1
      g_quark_from_string (fieldname));
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_get_value:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of the field to get
Packit f546b1
 *
Packit f546b1
 * Get the value of the field with name @fieldname.
Packit f546b1
 *
Packit f546b1
 * Returns: (nullable): the #GValue corresponding to the field with the given
Packit f546b1
 * name.
Packit f546b1
 */
Packit f546b1
const GValue *
Packit f546b1
gst_structure_get_value (const GstStructure * structure,
Packit f546b1
    const gchar * fieldname)
Packit f546b1
{
Packit f546b1
  GstStructureField *field;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (structure != NULL, NULL);
Packit f546b1
  g_return_val_if_fail (fieldname != NULL, NULL);
Packit f546b1
Packit f546b1
  field = gst_structure_get_field (structure, fieldname);
Packit f546b1
  if (field == NULL)
Packit f546b1
    return NULL;
Packit f546b1
Packit f546b1
  return &field->value;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_id_get_value:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @field: the #GQuark of the field to get
Packit f546b1
 *
Packit f546b1
 * Get the value of the field with GQuark @field.
Packit f546b1
 *
Packit f546b1
 * Returns: (nullable): the #GValue corresponding to the field with the given
Packit f546b1
 * name identifier.
Packit f546b1
 */
Packit f546b1
const GValue *
Packit f546b1
gst_structure_id_get_value (const GstStructure * structure, GQuark field)
Packit f546b1
{
Packit f546b1
  GstStructureField *gsfield;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (structure != NULL, NULL);
Packit f546b1
Packit f546b1
  gsfield = gst_structure_id_get_field (structure, field);
Packit f546b1
  if (gsfield == NULL)
Packit f546b1
    return NULL;
Packit f546b1
Packit f546b1
  return &gsfield->value;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_remove_field:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of the field to remove
Packit f546b1
 *
Packit f546b1
 * Removes the field with the given name.  If the field with the given
Packit f546b1
 * name does not exist, the structure is unchanged.
Packit f546b1
 */
Packit f546b1
void
Packit f546b1
gst_structure_remove_field (GstStructure * structure, const gchar * fieldname)
Packit f546b1
{
Packit f546b1
  GstStructureField *field;
Packit f546b1
  GQuark id;
Packit f546b1
  guint i, len;
Packit f546b1
Packit f546b1
  g_return_if_fail (structure != NULL);
Packit f546b1
  g_return_if_fail (fieldname != NULL);
Packit f546b1
  g_return_if_fail (IS_MUTABLE (structure));
Packit f546b1
Packit f546b1
  id = g_quark_from_string (fieldname);
Packit f546b1
  len = GST_STRUCTURE_FIELDS (structure)->len;
Packit f546b1
Packit f546b1
  for (i = 0; i < len; i++) {
Packit f546b1
    field = GST_STRUCTURE_FIELD (structure, i);
Packit f546b1
Packit f546b1
    if (field->name == id) {
Packit f546b1
      if (G_IS_VALUE (&field->value)) {
Packit f546b1
        g_value_unset (&field->value);
Packit f546b1
      }
Packit f546b1
      GST_STRUCTURE_FIELDS (structure) =
Packit f546b1
          g_array_remove_index (GST_STRUCTURE_FIELDS (structure), i);
Packit f546b1
      return;
Packit f546b1
    }
Packit f546b1
  }
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_remove_fields:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of the field to remove
Packit f546b1
 * @...: %NULL-terminated list of more fieldnames to remove
Packit f546b1
 *
Packit f546b1
 * Removes the fields with the given names. If a field does not exist, the
Packit f546b1
 * argument is ignored.
Packit f546b1
 */
Packit f546b1
void
Packit f546b1
gst_structure_remove_fields (GstStructure * structure,
Packit f546b1
    const gchar * fieldname, ...)
Packit f546b1
{
Packit f546b1
  va_list varargs;
Packit f546b1
Packit f546b1
  g_return_if_fail (structure != NULL);
Packit f546b1
  g_return_if_fail (fieldname != NULL);
Packit f546b1
  /* mutability checked in remove_field */
Packit f546b1
Packit f546b1
  va_start (varargs, fieldname);
Packit f546b1
  gst_structure_remove_fields_valist (structure, fieldname, varargs);
Packit f546b1
  va_end (varargs);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_remove_fields_valist:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of the field to remove
Packit f546b1
 * @varargs: %NULL-terminated list of more fieldnames to remove
Packit f546b1
 *
Packit f546b1
 * va_list form of gst_structure_remove_fields().
Packit f546b1
 */
Packit f546b1
void
Packit f546b1
gst_structure_remove_fields_valist (GstStructure * structure,
Packit f546b1
    const gchar * fieldname, va_list varargs)
Packit f546b1
{
Packit f546b1
  gchar *field = (gchar *) fieldname;
Packit f546b1
Packit f546b1
  g_return_if_fail (structure != NULL);
Packit f546b1
  g_return_if_fail (fieldname != NULL);
Packit f546b1
  /* mutability checked in remove_field */
Packit f546b1
Packit f546b1
  while (field) {
Packit f546b1
    gst_structure_remove_field (structure, field);
Packit f546b1
    field = va_arg (varargs, char *);
Packit f546b1
  }
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_remove_all_fields:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 *
Packit f546b1
 * Removes all fields in a GstStructure.
Packit f546b1
 */
Packit f546b1
void
Packit f546b1
gst_structure_remove_all_fields (GstStructure * structure)
Packit f546b1
{
Packit f546b1
  GstStructureField *field;
Packit f546b1
  int i;
Packit f546b1
Packit f546b1
  g_return_if_fail (structure != NULL);
Packit f546b1
  g_return_if_fail (IS_MUTABLE (structure));
Packit f546b1
Packit f546b1
  for (i = GST_STRUCTURE_FIELDS (structure)->len - 1; i >= 0; i--) {
Packit f546b1
    field = GST_STRUCTURE_FIELD (structure, i);
Packit f546b1
Packit f546b1
    if (G_IS_VALUE (&field->value)) {
Packit f546b1
      g_value_unset (&field->value);
Packit f546b1
    }
Packit f546b1
    GST_STRUCTURE_FIELDS (structure) =
Packit f546b1
        g_array_remove_index (GST_STRUCTURE_FIELDS (structure), i);
Packit f546b1
  }
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_get_field_type:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of the field
Packit f546b1
 *
Packit f546b1
 * Finds the field with the given name, and returns the type of the
Packit f546b1
 * value it contains.  If the field is not found, G_TYPE_INVALID is
Packit f546b1
 * returned.
Packit f546b1
 *
Packit f546b1
 * Returns: the #GValue of the field
Packit f546b1
 */
Packit f546b1
GType
Packit f546b1
gst_structure_get_field_type (const GstStructure * structure,
Packit f546b1
    const gchar * fieldname)
Packit f546b1
{
Packit f546b1
  GstStructureField *field;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (structure != NULL, G_TYPE_INVALID);
Packit f546b1
  g_return_val_if_fail (fieldname != NULL, G_TYPE_INVALID);
Packit f546b1
Packit f546b1
  field = gst_structure_get_field (structure, fieldname);
Packit f546b1
  if (field == NULL)
Packit f546b1
    return G_TYPE_INVALID;
Packit f546b1
Packit f546b1
  return G_VALUE_TYPE (&field->value);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_n_fields:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 *
Packit f546b1
 * Get the number of fields in the structure.
Packit f546b1
 *
Packit f546b1
 * Returns: the number of fields in the structure
Packit f546b1
 */
Packit f546b1
gint
Packit f546b1
gst_structure_n_fields (const GstStructure * structure)
Packit f546b1
{
Packit f546b1
  g_return_val_if_fail (structure != NULL, 0);
Packit f546b1
Packit f546b1
  return GST_STRUCTURE_FIELDS (structure)->len;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_nth_field_name:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @index: the index to get the name of
Packit f546b1
 *
Packit f546b1
 * Get the name of the given field number, counting from 0 onwards.
Packit f546b1
 *
Packit f546b1
 * Returns: the name of the given field number
Packit f546b1
 */
Packit f546b1
const gchar *
Packit f546b1
gst_structure_nth_field_name (const GstStructure * structure, guint index)
Packit f546b1
{
Packit f546b1
  GstStructureField *field;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (structure != NULL, NULL);
Packit f546b1
  g_return_val_if_fail (index < GST_STRUCTURE_FIELDS (structure)->len, NULL);
Packit f546b1
Packit f546b1
  field = GST_STRUCTURE_FIELD (structure, index);
Packit f546b1
Packit f546b1
  return g_quark_to_string (field->name);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_foreach:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @func: (scope call): a function to call for each field
Packit f546b1
 * @user_data: (closure): private data
Packit f546b1
 *
Packit f546b1
 * Calls the provided function once for each field in the #GstStructure. The
Packit f546b1
 * function must not modify the fields. Also see gst_structure_map_in_place()
Packit f546b1
 * and gst_structure_filter_and_map_in_place().
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the supplied function returns %TRUE For each of the fields,
Packit f546b1
 * %FALSE otherwise.
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_foreach (const GstStructure * structure,
Packit f546b1
    GstStructureForeachFunc func, gpointer user_data)
Packit f546b1
{
Packit f546b1
  guint i, len;
Packit f546b1
  GstStructureField *field;
Packit f546b1
  gboolean ret;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (structure != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (func != NULL, FALSE);
Packit f546b1
Packit f546b1
  len = GST_STRUCTURE_FIELDS (structure)->len;
Packit f546b1
Packit f546b1
  for (i = 0; i < len; i++) {
Packit f546b1
    field = GST_STRUCTURE_FIELD (structure, i);
Packit f546b1
Packit f546b1
    ret = func (field->name, &field->value, user_data);
Packit f546b1
    if (G_UNLIKELY (!ret))
Packit f546b1
      return FALSE;
Packit f546b1
  }
Packit f546b1
Packit f546b1
  return TRUE;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_map_in_place:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @func: (scope call): a function to call for each field
Packit f546b1
 * @user_data: (closure): private data
Packit f546b1
 *
Packit f546b1
 * Calls the provided function once for each field in the #GstStructure. In
Packit f546b1
 * contrast to gst_structure_foreach(), the function may modify but not delete the
Packit f546b1
 * fields. The structure must be mutable.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the supplied function returns %TRUE For each of the fields,
Packit f546b1
 * %FALSE otherwise.
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_map_in_place (GstStructure * structure,
Packit f546b1
    GstStructureMapFunc func, gpointer user_data)
Packit f546b1
{
Packit f546b1
  guint i, len;
Packit f546b1
  GstStructureField *field;
Packit f546b1
  gboolean ret;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (structure != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (IS_MUTABLE (structure), FALSE);
Packit f546b1
  g_return_val_if_fail (func != NULL, FALSE);
Packit f546b1
  len = GST_STRUCTURE_FIELDS (structure)->len;
Packit f546b1
Packit f546b1
  for (i = 0; i < len; i++) {
Packit f546b1
    field = GST_STRUCTURE_FIELD (structure, i);
Packit f546b1
Packit f546b1
    ret = func (field->name, &field->value, user_data);
Packit f546b1
    if (!ret)
Packit f546b1
      return FALSE;
Packit f546b1
  }
Packit f546b1
Packit f546b1
  return TRUE;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_filter_and_map_in_place:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @func: (scope call): a function to call for each field
Packit f546b1
 * @user_data: (closure): private data
Packit f546b1
 *
Packit f546b1
 * Calls the provided function once for each field in the #GstStructure. In
Packit f546b1
 * contrast to gst_structure_foreach(), the function may modify the fields.
Packit f546b1
 * In contrast to gst_structure_map_in_place(), the field is removed from
Packit f546b1
 * the structure if %FALSE is returned from the function.
Packit f546b1
 * The structure must be mutable.
Packit f546b1
 *
Packit f546b1
 * Since: 1.6
Packit f546b1
 */
Packit f546b1
void
Packit f546b1
gst_structure_filter_and_map_in_place (GstStructure * structure,
Packit f546b1
    GstStructureFilterMapFunc func, gpointer user_data)
Packit f546b1
{
Packit f546b1
  guint i, len;
Packit f546b1
  GstStructureField *field;
Packit f546b1
  gboolean ret;
Packit f546b1
Packit f546b1
  g_return_if_fail (structure != NULL);
Packit f546b1
  g_return_if_fail (IS_MUTABLE (structure));
Packit f546b1
  g_return_if_fail (func != NULL);
Packit f546b1
  len = GST_STRUCTURE_FIELDS (structure)->len;
Packit f546b1
Packit f546b1
  for (i = 0; i < len;) {
Packit f546b1
    field = GST_STRUCTURE_FIELD (structure, i);
Packit f546b1
Packit f546b1
    ret = func (field->name, &field->value, user_data);
Packit f546b1
Packit f546b1
    if (!ret) {
Packit f546b1
      if (G_IS_VALUE (&field->value)) {
Packit f546b1
        g_value_unset (&field->value);
Packit f546b1
      }
Packit f546b1
      GST_STRUCTURE_FIELDS (structure) =
Packit f546b1
          g_array_remove_index (GST_STRUCTURE_FIELDS (structure), i);
Packit f546b1
      len = GST_STRUCTURE_FIELDS (structure)->len;
Packit f546b1
    } else {
Packit f546b1
      i++;
Packit f546b1
    }
Packit f546b1
  }
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_id_has_field:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @field: #GQuark of the field name
Packit f546b1
 *
Packit f546b1
 * Check if @structure contains a field named @field.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the structure contains a field with the given name
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_id_has_field (const GstStructure * structure, GQuark field)
Packit f546b1
{
Packit f546b1
  GstStructureField *f;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (structure != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (field != 0, FALSE);
Packit f546b1
Packit f546b1
  f = gst_structure_id_get_field (structure, field);
Packit f546b1
Packit f546b1
  return (f != NULL);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_has_field:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of a field
Packit f546b1
 *
Packit f546b1
 * Check if @structure contains a field named @fieldname.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the structure contains a field with the given name
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_has_field (const GstStructure * structure,
Packit f546b1
    const gchar * fieldname)
Packit f546b1
{
Packit f546b1
  g_return_val_if_fail (structure != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (fieldname != NULL, FALSE);
Packit f546b1
Packit f546b1
  return gst_structure_id_has_field (structure,
Packit f546b1
      g_quark_from_string (fieldname));
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_id_has_field_typed:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @field: #GQuark of the field name
Packit f546b1
 * @type: the type of a value
Packit f546b1
 *
Packit f546b1
 * Check if @structure contains a field named @field and with GType @type.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the structure contains a field with the given name and type
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_id_has_field_typed (const GstStructure * structure,
Packit f546b1
    GQuark field, GType type)
Packit f546b1
{
Packit f546b1
  GstStructureField *f;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (structure != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (field != 0, FALSE);
Packit f546b1
Packit f546b1
  f = gst_structure_id_get_field (structure, field);
Packit f546b1
  if (f == NULL)
Packit f546b1
    return FALSE;
Packit f546b1
Packit f546b1
  return (G_VALUE_TYPE (&f->value) == type);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_has_field_typed:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of a field
Packit f546b1
 * @type: the type of a value
Packit f546b1
 *
Packit f546b1
 * Check if @structure contains a field named @fieldname and with GType @type.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the structure contains a field with the given name and type
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_has_field_typed (const GstStructure * structure,
Packit f546b1
    const gchar * fieldname, GType type)
Packit f546b1
{
Packit f546b1
  g_return_val_if_fail (structure != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (fieldname != NULL, FALSE);
Packit f546b1
Packit f546b1
  return gst_structure_id_has_field_typed (structure,
Packit f546b1
      g_quark_from_string (fieldname), type);
Packit f546b1
}
Packit f546b1
Packit f546b1
/* utility functions */
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_get_boolean:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of a field
Packit f546b1
 * @value: (out): a pointer to a #gboolean to set
Packit f546b1
 *
Packit f546b1
 * Sets the boolean pointed to by @value corresponding to the value of the
Packit f546b1
 * given field.  Caller is responsible for making sure the field exists
Packit f546b1
 * and has the correct type.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the value could be set correctly. If there was no field
Packit f546b1
 * with @fieldname or the existing field did not contain a boolean, this
Packit f546b1
 * function returns %FALSE.
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_get_boolean (const GstStructure * structure,
Packit f546b1
    const gchar * fieldname, gboolean * value)
Packit f546b1
{
Packit f546b1
  GstStructureField *field;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (structure != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (fieldname != NULL, FALSE);
Packit f546b1
Packit f546b1
  field = gst_structure_get_field (structure, fieldname);
Packit f546b1
Packit f546b1
  if (field == NULL || G_VALUE_TYPE (&field->value) != G_TYPE_BOOLEAN)
Packit f546b1
    return FALSE;
Packit f546b1
Packit f546b1
  *value = gst_g_value_get_boolean_unchecked (&field->value);
Packit f546b1
Packit f546b1
  return TRUE;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_get_int:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of a field
Packit f546b1
 * @value: (out): a pointer to an int to set
Packit f546b1
 *
Packit f546b1
 * Sets the int pointed to by @value corresponding to the value of the
Packit f546b1
 * given field.  Caller is responsible for making sure the field exists
Packit f546b1
 * and has the correct type.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the value could be set correctly. If there was no field
Packit f546b1
 * with @fieldname or the existing field did not contain an int, this function
Packit f546b1
 * returns %FALSE.
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_get_int (const GstStructure * structure,
Packit f546b1
    const gchar * fieldname, gint * value)
Packit f546b1
{
Packit f546b1
  GstStructureField *field;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (structure != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (fieldname != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (value != NULL, FALSE);
Packit f546b1
Packit f546b1
  field = gst_structure_get_field (structure, fieldname);
Packit f546b1
Packit f546b1
  if (field == NULL || G_VALUE_TYPE (&field->value) != G_TYPE_INT)
Packit f546b1
    return FALSE;
Packit f546b1
Packit f546b1
  *value = gst_g_value_get_int_unchecked (&field->value);
Packit f546b1
Packit f546b1
  return TRUE;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_get_uint:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of a field
Packit f546b1
 * @value: (out): a pointer to a uint to set
Packit f546b1
 *
Packit f546b1
 * Sets the uint pointed to by @value corresponding to the value of the
Packit f546b1
 * given field.  Caller is responsible for making sure the field exists
Packit f546b1
 * and has the correct type.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the value could be set correctly. If there was no field
Packit f546b1
 * with @fieldname or the existing field did not contain a uint, this function
Packit f546b1
 * returns %FALSE.
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_get_uint (const GstStructure * structure,
Packit f546b1
    const gchar * fieldname, guint * value)
Packit f546b1
{
Packit f546b1
  GstStructureField *field;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (structure != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (fieldname != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (value != NULL, FALSE);
Packit f546b1
Packit f546b1
  field = gst_structure_get_field (structure, fieldname);
Packit f546b1
Packit f546b1
  if (field == NULL || G_VALUE_TYPE (&field->value) != G_TYPE_UINT)
Packit f546b1
    return FALSE;
Packit f546b1
Packit f546b1
  *value = gst_g_value_get_uint_unchecked (&field->value);
Packit f546b1
Packit f546b1
  return TRUE;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_get_int64:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of a field
Packit f546b1
 * @value: (out): a pointer to a #gint64 to set
Packit f546b1
 *
Packit f546b1
 * Sets the #gint64 pointed to by @value corresponding to the value of the
Packit f546b1
 * given field. Caller is responsible for making sure the field exists
Packit f546b1
 * and has the correct type.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the value could be set correctly. If there was no field
Packit f546b1
 * with @fieldname or the existing field did not contain a #gint64, this function
Packit f546b1
 * returns %FALSE.
Packit f546b1
 *
Packit f546b1
 * Since: 1.4
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_get_int64 (const GstStructure * structure,
Packit f546b1
    const gchar * fieldname, gint64 * value)
Packit f546b1
{
Packit f546b1
  GstStructureField *field;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (structure != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (fieldname != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (value != NULL, FALSE);
Packit f546b1
Packit f546b1
  field = gst_structure_get_field (structure, fieldname);
Packit f546b1
Packit f546b1
  if (field == NULL || G_VALUE_TYPE (&field->value) != G_TYPE_INT64)
Packit f546b1
    return FALSE;
Packit f546b1
Packit f546b1
  *value = gst_g_value_get_int64_unchecked (&field->value);
Packit f546b1
Packit f546b1
  return TRUE;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_get_uint64:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of a field
Packit f546b1
 * @value: (out): a pointer to a #guint64 to set
Packit f546b1
 *
Packit f546b1
 * Sets the #guint64 pointed to by @value corresponding to the value of the
Packit f546b1
 * given field. Caller is responsible for making sure the field exists
Packit f546b1
 * and has the correct type.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the value could be set correctly. If there was no field
Packit f546b1
 * with @fieldname or the existing field did not contain a #guint64, this function
Packit f546b1
 * returns %FALSE.
Packit f546b1
 *
Packit f546b1
 * Since: 1.4
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_get_uint64 (const GstStructure * structure,
Packit f546b1
    const gchar * fieldname, guint64 * value)
Packit f546b1
{
Packit f546b1
  GstStructureField *field;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (structure != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (fieldname != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (value != NULL, FALSE);
Packit f546b1
Packit f546b1
  field = gst_structure_get_field (structure, fieldname);
Packit f546b1
Packit f546b1
  if (field == NULL || G_VALUE_TYPE (&field->value) != G_TYPE_UINT64)
Packit f546b1
    return FALSE;
Packit f546b1
Packit f546b1
  *value = gst_g_value_get_uint64_unchecked (&field->value);
Packit f546b1
Packit f546b1
  return TRUE;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_get_date:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of a field
Packit f546b1
 * @value: (out callee-allocates): a pointer to a #GDate to set
Packit f546b1
 *
Packit f546b1
 * Sets the date pointed to by @value corresponding to the date of the
Packit f546b1
 * given field.  Caller is responsible for making sure the field exists
Packit f546b1
 * and has the correct type.
Packit f546b1
 *
Packit f546b1
 * On success @value will point to a newly-allocated copy of the date which
Packit f546b1
 * should be freed with g_date_free() when no longer needed (note: this is
Packit f546b1
 * inconsistent with e.g. gst_structure_get_string() which doesn't return a
Packit f546b1
 * copy of the string).
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the value could be set correctly. If there was no field
Packit f546b1
 * with @fieldname or the existing field did not contain a data, this function
Packit f546b1
 * returns %FALSE.
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_get_date (const GstStructure * structure, const gchar * fieldname,
Packit f546b1
    GDate ** value)
Packit f546b1
{
Packit f546b1
  GstStructureField *field;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (structure != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (fieldname != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (value != NULL, FALSE);
Packit f546b1
Packit f546b1
  field = gst_structure_get_field (structure, fieldname);
Packit f546b1
Packit f546b1
  if (field == NULL || G_VALUE_TYPE (&field->value) != G_TYPE_DATE)
Packit f546b1
    return FALSE;
Packit f546b1
Packit f546b1
  /* FIXME: 2.0 g_value_dup_boxed() -> g_value_get_boxed() */
Packit f546b1
  *value = g_value_dup_boxed (&field->value);
Packit f546b1
Packit f546b1
  return TRUE;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_get_date_time:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of a field
Packit f546b1
 * @value: (out callee-allocates): a pointer to a #GstDateTime to set
Packit f546b1
 *
Packit f546b1
 * Sets the datetime pointed to by @value corresponding to the datetime of the
Packit f546b1
 * given field. Caller is responsible for making sure the field exists
Packit f546b1
 * and has the correct type.
Packit f546b1
 *
Packit f546b1
 * On success @value will point to a reference of the datetime which
Packit f546b1
 * should be unreffed with gst_date_time_unref() when no longer needed
Packit f546b1
 * (note: this is inconsistent with e.g. gst_structure_get_string()
Packit f546b1
 * which doesn't return a copy of the string).
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the value could be set correctly. If there was no field
Packit f546b1
 * with @fieldname or the existing field did not contain a data, this function
Packit f546b1
 * returns %FALSE.
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_get_date_time (const GstStructure * structure,
Packit f546b1
    const gchar * fieldname, GstDateTime ** value)
Packit f546b1
{
Packit f546b1
  GstStructureField *field;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (structure != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (fieldname != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (value != NULL, FALSE);
Packit f546b1
Packit f546b1
  field = gst_structure_get_field (structure, fieldname);
Packit f546b1
Packit f546b1
  if (field == NULL)
Packit f546b1
    return FALSE;
Packit f546b1
  if (!GST_VALUE_HOLDS_DATE_TIME (&field->value))
Packit f546b1
    return FALSE;
Packit f546b1
Packit f546b1
  /* FIXME 2.0: g_value_dup_boxed() -> g_value_get_boxed() */
Packit f546b1
  *value = g_value_dup_boxed (&field->value);
Packit f546b1
Packit f546b1
  return TRUE;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_get_clock_time:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of a field
Packit f546b1
 * @value: (out): a pointer to a #GstClockTime to set
Packit f546b1
 *
Packit f546b1
 * Sets the clock time pointed to by @value corresponding to the clock time
Packit f546b1
 * of the given field.  Caller is responsible for making sure the field exists
Packit f546b1
 * and has the correct type.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the value could be set correctly. If there was no field
Packit f546b1
 * with @fieldname or the existing field did not contain a #GstClockTime, this
Packit f546b1
 * function returns %FALSE.
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_get_clock_time (const GstStructure * structure,
Packit f546b1
    const gchar * fieldname, GstClockTime * value)
Packit f546b1
{
Packit f546b1
  return gst_structure_get_uint64 (structure, fieldname, value);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_get_double:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of a field
Packit f546b1
 * @value: (out): a pointer to a gdouble to set
Packit f546b1
 *
Packit f546b1
 * Sets the double pointed to by @value corresponding to the value of the
Packit f546b1
 * given field.  Caller is responsible for making sure the field exists
Packit f546b1
 * and has the correct type.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the value could be set correctly. If there was no field
Packit f546b1
 * with @fieldname or the existing field did not contain a double, this
Packit f546b1
 * function returns %FALSE.
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_get_double (const GstStructure * structure,
Packit f546b1
    const gchar * fieldname, gdouble * value)
Packit f546b1
{
Packit f546b1
  GstStructureField *field;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (structure != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (fieldname != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (value != NULL, FALSE);
Packit f546b1
Packit f546b1
  field = gst_structure_get_field (structure, fieldname);
Packit f546b1
Packit f546b1
  if (field == NULL || G_VALUE_TYPE (&field->value) != G_TYPE_DOUBLE)
Packit f546b1
    return FALSE;
Packit f546b1
Packit f546b1
  *value = gst_g_value_get_double_unchecked (&field->value);
Packit f546b1
Packit f546b1
  return TRUE;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_get_string:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of a field
Packit f546b1
 *
Packit f546b1
 * Finds the field corresponding to @fieldname, and returns the string
Packit f546b1
 * contained in the field's value.  Caller is responsible for making
Packit f546b1
 * sure the field exists and has the correct type.
Packit f546b1
 *
Packit f546b1
 * The string should not be modified, and remains valid until the next
Packit f546b1
 * call to a gst_structure_*() function with the given structure.
Packit f546b1
 *
Packit f546b1
 * Returns: (nullable): a pointer to the string or %NULL when the
Packit f546b1
 * field did not exist or did not contain a string.
Packit f546b1
 */
Packit f546b1
const gchar *
Packit f546b1
gst_structure_get_string (const GstStructure * structure,
Packit f546b1
    const gchar * fieldname)
Packit f546b1
{
Packit f546b1
  GstStructureField *field;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (structure != NULL, NULL);
Packit f546b1
  g_return_val_if_fail (fieldname != NULL, NULL);
Packit f546b1
Packit f546b1
  field = gst_structure_get_field (structure, fieldname);
Packit f546b1
Packit f546b1
  if (field == NULL || G_VALUE_TYPE (&field->value) != G_TYPE_STRING)
Packit f546b1
    return NULL;
Packit f546b1
Packit f546b1
  return gst_g_value_get_string_unchecked (&field->value);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_get_enum:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of a field
Packit f546b1
 * @enumtype: the enum type of a field
Packit f546b1
 * @value: (out): a pointer to an int to set
Packit f546b1
 *
Packit f546b1
 * Sets the int pointed to by @value corresponding to the value of the
Packit f546b1
 * given field.  Caller is responsible for making sure the field exists,
Packit f546b1
 * has the correct type and that the enumtype is correct.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the value could be set correctly. If there was no field
Packit f546b1
 * with @fieldname or the existing field did not contain an enum of the given
Packit f546b1
 * type, this function returns %FALSE.
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_get_enum (const GstStructure * structure,
Packit f546b1
    const gchar * fieldname, GType enumtype, gint * value)
Packit f546b1
{
Packit f546b1
  GstStructureField *field;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (structure != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (fieldname != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (enumtype != G_TYPE_INVALID, FALSE);
Packit f546b1
  g_return_val_if_fail (value != NULL, FALSE);
Packit f546b1
Packit f546b1
  field = gst_structure_get_field (structure, fieldname);
Packit f546b1
Packit f546b1
  if (field == NULL)
Packit f546b1
    return FALSE;
Packit f546b1
  if (!G_TYPE_CHECK_VALUE_TYPE (&field->value, enumtype))
Packit f546b1
    return FALSE;
Packit f546b1
Packit f546b1
  *value = g_value_get_enum (&field->value);
Packit f546b1
Packit f546b1
  return TRUE;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_get_fraction:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of a field
Packit f546b1
 * @value_numerator: (out): a pointer to an int to set
Packit f546b1
 * @value_denominator: (out): a pointer to an int to set
Packit f546b1
 *
Packit f546b1
 * Sets the integers pointed to by @value_numerator and @value_denominator
Packit f546b1
 * corresponding to the value of the given field.  Caller is responsible
Packit f546b1
 * for making sure the field exists and has the correct type.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the values could be set correctly. If there was no field
Packit f546b1
 * with @fieldname or the existing field did not contain a GstFraction, this
Packit f546b1
 * function returns %FALSE.
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_get_fraction (const GstStructure * structure,
Packit f546b1
    const gchar * fieldname, gint * value_numerator, gint * value_denominator)
Packit f546b1
{
Packit f546b1
  GstStructureField *field;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (structure != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (fieldname != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (value_numerator != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (value_denominator != NULL, FALSE);
Packit f546b1
Packit f546b1
  field = gst_structure_get_field (structure, fieldname);
Packit f546b1
Packit f546b1
  if (field == NULL || G_VALUE_TYPE (&field->value) != GST_TYPE_FRACTION)
Packit f546b1
    return FALSE;
Packit f546b1
Packit f546b1
  *value_numerator = gst_value_get_fraction_numerator (&field->value);
Packit f546b1
  *value_denominator = gst_value_get_fraction_denominator (&field->value);
Packit f546b1
Packit f546b1
  return TRUE;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_get_flagset:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of a field
Packit f546b1
 * @value_flags: (out) (allow-none): a pointer to a guint for the flags field
Packit f546b1
 * @value_mask: (out) (allow-none): a pointer to a guint for the mask field
Packit f546b1
 *
Packit f546b1
 * Read the GstFlagSet flags and mask out of the structure into the
Packit f546b1
 * provided pointers.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the values could be set correctly. If there was no field
Packit f546b1
 * with @fieldname or the existing field did not contain a GstFlagSet, this
Packit f546b1
 * function returns %FALSE.
Packit f546b1
 *
Packit f546b1
 * Since: 1.6
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_get_flagset (const GstStructure * structure,
Packit f546b1
    const gchar * fieldname, guint * value_flags, guint * value_mask)
Packit f546b1
{
Packit f546b1
  GstStructureField *field;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (structure != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (fieldname != NULL, FALSE);
Packit f546b1
Packit f546b1
  field = gst_structure_get_field (structure, fieldname);
Packit f546b1
Packit f546b1
  if (field == NULL || !GST_VALUE_HOLDS_FLAG_SET (&field->value))
Packit f546b1
    return FALSE;
Packit f546b1
Packit f546b1
  if (value_flags)
Packit f546b1
    *value_flags = gst_value_get_flagset_flags (&field->value);
Packit f546b1
  if (value_mask)
Packit f546b1
    *value_mask = gst_value_get_flagset_mask (&field->value);
Packit f546b1
Packit f546b1
  return TRUE;
Packit f546b1
}
Packit f546b1
Packit f546b1
static GType
Packit f546b1
gst_structure_value_get_generic_type (const GValue * val)
Packit f546b1
{
Packit f546b1
  if (G_VALUE_TYPE (val) == GST_TYPE_LIST
Packit f546b1
      || G_VALUE_TYPE (val) == GST_TYPE_ARRAY) {
Packit f546b1
    GArray *array = g_value_peek_pointer (val);
Packit f546b1
Packit f546b1
    if (array->len > 0) {
Packit f546b1
      GValue *value = &g_array_index (array, GValue, 0);
Packit f546b1
Packit f546b1
      return gst_structure_value_get_generic_type (value);
Packit f546b1
    } else {
Packit f546b1
      return G_TYPE_INT;
Packit f546b1
    }
Packit f546b1
  } else if (G_VALUE_TYPE (val) == GST_TYPE_INT_RANGE) {
Packit f546b1
    return G_TYPE_INT;
Packit f546b1
  } else if (G_VALUE_TYPE (val) == GST_TYPE_INT64_RANGE) {
Packit f546b1
    return G_TYPE_INT64;
Packit f546b1
  } else if (G_VALUE_TYPE (val) == GST_TYPE_DOUBLE_RANGE) {
Packit f546b1
    return G_TYPE_DOUBLE;
Packit f546b1
  } else if (G_VALUE_TYPE (val) == GST_TYPE_FRACTION_RANGE) {
Packit f546b1
    return GST_TYPE_FRACTION;
Packit f546b1
  }
Packit f546b1
  return G_VALUE_TYPE (val);
Packit f546b1
}
Packit f546b1
Packit f546b1
gboolean
Packit f546b1
priv_gst_structure_append_to_gstring (const GstStructure * structure,
Packit f546b1
    GString * s)
Packit f546b1
{
Packit f546b1
  GstStructureField *field;
Packit f546b1
  guint i, len;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (s != NULL, FALSE);
Packit f546b1
Packit f546b1
  len = GST_STRUCTURE_FIELDS (structure)->len;
Packit f546b1
  for (i = 0; i < len; i++) {
Packit f546b1
    char *t;
Packit f546b1
    GType type;
Packit f546b1
Packit f546b1
    field = GST_STRUCTURE_FIELD (structure, i);
Packit f546b1
Packit f546b1
    if (G_VALUE_TYPE (&field->value) == GST_TYPE_ARRAY) {
Packit f546b1
      t = _priv_gst_value_serialize_any_list (&field->value, "< ", " >", FALSE);
Packit f546b1
    } else if (G_VALUE_TYPE (&field->value) == GST_TYPE_LIST) {
Packit f546b1
      t = _priv_gst_value_serialize_any_list (&field->value, "{ ", " }", FALSE);
Packit f546b1
    } else {
Packit f546b1
      t = gst_value_serialize (&field->value);
Packit f546b1
    }
Packit f546b1
Packit f546b1
    type = gst_structure_value_get_generic_type (&field->value);
Packit f546b1
Packit f546b1
    g_string_append_len (s, ", ", 2);
Packit f546b1
    /* FIXME: do we need to escape fieldnames? */
Packit f546b1
    g_string_append (s, g_quark_to_string (field->name));
Packit f546b1
    g_string_append_len (s, "=(", 2);
Packit f546b1
    g_string_append (s, _priv_gst_value_gtype_to_abbr (type));
Packit f546b1
    g_string_append_c (s, ')');
Packit f546b1
    if (t) {
Packit f546b1
      g_string_append (s, t);
Packit f546b1
      g_free (t);
Packit f546b1
    } else {
Packit f546b1
      if (!G_TYPE_CHECK_VALUE_TYPE (&field->value, G_TYPE_STRING) &&
Packit f546b1
          !(G_TYPE_CHECK_VALUE_TYPE (&field->value, G_TYPE_POINTER) &&
Packit f546b1
              g_value_get_pointer (&field->value) == NULL))
Packit f546b1
        GST_WARNING ("No value transform to serialize field '%s' of type '%s'",
Packit f546b1
            g_quark_to_string (field->name),
Packit f546b1
            _priv_gst_value_gtype_to_abbr (type));
Packit f546b1
      /* TODO(ensonic): don't print NULL if field->value is not empty */
Packit f546b1
      g_string_append (s, "NULL");
Packit f546b1
    }
Packit f546b1
  }
Packit f546b1
Packit f546b1
  g_string_append_c (s, ';');
Packit f546b1
  return TRUE;
Packit f546b1
}
Packit f546b1
Packit f546b1
gboolean
Packit f546b1
priv__gst_structure_append_template_to_gstring (GQuark field_id,
Packit f546b1
    const GValue * value, gpointer user_data)
Packit f546b1
{
Packit f546b1
  GType type = gst_structure_value_get_generic_type (value);
Packit f546b1
  GString *s = (GString *) user_data;
Packit f546b1
Packit f546b1
  g_string_append_len (s, ", ", 2);
Packit f546b1
  /* FIXME: do we need to escape fieldnames? */
Packit f546b1
  g_string_append (s, g_quark_to_string (field_id));
Packit f546b1
  g_string_append_len (s, "=(", 2);
Packit f546b1
  g_string_append (s, _priv_gst_value_gtype_to_abbr (type));
Packit f546b1
  g_string_append_c (s, ')');
Packit f546b1
Packit f546b1
  //TODO(ensonic): table like GstStructureAbbreviation (or extend it)
Packit f546b1
  if (type == G_TYPE_INT) {
Packit f546b1
    g_string_append_len (s, "%i", 2);
Packit f546b1
  } else if (type == G_TYPE_UINT) {
Packit f546b1
    g_string_append_len (s, "%u", 2);
Packit f546b1
  } else if (type == G_TYPE_FLOAT) {
Packit f546b1
    g_string_append_len (s, "%f", 2);
Packit f546b1
  } else if (type == G_TYPE_DOUBLE) {
Packit f546b1
    g_string_append_len (s, "%lf", 3);
Packit f546b1
  } else if (type == G_TYPE_STRING) {
Packit f546b1
    g_string_append_len (s, "%s", 2);
Packit f546b1
  } else if (type == G_TYPE_BOOLEAN) {
Packit f546b1
    /* we normally store this as a string, but can parse it also from an int */
Packit f546b1
    g_string_append_len (s, "%i", 2);
Packit f546b1
  } else if (type == G_TYPE_INT64) {
Packit f546b1
    g_string_append (s, "%" G_GINT64_FORMAT);
Packit f546b1
  } else if (type == G_TYPE_UINT64) {
Packit f546b1
    g_string_append (s, "%" G_GUINT64_FORMAT);
Packit f546b1
  } else if (type == GST_TYPE_STRUCTURE) {
Packit f546b1
    g_string_append (s, "%" GST_WRAPPED_PTR_FORMAT);
Packit f546b1
  } else if (g_type_is_a (type, G_TYPE_ENUM)
Packit f546b1
      || g_type_is_a (type, G_TYPE_FLAGS)) {
Packit f546b1
    g_string_append_len (s, "%i", 2);
Packit f546b1
  } else if (type == G_TYPE_GTYPE) {
Packit f546b1
    g_string_append_len (s, "%s", 2);
Packit f546b1
  } else if (type == G_TYPE_POINTER) {
Packit f546b1
    g_string_append_len (s, "%p", 2);
Packit f546b1
  } else {
Packit f546b1
    GST_WARNING ("unhandled type: %s", g_type_name (type));
Packit f546b1
    g_string_append (s, "%" GST_WRAPPED_PTR_FORMAT);
Packit f546b1
  }
Packit f546b1
Packit f546b1
  return TRUE;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_to_string:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 *
Packit f546b1
 * Converts @structure to a human-readable string representation.
Packit f546b1
 *
Packit f546b1
 * For debugging purposes its easier to do something like this:
Packit f546b1
 * |[
Packit f546b1
 * GST_LOG ("structure is %" GST_PTR_FORMAT, structure);
Packit f546b1
 * ]|
Packit f546b1
 * This prints the structure in human readable form.
Packit f546b1
 *
Packit f546b1
 * The current implementation of serialization will lead to unexpected results
Packit f546b1
 * when there are nested #GstCaps / #GstStructure deeper than one level.
Packit f546b1
 *
Packit f546b1
 * Free-function: g_free
Packit f546b1
 *
Packit f546b1
 * Returns: (transfer full): a pointer to string allocated by g_malloc().
Packit f546b1
 *     g_free() after usage.
Packit f546b1
 */
Packit f546b1
gchar *
Packit f546b1
gst_structure_to_string (const GstStructure * structure)
Packit f546b1
{
Packit f546b1
  GString *s;
Packit f546b1
Packit f546b1
  /* NOTE:  This function is potentially called by the debug system,
Packit f546b1
   * so any calls to gst_log() (and GST_DEBUG(), GST_LOG(), etc.)
Packit f546b1
   * should be careful to avoid recursion.  This includes any functions
Packit f546b1
   * called by gst_structure_to_string.  In particular, calls should
Packit f546b1
   * not use the GST_PTR_FORMAT extension.  */
Packit f546b1
Packit f546b1
  g_return_val_if_fail (structure != NULL, NULL);
Packit f546b1
Packit f546b1
  /* we estimate a minimum size based on the number of fields in order to
Packit f546b1
   * avoid unnecessary reallocs within GString */
Packit f546b1
  s = g_string_sized_new (STRUCTURE_ESTIMATED_STRING_LEN (structure));
Packit f546b1
  g_string_append (s, g_quark_to_string (structure->name));
Packit f546b1
  priv_gst_structure_append_to_gstring (structure, s);
Packit f546b1
  return g_string_free (s, FALSE);
Packit f546b1
}
Packit f546b1
Packit f546b1
static gboolean
Packit f546b1
gst_structure_parse_field (gchar * str,
Packit f546b1
    gchar ** after, GstStructureField * field)
Packit f546b1
{
Packit f546b1
  gchar *name;
Packit f546b1
  gchar *name_end;
Packit f546b1
  gchar *s;
Packit f546b1
  gchar c;
Packit f546b1
Packit f546b1
  s = str;
Packit f546b1
Packit f546b1
  while (g_ascii_isspace (*s) || (s[0] == '\\' && g_ascii_isspace (s[1])))
Packit f546b1
    s++;
Packit f546b1
  name = s;
Packit f546b1
  if (G_UNLIKELY (!_priv_gst_value_parse_simple_string (s, &name_end))) {
Packit f546b1
    GST_WARNING ("failed to parse simple string, str=%s", str);
Packit f546b1
    return FALSE;
Packit f546b1
  }
Packit f546b1
Packit f546b1
  s = name_end;
Packit f546b1
  while (g_ascii_isspace (*s) || (s[0] == '\\' && g_ascii_isspace (s[1])))
Packit f546b1
    s++;
Packit f546b1
Packit f546b1
  if (G_UNLIKELY (*s != '=')) {
Packit f546b1
    GST_WARNING ("missing assignment operator in the field, str=%s", str);
Packit f546b1
    return FALSE;
Packit f546b1
  }
Packit f546b1
  s++;
Packit f546b1
Packit f546b1
  c = *name_end;
Packit f546b1
  *name_end = '\0';
Packit f546b1
  field->name = g_quark_from_string (name);
Packit f546b1
  GST_DEBUG ("trying field name '%s'", name);
Packit f546b1
  *name_end = c;
Packit f546b1
Packit f546b1
  if (G_UNLIKELY (!_priv_gst_value_parse_value (s, &s, &field->value,
Packit f546b1
              G_TYPE_INVALID))) {
Packit f546b1
    GST_WARNING ("failed to parse value %s", str);
Packit f546b1
    return FALSE;
Packit f546b1
  }
Packit f546b1
Packit f546b1
  *after = s;
Packit f546b1
  return TRUE;
Packit f546b1
}
Packit f546b1
Packit f546b1
gboolean
Packit f546b1
priv_gst_structure_parse_name (gchar * str, gchar ** start, gchar ** end,
Packit f546b1
    gchar ** next)
Packit f546b1
{
Packit f546b1
  char *w;
Packit f546b1
  char *r;
Packit f546b1
Packit f546b1
  r = str;
Packit f546b1
Packit f546b1
  /* skip spaces (FIXME: _isspace treats tabs and newlines as space!) */
Packit f546b1
  while (*r && (g_ascii_isspace (*r) || (r[0] == '\\'
Packit f546b1
              && g_ascii_isspace (r[1]))))
Packit f546b1
    r++;
Packit f546b1
Packit f546b1
  *start = r;
Packit f546b1
Packit f546b1
  if (G_UNLIKELY (!_priv_gst_value_parse_string (r, &w, &r, TRUE))) {
Packit f546b1
    GST_WARNING ("Failed to parse structure string '%s'", str);
Packit f546b1
    return FALSE;
Packit f546b1
  }
Packit f546b1
Packit f546b1
  *end = w;
Packit f546b1
  *next = r;
Packit f546b1
Packit f546b1
  return TRUE;
Packit f546b1
}
Packit f546b1
Packit f546b1
gboolean
Packit f546b1
priv_gst_structure_parse_fields (gchar * str, gchar ** end,
Packit f546b1
    GstStructure * structure)
Packit f546b1
{
Packit f546b1
  gchar *r;
Packit f546b1
  GstStructureField field;
Packit f546b1
Packit f546b1
  r = str;
Packit f546b1
Packit f546b1
  do {
Packit f546b1
    while (*r && (g_ascii_isspace (*r) || (r[0] == '\\'
Packit f546b1
                && g_ascii_isspace (r[1]))))
Packit f546b1
      r++;
Packit f546b1
    if (*r == ';') {
Packit f546b1
      /* end of structure, get the next char and finish */
Packit f546b1
      r++;
Packit f546b1
      break;
Packit f546b1
    }
Packit f546b1
    if (*r == '\0') {
Packit f546b1
      /* accept \0 as end delimiter */
Packit f546b1
      break;
Packit f546b1
    }
Packit f546b1
    if (G_UNLIKELY (*r != ',')) {
Packit f546b1
      GST_WARNING ("Failed to find delimiter, r=%s", r);
Packit f546b1
      return FALSE;
Packit f546b1
    }
Packit f546b1
    r++;
Packit f546b1
    while (*r && (g_ascii_isspace (*r) || (r[0] == '\\'
Packit f546b1
                && g_ascii_isspace (r[1]))))
Packit f546b1
      r++;
Packit f546b1
Packit f546b1
    memset (&field, 0, sizeof (field));
Packit f546b1
    if (G_UNLIKELY (!gst_structure_parse_field (r, &r, &field))) {
Packit f546b1
      GST_WARNING ("Failed to parse field, r=%s", r);
Packit f546b1
      return FALSE;
Packit f546b1
    }
Packit f546b1
    gst_structure_set_field (structure, &field);
Packit f546b1
  } while (TRUE);
Packit f546b1
Packit f546b1
  *end = r;
Packit f546b1
Packit f546b1
  return TRUE;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_new_from_string:
Packit f546b1
 * @string: a string representation of a #GstStructure
Packit f546b1
 *
Packit f546b1
 * Creates a #GstStructure from a string representation.
Packit f546b1
 * If end is not %NULL, a pointer to the place inside the given string
Packit f546b1
 * where parsing ended will be returned.
Packit f546b1
 *
Packit f546b1
 * The current implementation of serialization will lead to unexpected results
Packit f546b1
 * when there are nested #GstCaps / #GstStructure deeper than one level.
Packit f546b1
 *
Packit f546b1
 * Free-function: gst_structure_free
Packit f546b1
 *
Packit f546b1
 * Returns: (transfer full) (nullable): a new #GstStructure or %NULL
Packit f546b1
 *     when the string could not be parsed. Free with
Packit f546b1
 *     gst_structure_free() after use.
Packit f546b1
 *
Packit f546b1
 * Since: 1.2
Packit f546b1
 */
Packit f546b1
GstStructure *
Packit f546b1
gst_structure_new_from_string (const gchar * string)
Packit f546b1
{
Packit f546b1
  return gst_structure_from_string (string, NULL);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_from_string:
Packit f546b1
 * @string: a string representation of a #GstStructure.
Packit f546b1
 * @end: (out) (allow-none) (transfer none) (skip): pointer to store the end of the string in.
Packit f546b1
 *
Packit f546b1
 * Creates a #GstStructure from a string representation.
Packit f546b1
 * If end is not %NULL, a pointer to the place inside the given string
Packit f546b1
 * where parsing ended will be returned.
Packit f546b1
 *
Packit f546b1
 * Free-function: gst_structure_free
Packit f546b1
 *
Packit f546b1
 * Returns: (transfer full) (nullable): a new #GstStructure or %NULL
Packit f546b1
 *     when the string could not be parsed. Free with
Packit f546b1
 *     gst_structure_free() after use.
Packit f546b1
 */
Packit f546b1
GstStructure *
Packit f546b1
gst_structure_from_string (const gchar * string, gchar ** end)
Packit f546b1
{
Packit f546b1
  char *name;
Packit f546b1
  char *copy;
Packit f546b1
  char *w;
Packit f546b1
  char *r;
Packit f546b1
  char save;
Packit f546b1
  GstStructure *structure = NULL;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (string != NULL, NULL);
Packit f546b1
Packit f546b1
  copy = g_strdup (string);
Packit f546b1
  r = copy;
Packit f546b1
Packit f546b1
  if (!priv_gst_structure_parse_name (r, &name, &w, &r))
Packit f546b1
    goto error;
Packit f546b1
Packit f546b1
  save = *w;
Packit f546b1
  *w = '\0';
Packit f546b1
  structure = gst_structure_new_empty (name);
Packit f546b1
  *w = save;
Packit f546b1
Packit f546b1
  if (G_UNLIKELY (structure == NULL))
Packit f546b1
    goto error;
Packit f546b1
Packit f546b1
  if (!priv_gst_structure_parse_fields (r, &r, structure))
Packit f546b1
    goto error;
Packit f546b1
Packit f546b1
  if (end)
Packit f546b1
    *end = (char *) string + (r - copy);
Packit f546b1
  else if (*r)
Packit f546b1
    g_warning ("gst_structure_from_string did not consume whole string,"
Packit f546b1
        " but caller did not provide end pointer (\"%s\")", string);
Packit f546b1
Packit f546b1
  g_free (copy);
Packit f546b1
  return structure;
Packit f546b1
Packit f546b1
error:
Packit f546b1
  if (structure)
Packit f546b1
    gst_structure_free (structure);
Packit f546b1
  g_free (copy);
Packit f546b1
  return NULL;
Packit f546b1
}
Packit f546b1
Packit f546b1
static void
Packit f546b1
gst_structure_transform_to_string (const GValue * src_value,
Packit f546b1
    GValue * dest_value)
Packit f546b1
{
Packit f546b1
  g_return_if_fail (src_value != NULL);
Packit f546b1
  g_return_if_fail (dest_value != NULL);
Packit f546b1
Packit f546b1
  dest_value->data[0].v_pointer =
Packit f546b1
      gst_structure_to_string (src_value->data[0].v_pointer);
Packit f546b1
}
Packit f546b1
Packit f546b1
static GstStructure *
Packit f546b1
gst_structure_copy_conditional (const GstStructure * structure)
Packit f546b1
{
Packit f546b1
  if (structure)
Packit f546b1
    return gst_structure_copy (structure);
Packit f546b1
  return NULL;
Packit f546b1
}
Packit f546b1
Packit f546b1
/* fixate utility functions */
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_fixate_field_nearest_int:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @field_name: a field in @structure
Packit f546b1
 * @target: the target value of the fixation
Packit f546b1
 *
Packit f546b1
 * Fixates a #GstStructure by changing the given field to the nearest
Packit f546b1
 * integer to @target that is a subset of the existing field.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the structure could be fixated
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_fixate_field_nearest_int (GstStructure * structure,
Packit f546b1
    const char *field_name, int target)
Packit f546b1
{
Packit f546b1
  const GValue *value;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (gst_structure_has_field (structure, field_name), FALSE);
Packit f546b1
  g_return_val_if_fail (IS_MUTABLE (structure), FALSE);
Packit f546b1
Packit f546b1
  value = gst_structure_get_value (structure, field_name);
Packit f546b1
Packit f546b1
  if (G_VALUE_TYPE (value) == G_TYPE_INT) {
Packit f546b1
    /* already fixed */
Packit f546b1
    return FALSE;
Packit f546b1
  } else if (G_VALUE_TYPE (value) == GST_TYPE_INT_RANGE) {
Packit f546b1
    int x;
Packit f546b1
Packit f546b1
    x = gst_value_get_int_range_min (value);
Packit f546b1
    if (target < x)
Packit f546b1
      target = x;
Packit f546b1
    x = gst_value_get_int_range_max (value);
Packit f546b1
    if (target > x)
Packit f546b1
      target = x;
Packit f546b1
    gst_structure_set (structure, field_name, G_TYPE_INT, target, NULL);
Packit f546b1
    return TRUE;
Packit f546b1
  } else if (G_VALUE_TYPE (value) == GST_TYPE_LIST) {
Packit f546b1
    const GValue *list_value;
Packit f546b1
    int i, n;
Packit f546b1
    int best = 0;
Packit f546b1
    int best_index = -1;
Packit f546b1
Packit f546b1
    n = gst_value_list_get_size (value);
Packit f546b1
    for (i = 0; i < n; i++) {
Packit f546b1
      list_value = gst_value_list_get_value (value, i);
Packit f546b1
      if (G_VALUE_TYPE (list_value) == G_TYPE_INT) {
Packit f546b1
        int x = gst_g_value_get_int_unchecked (list_value);
Packit f546b1
Packit f546b1
        if (best_index == -1 || (ABS (target - x) < ABS (target - best))) {
Packit f546b1
          best_index = i;
Packit f546b1
          best = x;
Packit f546b1
        }
Packit f546b1
      }
Packit f546b1
    }
Packit f546b1
    if (best_index != -1) {
Packit f546b1
      gst_structure_set (structure, field_name, G_TYPE_INT, best, NULL);
Packit f546b1
      return TRUE;
Packit f546b1
    }
Packit f546b1
    return FALSE;
Packit f546b1
  }
Packit f546b1
Packit f546b1
  return FALSE;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_fixate_field_nearest_double:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @field_name: a field in @structure
Packit f546b1
 * @target: the target value of the fixation
Packit f546b1
 *
Packit f546b1
 * Fixates a #GstStructure by changing the given field to the nearest
Packit f546b1
 * double to @target that is a subset of the existing field.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the structure could be fixated
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_fixate_field_nearest_double (GstStructure * structure,
Packit f546b1
    const char *field_name, double target)
Packit f546b1
{
Packit f546b1
  const GValue *value;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (gst_structure_has_field (structure, field_name), FALSE);
Packit f546b1
  g_return_val_if_fail (IS_MUTABLE (structure), FALSE);
Packit f546b1
Packit f546b1
  value = gst_structure_get_value (structure, field_name);
Packit f546b1
Packit f546b1
  if (G_VALUE_TYPE (value) == G_TYPE_DOUBLE) {
Packit f546b1
    /* already fixed */
Packit f546b1
    return FALSE;
Packit f546b1
  } else if (G_VALUE_TYPE (value) == GST_TYPE_DOUBLE_RANGE) {
Packit f546b1
    double x;
Packit f546b1
Packit f546b1
    x = gst_value_get_double_range_min (value);
Packit f546b1
    if (target < x)
Packit f546b1
      target = x;
Packit f546b1
    x = gst_value_get_double_range_max (value);
Packit f546b1
    if (target > x)
Packit f546b1
      target = x;
Packit f546b1
    gst_structure_set (structure, field_name, G_TYPE_DOUBLE, target, NULL);
Packit f546b1
    return TRUE;
Packit f546b1
  } else if (G_VALUE_TYPE (value) == GST_TYPE_LIST) {
Packit f546b1
    const GValue *list_value;
Packit f546b1
    int i, n;
Packit f546b1
    double best = 0;
Packit f546b1
    int best_index = -1;
Packit f546b1
Packit f546b1
    n = gst_value_list_get_size (value);
Packit f546b1
    for (i = 0; i < n; i++) {
Packit f546b1
      list_value = gst_value_list_get_value (value, i);
Packit f546b1
      if (G_VALUE_TYPE (list_value) == G_TYPE_DOUBLE) {
Packit f546b1
        double x = gst_g_value_get_double_unchecked (list_value);
Packit f546b1
Packit f546b1
        if (best_index == -1 || (ABS (target - x) < ABS (target - best))) {
Packit f546b1
          best_index = i;
Packit f546b1
          best = x;
Packit f546b1
        }
Packit f546b1
      }
Packit f546b1
    }
Packit f546b1
    if (best_index != -1) {
Packit f546b1
      gst_structure_set (structure, field_name, G_TYPE_DOUBLE, best, NULL);
Packit f546b1
      return TRUE;
Packit f546b1
    }
Packit f546b1
    return FALSE;
Packit f546b1
  }
Packit f546b1
Packit f546b1
  return FALSE;
Packit f546b1
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_fixate_field_boolean:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @field_name: a field in @structure
Packit f546b1
 * @target: the target value of the fixation
Packit f546b1
 *
Packit f546b1
 * Fixates a #GstStructure by changing the given @field_name field to the given
Packit f546b1
 * @target boolean if that field is not fixed yet.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the structure could be fixated
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_fixate_field_boolean (GstStructure * structure,
Packit f546b1
    const char *field_name, gboolean target)
Packit f546b1
{
Packit f546b1
  const GValue *value;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (gst_structure_has_field (structure, field_name), FALSE);
Packit f546b1
  g_return_val_if_fail (IS_MUTABLE (structure), FALSE);
Packit f546b1
Packit f546b1
  value = gst_structure_get_value (structure, field_name);
Packit f546b1
Packit f546b1
  if (G_VALUE_TYPE (value) == G_TYPE_BOOLEAN) {
Packit f546b1
    /* already fixed */
Packit f546b1
    return FALSE;
Packit f546b1
  } else if (G_VALUE_TYPE (value) == GST_TYPE_LIST) {
Packit f546b1
    const GValue *list_value;
Packit f546b1
    int i, n;
Packit f546b1
    int best = 0;
Packit f546b1
    int best_index = -1;
Packit f546b1
Packit f546b1
    n = gst_value_list_get_size (value);
Packit f546b1
    for (i = 0; i < n; i++) {
Packit f546b1
      list_value = gst_value_list_get_value (value, i);
Packit f546b1
      if (G_VALUE_TYPE (list_value) == G_TYPE_BOOLEAN) {
Packit f546b1
        gboolean x = gst_g_value_get_boolean_unchecked (list_value);
Packit f546b1
Packit f546b1
        if (best_index == -1 || x == target) {
Packit f546b1
          best_index = i;
Packit f546b1
          best = x;
Packit f546b1
        }
Packit f546b1
      }
Packit f546b1
    }
Packit f546b1
    if (best_index != -1) {
Packit f546b1
      gst_structure_set (structure, field_name, G_TYPE_BOOLEAN, best, NULL);
Packit f546b1
      return TRUE;
Packit f546b1
    }
Packit f546b1
    return FALSE;
Packit f546b1
  }
Packit f546b1
Packit f546b1
  return FALSE;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_fixate_field_string:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @field_name: a field in @structure
Packit f546b1
 * @target: the target value of the fixation
Packit f546b1
 *
Packit f546b1
 * Fixates a #GstStructure by changing the given @field_name field to the given
Packit f546b1
 * @target string if that field is not fixed yet.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the structure could be fixated
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_fixate_field_string (GstStructure * structure,
Packit f546b1
    const gchar * field_name, const gchar * target)
Packit f546b1
{
Packit f546b1
  const GValue *value;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (gst_structure_has_field (structure, field_name), FALSE);
Packit f546b1
  g_return_val_if_fail (IS_MUTABLE (structure), FALSE);
Packit f546b1
Packit f546b1
  value = gst_structure_get_value (structure, field_name);
Packit f546b1
Packit f546b1
  if (G_VALUE_TYPE (value) == G_TYPE_STRING) {
Packit f546b1
    /* already fixed */
Packit f546b1
    return FALSE;
Packit f546b1
  } else if (G_VALUE_TYPE (value) == GST_TYPE_LIST) {
Packit f546b1
    const GValue *list_value;
Packit f546b1
    int i, n;
Packit f546b1
    const gchar *best = NULL;
Packit f546b1
    int best_index = -1;
Packit f546b1
Packit f546b1
    n = gst_value_list_get_size (value);
Packit f546b1
    for (i = 0; i < n; i++) {
Packit f546b1
      list_value = gst_value_list_get_value (value, i);
Packit f546b1
      if (G_VALUE_TYPE (list_value) == G_TYPE_STRING) {
Packit f546b1
        const gchar *x = g_value_get_string (list_value);
Packit f546b1
Packit f546b1
        if (best_index == -1 || g_str_equal (x, target)) {
Packit f546b1
          best_index = i;
Packit f546b1
          best = x;
Packit f546b1
        }
Packit f546b1
      }
Packit f546b1
    }
Packit f546b1
    if (best_index != -1) {
Packit f546b1
      gst_structure_set (structure, field_name, G_TYPE_STRING, best, NULL);
Packit f546b1
      return TRUE;
Packit f546b1
    }
Packit f546b1
    return FALSE;
Packit f546b1
  }
Packit f546b1
Packit f546b1
  return FALSE;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_fixate_field_nearest_fraction:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @field_name: a field in @structure
Packit f546b1
 * @target_numerator: The numerator of the target value of the fixation
Packit f546b1
 * @target_denominator: The denominator of the target value of the fixation
Packit f546b1
 *
Packit f546b1
 * Fixates a #GstStructure by changing the given field to the nearest
Packit f546b1
 * fraction to @target_numerator/@target_denominator that is a subset
Packit f546b1
 * of the existing field.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the structure could be fixated
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_fixate_field_nearest_fraction (GstStructure * structure,
Packit f546b1
    const char *field_name, const gint target_numerator,
Packit f546b1
    const gint target_denominator)
Packit f546b1
{
Packit f546b1
  const GValue *value;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (gst_structure_has_field (structure, field_name), FALSE);
Packit f546b1
  g_return_val_if_fail (IS_MUTABLE (structure), FALSE);
Packit f546b1
  g_return_val_if_fail (target_denominator != 0, FALSE);
Packit f546b1
Packit f546b1
  value = gst_structure_get_value (structure, field_name);
Packit f546b1
Packit f546b1
  if (G_VALUE_TYPE (value) == GST_TYPE_FRACTION) {
Packit f546b1
    /* already fixed */
Packit f546b1
    return FALSE;
Packit f546b1
  } else if (G_VALUE_TYPE (value) == GST_TYPE_FRACTION_RANGE) {
Packit f546b1
    const GValue *x, *new_value;
Packit f546b1
    GValue target = { 0 };
Packit f546b1
    g_value_init (&target, GST_TYPE_FRACTION);
Packit f546b1
    gst_value_set_fraction (&target, target_numerator, target_denominator);
Packit f546b1
Packit f546b1
    new_value = ⌖
Packit f546b1
    x = gst_value_get_fraction_range_min (value);
Packit f546b1
    if (gst_value_compare (&target, x) == GST_VALUE_LESS_THAN)
Packit f546b1
      new_value = x;
Packit f546b1
    x = gst_value_get_fraction_range_max (value);
Packit f546b1
    if (gst_value_compare (&target, x) == GST_VALUE_GREATER_THAN)
Packit f546b1
      new_value = x;
Packit f546b1
Packit f546b1
    gst_structure_set_value (structure, field_name, new_value);
Packit f546b1
    g_value_unset (&target);
Packit f546b1
    return TRUE;
Packit f546b1
  } else if (G_VALUE_TYPE (value) == GST_TYPE_LIST) {
Packit f546b1
    const GValue *list_value;
Packit f546b1
    int i, n;
Packit f546b1
    const GValue *best = NULL;
Packit f546b1
    gdouble target;
Packit f546b1
    gdouble cur_diff;
Packit f546b1
    gdouble best_diff = G_MAXDOUBLE;
Packit f546b1
Packit f546b1
    target = (gdouble) target_numerator / (gdouble) target_denominator;
Packit f546b1
Packit f546b1
    GST_DEBUG ("target %g, best %g", target, best_diff);
Packit f546b1
Packit f546b1
    best = NULL;
Packit f546b1
Packit f546b1
    n = gst_value_list_get_size (value);
Packit f546b1
    for (i = 0; i < n; i++) {
Packit f546b1
      list_value = gst_value_list_get_value (value, i);
Packit f546b1
      if (G_VALUE_TYPE (list_value) == GST_TYPE_FRACTION) {
Packit f546b1
        gint num, denom;
Packit f546b1
        gdouble list_double;
Packit f546b1
Packit f546b1
        num = gst_value_get_fraction_numerator (list_value);
Packit f546b1
        denom = gst_value_get_fraction_denominator (list_value);
Packit f546b1
Packit f546b1
        list_double = ((gdouble) num / (gdouble) denom);
Packit f546b1
        cur_diff = target - list_double;
Packit f546b1
Packit f546b1
        GST_DEBUG ("curr diff %g, list %g", cur_diff, list_double);
Packit f546b1
Packit f546b1
        if (cur_diff < 0)
Packit f546b1
          cur_diff = -cur_diff;
Packit f546b1
Packit f546b1
        if (!best || cur_diff < best_diff) {
Packit f546b1
          GST_DEBUG ("new best %g", list_double);
Packit f546b1
          best = list_value;
Packit f546b1
          best_diff = cur_diff;
Packit f546b1
        }
Packit f546b1
      }
Packit f546b1
    }
Packit f546b1
    if (best != NULL) {
Packit f546b1
      gst_structure_set_value (structure, field_name, best);
Packit f546b1
      return TRUE;
Packit f546b1
    }
Packit f546b1
  }
Packit f546b1
Packit f546b1
  return FALSE;
Packit f546b1
}
Packit f546b1
Packit f546b1
static gboolean
Packit f546b1
default_fixate (GQuark field_id, const GValue * value, gpointer data)
Packit f546b1
{
Packit f546b1
  GstStructure *s = data;
Packit f546b1
  GValue v = { 0 };
Packit f546b1
Packit f546b1
  if (gst_value_fixate (&v, value)) {
Packit f546b1
    gst_structure_id_take_value (s, field_id, &v);
Packit f546b1
  }
Packit f546b1
  return TRUE;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_fixate_field:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @field_name: a field in @structure
Packit f546b1
 *
Packit f546b1
 * Fixates a #GstStructure by changing the given field with its fixated value.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the structure field could be fixated
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_fixate_field (GstStructure * structure, const char *field_name)
Packit f546b1
{
Packit f546b1
  GstStructureField *field;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (structure != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (IS_MUTABLE (structure), FALSE);
Packit f546b1
Packit f546b1
  if (!(field = gst_structure_get_field (structure, field_name)))
Packit f546b1
    return FALSE;
Packit f546b1
Packit f546b1
  return default_fixate (field->name, &field->value, structure);
Packit f546b1
}
Packit f546b1
Packit f546b1
/* our very own version of G_VALUE_LCOPY that allows NULL return locations
Packit f546b1
 * (useful for message parsing functions where the return location is user
Packit f546b1
 * supplied and the user may pass %NULL if the value isn't of interest) */
Packit f546b1
#define GST_VALUE_LCOPY(value, var_args, flags, __error, fieldname)           \
Packit f546b1
G_STMT_START {                                                                \
Packit f546b1
  const GValue *_value = (value);                                             \
Packit f546b1
  guint _flags = (flags);                                                     \
Packit f546b1
  GType _value_type = G_VALUE_TYPE (_value);                                  \
Packit f546b1
  GTypeValueTable *_vtable = g_type_value_table_peek (_value_type);           \
Packit f546b1
  const gchar *_lcopy_format = _vtable->lcopy_format;                         \
Packit f546b1
  GTypeCValue _cvalues[G_VALUE_COLLECT_FORMAT_MAX_LENGTH] = { { 0, }, };      \
Packit f546b1
  guint _n_values = 0;                                                        \
Packit f546b1
                                                                              \
Packit f546b1
  while (*_lcopy_format != '\0') {                                            \
Packit f546b1
    g_assert (*_lcopy_format == G_VALUE_COLLECT_POINTER);                     \
Packit f546b1
    _cvalues[_n_values++].v_pointer = va_arg ((var_args), gpointer);          \
Packit f546b1
    _lcopy_format++;                                                          \
Packit f546b1
  }                                                                           \
Packit f546b1
  if (_n_values == 2 && !!_cvalues[0].v_pointer != !!_cvalues[1].v_pointer) { \
Packit f546b1
    *(__error) = g_strdup_printf ("either all or none of the return "         \
Packit f546b1
        "locations for field '%s' need to be NULL", fieldname);               \
Packit f546b1
  } else if (_cvalues[0].v_pointer != NULL) {                                 \
Packit f546b1
    *(__error) = _vtable->lcopy_value (_value, _n_values, _cvalues, _flags);  \
Packit f546b1
  }                                                                           \
Packit f546b1
} G_STMT_END
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_get_valist:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @first_fieldname: the name of the first field to read
Packit f546b1
 * @args: variable arguments
Packit f546b1
 *
Packit f546b1
 * Parses the variable arguments and reads fields from @structure accordingly.
Packit f546b1
 * valist-variant of gst_structure_get(). Look at the documentation of
Packit f546b1
 * gst_structure_get() for more details.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE, or %FALSE if there was a problem reading any of the fields
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_get_valist (const GstStructure * structure,
Packit f546b1
    const char *first_fieldname, va_list args)
Packit f546b1
{
Packit f546b1
  const char *field_name;
Packit f546b1
  GType expected_type = G_TYPE_INVALID;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (GST_IS_STRUCTURE (structure), FALSE);
Packit f546b1
  g_return_val_if_fail (first_fieldname != NULL, FALSE);
Packit f546b1
Packit f546b1
  field_name = first_fieldname;
Packit f546b1
  while (field_name) {
Packit f546b1
    const GValue *val = NULL;
Packit f546b1
    gchar *err = NULL;
Packit f546b1
Packit f546b1
    expected_type = va_arg (args, GType);
Packit f546b1
Packit f546b1
    val = gst_structure_get_value (structure, field_name);
Packit f546b1
Packit f546b1
    if (val == NULL)
Packit f546b1
      goto no_such_field;
Packit f546b1
Packit f546b1
    if (G_VALUE_TYPE (val) != expected_type)
Packit f546b1
      goto wrong_type;
Packit f546b1
Packit f546b1
    GST_VALUE_LCOPY (val, args, 0, &err, field_name);
Packit f546b1
    if (err) {
Packit f546b1
      g_warning ("%s: %s", G_STRFUNC, err);
Packit f546b1
      g_free (err);
Packit f546b1
      return FALSE;
Packit f546b1
    }
Packit f546b1
Packit f546b1
    field_name = va_arg (args, const gchar *);
Packit f546b1
  }
Packit f546b1
Packit f546b1
  return TRUE;
Packit f546b1
Packit f546b1
/* ERRORS */
Packit f546b1
no_such_field:
Packit f546b1
  {
Packit f546b1
    GST_INFO ("Expected field '%s' in structure: %" GST_PTR_FORMAT,
Packit f546b1
        field_name, structure);
Packit f546b1
    return FALSE;
Packit f546b1
  }
Packit f546b1
wrong_type:
Packit f546b1
  {
Packit f546b1
    GST_INFO ("Expected field '%s' in structure to be of type '%s', but "
Packit f546b1
        "field was of type '%s': %" GST_PTR_FORMAT, field_name,
Packit f546b1
        GST_STR_NULL (g_type_name (expected_type)),
Packit f546b1
        G_VALUE_TYPE_NAME (gst_structure_get_value (structure, field_name)),
Packit f546b1
        structure);
Packit f546b1
    return FALSE;
Packit f546b1
  }
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_id_get_valist:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @first_field_id: the quark of the first field to read
Packit f546b1
 * @args: variable arguments
Packit f546b1
 *
Packit f546b1
 * Parses the variable arguments and reads fields from @structure accordingly.
Packit f546b1
 * valist-variant of gst_structure_id_get(). Look at the documentation of
Packit f546b1
 * gst_structure_id_get() for more details.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE, or %FALSE if there was a problem reading any of the fields
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_id_get_valist (const GstStructure * structure,
Packit f546b1
    GQuark first_field_id, va_list args)
Packit f546b1
{
Packit f546b1
  GQuark field_id;
Packit f546b1
  GType expected_type = G_TYPE_INVALID;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (GST_IS_STRUCTURE (structure), FALSE);
Packit f546b1
  g_return_val_if_fail (first_field_id != 0, FALSE);
Packit f546b1
Packit f546b1
  field_id = first_field_id;
Packit f546b1
  while (field_id) {
Packit f546b1
    const GValue *val = NULL;
Packit f546b1
    gchar *err = NULL;
Packit f546b1
Packit f546b1
    expected_type = va_arg (args, GType);
Packit f546b1
Packit f546b1
    val = gst_structure_id_get_value (structure, field_id);
Packit f546b1
Packit f546b1
    if (val == NULL)
Packit f546b1
      goto no_such_field;
Packit f546b1
Packit f546b1
    if (G_VALUE_TYPE (val) != expected_type)
Packit f546b1
      goto wrong_type;
Packit f546b1
Packit f546b1
    GST_VALUE_LCOPY (val, args, 0, &err, g_quark_to_string (field_id));
Packit f546b1
    if (err) {
Packit f546b1
      g_warning ("%s: %s", G_STRFUNC, err);
Packit f546b1
      g_free (err);
Packit f546b1
      return FALSE;
Packit f546b1
    }
Packit f546b1
Packit f546b1
    field_id = va_arg (args, GQuark);
Packit f546b1
  }
Packit f546b1
Packit f546b1
  return TRUE;
Packit f546b1
Packit f546b1
/* ERRORS */
Packit f546b1
no_such_field:
Packit f546b1
  {
Packit f546b1
    GST_DEBUG ("Expected field '%s' in structure: %" GST_PTR_FORMAT,
Packit f546b1
        GST_STR_NULL (g_quark_to_string (field_id)), structure);
Packit f546b1
    return FALSE;
Packit f546b1
  }
Packit f546b1
wrong_type:
Packit f546b1
  {
Packit f546b1
    GST_DEBUG ("Expected field '%s' in structure to be of type '%s', but "
Packit f546b1
        "field was of type '%s': %" GST_PTR_FORMAT,
Packit f546b1
        g_quark_to_string (field_id),
Packit f546b1
        GST_STR_NULL (g_type_name (expected_type)),
Packit f546b1
        G_VALUE_TYPE_NAME (gst_structure_id_get_value (structure, field_id)),
Packit f546b1
        structure);
Packit f546b1
    return FALSE;
Packit f546b1
  }
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_get:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @first_fieldname: the name of the first field to read
Packit f546b1
 * @...: variable arguments
Packit f546b1
 *
Packit f546b1
 * Parses the variable arguments and reads fields from @structure accordingly.
Packit f546b1
 * Variable arguments should be in the form field name, field type
Packit f546b1
 * (as a GType), pointer(s) to a variable(s) to hold the return value(s).
Packit f546b1
 * The last variable argument should be %NULL.
Packit f546b1
 *
Packit f546b1
 * For refcounted (mini)objects you will receive a new reference which
Packit f546b1
 * you must release with a suitable _unref() when no longer needed. For
Packit f546b1
 * strings and boxed types you will receive a copy which you will need to
Packit f546b1
 * release with either g_free() or the suitable function for the boxed type.
Packit f546b1
 *
Packit f546b1
 * Returns: %FALSE if there was a problem reading any of the fields (e.g.
Packit f546b1
 *     because the field requested did not exist, or was of a type other
Packit f546b1
 *     than the type specified), otherwise %TRUE.
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_get (const GstStructure * structure, const char *first_fieldname,
Packit f546b1
    ...)
Packit f546b1
{
Packit f546b1
  gboolean ret;
Packit f546b1
  va_list args;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (GST_IS_STRUCTURE (structure), FALSE);
Packit f546b1
  g_return_val_if_fail (first_fieldname != NULL, FALSE);
Packit f546b1
Packit f546b1
  va_start (args, first_fieldname);
Packit f546b1
  ret = gst_structure_get_valist (structure, first_fieldname, args);
Packit f546b1
  va_end (args);
Packit f546b1
Packit f546b1
  return ret;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_id_get:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @first_field_id: the quark of the first field to read
Packit f546b1
 * @...: variable arguments
Packit f546b1
 *
Packit f546b1
 * Parses the variable arguments and reads fields from @structure accordingly.
Packit f546b1
 * Variable arguments should be in the form field id quark, field type
Packit f546b1
 * (as a GType), pointer(s) to a variable(s) to hold the return value(s).
Packit f546b1
 * The last variable argument should be %NULL (technically it should be a
Packit f546b1
 * 0 quark, but we require %NULL so compilers that support it can check for
Packit f546b1
 * the %NULL terminator and warn if it's not there).
Packit f546b1
 *
Packit f546b1
 * This function is just like gst_structure_get() only that it is slightly
Packit f546b1
 * more efficient since it saves the string-to-quark lookup in the global
Packit f546b1
 * quark hashtable.
Packit f546b1
 *
Packit f546b1
 * For refcounted (mini)objects you will receive a new reference which
Packit f546b1
 * you must release with a suitable _unref() when no longer needed. For
Packit f546b1
 * strings and boxed types you will receive a copy which you will need to
Packit f546b1
 * release with either g_free() or the suitable function for the boxed type.
Packit f546b1
 *
Packit f546b1
 * Returns: %FALSE if there was a problem reading any of the fields (e.g.
Packit f546b1
 *     because the field requested did not exist, or was of a type other
Packit f546b1
 *     than the type specified), otherwise %TRUE.
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_id_get (const GstStructure * structure, GQuark first_field_id,
Packit f546b1
    ...)
Packit f546b1
{
Packit f546b1
  gboolean ret;
Packit f546b1
  va_list args;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (GST_IS_STRUCTURE (structure), FALSE);
Packit f546b1
  g_return_val_if_fail (first_field_id != 0, FALSE);
Packit f546b1
Packit f546b1
  va_start (args, first_field_id);
Packit f546b1
  ret = gst_structure_id_get_valist (structure, first_field_id, args);
Packit f546b1
  va_end (args);
Packit f546b1
Packit f546b1
  return ret;
Packit f546b1
}
Packit f546b1
Packit f546b1
static gboolean
Packit f546b1
gst_structure_is_equal_foreach (GQuark field_id, const GValue * val2,
Packit f546b1
    gpointer data)
Packit f546b1
{
Packit f546b1
  const GstStructure *struct1 = (const GstStructure *) data;
Packit f546b1
  const GValue *val1 = gst_structure_id_get_value (struct1, field_id);
Packit f546b1
Packit f546b1
  if (G_UNLIKELY (val1 == NULL))
Packit f546b1
    return FALSE;
Packit f546b1
  if (gst_value_compare (val1, val2) == GST_VALUE_EQUAL) {
Packit f546b1
    return TRUE;
Packit f546b1
  }
Packit f546b1
Packit f546b1
  return FALSE;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_is_equal:
Packit f546b1
 * @structure1: a #GstStructure.
Packit f546b1
 * @structure2: a #GstStructure.
Packit f546b1
 *
Packit f546b1
 * Tests if the two #GstStructure are equal.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the two structures have the same name and field.
Packit f546b1
 **/
Packit f546b1
gboolean
Packit f546b1
gst_structure_is_equal (const GstStructure * structure1,
Packit f546b1
    const GstStructure * structure2)
Packit f546b1
{
Packit f546b1
  g_return_val_if_fail (GST_IS_STRUCTURE (structure1), FALSE);
Packit f546b1
  g_return_val_if_fail (GST_IS_STRUCTURE (structure2), FALSE);
Packit f546b1
Packit f546b1
  if (G_UNLIKELY (structure1 == structure2))
Packit f546b1
    return TRUE;
Packit f546b1
Packit f546b1
  if (structure1->name != structure2->name) {
Packit f546b1
    return FALSE;
Packit f546b1
  }
Packit f546b1
  if (GST_STRUCTURE_FIELDS (structure1)->len !=
Packit f546b1
      GST_STRUCTURE_FIELDS (structure2)->len) {
Packit f546b1
    return FALSE;
Packit f546b1
  }
Packit f546b1
Packit f546b1
  return gst_structure_foreach (structure1, gst_structure_is_equal_foreach,
Packit f546b1
      (gpointer) structure2);
Packit f546b1
}
Packit f546b1
Packit f546b1
Packit f546b1
typedef struct
Packit f546b1
{
Packit f546b1
  GstStructure *dest;
Packit f546b1
  const GstStructure *intersect;
Packit f546b1
}
Packit f546b1
IntersectData;
Packit f546b1
Packit f546b1
static gboolean
Packit f546b1
gst_structure_intersect_field1 (GQuark id, const GValue * val1, gpointer data)
Packit f546b1
{
Packit f546b1
  IntersectData *idata = (IntersectData *) data;
Packit f546b1
  const GValue *val2 = gst_structure_id_get_value (idata->intersect, id);
Packit f546b1
Packit f546b1
  if (G_UNLIKELY (val2 == NULL)) {
Packit f546b1
    gst_structure_id_set_value (idata->dest, id, val1);
Packit f546b1
  } else {
Packit f546b1
    GValue dest_value = { 0 };
Packit f546b1
    if (gst_value_intersect (&dest_value, val1, val2)) {
Packit f546b1
      gst_structure_id_take_value (idata->dest, id, &dest_value);
Packit f546b1
    } else {
Packit f546b1
      return FALSE;
Packit f546b1
    }
Packit f546b1
  }
Packit f546b1
  return TRUE;
Packit f546b1
}
Packit f546b1
Packit f546b1
static gboolean
Packit f546b1
gst_structure_intersect_field2 (GQuark id, const GValue * val1, gpointer data)
Packit f546b1
{
Packit f546b1
  IntersectData *idata = (IntersectData *) data;
Packit f546b1
  const GValue *val2 = gst_structure_id_get_value (idata->intersect, id);
Packit f546b1
Packit f546b1
  if (G_UNLIKELY (val2 == NULL)) {
Packit f546b1
    gst_structure_id_set_value (idata->dest, id, val1);
Packit f546b1
  }
Packit f546b1
  return TRUE;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_intersect:
Packit f546b1
 * @struct1: a #GstStructure
Packit f546b1
 * @struct2: a #GstStructure
Packit f546b1
 *
Packit f546b1
 * Intersects @struct1 and @struct2 and returns the intersection.
Packit f546b1
 *
Packit f546b1
 * Returns: (nullable): Intersection of @struct1 and @struct2
Packit f546b1
 */
Packit f546b1
GstStructure *
Packit f546b1
gst_structure_intersect (const GstStructure * struct1,
Packit f546b1
    const GstStructure * struct2)
Packit f546b1
{
Packit f546b1
  IntersectData data;
Packit f546b1
Packit f546b1
  g_assert (struct1 != NULL);
Packit f546b1
  g_assert (struct2 != NULL);
Packit f546b1
Packit f546b1
  if (G_UNLIKELY (struct1->name != struct2->name))
Packit f546b1
    return NULL;
Packit f546b1
Packit f546b1
  /* copy fields from struct1 which we have not in struct2 to target
Packit f546b1
   * intersect if we have the field in both */
Packit f546b1
  data.dest = gst_structure_new_id_empty (struct1->name);
Packit f546b1
  data.intersect = struct2;
Packit f546b1
  if (G_UNLIKELY (!gst_structure_foreach ((GstStructure *) struct1,
Packit f546b1
              gst_structure_intersect_field1, &data)))
Packit f546b1
    goto error;
Packit f546b1
Packit f546b1
  /* copy fields from struct2 which we have not in struct1 to target */
Packit f546b1
  data.intersect = struct1;
Packit f546b1
  if (G_UNLIKELY (!gst_structure_foreach ((GstStructure *) struct2,
Packit f546b1
              gst_structure_intersect_field2, &data)))
Packit f546b1
    goto error;
Packit f546b1
Packit f546b1
  return data.dest;
Packit f546b1
Packit f546b1
error:
Packit f546b1
  gst_structure_free (data.dest);
Packit f546b1
  return NULL;
Packit f546b1
}
Packit f546b1
Packit f546b1
static gboolean
Packit f546b1
gst_caps_structure_can_intersect_field (GQuark id, const GValue * val1,
Packit f546b1
    gpointer data)
Packit f546b1
{
Packit f546b1
  GstStructure *other = (GstStructure *) data;
Packit f546b1
  const GValue *val2 = gst_structure_id_get_value (other, id);
Packit f546b1
Packit f546b1
  if (G_LIKELY (val2)) {
Packit f546b1
    if (!gst_value_can_intersect (val1, val2)) {
Packit f546b1
      return FALSE;
Packit f546b1
    } else {
Packit f546b1
      gint eq = gst_value_compare (val1, val2);
Packit f546b1
Packit f546b1
      if (eq == GST_VALUE_UNORDERED) {
Packit f546b1
        /* we need to try interseting */
Packit f546b1
        if (!gst_value_intersect (NULL, val1, val2)) {
Packit f546b1
          return FALSE;
Packit f546b1
        }
Packit f546b1
      } else if (eq != GST_VALUE_EQUAL) {
Packit f546b1
        return FALSE;
Packit f546b1
      }
Packit f546b1
    }
Packit f546b1
  }
Packit f546b1
  return TRUE;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_can_intersect:
Packit f546b1
 * @struct1: a #GstStructure
Packit f546b1
 * @struct2: a #GstStructure
Packit f546b1
 *
Packit f546b1
 * Tries intersecting @struct1 and @struct2 and reports whether the result
Packit f546b1
 * would not be empty.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if intersection would not be empty
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_can_intersect (const GstStructure * struct1,
Packit f546b1
    const GstStructure * struct2)
Packit f546b1
{
Packit f546b1
  g_return_val_if_fail (GST_IS_STRUCTURE (struct1), FALSE);
Packit f546b1
  g_return_val_if_fail (GST_IS_STRUCTURE (struct2), FALSE);
Packit f546b1
Packit f546b1
  if (G_UNLIKELY (struct1->name != struct2->name))
Packit f546b1
    return FALSE;
Packit f546b1
Packit f546b1
  /* tries to intersect if we have the field in both */
Packit f546b1
  return gst_structure_foreach ((GstStructure *) struct1,
Packit f546b1
      gst_caps_structure_can_intersect_field, (gpointer) struct2);
Packit f546b1
}
Packit f546b1
Packit f546b1
static gboolean
Packit f546b1
gst_caps_structure_is_superset_field (GQuark field_id, const GValue * value,
Packit f546b1
    gpointer user_data)
Packit f546b1
{
Packit f546b1
  GstStructure *subset = user_data;
Packit f546b1
  const GValue *other;
Packit f546b1
  int comparison;
Packit f546b1
Packit f546b1
  if (!(other = gst_structure_id_get_value (subset, field_id)))
Packit f546b1
    /* field is missing in the subset => no subset */
Packit f546b1
    return FALSE;
Packit f546b1
Packit f546b1
  comparison = gst_value_compare (value, other);
Packit f546b1
Packit f546b1
  /* equal values are subset */
Packit f546b1
  if (comparison == GST_VALUE_EQUAL)
Packit f546b1
    return TRUE;
Packit f546b1
Packit f546b1
  /* ordered, but unequal, values are not */
Packit f546b1
  if (comparison != GST_VALUE_UNORDERED)
Packit f546b1
    return FALSE;
Packit f546b1
Packit f546b1
  return gst_value_is_subset (other, value);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_is_subset:
Packit f546b1
 * @subset: a #GstStructure
Packit f546b1
 * @superset: a potentially greater #GstStructure
Packit f546b1
 *
Packit f546b1
 * Checks if @subset is a subset of @superset, i.e. has the same
Packit f546b1
 * structure name and for all fields that are existing in @superset,
Packit f546b1
 * @subset has a value that is a subset of the value in @superset.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if @subset is a subset of @superset
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_is_subset (const GstStructure * subset,
Packit f546b1
    const GstStructure * superset)
Packit f546b1
{
Packit f546b1
  if ((superset->name != subset->name) ||
Packit f546b1
      (gst_structure_n_fields (superset) > gst_structure_n_fields (subset)))
Packit f546b1
    return FALSE;
Packit f546b1
Packit f546b1
  return gst_structure_foreach ((GstStructure *) superset,
Packit f546b1
      gst_caps_structure_is_superset_field, (gpointer) subset);
Packit f546b1
}
Packit f546b1
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_fixate:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 *
Packit f546b1
 * Fixate all values in @structure using gst_value_fixate().
Packit f546b1
 * @structure will be modified in-place and should be writable.
Packit f546b1
 */
Packit f546b1
void
Packit f546b1
gst_structure_fixate (GstStructure * structure)
Packit f546b1
{
Packit f546b1
  g_return_if_fail (GST_IS_STRUCTURE (structure));
Packit f546b1
Packit f546b1
  gst_structure_foreach (structure, default_fixate, structure);
Packit f546b1
}
Packit f546b1
Packit f546b1
static gboolean
Packit f546b1
_gst_structure_get_any_list (GstStructure * structure, GType type,
Packit f546b1
    const gchar * fieldname, GValueArray ** array)
Packit f546b1
{
Packit f546b1
  GstStructureField *field;
Packit f546b1
  GValue val = G_VALUE_INIT;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (structure != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (fieldname != NULL, FALSE);
Packit f546b1
  g_return_val_if_fail (array != NULL, FALSE);
Packit f546b1
Packit f546b1
  field = gst_structure_get_field (structure, fieldname);
Packit f546b1
Packit f546b1
  if (field == NULL || G_VALUE_TYPE (&field->value) != type)
Packit f546b1
    return FALSE;
Packit f546b1
Packit f546b1
  g_value_init (&val, G_TYPE_VALUE_ARRAY);
Packit f546b1
Packit f546b1
  if (g_value_transform (&field->value, &val)) {
Packit f546b1
    *array = g_value_get_boxed (&val;;
Packit f546b1
    return TRUE;
Packit f546b1
  }
Packit f546b1
Packit f546b1
  g_value_unset (&val;;
Packit f546b1
  return FALSE;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_get_array:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of a field
Packit f546b1
 * @array: (out): a pointer to a #GValueArray
Packit f546b1
 *
Packit f546b1
 * This is useful in language bindings where unknown #GValue types are not
Packit f546b1
 * supported. This function will convert the %GST_TYPE_ARRAY and
Packit f546b1
 * %GST_TYPE_LIST into a newly allocated #GValueArray and return it through
Packit f546b1
 * @array. Be aware that this is slower then getting the #GValue directly.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the value could be set correctly. If there was no field
Packit f546b1
 * with @fieldname or the existing field did not contain an int, this function
Packit f546b1
 * returns %FALSE.
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_get_array (GstStructure * structure, const gchar * fieldname,
Packit f546b1
    GValueArray ** array)
Packit f546b1
{
Packit f546b1
  return _gst_structure_get_any_list (structure, GST_TYPE_ARRAY, fieldname,
Packit f546b1
      array);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_get_list:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of a field
Packit f546b1
 * @array: (out): a pointer to a #GValueArray
Packit f546b1
 *
Packit f546b1
 * This is useful in language bindings where unknown #GValue types are not
Packit f546b1
 * supported. This function will convert the %GST_TYPE_ARRAY and
Packit f546b1
 * %GST_TYPE_LIST into a newly allocated GValueArray and return it through
Packit f546b1
 * @array. Be aware that this is slower then getting the #GValue directly.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the value could be set correctly. If there was no field
Packit f546b1
 * with @fieldname or the existing field did not contain an int, this function
Packit f546b1
 * returns %FALSE.
Packit f546b1
 *
Packit f546b1
 * Since 1.12
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_structure_get_list (GstStructure * structure, const gchar * fieldname,
Packit f546b1
    GValueArray ** array)
Packit f546b1
{
Packit f546b1
  return _gst_structure_get_any_list (structure, GST_TYPE_LIST, fieldname,
Packit f546b1
      array);
Packit f546b1
}
Packit f546b1
Packit f546b1
static void
Packit f546b1
_gst_structure_set_any_list (GstStructure * structure, GType type,
Packit f546b1
    const gchar * fieldname, const GValueArray * array)
Packit f546b1
{
Packit f546b1
  GValue arval = G_VALUE_INIT;
Packit f546b1
  GValue value = G_VALUE_INIT;
Packit f546b1
Packit f546b1
  g_return_if_fail (structure != NULL);
Packit f546b1
  g_return_if_fail (fieldname != NULL);
Packit f546b1
  g_return_if_fail (array != NULL);
Packit f546b1
  g_return_if_fail (IS_MUTABLE (structure));
Packit f546b1
Packit f546b1
  g_value_init (&value, type);
Packit f546b1
  g_value_init (&arval, G_TYPE_VALUE_ARRAY);
Packit f546b1
  g_value_set_static_boxed (&arval, array);
Packit f546b1
Packit f546b1
  if (g_value_transform (&arval, &value)) {
Packit f546b1
    gst_structure_id_set_value_internal (structure,
Packit f546b1
        g_quark_from_string (fieldname), &value);
Packit f546b1
  } else {
Packit f546b1
    g_warning ("Failed to convert a GValueArray");
Packit f546b1
  }
Packit f546b1
Packit f546b1
  g_value_unset (&arval);
Packit f546b1
  g_value_unset (&value);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_set_array:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of a field
Packit f546b1
 * @array: a pointer to a #GValueArray
Packit f546b1
 *
Packit f546b1
 * This is useful in language bindings where unknown GValue types are not
Packit f546b1
 * supported. This function will convert a @array to %GST_TYPE_ARRAY and set
Packit f546b1
 * the field specified by @fieldname.  Be aware that this is slower then using
Packit f546b1
 * %GST_TYPE_ARRAY in a #GValue directly.
Packit f546b1
 *
Packit f546b1
 * Since 1.12
Packit f546b1
 */
Packit f546b1
void
Packit f546b1
gst_structure_set_array (GstStructure * structure, const gchar * fieldname,
Packit f546b1
    const GValueArray * array)
Packit f546b1
{
Packit f546b1
  _gst_structure_set_any_list (structure, GST_TYPE_ARRAY, fieldname, array);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_structure_set_list:
Packit f546b1
 * @structure: a #GstStructure
Packit f546b1
 * @fieldname: the name of a field
Packit f546b1
 * @array: a pointer to a #GValueArray
Packit f546b1
 *
Packit f546b1
 * This is useful in language bindings where unknown GValue types are not
Packit f546b1
 * supported. This function will convert a @array to %GST_TYPE_ARRAY and set
Packit f546b1
 * the field specified by @fieldname. Be aware that this is slower then using
Packit f546b1
 * %GST_TYPE_ARRAY in a #GValue directly.
Packit f546b1
 *
Packit f546b1
 * Since 1.12
Packit f546b1
 */
Packit f546b1
void
Packit f546b1
gst_structure_set_list (GstStructure * structure, const gchar * fieldname,
Packit f546b1
    const GValueArray * array)
Packit f546b1
{
Packit f546b1
  _gst_structure_set_any_list (structure, GST_TYPE_LIST, fieldname, array);
Packit f546b1
}