Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Verkamp <daniel@drv.nu>2014-04-30 06:26:05 +0400
committerMichael Niedermayer <michaelni@gmx.at>2014-04-30 18:41:35 +0400
commit5e7d21c7ad02e37caa1bcb50ab8ad64e7d7fb86c (patch)
tree20eb13371083ec6c50fe3533141c240f51780624 /libavformat
parentbb6d00f01417718315d7944c6c33950ea88fb287 (diff)
ff_put_wav_header: add flag to force WAVEFORMATEX
Partially undoes commit 2c4e08d89327595f7f4be57dda4b3775e1198d5e: riff: always generate a proper WAVEFORMATEX structure in ff_put_wav_header A new flag, FF_PUT_WAV_HEADER_FORCE_WAVEFORMATEX, is added to force the use of WAVEFORMATEX rather than PCMWAVEFORMAT even for PCM codecs. This flag is used in the Matroska muxer (the cause of the original change) and in the ASF muxer, because the specifications for these formats indicate explicitly that WAVEFORMATEX should be used. Muxers for other formats will return to the original behavior of writing PCMWAVEFORMAT when writing a header for raw PCM. In particular, this causes raw PCM in WAV to generate the canonical 44-byte header expected by some tools. Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/asfenc.c2
-rw-r--r--libavformat/avienc.c2
-rw-r--r--libavformat/matroskaenc.c2
-rw-r--r--libavformat/movenc.c4
-rw-r--r--libavformat/riff.h16
-rw-r--r--libavformat/riffenc.c9
-rw-r--r--libavformat/wavenc.c4
-rw-r--r--libavformat/wtvenc.c2
8 files changed, 29 insertions, 12 deletions
diff --git a/libavformat/asfenc.c b/libavformat/asfenc.c
index 8add6e0b12..23d83b712d 100644
--- a/libavformat/asfenc.c
+++ b/libavformat/asfenc.c
@@ -527,7 +527,7 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size,
if (enc->codec_type == AVMEDIA_TYPE_AUDIO) {
/* WAVEFORMATEX header */
- int wavsize = ff_put_wav_header(pb, enc);
+ int wavsize = ff_put_wav_header(pb, enc, FF_PUT_WAV_HEADER_FORCE_WAVEFORMATEX);
if (wavsize < 0)
return -1;
diff --git a/libavformat/avienc.c b/libavformat/avienc.c
index 7d5aee0059..89e2a539a0 100644
--- a/libavformat/avienc.c
+++ b/libavformat/avienc.c
@@ -325,7 +325,7 @@ static int avi_write_header(AVFormatContext *s)
av_get_pix_fmt_name(stream->pix_fmt));
break;
case AVMEDIA_TYPE_AUDIO:
- if ((ret = ff_put_wav_header(pb, stream)) < 0)
+ if ((ret = ff_put_wav_header(pb, stream, 0)) < 0)
return ret;
break;
default:
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index a628c7ab01..62e2d57ab9 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -593,7 +593,7 @@ static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, AVCodecCo
if (!codec->codec_tag)
codec->codec_tag = tag;
- ff_put_wav_header(dyn_cp, codec);
+ ff_put_wav_header(dyn_cp, codec, FF_PUT_WAV_HEADER_FORCE_WAVEFORMATEX);
}
codecpriv_size = avio_close_dyn_buf(dyn_cp, &codecpriv);
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 22b4ca6c98..bb0cb55f2b 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -401,7 +401,7 @@ static int mov_write_ms_tag(AVIOContext *pb, MOVTrack *track)
avio_wb32(pb, 0);
avio_wl32(pb, track->tag); // store it byteswapped
track->enc->codec_tag = av_bswap16(track->tag >> 16);
- ff_put_wav_header(pb, track->enc);
+ ff_put_wav_header(pb, track->enc, 0);
return update_size(pb, pos);
}
@@ -410,7 +410,7 @@ static int mov_write_wfex_tag(AVIOContext *pb, MOVTrack *track)
int64_t pos = avio_tell(pb);
avio_wb32(pb, 0);
ffio_wfourcc(pb, "wfex");
- ff_put_wav_header(pb, track->enc);
+ ff_put_wav_header(pb, track->enc, FF_PUT_WAV_HEADER_FORCE_WAVEFORMATEX);
return update_size(pb, pos);
}
diff --git a/libavformat/riff.h b/libavformat/riff.h
index dba38034e9..6f07179b2a 100644
--- a/libavformat/riff.h
+++ b/libavformat/riff.h
@@ -46,7 +46,21 @@ void ff_end_tag(AVIOContext *pb, int64_t start);
int ff_get_bmp_header(AVIOContext *pb, AVStream *st, unsigned *esize);
void ff_put_bmp_header(AVIOContext *pb, AVCodecContext *enc, const AVCodecTag *tags, int for_asf, int ignore_extradata);
-int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc);
+
+/**
+ * Tell ff_put_wav_header() to use WAVEFORMATEX even for PCM codecs.
+ */
+#define FF_PUT_WAV_HEADER_FORCE_WAVEFORMATEX 0x00000001
+
+/**
+ * Write WAVEFORMAT header structure.
+ *
+ * @param flags a combination of FF_PUT_WAV_HEADER_* constants
+ *
+ * @return the size or -1 on error
+ */
+int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc, int flags);
+
enum AVCodecID ff_wav_codec_get_id(unsigned int tag, int bps);
int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size);
diff --git a/libavformat/riffenc.c b/libavformat/riffenc.c
index 6c91cb693a..8701358e51 100644
--- a/libavformat/riffenc.c
+++ b/libavformat/riffenc.c
@@ -51,7 +51,7 @@ void ff_end_tag(AVIOContext *pb, int64_t start)
/* WAVEFORMATEX header */
/* returns the size or -1 on error */
-int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc)
+int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc, int flags)
{
int bps, blkalign, bytespersec, frame_size;
int hdrsize;
@@ -189,9 +189,12 @@ int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc)
avio_wl32(pb, 0xAA000080);
avio_wl32(pb, 0x719B3800);
}
- } else {
+ } else if ((flags & FF_PUT_WAV_HEADER_FORCE_WAVEFORMATEX) ||
+ enc->codec_tag != 0x0001 /* PCM */ ||
+ riff_extradata - riff_extradata_start) {
+ /* WAVEFORMATEX */
avio_wl16(pb, riff_extradata - riff_extradata_start); /* cbSize */
- }
+ } /* else PCMWAVEFORMAT */
avio_write(pb, riff_extradata_start, riff_extradata - riff_extradata_start);
hdrsize = avio_tell(pb) - hdrstart;
if (hdrsize & 1) {
diff --git a/libavformat/wavenc.c b/libavformat/wavenc.c
index 0067dfef29..0ddd218343 100644
--- a/libavformat/wavenc.c
+++ b/libavformat/wavenc.c
@@ -141,7 +141,7 @@ static int wav_write_header(AVFormatContext *s)
/* format header */
fmt = ff_start_tag(pb, "fmt ");
- if (ff_put_wav_header(pb, s->streams[0]->codec) < 0) {
+ if (ff_put_wav_header(pb, s->streams[0]->codec, 0) < 0) {
av_log(s, AV_LOG_ERROR, "%s codec not supported in WAVE format\n",
s->streams[0]->codec->codec ? s->streams[0]->codec->codec->name : "NONE");
return -1;
@@ -323,7 +323,7 @@ static int w64_write_header(AVFormatContext *s)
avio_wl64(pb, -1);
avio_write(pb, ff_w64_guid_wave, sizeof(ff_w64_guid_wave));
start_guid(pb, ff_w64_guid_fmt, &start);
- if ((ret = ff_put_wav_header(pb, s->streams[0]->codec)) < 0) {
+ if ((ret = ff_put_wav_header(pb, s->streams[0]->codec, 0)) < 0) {
av_log(s, AV_LOG_ERROR, "%s codec not supported\n",
s->streams[0]->codec->codec ? s->streams[0]->codec->codec->name : "NONE");
return ret;
diff --git a/libavformat/wtvenc.c b/libavformat/wtvenc.c
index f051c660ba..634545d459 100644
--- a/libavformat/wtvenc.c
+++ b/libavformat/wtvenc.c
@@ -289,7 +289,7 @@ static int write_stream_codec_info(AVFormatContext *s, AVStream *st)
if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
put_videoinfoheader2(pb, st);
} else {
- if (ff_put_wav_header(pb, st->codec) < 0)
+ if (ff_put_wav_header(pb, st->codec, 0) < 0)
format_type = &ff_format_none;
}
hdr_size = avio_tell(pb) - hdr_pos_start;