AVDictionary结构体相关源码介绍

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/isluckyguo/article/details/51593272

本文对AVDictionary结构体部分相关函数代码进行了介绍

本文研究分析AVDictionary相关代码

 struct AVDictionary {
     int count;
     AVDictionaryEntry *elems;
 };

typedef struct AVDictionaryEntry {
    char *key;
    char *value;
} AVDictionaryEntry;
/*
 *这就是一个键值对或者叫键值对数组。为了create一个AVDictionary,
 *用到了av_dict_set()函数,将一个空指针传入该函数,这个空指针为
 *空的AVDictionary。生成AVDictionary后,可以通过av_dict_get()函
 *来找回一个数组或者递归所有数组,最后用av_dict_free()来释放。
 */
	AVDictionary *d = NULL;           // "create" an empty dictionary
	AVDictionaryEntry *t = NULL;
	av_dict_set(&d, "foo", "bar", 0); // add an entry
	char *k = av_strdup("key");       // if your strings are already allocated,
	char *v = av_strdup("value");     // you can avoid copying them like this
	av_dict_set(&d, k, v, AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
	while (t = av_dict_get(d, "", t, AV_DICT_IGNORE_SUFFIX)) {
	    <....>                             // iterate over all entries in d
	}
	av_dict_free(&d);
	
	/*
	 *介绍主要函数
	 */
	/*
	 *这个函数是把给定的key/value放入*pm中,如果数组已存在则覆盖
	 *Note:增加一个新的数组到dictionary中会使之前由av_dict_get()返回的数组失效
	 *  pm   指向一个dictionary的指针的指针。如果*pm是空,那么一个dictionary结构将
	 *       由函数分配并放入*pm
	 *  key  数组中的key值要加入*pm,由av_strduped设置一个值或者根据一个flag增加
	 *  value 数组中的value值要加入*pm,由av_strduped设置一个值或者根据一个flag增加
	 *
	 *  函数成功执行返回0,否则返回<0
	*/
		 int av_dict_set	(	AVDictionary ** 	pm,
	        const char * 	key,
	        const char * 	value,
	        int 	flags )		
	  
	 /*
	  *通过匹配的key值得到一个dictionary entry,返回的entry key或value值不能被修改
	  *为递归所有dictionary entry,可以set the matching key to null,并且set the 
	  *AV_DICT_IGNORE_SUFFIX flag
	  *   prev  Set to the previous matching element to find the next.If set to null
	  *         the first matching element is returned
	  *   key   matching key
	  *   flags a collection of AV_DICT_ *flags,控制着如何检索数组
	  *
	  * 执行结果是:found entry or NULL in case no matching entry was found in the dictionary
	 */
		  AVDictionaryEntry* av_dict_get	(	const AVDictionary * 	m,
	                 const char * 	key,
	                 const AVDictionaryEntry * 	prev,
	                 int 	flags )	      
	  
	 /*
	  *对av_dict_set的一个包装处理,将其参数value转换成一个string类型并存储下来
	  */ 
	     int av_dict_set_int	(	AVDictionary ** 	pm,
                    const char * 	key,
                    int64_t 	value,
                    int 	flags )	
<pre name="code" class="cpp">/*
	  *拷贝entries从一个AVDictionary到另一个AVDictionary
	  *   dst   指向一个AVDictionary结构体
	  *   src   指向原AVDictionary结构体
	  *   flag  在set dst中的entries时用到
	  *   成功返回0,失败返回负。
	  */ 
	  int av_dict_copy	(	AVDictionary ** 	dst,
               const AVDictionary * 	src,
               int 	flags )


 
 

猜你喜欢

转载自blog.csdn.net/isluckyguo/article/details/51593272