Sony Wave64 muxer

Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
Paul B Mahol 2012-12-28 13:40:55 +00:00
parent fe5a2fc46c
commit 9a74282644
13 changed files with 169 additions and 23 deletions

View File

@ -51,6 +51,7 @@ version <next>:
- pp (postproc) filter ported from MPlayer
- NIST Sphere demuxer
- MPL2, VPlayer, MPlayer, AQTitle, PJS and SubViewer v1 subtitles demuxers and decoders
- Sony Wave64 muxer
version 1.0:

1
configure vendored
View File

@ -1899,6 +1899,7 @@ tg2_muxer_select="mov_muxer"
tgp_muxer_select="mov_muxer"
vobsub_demuxer_select="mpegps_demuxer"
w64_demuxer_deps="wav_demuxer"
w64_muxer_deps="wav_muxer"
# indevs / outdevs
alsa_indev_deps="alsa_asoundlib_h snd_pcm_htimestamp"

View File

@ -374,7 +374,7 @@ library:
@item Sony OpenMG (OMA) @tab X @tab X
@tab Audio format used in Sony Sonic Stage and Sony Vegas.
@item Sony PlayStation STR @tab @tab X
@item Sony Wave64 (W64) @tab @tab X
@item Sony Wave64 (W64) @tab X @tab X
@item SoX native format @tab X @tab X
@item SUN AU format @tab X @tab X
@item Text files @tab @tab X

View File

@ -372,7 +372,8 @@ OBJS-$(CONFIG_VOC_DEMUXER) += vocdec.o voc.o
OBJS-$(CONFIG_VOC_MUXER) += vocenc.o voc.o
OBJS-$(CONFIG_VPLAYER_DEMUXER) += vplayerdec.o
OBJS-$(CONFIG_VQF_DEMUXER) += vqf.o
OBJS-$(CONFIG_W64_DEMUXER) += wavdec.o pcm.o
OBJS-$(CONFIG_W64_DEMUXER) += wavdec.o w64.o pcm.o
OBJS-$(CONFIG_W64_MUXER) += wavenc.o w64.o
OBJS-$(CONFIG_WAV_DEMUXER) += wavdec.o pcm.o
OBJS-$(CONFIG_WAV_MUXER) += wavenc.o
OBJS-$(CONFIG_WC3_DEMUXER) += wc3movie.o

View File

@ -282,7 +282,7 @@ void av_register_all(void)
REGISTER_MUXDEMUX(VOC, voc);
REGISTER_DEMUXER (VPLAYER, vplayer);
REGISTER_DEMUXER (VQF, vqf);
REGISTER_DEMUXER (W64, w64);
REGISTER_MUXDEMUX(W64, w64);
REGISTER_MUXDEMUX(WAV, wav);
REGISTER_DEMUXER (WC3, wc3);
REGISTER_MUXER (WEBM, webm);

View File

@ -30,7 +30,7 @@
#include "libavutil/avutil.h"
#define LIBAVFORMAT_VERSION_MAJOR 54
#define LIBAVFORMAT_VERSION_MINOR 57
#define LIBAVFORMAT_VERSION_MINOR 58
#define LIBAVFORMAT_VERSION_MICRO 100
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \

33
libavformat/w64.c Normal file
View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2009 Daniel Verkamp
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "w64.h"
const uint8_t ff_w64_guid_riff[16] = { 'r', 'i', 'f', 'f',
0x2E, 0x91, 0xCF, 0x11, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00 };
const uint8_t ff_w64_guid_wave[16] = { 'w', 'a', 'v', 'e',
0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };
const uint8_t ff_w64_guid_fmt [16] = { 'f', 'm', 't', ' ',
0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };
const uint8_t ff_w64_guid_data[16] = { 'd', 'a', 't', 'a',
0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };

29
libavformat/w64.h Normal file
View File

