From: Benjamin Larsson <[email protected]>
Signed-off-by: Anton Khirnov <[email protected]>
---
Changelog | 4 ++
doc/general.texi | 1 +
libavformat/Makefile | 1 +
libavformat/allformats.c | 1 +
libavformat/wav.c | 82 +++++++++++++++++++++++++++++++++++++++++++++-
5 files changed, 88 insertions(+), 1 deletions(-)
diff --git a/Changelog b/Changelog
index b785197..afd1b85 100644
--- a/Changelog
+++ b/Changelog
@@ -2,6 +2,10 @@ Entries are sorted chronologically from oldest to youngest
within each release,
releases are sorted from youngest to oldest.
+vesion <next>:
+- bwf muxer
+
+
version 0.7:
- E-AC-3 audio encoder
diff --git a/doc/general.texi b/doc/general.texi
index c97a757..2083395 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -66,6 +66,7 @@ library:
@tab Used in Z and Z95 games.
@item Brute Force & Ignorance @tab @tab X
@tab Used in the game Flash Traffic: City of Angels.
+@item BWF @tab @tab X
@item Interplay C93 @tab @tab X
@tab Used in the game Cyberia from Interplay.
@item Delphine Software International CIN @tab @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index a20db26..b6e9ac4 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -44,6 +44,7 @@ OBJS-$(CONFIG_AVS_DEMUXER) += avs.o vocdec.o
voc.o
OBJS-$(CONFIG_BETHSOFTVID_DEMUXER) += bethsoftvid.o
OBJS-$(CONFIG_BFI_DEMUXER) += bfi.o
OBJS-$(CONFIG_BINK_DEMUXER) += bink.o
+OBJS-$(CONFIG_BWF_MUXER) += wav.o riff.o
OBJS-$(CONFIG_C93_DEMUXER) += c93.o vocdec.o voc.o
OBJS-$(CONFIG_CAF_DEMUXER) += cafdec.o caf.o mov.o riff.o isom.o
OBJS-$(CONFIG_CAVSVIDEO_DEMUXER) += cavsvideodec.o rawdec.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index f1c3d3b..5d787a7 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -70,6 +70,7 @@ void av_register_all(void)
REGISTER_DEMUXER (BETHSOFTVID, bethsoftvid);
REGISTER_DEMUXER (BFI, bfi);
REGISTER_DEMUXER (BINK, bink);
+ REGISTER_MUXER (BWF, bwf);
REGISTER_DEMUXER (C93, c93);
REGISTER_DEMUXER (CAF, caf);
REGISTER_MUXDEMUX (CAVSVIDEO, cavsvideo);
diff --git a/libavformat/wav.c b/libavformat/wav.c
index 3914610..29b2824 100644
--- a/libavformat/wav.c
+++ b/libavformat/wav.c
@@ -28,6 +28,8 @@
#include "avio_internal.h"
#include "pcm.h"
#include "riff.h"
+#include "avio.h"
+#include "avio_internal.h"
typedef struct {
int64_t data;
@@ -38,7 +40,65 @@ typedef struct {
int w64;
} WAVContext;
-#if CONFIG_WAV_MUXER
+#if CONFIG_BWF_MUXER
+extern AVOutputFormat ff_bwf_muxer;
+
+static inline void bwf_write_bext_string(AVFormatContext *s, const char *key,
int maxlen)
+{
+ AVDictionaryEntry *tag;
+ int len = 0;
+
+ if (tag = av_dict_get(s->metadata, key, NULL, 0)) {
+ len = strlen(tag->value);
+ len = FFMIN(len, maxlen);
+ avio_write(s->pb, tag->value, len);
+ }
+
+ ffio_fill(s->pb, 0, maxlen - len);
+}
+
+static void bwf_write_bext_chunk(AVFormatContext *s)
+{
+ AVDictionaryEntry *tmp_tag;
+ uint64_t time_reference = 0;
+ int64_t bext = ff_start_tag(s->pb, "bext");
+
+ bwf_write_bext_string(s, "description", 256);
+ bwf_write_bext_string(s, "originator", 32);
+ bwf_write_bext_string(s, "originator_reference", 32);
+ bwf_write_bext_string(s, "origination_date", 10);
+ bwf_write_bext_string(s, "origination_time", 8);
+
+ if (tmp_tag = av_dict_get(s->metadata, "time_reference", NULL, 0))
+ time_reference = strtoll(tmp_tag->value, NULL, 10);
+ avio_wl64(s->pb, time_reference);
+ avio_wl16(s->pb, 1); // set version to 1
+
+ if (tmp_tag = av_dict_get(s->metadata, "umid", NULL, 0)) {
+ unsigned char umidpart_str[17] = {0};
+ int i;
+ uint64_t umidpart;
+ int len = strlen(tmp_tag->value+2);
+
+ for (i = 0; i < len/16; i++) {
+ memcpy(umidpart_str, tmp_tag->value + 2 + (i*16), 16);
+ umidpart = strtoll(umidpart_str, NULL, 16);
+ avio_wb64(s->pb, umidpart);
+ }
+ ffio_fill(s->pb, 0, 64 - i*8);
+ } else
+ ffio_fill(s->pb, 0, 64); // zero UMID
+
+ ffio_fill(s->pb, 0, 190); // Reserved
+
+ if (tmp_tag = av_dict_get(s->metadata, "coding_history", NULL, 0))
+ avio_put_str(s->pb, tmp_tag->value);
+
+ ff_end_tag(s->pb, bext);
+}
+#endif /* CONFIG_BWF_MUXER */
+
+#if CONFIG_WAV_MUXER || CONFIG_BWF_MUXER
static int wav_write_header(AVFormatContext *s)
{
WAVContext *wav = s->priv_data;
@@ -65,6 +125,11 @@ static int wav_write_header(AVFormatContext *s)
ff_end_tag(pb, fact);
}
+#if CONFIG_BWF_MUXER
+ if (s->oformat == &ff_bwf_muxer)
+ bwf_write_bext_chunk(s);
+#endif
+
av_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate);
wav->maxpts = wav->last_duration = 0;
wav->minpts = INT64_MAX;
@@ -124,7 +189,9 @@ static int wav_write_trailer(AVFormatContext *s)
}
return 0;
}
+#endif /* CONFIG_WAV_MUXER || CONFIG_BWF_MUXER */
+#if CONFIG_WAV_MUXER
AVOutputFormat ff_wav_muxer = {
"wav",
NULL_IF_CONFIG_SMALL("WAV format"),
@@ -140,6 +207,19 @@ AVOutputFormat ff_wav_muxer = {
};
#endif /* CONFIG_WAV_MUXER */
+#if CONFIG_BWF_MUXER
+AVOutputFormat ff_bwf_muxer = {
+ .name = "bwf",
+ .long_name = NULL_IF_CONFIG_SMALL("Broadcast Wave format"),
+ .extensions = "wav,bwf",
+ .priv_data_size = sizeof(WAVContext),
+ .audio_codec = CODEC_ID_PCM_S16LE,
+ .write_header = wav_write_header,
+ .write_packet = wav_write_packet,
+ .write_trailer = wav_write_trailer,
+ .codec_tag = (const AVCodecTag* const []){ff_codec_wav_tags, 0},
+};
+#endif /* CONFIG_BWF_MUXER */
#if CONFIG_WAV_DEMUXER
--
1.7.5.3
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel