Path: blob/master/dep/ffmpeg/include/libavutil/dict.h
7496 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#define AV_DICT_DEDUP 128 /**< If inserting a value that already exists for a key, do nothing. Only relevant with AV_DICT_MULTIKEY. */85/**86* @}87*/8889typedef struct AVDictionaryEntry {90char *key;91char *value;92} AVDictionaryEntry;9394typedef struct AVDictionary AVDictionary;9596/**97* Get a dictionary entry with matching key.98*99* The returned entry key or value must not be changed, or it will100* cause undefined behavior.101*102* @param prev Set to the previous matching element to find the next.103* If set to NULL the first matching element is returned.104* @param key Matching key105* @param flags A collection of AV_DICT_* flags controlling how the106* entry is retrieved107*108* @return Found entry or NULL in case no matching entry was found in the dictionary109*/110AVDictionaryEntry *av_dict_get(const AVDictionary *m, const char *key,111const AVDictionaryEntry *prev, int flags);112113/**114* Iterate over a dictionary115*116* Iterates through all entries in the dictionary.117*118* @warning The returned AVDictionaryEntry key/value must not be changed.119*120* @warning As av_dict_set() invalidates all previous entries returned121* by this function, it must not be called while iterating over the dict.122*123* Typical usage:124* @code125* const AVDictionaryEntry *e = NULL;126* while ((e = av_dict_iterate(m, e))) {127* // ...128* }129* @endcode130*131* @param m The dictionary to iterate over132* @param prev Pointer to the previous AVDictionaryEntry, NULL initially133*134* @retval AVDictionaryEntry* The next element in the dictionary135* @retval NULL No more elements in the dictionary136*/137const AVDictionaryEntry *av_dict_iterate(const AVDictionary *m,138const AVDictionaryEntry *prev);139140/**141* Get number of entries in dictionary.142*143* @param m dictionary144* @return number of entries in dictionary145*/146int av_dict_count(const AVDictionary *m);147148/**149* Set the given entry in *pm, overwriting an existing entry.150*151* Note: If AV_DICT_DONT_STRDUP_KEY or AV_DICT_DONT_STRDUP_VAL is set,152* these arguments will be freed on error.153*154* @warning Adding a new entry to a dictionary invalidates all existing entries155* previously returned with av_dict_get() or av_dict_iterate().156*157* @param pm Pointer to a pointer to a dictionary struct. If *pm is NULL158* a dictionary struct is allocated and put in *pm.159* @param key Entry key to add to *pm (will either be av_strduped or added as a new key depending on flags)160* @param value Entry value to add to *pm (will be av_strduped or added as a new key depending on flags).161* Passing a NULL value will cause an existing entry to be deleted.162*163* @return >= 0 on success otherwise an error code <0164*/165int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags);166167/**168* Convenience wrapper for av_dict_set() that converts the value to a string169* and stores it.170*171* Note: If ::AV_DICT_DONT_STRDUP_KEY is set, key will be freed on error.172*/173int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags);174175/**176* Parse the key/value pairs list and add the parsed entries to a dictionary.177*178* In case of failure, all the successfully set entries are stored in179* *pm. You may need to manually free the created dictionary.180*181* @param key_val_sep A 0-terminated list of characters used to separate182* key from value183* @param pairs_sep A 0-terminated list of characters used to separate184* two pairs from each other185* @param flags Flags to use when adding to the dictionary.186* ::AV_DICT_DONT_STRDUP_KEY and ::AV_DICT_DONT_STRDUP_VAL187* are ignored since the key/value tokens will always188* be duplicated.189*190* @return 0 on success, negative AVERROR code on failure191*/192int av_dict_parse_string(AVDictionary **pm, const char *str,193const char *key_val_sep, const char *pairs_sep,194int flags);195196/**197* Copy entries from one AVDictionary struct into another.198*199* @note Metadata is read using the ::AV_DICT_IGNORE_SUFFIX flag200*201* @param dst Pointer to a pointer to a AVDictionary struct to copy into. If *dst is NULL,202* this function will allocate a struct for you and put it in *dst203* @param src Pointer to the source AVDictionary struct to copy items from.204* @param flags Flags to use when setting entries in *dst205*206* @return 0 on success, negative AVERROR code on failure. If dst was allocated207* by this function, callers should free the associated memory.208*/209int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags);210211/**212* Free all the memory allocated for an AVDictionary struct213* and all keys and values.214*/215void av_dict_free(AVDictionary **m);216217/**218* Get dictionary entries as a string.219*220* Create a string containing dictionary's entries.221* Such string may be passed back to av_dict_parse_string().222* @note String is escaped with backslashes ('\').223*224* @warning Separators cannot be neither '\\' nor '\0'. They also cannot be the same.225*226* @param[in] m The dictionary227* @param[out] buffer Pointer to buffer that will be allocated with string containing entries.228* Buffer must be freed by the caller when is no longer needed.229* @param[in] key_val_sep Character used to separate key from value230* @param[in] pairs_sep Character used to separate two pairs from each other231*232* @return >= 0 on success, negative on error233*/234int av_dict_get_string(const AVDictionary *m, char **buffer,235const char key_val_sep, const char pairs_sep);236237/**238* @}239*/240241#endif /* AVUTIL_DICT_H */242243244