Commit a181981e authored by Michael Niedermayer's avatar Michael Niedermayer

Add flags to prevent strdup() on arguments to av_metadata_set2().

I cannot use the same ABI as ffmbc as value 2 is already used in ffmpeg,
besides the name AV_METADATA_NONCONST* makes no sense to me.
Add av_metadata_set2() that takes flags.

Originally committed as revision 20834 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 813338a0
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#define AVFORMAT_AVFORMAT_H #define AVFORMAT_AVFORMAT_H
#define LIBAVFORMAT_VERSION_MAJOR 52 #define LIBAVFORMAT_VERSION_MAJOR 52
#define LIBAVFORMAT_VERSION_MINOR 42 #define LIBAVFORMAT_VERSION_MINOR 43
#define LIBAVFORMAT_VERSION_MICRO 0 #define LIBAVFORMAT_VERSION_MICRO 0
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
...@@ -81,6 +81,8 @@ struct AVFormatContext; ...@@ -81,6 +81,8 @@ struct AVFormatContext;
#define AV_METADATA_MATCH_CASE 1 #define AV_METADATA_MATCH_CASE 1
#define AV_METADATA_IGNORE_SUFFIX 2 #define AV_METADATA_IGNORE_SUFFIX 2
#define AV_METADATA_DONT_STRDUP_KEY 4
#define AV_METADATA_DONT_STRDUP_VAL 8
typedef struct { typedef struct {
char *key; char *key;
...@@ -99,6 +101,7 @@ typedef struct AVMetadataConv AVMetadataConv; ...@@ -99,6 +101,7 @@ typedef struct AVMetadataConv AVMetadataConv;
AVMetadataTag * AVMetadataTag *
av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int flags); av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int flags);
#if LIBAVFORMAT_VERSION_MAJOR == 52
/** /**
* Sets the given tag in m, overwriting an existing tag. * Sets the given tag in m, overwriting an existing tag.
* @param key tag key to add to m (will be av_strduped) * @param key tag key to add to m (will be av_strduped)
...@@ -106,6 +109,15 @@ av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int f ...@@ -106,6 +109,15 @@ av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int f
* @return >= 0 on success otherwise an error code <0 * @return >= 0 on success otherwise an error code <0
*/ */
int av_metadata_set(AVMetadata **pm, const char *key, const char *value); int av_metadata_set(AVMetadata **pm, const char *key, const char *value);
#endif
/**
* Sets the given tag in m, overwriting an existing tag.
* @param key tag key to add to m (will be av_strduped depending on flags)
* @param value tag value to add to m (will be av_strduped depending on flags)
* @return >= 0 on success otherwise an error code <0
*/
int av_metadata_set2(AVMetadata **pm, const char *key, const char *value, int flags);
/** /**
* Converts all the metadata sets from ctx according to the source and * Converts all the metadata sets from ctx according to the source and
......
...@@ -46,7 +46,7 @@ av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int f ...@@ -46,7 +46,7 @@ av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int f
return NULL; return NULL;
} }
int av_metadata_set(AVMetadata **pm, const char *key, const char *value) int av_metadata_set2(AVMetadata **pm, const char *key, const char *value, int flags)
{ {
AVMetadata *m= *pm; AVMetadata *m= *pm;
AVMetadataTag *tag= av_metadata_get(m, key, NULL, AV_METADATA_MATCH_CASE); AVMetadataTag *tag= av_metadata_get(m, key, NULL, AV_METADATA_MATCH_CASE);
...@@ -66,7 +66,13 @@ int av_metadata_set(AVMetadata **pm, const char *key, const char *value) ...@@ -66,7 +66,13 @@ int av_metadata_set(AVMetadata **pm, const char *key, const char *value)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
if(value){ if(value){
if(flags & AV_METADATA_DONT_STRDUP_KEY){
m->elems[m->count].key = key;
}else
m->elems[m->count].key = av_strdup(key ); m->elems[m->count].key = av_strdup(key );
if(flags & AV_METADATA_DONT_STRDUP_VAL){
m->elems[m->count].value= value;
}else
m->elems[m->count].value= av_strdup(value); m->elems[m->count].value= av_strdup(value);
m->count++; m->count++;
} }
...@@ -78,6 +84,13 @@ int av_metadata_set(AVMetadata **pm, const char *key, const char *value) ...@@ -78,6 +84,13 @@ int av_metadata_set(AVMetadata **pm, const char *key, const char *value)
return 0; return 0;
} }
#if LIBAVFORMAT_VERSION_MAJOR == 52
int av_metadata_set(AVMetadata **pm, const char *key, const char *value)
{
return av_metadata_set2(pm, key, value, 0);
}
#endif
void av_metadata_free(AVMetadata **pm) void av_metadata_free(AVMetadata **pm)
{ {
AVMetadata *m= *pm; AVMetadata *m= *pm;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment