Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-06-09 06:47:19 +0400
committerMichael Niedermayer <michaelni@gmx.at>2011-06-09 06:47:19 +0400
commitf9ecb849ef39bc337d9439b829fe08da5c95cc3d (patch)
tree761e860a10084d8de4f07815911f697fe11610b9 /libavutil
parent7b8ed831eb8432d202dad16dedc1758b018bb1fa (diff)
parenta71bcd1a7f66e210971c44452dc4cdae7bdbd98a (diff)
Merge remote-tracking branch 'qatar/master'
* qatar/master: crypto: Use av_freep instead of av_free lavf: don't try to free private options if priv_data is NULL. swscale: fix types of assembly arguments. swscale: move two macros that are only used once into caller. swscale: remove unused function. options: Add missing braces around struct initializer. mov: Remove leftover crufty debug statement with references to a local file. dvbsubdec: Fix compilation of debug code. Remove all uses of now deprecated metadata functions. Move metadata API from lavf to lavu. Conflicts: doc/APIchanges libavformat/aiffdec.c libavformat/asfdec.c libavformat/avformat.h libavformat/avidec.c libavformat/cafdec.c libavformat/matroskaenc.c libavformat/mov.c libavformat/mp3enc.c libavformat/wtv.c libavutil/avutil.h libavutil/internal.h libswscale/swscale.c libswscale/x86/swscale_template.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/Makefile2
-rw-r--r--libavutil/avutil.h2
-rw-r--r--libavutil/dict.c110
-rw-r--r--libavutil/dict.h78
-rw-r--r--libavutil/internal.h6
5 files changed, 197 insertions, 1 deletions
diff --git a/libavutil/Makefile b/libavutil/Makefile
index 01231bd52d..0d8f01dd8d 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -27,6 +27,7 @@ HEADERS = adler32.h \
mathematics.h \
md5.h \
mem.h \
+ dict.h \
opt.h \
parseutils.h \
pixdesc.h \
@@ -60,6 +61,7 @@ OBJS = adler32.o \
mathematics.o \
md5.o \
mem.o \
+ dict.o \
opt.o \
parseutils.o \
pixdesc.o \
diff --git a/libavutil/avutil.h b/libavutil/avutil.h
index 44567e99da..500c700851 100644
--- a/libavutil/avutil.h
+++ b/libavutil/avutil.h
@@ -40,7 +40,7 @@
#define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c)
#define LIBAVUTIL_VERSION_MAJOR 51
-#define LIBAVUTIL_VERSION_MINOR 7
+#define LIBAVUTIL_VERSION_MINOR 8
#define LIBAVUTIL_VERSION_MICRO 0
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
diff --git a/libavutil/dict.c b/libavutil/dict.c
new file mode 100644
index 0000000000..56f1513d32
--- /dev/null
+++ b/libavutil/dict.c
@@ -0,0 +1,110 @@
+/*
+ * copyright (c) 2009 Michael Niedermayer
+ *
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Libav is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <strings.h>
+#include "dict.h"
+#include "internal.h"
+#include "mem.h"
+
+AVDictionaryEntry *
+av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
+{
+ unsigned int i, j;
+
+ if(!m)
+ return NULL;
+
+ if(prev) i= prev - m->elems + 1;
+ else i= 0;
+
+ for(; i<m->count; i++){
+ const char *s= m->elems[i].key;
+ if(flags & AV_DICT_MATCH_CASE) for(j=0; s[j] == key[j] && key[j]; j++);
+ else for(j=0; toupper(s[j]) == toupper(key[j]) && key[j]; j++);
+ if(key[j])
+ continue;
+ if(s[j] && !(flags & AV_DICT_IGNORE_SUFFIX))
+ continue;
+ return &m->elems[i];
+ }
+ return NULL;
+}
+
+int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
+{
+ AVDictionary *m = *pm;
+ AVDictionaryEntry *tag = av_dict_get(m, key, NULL, flags);
+
+ if(!m)
+ m = *pm = av_mallocz(sizeof(*m));
+
+ if(tag) {
+ if (flags & AV_DICT_DONT_OVERWRITE)
+ return 0;
+ av_free(tag->value);
+ av_free(tag->key);
+ *tag = m->elems[--m->count];
+ } else {
+ AVDictionaryEntry *tmp = av_realloc(m->elems, (m->count+1) * sizeof(*m->elems));
+ if(tmp) {
+ m->elems = tmp;
+ } else
+ return AVERROR(ENOMEM);
+ }
+ if (value) {
+ if (flags & AV_DICT_DONT_STRDUP_KEY) {
+ m->elems[m->count].key = key;
+ } else
+ m->elems[m->count].key = av_strdup(key );
+ if (flags & AV_DICT_DONT_STRDUP_VAL) {
+ m->elems[m->count].value = value;
+ } else
+ m->elems[m->count].value = av_strdup(value);
+ m->count++;
+ }
+ if (!m->count) {
+ av_free(m->elems);
+ av_freep(pm);
+ }
+
+ return 0;
+}
+
+void av_dict_free(AVDictionary **pm)
+{
+ AVDictionary *m = *pm;
+
+ if (m) {
+ while(m->count--) {
+ av_free(m->elems[m->count].key);
+ av_free(m->elems[m->count].value);
+ }
+ av_free(m->elems);
+ }
+ av_freep(pm);
+}
+
+void av_dict_copy(AVDictionary **dst, AVDictionary *src, int flags)
+{
+ AVDictionaryEntry *t = NULL;
+
+ while ((t = av_dict_get(src, "", t, AV_DICT_IGNORE_SUFFIX)))
+ av_dict_set(dst, t->key, t->value, flags);
+}
diff --git a/libavutil/dict.h b/libavutil/dict.h
new file mode 100644
index 0000000000..bfd7f2682c
--- /dev/null
+++ b/libavutil/dict.h
@@ -0,0 +1,78 @@
+/*
+ *
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Libav is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file Public dictionary API.
+ */
+
+#ifndef AVUTIL_DICT_H
+#define AVUTIL_DICT_H
+
+#define AV_DICT_MATCH_CASE 1
+#define AV_DICT_IGNORE_SUFFIX 2
+#define AV_DICT_DONT_STRDUP_KEY 4
+#define AV_DICT_DONT_STRDUP_VAL 8
+#define AV_DICT_DONT_OVERWRITE 16 ///< Don't overwrite existing entries.
+
+typedef struct {
+ char *key;
+ char *value;
+} AVDictionaryEntry;
+
+typedef struct AVDictionary AVDictionary;
+
+/**
+ * Get a dictionary entry with matching key.
+ *
+ * @param prev Set to the previous matching element to find the next.
+ * If set to NULL the first matching element is returned.
+ * @param flags Allows case as well as suffix-insensitive comparisons.
+ * @return Found entry or NULL, changing key or value leads to undefined behavior.
+ */
+AVDictionaryEntry *
+av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags);
+
+/**
+ * Set the given entry in *pm, overwriting an existing entry.
+ *
+ * @param pm pointer to a pointer to a dictionary struct. If *pm is NULL
+ * a dictionary struct is allocated and put in *pm.
+ * @param key entry key to add to *pm (will be av_strduped depending on flags)
+ * @param value entry value to add to *pm (will be av_strduped depending on flags).
+ * Passing a NULL value will cause an existing tag to be deleted.
+ * @return >= 0 on success otherwise an error code <0
+ */
+int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags);
+
+/**
+ * Copy entries from one AVDictionary struct into another.
+ * @param dst pointer to a pointer to a AVDictionary struct. If *dst is NULL,
+ * this function will allocate a struct for you and put it in *dst
+ * @param src pointer to source AVDictionary struct
+ * @param flags flags to use when setting entries in *dst
+ * @note metadata is read using the AV_DICT_IGNORE_SUFFIX flag
+ */
+void av_dict_copy(AVDictionary **dst, AVDictionary *src, int flags);
+
+/**
+ * Free all the memory allocated for an AVDictionary struct.
+ */
+void av_dict_free(AVDictionary **m);
+
+#endif // AVUTIL_DICT_H
diff --git a/libavutil/internal.h b/libavutil/internal.h
index d9ab8e9723..eecc1280df 100644
--- a/libavutil/internal.h
+++ b/libavutil/internal.h
@@ -38,6 +38,12 @@
#include "attributes.h"
#include "timer.h"
#include "cpu.h"
+#include "dict.h"
+
+struct AVDictionary {
+ int count;
+ AVDictionaryEntry *elems;
+};
#ifndef attribute_align_arg
#if ARCH_X86_32 && AV_GCC_VERSION_AT_LEAST(4,2)