summaryrefslogtreecommitdiff
path: root/libavformat
diff options
context:
space:
mode:
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>2014-07-29 21:10:39 +0200
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>2014-08-16 14:31:41 +0200
commita0941c8a2b3e55dc4482c874523afcb7ed6e93e6 (patch)
tree9e472048b168454605936246a7aeab4c0bade8f6 /libavformat
parentc2829dc925ffcc2a5934f3e99360a89fb0a3cad5 (diff)
Use new av_dict_set_int helper function.
Get rid of the many, slightly differing, implementations of basically the same thing. Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/cinedec.c4
-rw-r--r--libavformat/ftp.c10
-rw-r--r--libavformat/hls.c17
-rw-r--r--libavformat/id3v1.c4
-rw-r--r--libavformat/matroskadec.c31
-rw-r--r--libavformat/mlvdec.c16
-rw-r--r--libavformat/mov.c14
-rw-r--r--libavformat/mxfdec.c8
-rw-r--r--libavformat/smoothstreamingenc.c4
-rw-r--r--libavformat/vqf.c6
10 files changed, 28 insertions, 86 deletions
diff --git a/libavformat/cinedec.c b/libavformat/cinedec.c
index 372088495e..7daf0e0190 100644
--- a/libavformat/cinedec.c
+++ b/libavformat/cinedec.c
@@ -73,9 +73,7 @@ static int cine_read_probe(AVProbeData *p)
static int set_metadata_int(AVDictionary **dict, const char *key, int value)
{
if (value) {
- char buf[64];
- snprintf(buf, sizeof(buf), "%i", value);
- return av_dict_set(dict, key, buf, 0);
+ return av_dict_set_int(dict, key, value, 0);
}
return 0;
}
diff --git a/libavformat/ftp.c b/libavformat/ftp.c
index 66c066549e..9ee9b1630f 100644
--- a/libavformat/ftp.c
+++ b/libavformat/ftp.c
@@ -455,7 +455,7 @@ static int ftp_features(FTPContext *s)
static int ftp_connect_control_connection(URLContext *h)
{
- char buf[CONTROL_BUFFER_SIZE], opts_format[20], *response = NULL;
+ char buf[CONTROL_BUFFER_SIZE], *response = NULL;
int err;
AVDictionary *opts = NULL;
FTPContext *s = h->priv_data;
@@ -465,8 +465,7 @@ static int ftp_connect_control_connection(URLContext *h)
ff_url_join(buf, sizeof(buf), "tcp", NULL,
s->hostname, s->server_control_port, NULL);
if (s->rw_timeout != -1) {
- snprintf(opts_format, sizeof(opts_format), "%d", s->rw_timeout);
- av_dict_set(&opts, "timeout", opts_format, 0);
+ av_dict_set_int(&opts, "timeout", s->rw_timeout, 0);
} /* if option is not given, don't pass it and let tcp use its own default */
err = ffurl_open(&s->conn_control, buf, AVIO_FLAG_READ_WRITE,
&h->interrupt_callback, &opts);
@@ -505,7 +504,7 @@ static int ftp_connect_control_connection(URLContext *h)
static int ftp_connect_data_connection(URLContext *h)
{
int err;
- char buf[CONTROL_BUFFER_SIZE], opts_format[20];
+ char buf[CONTROL_BUFFER_SIZE];
AVDictionary *opts = NULL;
FTPContext *s = h->priv_data;
@@ -519,8 +518,7 @@ static int ftp_connect_data_connection(URLContext *h)
/* Open data connection */
ff_url_join(buf, sizeof(buf), "tcp", NULL, s->hostname, s->server_data_port, NULL);
if (s->rw_timeout != -1) {
- snprintf(opts_format, sizeof(opts_format), "%d", s->rw_timeout);
- av_dict_set(&opts, "timeout", opts_format, 0);
+ av_dict_set_int(&opts, "timeout", s->rw_timeout, 0);
} /* if option is not given, don't pass it and let tcp use its own default */
err = ffurl_open(&s->conn_data, buf, h->flags,
&h->interrupt_callback, &opts);
diff --git a/libavformat/hls.c b/libavformat/hls.c
index 2ea62c614c..0c86461f0f 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -919,14 +919,8 @@ static int open_input(HLSContext *c, struct playlist *pls)
if (seg->size >= 0) {
/* try to restrict the HTTP request to the part we want
* (if this is in fact a HTTP request) */
- char offset[24] = { 0 };
- char end_offset[24] = { 0 };
- snprintf(offset, sizeof(offset) - 1, "%"PRId64,
- seg->url_offset);
- snprintf(end_offset, sizeof(end_offset) - 1, "%"PRId64,
- seg->url_offset + seg->size);
- av_dict_set(&opts, "offset", offset, 0);
- av_dict_set(&opts, "end_offset", end_offset, 0);
+ av_dict_set_int(&opts, "offset", seg->url_offset, 0);
+ av_dict_set_int(&opts, "end_offset", seg->url_offset + seg->size, 0);
}
av_log(pls->parent, AV_LOG_VERBOSE, "HLS request for url '%s', offset %"PRId64", playlist %d\n",
@@ -1397,15 +1391,12 @@ static int hls_read_header(AVFormatContext *s)
/* Create a program for each variant */
for (i = 0; i < c->n_variants; i++) {
struct variant *v = c->variants[i];
- char bitrate_str[20];
AVProgram *program;
- snprintf(bitrate_str, sizeof(bitrate_str), "%d", v->bandwidth);
-
program = av_new_program(s, i);
if (!program)
goto fail;
- av_dict_set(&program->metadata, "variant_bitrate", bitrate_str, 0);
+ av_dict_set_int(&program->metadata, "variant_bitrate", v->bandwidth, 0);
for (j = 0; j < v->n_playlists; j++) {
struct playlist *pls = v->playlists[j];
@@ -1419,7 +1410,7 @@ static int hls_read_header(AVFormatContext *s)
/* Set variant_bitrate for streams unique to this variant */
if (!is_shared && v->bandwidth)
- av_dict_set(&st->metadata, "variant_bitrate", bitrate_str, 0);
+ av_dict_set_int(&st->metadata, "variant_bitrate", v->bandwidth, 0);
}
}
}
diff --git a/libavformat/id3v1.c b/libavformat/id3v1.c
index d73adc713b..0617a9cf82 100644
--- a/libavformat/id3v1.c
+++ b/libavformat/id3v1.c
@@ -203,7 +203,6 @@ static void get_string(AVFormatContext *s, const char *key,
*/
static int parse_tag(AVFormatContext *s, const uint8_t *buf)
{
- char str[5];
int genre;
if (!(buf[0] == 'T' &&
@@ -216,8 +215,7 @@ static int parse_tag(AVFormatContext *s, const uint8_t *buf)
get_string(s, "date", buf + 93, 4);
get_string(s, "comment", buf + 97, 30);
if (buf[125] == 0 && buf[126] != 0) {
- snprintf(str, sizeof(str), "%d", buf[126]);
- av_dict_set(&s->metadata, "track", str, 0);
+ av_dict_set_int(&s->metadata, "track", buf[126], 0);
}
genre = buf[127];
if (genre <= ID3v1_GENRE_MAX)
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 09d23f67ed..c19e8e9ca8 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -3345,30 +3345,18 @@ static int webm_dash_manifest_cues(AVFormatContext *s)
matroska_parse_cues(matroska);
// cues start
- buf = av_asprintf("%" PRId64, cues_start);
- if (!buf) return AVERROR(ENOMEM);
- av_dict_set(&s->streams[0]->metadata, CUES_START, buf, 0);
- av_free(buf);
+ av_dict_set_int(&s->streams[0]->metadata, CUES_START, cues_start, 0);
// cues end
- buf = av_asprintf("%" PRId64, cues_end);
- if (!buf) return AVERROR(ENOMEM);
- av_dict_set(&s->streams[0]->metadata, CUES_END, buf, 0);
- av_free(buf);
+ av_dict_set_int(&s->streams[0]->metadata, CUES_END, cues_end, 0);
// bandwidth
bandwidth = webm_dash_manifest_compute_bandwidth(s, cues_start);
if (bandwidth < 0) return -1;
- buf = av_asprintf("%" PRId64, bandwidth);
- if (!buf) return AVERROR(ENOMEM);
- av_dict_set(&s->streams[0]->metadata, BANDWIDTH, buf, 0);
- av_free(buf);
+ av_dict_set_int(&s->streams[0]->metadata, BANDWIDTH, bandwidth, 0);
// check if all clusters start with key frames
- buf = av_asprintf("%d", webm_clusters_start_with_keyframe(s));
- if (!buf) return AVERROR(ENOMEM);
- av_dict_set(&s->streams[0]->metadata, CLUSTER_KEYFRAME, buf, 0);
- av_free(buf);
+ av_dict_set_int(&s->streams[0]->metadata, CLUSTER_KEYFRAME, webm_clusters_start_with_keyframe(s), 0);
// store cue point timestamps as a comma separated list for checking subsegment alignment in
// the muxer. assumes that each timestamp cannot be more than 20 characters long.
@@ -3399,10 +3387,8 @@ static int webm_dash_manifest_read_header(AVFormatContext *s)
}
// initialization range
- buf = av_asprintf("%" PRId64, avio_tell(s->pb) - 5); // 5 is the offset of Cluster ID.
- if (!buf) return AVERROR(ENOMEM);
- av_dict_set(&s->streams[0]->metadata, INITIALIZATION_RANGE, buf, 0);
- av_free(buf);
+ // 5 is the offset of Cluster ID.
+ av_dict_set_int(&s->streams[0]->metadata, INITIALIZATION_RANGE, avio_tell(s->pb) - 5, 0);
// basename of the file
buf = strrchr(s->filename, '/');
@@ -3417,10 +3403,7 @@ static int webm_dash_manifest_read_header(AVFormatContext *s)
// track number
tracks = matroska->tracks.elem;
- buf = av_asprintf("%" PRId64, tracks[0].num);
- if (!buf) return AVERROR(ENOMEM);
- av_dict_set(&s->streams[0]->metadata, TRACK_NUMBER, buf, 0);
- av_free(buf);
+ av_dict_set_int(&s->streams[0]->metadata, TRACK_NUMBER, tracks[0].num, 0);
// parse the cues and populate Cue related fields
return webm_dash_manifest_cues(s);
diff --git a/libavformat/mlvdec.c b/libavformat/mlvdec.c
index 0ed1bfaa30..1855ea46ce 100644
--- a/libavformat/mlvdec.c
+++ b/libavformat/mlvdec.c
@@ -95,30 +95,22 @@ static void read_string(AVFormatContext *avctx, AVIOContext *pb, const char *tag
static void read_uint8(AVFormatContext *avctx, AVIOContext *pb, const char *tag, const char *fmt)
{
- char value[4];
- snprintf(value, sizeof(value), "%i", avio_r8(pb));
- av_dict_set(&avctx->metadata, tag, value, 0);
+ av_dict_set_int(&avctx->metadata, tag, avio_r8(pb), 0);
}
static void read_uint16(AVFormatContext *avctx, AVIOContext *pb, const char *tag, const char *fmt)
{
- char value[8];
- snprintf(value, sizeof(value), "%i", avio_rl16(pb));
- av_dict_set(&avctx->metadata, tag, value, 0);
+ av_dict_set_int(&avctx->metadata, tag, avio_rl16(pb), 0);
}
static void read_uint32(AVFormatContext *avctx, AVIOContext *pb, const char *tag, const char *fmt)
{
- char value[16];
- snprintf(value, sizeof(value), fmt, avio_rl32(pb));
- av_dict_set(&avctx->metadata, tag, value, 0);
+ av_dict_set_int(&avctx->metadata, tag, avio_rl32(pb), 0);
}
static void read_uint64(AVFormatContext *avctx, AVIOContext *pb, const char *tag, const char *fmt)
{
- char value[32];
- snprintf(value, sizeof(value), fmt, avio_rl64(pb));
- av_dict_set(&avctx->metadata, tag, value, 0);
+ av_dict_set_int(&avctx->metadata, tag, avio_rl64(pb), 0);
}
static int scan_file(AVFormatContext *avctx, AVStream *vst, AVStream *ast, int file)
diff --git a/libavformat/mov.c b/libavformat/mov.c
index a531fd47c8..d28553a5ed 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -92,16 +92,13 @@ static int mov_metadata_track_or_disc_number(MOVContext *c, AVIOContext *pb,
static int mov_metadata_int8_bypass_padding(MOVContext *c, AVIOContext *pb,
unsigned len, const char *key)
{
- char buf[16];
-
/* bypass padding bytes */
avio_r8(pb);
avio_r8(pb);
avio_r8(pb);
- snprintf(buf, sizeof(buf), "%d", avio_r8(pb));
c->fc->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED;
- av_dict_set(&c->fc->metadata, key, buf, 0);
+ av_dict_set_int(&c->fc->metadata, key, avio_r8(pb), 0);
return 0;
}
@@ -109,11 +106,8 @@ static int mov_metadata_int8_bypass_padding(MOVContext *c, AVIOContext *pb,
static int mov_metadata_int8_no_padding(MOVContext *c, AVIOContext *pb,
unsigned len, const char *key)
{
- char buf[16];
-
- snprintf(buf, sizeof(buf), "%d", avio_r8(pb));
c->fc->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED;
- av_dict_set(&c->fc->metadata, key, buf, 0);
+ av_dict_set_int(&c->fc->metadata, key, avio_r8(pb), 0);
return 0;
}
@@ -736,7 +730,6 @@ static int mov_read_ftyp(MOVContext *c, AVIOContext *pb, MOVAtom atom)
{
uint32_t minor_ver;
int comp_brand_size;
- char minor_ver_str[11]; /* 32 bit integer -> 10 digits + null */
char* comp_brands_str;
uint8_t type[5] = {0};
@@ -746,8 +739,7 @@ static int mov_read_ftyp(MOVContext *c, AVIOContext *pb, MOVAtom atom)
av_log(c->fc, AV_LOG_DEBUG, "ISO: File Type Major Brand: %.4s\n",(char *)&type);
av_dict_set(&c->fc->metadata, "major_brand", type, 0);
minor_ver = avio_rb32(pb); /* minor version */
- snprintf(minor_ver_str, sizeof(minor_ver_str), "%"PRIu32"", minor_ver);
- av_dict_set(&c->fc->metadata, "minor_version", minor_ver_str, 0);
+ av_dict_set_int(&c->fc->metadata, "minor_version", minor_ver, 0);
comp_brand_size = atom.size - 8;
if (comp_brand_size < 0)
diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 2fc1ce0c4f..ed1cecbf46 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -1632,14 +1632,10 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
}
st->need_parsing = AVSTREAM_PARSE_HEADERS;
if (material_track->sequence->origin) {
- char material_origin[3];
- snprintf(material_origin, sizeof(material_origin), "%d", material_track->sequence->origin);
- av_dict_set(&st->metadata, "material_track_origin", material_origin, 0);
+ av_dict_set_int(&st->metadata, "material_track_origin", material_track->sequence->origin, 0);
}
if (source_track->sequence->origin) {
- char source_origin[3];
- snprintf(source_origin, sizeof(source_origin), "%d", source_track->sequence->origin);
- av_dict_set(&st->metadata, "source_track_origin", source_origin, 0);
+ av_dict_set_int(&st->metadata, "source_track_origin", source_track->sequence->origin, 0);
}
} else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
container_ul = mxf_get_codec_ul(mxf_sound_essence_container_uls, essence_container_ul);
diff --git a/libavformat/smoothstreamingenc.c b/libavformat/smoothstreamingenc.c
index 9491005422..0781a0a370 100644
--- a/libavformat/smoothstreamingenc.c
+++ b/libavformat/smoothstreamingenc.c
@@ -315,7 +315,6 @@ static int ism_write_header(AVFormatContext *s)
AVFormatContext *ctx;
AVStream *st;
AVDictionary *opts = NULL;
- char buf[10];
if (!s->streams[i]->codec->bit_rate) {
av_log(s, AV_LOG_ERROR, "No bit rate set for stream %d\n", i);
@@ -351,8 +350,7 @@ static int ism_write_header(AVFormatContext *s)
goto fail;
}
- snprintf(buf, sizeof(buf), "%d", c->lookahead_count);
- av_dict_set(&opts, "ism_lookahead", buf, 0);
+ av_dict_set_int(&opts, "ism_lookahead", c->lookahead_count, 0);
av_dict_set(&opts, "movflags", "frag_custom", 0);
if ((ret = avformat_write_header(ctx, &opts)) < 0) {
goto fail;
diff --git a/libavformat/vqf.c b/libavformat/vqf.c
index d1ea0b4115..15e8246432 100644
--- a/libavformat/vqf.c
+++ b/libavformat/vqf.c
@@ -144,11 +144,7 @@ static int vqf_read_header(AVFormatContext *s)
break;
case MKTAG('D','S','I','Z'): // size of compressed data
{
- char buf[8] = {0};
- int size = avio_rb32(s->pb);
-
- snprintf(buf, sizeof(buf), "%d", size);
- av_dict_set(&s->metadata, "size", buf, 0);
+ av_dict_set_int(&s->metadata, "size", avio_rb32(s->pb), 0);
}
break;
case MKTAG('Y','E','A','R'): // recording date