Path: blob/master/dep/ffmpeg/include/libavutil/dict.h
4216 views
/*1* This file is part of FFmpeg.2*3* FFmpeg is free software; you can redistribute it and/or4* modify it under the terms of the GNU Lesser General Public5* License as published by the Free Software Foundation; either6* version 2.1 of the License, or (at your option) any later version.7*8* FFmpeg is distributed in the hope that it will be useful,9* but WITHOUT ANY WARRANTY; without even the implied warranty of10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU11* Lesser General Public License for more details.12*13* You should have received a copy of the GNU Lesser General Public14* License along with FFmpeg; if not, write to the Free Software15* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA16*/1718/**19* @file20* Public dictionary API.21* @deprecated22* AVDictionary is provided for compatibility with libav. It is both in23* implementation as well as API inefficient. It does not scale and is24* extremely slow with large dictionaries.25* It is recommended that new code uses our tree container from tree.c/h26* where applicable, which uses AVL trees to achieve O(log n) performance.27*/2829#ifndef AVUTIL_DICT_H30#define AVUTIL_DICT_H3132#include <stdint.h>3334/**35* @addtogroup lavu_dict AVDictionary36* @ingroup lavu_data37*38* @brief Simple key:value store39*40* @{41* Dictionaries are used for storing key-value pairs.42*43* - To **create an AVDictionary**, simply pass an address of a NULL44* pointer to av_dict_set(). NULL can be used as an empty dictionary45* wherever a pointer to an AVDictionary is required.46* - To **insert an entry**, use av_dict_set().47* - Use av_dict_get() to **retrieve an entry**.48* - To **iterate over all entries**, use av_dict_iterate().49* - In order to **free the dictionary and all its contents**, use av_dict_free().50*51@code52AVDictionary *d = NULL; // "create" an empty dictionary53AVDictionaryEntry *t = NULL;5455av_dict_set(&d, "foo", "bar", 0); // add an entry5657char *k = av_strdup("key"); // if your strings are already allocated,58char *v = av_strdup("value"); // you can avoid copying them like this59av_dict_set(&d, k, v, AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);6061while ((t = av_dict_iterate(d, t))) {62<....> // iterate over all entries in d63}64av_dict_free(&d);65@endcode66*/6768/**69* @name AVDictionary Flags70* Flags that influence behavior of the matching of keys or insertion to the dictionary.71* @{72*/73#define AV_DICT_MATCH_CASE 1 /**< Only get an entry with exact-case key match. Only relevant in av_dict_get(). */74#define AV_DICT_IGNORE_SUFFIX 2 /**< Return first entry in a dictionary whose first part corresponds to the search key,75ignoring the suffix of the found key string. Only relevant in av_dict_get(). */76#define AV_DICT_DONT_STRDUP_KEY 4 /**< Take ownership of a key that's been77allocated with av_malloc() or another memory allocation function. */78#define AV_DICT_DONT_STRDUP_VAL 8 /**< Take ownership of a value that's been79allocated with av_malloc() or another memory allocation function. */80#define AV_DICT_DONT_OVERWRITE 16 /**< Don't overwrite existing entries. */81#define AV_DICT_APPEND 32 /**< If the entry already exists, append to it. Note that no82delimiter is added, the strings are simply concatenated. */83#define AV_DICT_MULTIKEY 64 /**< Allow to store several equal keys in the dictionary */84/**85* @}86*/8788typedef struct AVDictionaryEntry {89char *key;90char *value;91} AVDictionaryEntry;9293typedef struct AVDictionary AVDictionary;9495/**96* Get a dictionary entry with matching key.97*98* The returned entry key or value must not be changed, or it will99* cause undefined behavior.100*101* @param prev Set to the previous matching element to find the next.102* If set to NULL the first matching element is returned.103* @param key Matching key104* @param flags A collection of AV_DICT_* flags controlling how the105* entry is retrieved106*107* @return Found entry or NULL in case no matching entry was found in the dictionary108*/109AVDictionaryEntry *av_dict_get(const AVDictionary *m, const char *key,110const AVDictionaryEntry *prev, int flags);111112/**113* Iterate over a dictionary114*115* Iterates through all entries in the dictionary.116*117* @warning The returned AVDictionaryEntry key/value must not be changed.118*119* @warning As av_dict_set() invalidates all previous entries returned120* by this function, it must not be called while iterating over the dict.121*122* Typical usage:123* @code124* const AVDictionaryEntry *e = NULL;125* while ((e = av_dict_iterate(m, e))) {126* // ...127* }128* @endcode129*130* @param m The dictionary to iterate over131* @param prev Pointer to the previous AVDictionaryEntry, NULL initially132*133* @retval AVDictionaryEntry* The next element in the dictionary134* @retval NULL No more elements in the dictionary135*/136const AVDictionaryEntry *av_dict_iterate(const AVDictionary *m,137const AVDictionaryEntry *prev);138139/**140* Get number of entries in dictionary.141*142* @param m dictionary143* @return number of entries in dictionary144*/145int av_dict_count(const AVDictionary *m);146147/**148* Set the given entry in *pm, overwriting an existing entry.149*150* Note: If AV_DICT_DONT_STRDUP_KEY or AV_DICT_DONT_STRDUP_VAL is set,151* these arguments will be freed on error.152*153* @warning Adding a new entry to a dictionary invalidates all existing entries154* previously returned with av_dict_get() or av_dict_iterate().155*156* @param pm Pointer to a pointer to a dictionary struct. If *pm is NULL157* a dictionary struct is allocated and put in *pm.158* @param key Entry key to add to *pm (will either be av_strduped or added as a new key depending on flags)159* @param value Entry value to add to *pm (will be av_strduped or added as a new key depending on flags).160* Passing a NULL value will cause an existing entry to be deleted.161*162* @return >= 0 on success otherwise an error code <0163*/164int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags);165166/**167* Convenience wrapper for av_dict_set() that converts the value to a string168* and stores it.169*170* Note: If ::AV_DICT_DONT_STRDUP_KEY is set, key will be freed on error.171*/172int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags);173174/**175* Parse the key/value pairs list and add the parsed entries to a dictionary.176*177* In case of failure, all the successfully set entries are stored in178* *pm. You may need to manually free the created dictionary.179*180* @param key_val_sep A 0-terminated list of characters used to separate181* key from value182* @param pairs_sep A 0-terminated list of characters used to separate183* two pairs from each other184* @param flags Flags to use when adding to the dictionary.185* ::AV_DICT_DONT_STRDUP_KEY and ::AV_DICT_DONT_STRDUP_VAL186* are ignored since the key/value tokens will always187* be duplicated.188*189* @return 0 on success, negative AVERROR code on failure190*/191int av_dict_parse_string(AVDictionary **pm, const char *str,192const char *key_val_sep, const char *pairs_sep,193int flags);194195/**196* Copy entries from one AVDictionary struct into another.197*198* @note Metadata is read using the ::AV_DICT_IGNORE_SUFFIX flag199*200* @param dst Pointer to a pointer to a AVDictionary struct to copy into. If *dst is NULL,201* this function will allocate a struct for you and put it in *dst202* @param src Pointer to the source AVDictionary struct to copy items from.203* @param flags Flags to use when setting entries in *dst204*205* @return 0 on success, negative AVERROR code on failure. If dst was allocated206* by this function, callers should free the associated memory.207*/208int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags);209210/**211* Free all the memory allocated for an AVDictionary struct212* and all keys and values.213*/214void av_dict_free(AVDictionary **m);215216/**217* Get dictionary entries as a string.218*219* Create a string containing dictionary's entries.220* Such string may be passed back to av_dict_parse_string().221* @note String is escaped with backslashes ('\').222*223* @warning Separators cannot be neither '\\' nor '\0'. They also cannot be the same.224*225* @param[in] m The dictionary226* @param[out] buffer Pointer to buffer that will be allocated with string containg entries.227* Buffer must be freed by the caller when is no longer needed.228* @param[in] key_val_sep Character used to separate key from value229* @param[in] pairs_sep Character used to separate two pairs from each other230*231* @return >= 0 on success, negative on error232*/233int av_dict_get_string(const AVDictionary *m, char **buffer,234const char key_val_sep, const char pairs_sep);235236/**237* @}238*/239240#endif /* AVUTIL_DICT_H */241242243