[FFmpeg-devel] [PATCH 2/4] dict.c: Add av_dict_set_int helper function.

wm4 nfxjfg at googlemail.com
Wed Jul 30 21:22:27 CEST 2014


On Wed, 30 Jul 2014 20:38:06 +0200
Reimar Döffinger <Reimar.Doeffinger at gmx.de> wrote:

> This allows getting rid of the many, slightly differing, implementations
> of basically the same thing.
> 
> Signed-off-by: Reimar Döffinger <Reimar.Doeffinger at gmx.de>
> ---
>  doc/APIchanges                   |  3 +++
>  ffmpeg_opt.c                     | 12 +++---------
>  ffplay.c                         |  2 +-
>  libavfilter/vf_bbox.c            |  4 +---
>  libavfilter/vf_cropdetect.c      |  4 +---
>  libavformat/cinedec.c            |  4 +---
>  libavformat/ftp.c                | 10 ++++------
>  libavformat/hls.c                | 17 ++++-------------
>  libavformat/id3v1.c              |  4 +---
>  libavformat/matroskadec.c        | 31 +++++++------------------------
>  libavformat/mlvdec.c             | 16 ++++------------
>  libavformat/mov.c                | 14 +++-----------
>  libavformat/mxfdec.c             |  8 ++------
>  libavformat/smoothstreamingenc.c |  4 +---
>  libavformat/vqf.c                |  6 +-----
>  libavutil/dict.c                 |  8 ++++++++
>  libavutil/dict.h                 |  8 ++++++++
>  libavutil/version.h              |  2 +-
>  18 files changed, 54 insertions(+), 103 deletions(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 5a0989d..84d46d1 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -15,6 +15,9 @@ libavutil:     2012-10-22
>  
>  API changes, most recent first:
>  
> +2014-xx-xx - xxxxxxx - lavu 52.95.100 - dict.h
> +  Add av_dict_set_int helper function.
> +
>  2014-07-30 - xxxxxxx - lavu 52.94.100 - frame.h
>    Add av_frame_side_data_name()
>  
> diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
> index 2adefc5..4ff9f0a 100644
> --- a/ffmpeg_opt.c
> +++ b/ffmpeg_opt.c
> @@ -785,7 +785,6 @@ static int open_input_file(OptionsContext *o, const char *filename)
>      AVInputFormat *file_iformat = NULL;
>      int err, i, ret;
>      int64_t timestamp;
> -    uint8_t buf[128];
>      AVDictionary **opts;
>      AVDictionary *unused_opts = NULL;
>      AVDictionaryEntry *e = NULL;
> @@ -814,8 +813,7 @@ static int open_input_file(OptionsContext *o, const char *filename)
>          exit_program(1);
>      }
>      if (o->nb_audio_sample_rate) {
> -        snprintf(buf, sizeof(buf), "%d", o->audio_sample_rate[o->nb_audio_sample_rate - 1].u.i);
> -        av_dict_set(&o->g->format_opts, "sample_rate", buf, 0);
> +        av_dict_set_int(&o->g->format_opts, "sample_rate", o->audio_sample_rate[o->nb_audio_sample_rate - 1].u.i, 0);
>      }
>      if (o->nb_audio_channels) {
>          /* because we set audio_channels based on both the "ac" and
> @@ -824,9 +822,7 @@ static int open_input_file(OptionsContext *o, const char *filename)
>          if (file_iformat && file_iformat->priv_class &&
>              av_opt_find(&file_iformat->priv_class, "channels", NULL, 0,
>                          AV_OPT_SEARCH_FAKE_OBJ)) {
> -            snprintf(buf, sizeof(buf), "%d",
> -                     o->audio_channels[o->nb_audio_channels - 1].u.i);
> -            av_dict_set(&o->g->format_opts, "channels", buf, 0);
> +            av_dict_set_int(&o->g->format_opts, "channels", o->audio_channels[o->nb_audio_channels - 1].u.i, 0);
>          }
>      }
>      if (o->nb_frame_rates) {
> @@ -2038,9 +2034,7 @@ loop_end:
>          assert_file_overwrite(filename);
>  
>      if (o->mux_preload) {
> -        uint8_t buf[64];
> -        snprintf(buf, sizeof(buf), "%d", (int)(o->mux_preload*AV_TIME_BASE));
> -        av_dict_set(&of->opts, "preload", buf, 0);
> +        av_dict_set_int(&of->opts, "preload", o->mux_preload*AV_TIME_BASE, 0);
>      }
>      oc->max_delay = (int)(o->mux_max_delay * AV_TIME_BASE);
>  
> diff --git a/ffplay.c b/ffplay.c
> index af0e199..173a2e4 100644
> --- a/ffplay.c
> +++ b/ffplay.c
> @@ -2582,7 +2582,7 @@ static int stream_component_open(VideoState *is, int stream_index)
>      if (!av_dict_get(opts, "threads", NULL, 0))
>          av_dict_set(&opts, "threads", "auto", 0);
>      if (stream_lowres)
> -        av_dict_set(&opts, "lowres", av_asprintf("%d", stream_lowres), AV_DICT_DONT_STRDUP_VAL);
> +        av_dict_set_int(&opts, "lowres", stream_lowres, 0);
>      if (avctx->codec_type == AVMEDIA_TYPE_VIDEO || avctx->codec_type == AVMEDIA_TYPE_AUDIO)
>          av_dict_set(&opts, "refcounted_frames", "1", 0);
>      if (avcodec_open2(avctx, codec, &opts) < 0)
> diff --git a/libavfilter/vf_bbox.c b/libavfilter/vf_bbox.c
> index 6c6aab1..1e6feff 100644
> --- a/libavfilter/vf_bbox.c
> +++ b/libavfilter/vf_bbox.c
> @@ -61,8 +61,7 @@ static int query_formats(AVFilterContext *ctx)
>  }
>  
>  #define SET_META(key, value) \
> -    snprintf(buf, sizeof(buf), "%d", value);  \
> -    av_dict_set(metadata, key, buf, 0);
> +    av_dict_set_int(metadata, key, value, 0);
>  
>  static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
>  {
> @@ -70,7 +69,6 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
>      BBoxContext *bbox = ctx->priv;
>      FFBoundingBox box;
>      int has_bbox, w, h;
> -    char buf[32];
>  
>      has_bbox =
>          ff_calculate_bounding_box(&box,
> diff --git a/libavfilter/vf_cropdetect.c b/libavfilter/vf_cropdetect.c
> index ed8e7a8..f85a0bb 100644
> --- a/libavfilter/vf_cropdetect.c
> +++ b/libavfilter/vf_cropdetect.c
> @@ -113,8 +113,7 @@ static int config_input(AVFilterLink *inlink)
>  }
>  
>  #define SET_META(key, value) \
> -    snprintf(buf, sizeof(buf), "%d", value);  \
> -    av_dict_set(metadata, key, buf, 0)
> +    av_dict_set_int(metadata, key, value, 0)
>  
>  static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
>  {
> @@ -123,7 +122,6 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
>      int bpp = s->max_pixsteps[0];
>      int w, h, x, y, shrink_by;
>      AVDictionary **metadata;
> -    char buf[32];
>  
>      // ignore first 2 frames - they may be empty
>      if (++s->frame_nb > 0) {
> diff --git a/libavformat/cinedec.c b/libavformat/cinedec.c
> index 3720884..7daf0e0 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 66c0665..9ee9b16 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 3897723..e8d8815 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 d73adc7..0617a9c 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 50b75e7..8db4447 100644
> --- a/libavformat/matroskadec.c
> +++ b/libavformat/matroskadec.c
> @@ -3343,30 +3343,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.
> @@ -3397,10 +3385,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, '/');
> @@ -3415,10 +3401,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 a980ed6..5d84865 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 ab85918..917c012 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -91,15 +91,12 @@ 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));
> -    av_dict_set(&c->fc->metadata, key, buf, 0);
> +    av_dict_set_int(&c->fc->metadata, key, avio_r8(pb), 0);
>  
>      return 0;
>  }
> @@ -107,10 +104,7 @@ 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));
> -    av_dict_set(&c->fc->metadata, key, buf, 0);
> +    av_dict_set_int(&c->fc->metadata, key, avio_r8(pb), 0);
>  
>      return 0;
>  }
> @@ -728,7 +722,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};
>  
> @@ -738,8 +731,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 467d184..28bcc22 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 9491005..0781a0a 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 74c7f5f..cbf3d71 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
> diff --git a/libavutil/dict.c b/libavutil/dict.c
> index aea8910..cb7be9c 100644
> --- a/libavutil/dict.c
> +++ b/libavutil/dict.c
> @@ -122,6 +122,14 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value,
>      return 0;
>  }
>  
> +int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value,
> +                int flags)
> +{
> +    char valuestr[22];
> +    snprintf(valuestr, sizeof(valuestr), "%"PRId64, value);
> +    return av_dict_set_int(pm, key, valuestr, flags);
> +}
> +
>  static int parse_key_value_pair(AVDictionary **pm, const char **buf,
>                                  const char *key_val_sep, const char *pairs_sep,
>                                  int flags)
> diff --git a/libavutil/dict.h b/libavutil/dict.h
> index 025d867..06f1621 100644
> --- a/libavutil/dict.h
> +++ b/libavutil/dict.h
> @@ -31,6 +31,8 @@
>  #ifndef AVUTIL_DICT_H
>  #define AVUTIL_DICT_H
>  
> +#include <stdint.h>
> +
>  #include "version.h"
>  
>  /**
> @@ -123,6 +125,12 @@ int av_dict_count(const AVDictionary *m);
>  int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags);
>  
>  /**
> + * Convenience wrapper for av_dict_set that converts the value to a string
> + * and stores it.
> + */
> +int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags);
> +
> +/**

I think that's a pretty good idea, but you could make it more general
by adding something like av_dict_set_fmt(), which adds a
snprintf-formatted value. av_dict_set_int could then call this too.

Also, maybe it would be better to split the libavutil and the other
changes into 2 commits.

>   * Parse the key/value pairs list and add the parsed entries to a dictionary.
>   *
>   * In case of failure, all the successfully set entries are stored in
> diff --git a/libavutil/version.h b/libavutil/version.h
> index 42e2db5..9af8f5f 100644
> --- a/libavutil/version.h
> +++ b/libavutil/version.h
> @@ -56,7 +56,7 @@
>   */
>  
>  #define LIBAVUTIL_VERSION_MAJOR  52
> -#define LIBAVUTIL_VERSION_MINOR  94
> +#define LIBAVUTIL_VERSION_MINOR  95
>  #define LIBAVUTIL_VERSION_MICRO 100
>  
>  #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \



More information about the ffmpeg-devel mailing list