@ -0,0 +1,29 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVFORMAT_W64_H
#define AVFORMAT_W64_H
#include <stdint.h>
extern const uint8_t ff_w64_guid_riff[16];
extern const uint8_t ff_w64_guid_wave[16];
extern const uint8_t ff_w64_guid_fmt [16];
extern const uint8_t ff_w64_guid_data[16];
#endif /* AVFORMAT_W64_H */

View File

@ -33,6 +33,7 @@
#include "avio_internal.h"
#include "pcm.h"
#include "riff.h"
#include "w64.h"
#include "avio.h"
#include "metadata.h"
@ -396,9 +397,6 @@ static int64_t find_guid(AVIOContext *pb, const uint8_t guid1[16])
return -1;
}
static const uint8_t guid_data[16] = { 'd', 'a', 't', 'a',
0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };
#define MAX_SIZE 4096
static int wav_read_packet(AVFormatContext *s,
@ -455,7 +453,7 @@ smv_out:
left= INT_MAX;
if (left <= 0){
if (CONFIG_W64_DEMUXER && wav->w64)
left = find_guid(s->pb, guid_data) - 24;
left = find_guid(s->pb, ff_w64_guid_data) - 24;
else
left = find_tag(s->pb, MKTAG('d', 'a', 't', 'a'));
if (left < 0) {
@ -541,21 +539,12 @@ AVInputFormat ff_wav_demuxer = {
#if CONFIG_W64_DEMUXER
static const uint8_t guid_riff[16] = { 'r', 'i', 'f', 'f',
0x2E, 0x91, 0xCF, 0x11, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00 };
static const uint8_t guid_wave[16] = { 'w', 'a', 'v', 'e',
0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };
static const uint8_t guid_fmt [16] = { 'f', 'm', 't', ' ',
0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };
static int w64_probe(AVProbeData *p)
{
if (p->buf_size <= 40)
return 0;
if (!memcmp(p->buf, guid_riff, 16) &&
!memcmp(p->buf + 24, guid_wave, 16))
if (!memcmp(p->buf, ff_w64_guid_riff, 16) &&
!memcmp(p->buf + 24, ff_w64_guid_wave, 16))
return AVPROBE_SCORE_MAX;
else
return 0;
@ -571,19 +560,19 @@ static int w64_read_header(AVFormatContext *s)
int ret;
avio_read(pb, guid, 16);
if (memcmp(guid, guid_riff, 16))
if (memcmp(guid, ff_w64_guid_riff, 16))
return -1;
if (avio_rl64(pb) < 16 + 8 + 16 + 8 + 16 + 8) /* riff + wave + fmt + sizes */
return -1;
avio_read(pb, guid, 16);
if (memcmp(guid, guid_wave, 16)) {
if (memcmp(guid, ff_w64_guid_wave, 16)) {
av_log(s, AV_LOG_ERROR, "could not find wave guid\n");
return -1;
}
size = find_guid(pb, guid_fmt);
size = find_guid(pb, ff_w64_guid_fmt);
if (size < 0) {
av_log(s, AV_LOG_ERROR, "could not find fmt guid\n");
return -1;
@ -604,7 +593,7 @@ static int w64_read_header(AVFormatContext *s)
avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
size = find_guid(pb, guid_data);
size = find_guid(pb, ff_w64_guid_data);
if (size < 0) {
av_log(s, AV_LOG_ERROR, "could not find data guid\n");
return -1;

View File

@ -2,6 +2,9 @@
* WAV muxer
* Copyright (c) 2001, 2002 Fabrice Bellard
*
* Sony Wave64 muxer
* Copyright (c) 2012 Paul B Mahol
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
@ -43,6 +46,7 @@ typedef struct WAVMuxContext {
int write_bext;
} WAVMuxContext;
#if CONFIG_WAV_MUXER
static inline void bwf_write_bext_string(AVFormatContext *s, const char *key, int maxlen)
{
AVDictionaryEntry *tag;
@ -218,3 +222,83 @@ AVOutputFormat ff_wav_muxer = {
.codec_tag = (const AVCodecTag* const []){ ff_codec_wav_tags, 0 },
.priv_class = &wav_muxer_class,
};
#endif /* CONFIG_WAV_MUXER */
#if CONFIG_W64_MUXER
#include "w64.h"
static void start_guid(AVIOContext *pb, const uint8_t *guid, int64_t *pos)
{
*pos = avio_tell(pb);
avio_write(pb, guid, 16);
avio_wl64(pb, INT64_MAX);
}
static void end_guid(AVIOContext *pb, int64_t start)
{
int64_t end, pos = avio_tell(pb);
end = FFALIGN(pos, 8);
ffio_fill(pb, 0, end - pos);
avio_seek(pb, start + 16, SEEK_SET);
avio_wl64(pb, end - start);
avio_seek(pb, end, SEEK_SET);
}
static int w64_write_header(AVFormatContext *s)
{
WAVMuxContext *wav = s->priv_data;
AVIOContext *pb = s->pb;
int64_t start;
int ret;
avio_write(pb, ff_w64_guid_riff, sizeof(ff_w64_guid_riff));
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) {
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;
}
end_guid(pb, start);
start_guid(pb, ff_w64_guid_data, &wav->data);
return 0;
}
static int w64_write_trailer(AVFormatContext *s)
{
AVIOContext *pb = s->pb;
WAVMuxContext *wav = s->priv_data;
int64_t file_size;
if (pb->seekable) {
end_guid(pb, wav->data);
file_size = avio_tell(pb);
avio_seek(pb, 16, SEEK_SET);
avio_wl64(pb, file_size);
avio_seek(pb, file_size, SEEK_SET);
avio_flush(pb);
}
return 0;
}
AVOutputFormat ff_w64_muxer = {
.name = "w64",
.long_name = NULL_IF_CONFIG_SMALL("Sony Wave64"),
.extensions = "w64",
.priv_data_size = sizeof(WAVMuxContext),
.audio_codec = AV_CODEC_ID_PCM_S16LE,
.video_codec = AV_CODEC_ID_NONE,
.write_header = w64_write_header,
.write_packet = wav_write_packet,
.write_trailer = w64_write_trailer,
.flags = AVFMT_TS_NONSTRICT,
.codec_tag = (const AVCodecTag* const []){ ff_codec_wav_tags, 0 },
};
#endif /* CONFIG_W64_MUXER */

View File

@ -45,6 +45,7 @@ FATE_LAVF-$(call ENCDEC2, MPEG2VIDEO, MP2, MPEGTS) += ts
FATE_LAVF-$(call ENCDEC, PCM_U8, VOC) += voc
FATE_LAVF-$(call ENCDEC, PCM_S16LE, VOC) += voc_s16
FATE_LAVF-$(call ENCDEC, PCM_S16LE, WAV) += wav
FATE_LAVF-$(call ENCMUX, PCM_S16LE, W64) += w64
FATE_LAVF-$(call ENCDEC, MP2, WTV) += wtv
FATE_LAVF-$(call ENCDEC, XBM, IMAGE2) += xbm
FATE_LAVF-$(call ENCDEC, XWD, IMAGE2) += xwd

View File

@ -334,6 +334,10 @@ if [ -n "$do_ircam" ] ; then
do_audio_only ircam
fi
if [ -n "$do_w64" ] ; then
do_audio_only w64
fi
# pix_fmt conversions
if [ -n "$do_pixfmt" ] ; then

3
tests/ref/lavf/w64 Normal file
View File

@ -0,0 +1,3 @@
420bf38762386ae2ba8bf2e85b6cc7f2 *./tests/data/lavf/lavf.w64
90224 ./tests/data/lavf/lavf.w64
./tests/data/lavf/lavf.w64 CRC=0xf1ae5536