Skip to content

Commit

Permalink
lavf: move RIFF INFO tag writing from avienc to riff
Browse files Browse the repository at this point in the history
It will be useful in the wav muxer.

Signed-off-by: Anton Khirnov <[email protected]>
  • Loading branch information
vasilvv authored and elenril committed Oct 16, 2012
1 parent a119c64 commit 71e9241
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 24 deletions.
24 changes: 2 additions & 22 deletions libavformat/avienc.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,6 @@ static char* avi_stream2fourcc(char* tag, int index, enum AVMediaType type)
return tag;
}

static void avi_write_info_tag(AVIOContext *pb, const char *tag, const char *str)
{
int len = strlen(str);
if (len > 0) {
len++;
ffio_wfourcc(pb, tag);
avio_wl32(pb, len);
avio_put_str(pb, str);
if (len & 1)
avio_w8(pb, 0);
}
}

static int avi_write_counters(AVFormatContext* s, int riff_id)
{
AVIOContext *pb = s->pb;
Expand Down Expand Up @@ -300,7 +287,7 @@ static int avi_write_header(AVFormatContext *s)
}
ff_end_tag(pb, strf);
if ((t = av_dict_get(s->streams[i]->metadata, "title", NULL, 0))) {
avi_write_info_tag(s->pb, "strn", t->value);
ff_riff_write_info_tag(s->pb, "strn", t->value);
t = NULL;
}
}
Expand Down Expand Up @@ -377,14 +364,7 @@ static int avi_write_header(AVFormatContext *s)

ff_end_tag(pb, list1);

list2 = ff_start_tag(pb, "LIST");
ffio_wfourcc(pb, "INFO");
ff_metadata_conv(&s->metadata, ff_riff_info_conv, NULL);
for (i = 0; *ff_riff_tags[i]; i++) {
if ((t = av_dict_get(s->metadata, ff_riff_tags[i], NULL, AV_DICT_MATCH_CASE)))
avi_write_info_tag(s->pb, t->key, t->value);
}
ff_end_tag(pb, list2);
ff_riff_write_info(s);

/* some padding for easier tag editing */
list2 = ff_start_tag(pb, "JUNK");
Expand Down
32 changes: 31 additions & 1 deletion libavformat/riff.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* RIFF codec tags
* RIFF common functions and data
* Copyright (c) 2000 Fabrice Bellard
*
* This file is part of Libav.
Expand Down Expand Up @@ -708,3 +708,33 @@ int ff_read_riff_info(AVFormatContext *s, int64_t size)

return 0;
}

void ff_riff_write_info_tag(AVIOContext *pb, const char *tag, const char *str)
{
int len = strlen(str);
if (len > 0) {
len++;
ffio_wfourcc(pb, tag);
avio_wl32(pb, len);
avio_put_str(pb, str);
if (len & 1)
avio_w8(pb, 0);
}
}

void ff_riff_write_info(AVFormatContext *s)
{
AVIOContext *pb = s->pb;
int i;
int64_t list_pos;
AVDictionaryEntry *t = NULL;

list_pos = ff_start_tag(pb, "LIST");
ffio_wfourcc(pb, "INFO");
ff_metadata_conv(&s->metadata, ff_riff_info_conv, NULL);
for (i = 0; *ff_riff_tags[i]; i++) {
if ((t = av_dict_get(s->metadata, ff_riff_tags[i], NULL, AV_DICT_MATCH_CASE)))
ff_riff_write_info_tag(s->pb, t->key, t->value);
}
ff_end_tag(pb, list_pos);
}
12 changes: 11 additions & 1 deletion libavformat/riff.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* RIFF codec tags
* RIFF common functions and data
* copyright (c) 2000 Fabrice Bellard
*
* This file is part of Libav.
Expand Down Expand Up @@ -60,4 +60,14 @@ void ff_parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssiz

int ff_read_riff_info(AVFormatContext *s, int64_t size);

/**
* Write all recognized RIFF tags from s->metadata
*/
void ff_riff_write_info(AVFormatContext *s);

/**
* Write a single RIFF info tag
*/
void ff_riff_write_info_tag(AVIOContext *pb, const char *tag, const char *str);

#endif /* AVFORMAT_RIFF_H */

0 comments on commit 71e9241

Please sign in to comment.