2 * Creative Voice File muxer.
3 * Copyright (c) 2006 Aurelien Jacobs <aurel@gnuage.org>
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
25 typedef struct voc_enc_context
{
29 static int voc_write_header(AVFormatContext
*s
)
31 ByteIOContext
*pb
= s
->pb
;
32 const int header_size
= 26;
33 const int version
= 0x0114;
35 if (s
->nb_streams
!= 1
36 || s
->streams
[0]->codec
->codec_type
!= CODEC_TYPE_AUDIO
)
37 return AVERROR_PATCHWELCOME
;
39 put_buffer(pb
, voc_magic
, sizeof(voc_magic
) - 1);
40 put_le16(pb
, header_size
);
41 put_le16(pb
, version
);
42 put_le16(pb
, ~version
+ 0x1234);
47 static int voc_write_packet(AVFormatContext
*s
, AVPacket
*pkt
)
49 voc_enc_context_t
*voc
= s
->priv_data
;
50 AVCodecContext
*enc
= s
->streams
[0]->codec
;
51 ByteIOContext
*pb
= s
->pb
;
53 if (!voc
->param_written
) {
54 if (enc
->codec_tag
> 0xFF) {
55 put_byte(pb
, VOC_TYPE_NEW_VOICE_DATA
);
56 put_le24(pb
, pkt
->size
+ 12);
57 put_le32(pb
, enc
->sample_rate
);
58 put_byte(pb
, enc
->bits_per_sample
);
59 put_byte(pb
, enc
->channels
);
60 put_le16(pb
, enc
->codec_tag
);
63 if (s
->streams
[0]->codec
->channels
> 1) {
64 put_byte(pb
, VOC_TYPE_EXTENDED
);
66 put_le16(pb
, 65536-256000000/(enc
->sample_rate
*enc
->channels
));
67 put_byte(pb
, enc
->codec_tag
);
68 put_byte(pb
, enc
->channels
- 1);
70 put_byte(pb
, VOC_TYPE_VOICE_DATA
);
71 put_le24(pb
, pkt
->size
+ 2);
72 put_byte(pb
, 256 - 1000000 / enc
->sample_rate
);
73 put_byte(pb
, enc
->codec_tag
);
75 voc
->param_written
= 1;
77 put_byte(pb
, VOC_TYPE_VOICE_DATA_CONT
);
78 put_le24(pb
, pkt
->size
);
81 put_buffer(pb
, pkt
->data
, pkt
->size
);
85 static int voc_write_trailer(AVFormatContext
*s
)
91 AVOutputFormat voc_muxer
= {
93 "Creative Voice File format",
96 sizeof(voc_enc_context_t
),
102 .codec_tag
=(const AVCodecTag
*[]){voc_codec_tags
, 0},