3 * Copyright (c) 2012 Paul B Mahol
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "libavutil/intreadwrite.h"
27 typedef struct WVMuxContext {
31 static int write_header(AVFormatContext *s)
33 AVCodecContext *codec = s->streams[0]->codec;
35 if (s->nb_streams > 1) {
36 av_log(s, AV_LOG_ERROR, "only one stream is supported\n");
37 return AVERROR(EINVAL);
39 if (codec->codec_id != AV_CODEC_ID_WAVPACK) {
40 av_log(s, AV_LOG_ERROR, "unsupported codec\n");
41 return AVERROR(EINVAL);
46 static int write_packet(AVFormatContext *ctx, AVPacket *pkt)
48 WVMuxContext *s = ctx->priv_data;
51 s->samples += AV_RL32(pkt->data + 20);
52 avio_write(ctx->pb, pkt->data, pkt->size);
57 static int write_trailer(AVFormatContext *ctx)
59 WVMuxContext *s = ctx->priv_data;
63 if (ctx->pb->seekable && s->samples) {
64 avio_seek(ctx->pb, 12, SEEK_SET);
65 if (s->samples < 0xFFFFFFFFu)
66 avio_wl32(ctx->pb, s->samples);
68 avio_wl32(ctx->pb, 0xFFFFFFFFu);
75 AVOutputFormat ff_wv_muxer = {
77 .long_name = NULL_IF_CONFIG_SMALL("WavPack"),
78 .priv_data_size = sizeof(WVMuxContext),
80 .audio_codec = AV_CODEC_ID_WAVPACK,
81 .video_codec = AV_CODEC_ID_NONE,
82 .write_header = write_header,
83 .write_packet = write_packet,
84 .write_trailer = write_trailer,
85 .flags = AVFMT_NOTIMESTAMPS,