Mercurial > libavformat.hg
comparison vocenc.c @ 1535:a3fbb2b1fccf libavformat
split voc.c into vocdec.c and vocenc.c
author | aurel |
---|---|
date | Tue, 21 Nov 2006 13:08:04 +0000 |
parents | voc.c@0899bfe4105c |
children | 6dc55143f99f |
comparison
equal
deleted
inserted
replaced
1534:4bf9dc98e127 | 1535:a3fbb2b1fccf |
---|---|
1 /* | |
2 * Creative Voice File muxer. | |
3 * Copyright (c) 2006 Aurelien Jacobs <aurel@gnuage.org> | |
4 * | |
5 * This file is part of FFmpeg. | |
6 * | |
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. | |
11 * | |
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. | |
16 * | |
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 St, Fifth Floor, Boston, MA 02110-1301 USA | |
20 */ | |
21 | |
22 #include "avformat.h" | |
23 #include "riff.h" /* for CodecTag */ | |
24 #include "voc.h" | |
25 | |
26 | |
27 static const unsigned char voc_magic[] = "Creative Voice File\x1A"; | |
28 | |
29 static const CodecTag voc_codec_tags[] = { | |
30 {CODEC_ID_PCM_U8, 0x00}, | |
31 {CODEC_ID_ADPCM_SBPRO_4, 0x01}, | |
32 {CODEC_ID_ADPCM_SBPRO_3, 0x02}, | |
33 {CODEC_ID_ADPCM_SBPRO_2, 0x03}, | |
34 {CODEC_ID_PCM_S16LE, 0x04}, | |
35 {CODEC_ID_PCM_ALAW, 0x06}, | |
36 {CODEC_ID_PCM_MULAW, 0x07}, | |
37 {CODEC_ID_ADPCM_CT, 0x0200}, | |
38 {0, 0}, | |
39 }; | |
40 | |
41 | |
42 typedef struct voc_enc_context { | |
43 int param_written; | |
44 } voc_enc_context_t; | |
45 | |
46 static int voc_write_header(AVFormatContext *s) | |
47 { | |
48 ByteIOContext *pb = &s->pb; | |
49 const int header_size = 26; | |
50 const int version = 0x0114; | |
51 | |
52 if (s->nb_streams != 1 | |
53 || s->streams[0]->codec->codec_type != CODEC_TYPE_AUDIO) | |
54 return AVERROR_NOTSUPP; | |
55 | |
56 put_buffer(pb, voc_magic, sizeof(voc_magic) - 1); | |
57 put_le16(pb, header_size); | |
58 put_le16(pb, version); | |
59 put_le16(pb, ~version + 0x1234); | |
60 | |
61 return 0; | |
62 } | |
63 | |
64 static int voc_write_packet(AVFormatContext *s, AVPacket *pkt) | |
65 { | |
66 voc_enc_context_t *voc = s->priv_data; | |
67 AVCodecContext *enc = s->streams[0]->codec; | |
68 ByteIOContext *pb = &s->pb; | |
69 | |
70 if (!voc->param_written) { | |
71 int format = codec_get_tag(voc_codec_tags, enc->codec_id); | |
72 | |
73 if (format > 0xFF) { | |
74 put_byte(pb, VOC_TYPE_NEW_VOICE_DATA); | |
75 put_le24(pb, pkt->size + 12); | |
76 put_le32(pb, enc->sample_rate); | |
77 put_byte(pb, enc->bits_per_sample); | |
78 put_byte(pb, enc->channels); | |
79 put_le16(pb, format); | |
80 put_le32(pb, 0); | |
81 } else { | |
82 if (s->streams[0]->codec->channels > 1) { | |
83 put_byte(pb, VOC_TYPE_EXTENDED); | |
84 put_le24(pb, 4); | |
85 put_le16(pb, 65536-256000000/(enc->sample_rate*enc->channels)); | |
86 put_byte(pb, format); | |
87 put_byte(pb, enc->channels - 1); | |
88 } | |
89 put_byte(pb, VOC_TYPE_VOICE_DATA); | |
90 put_le24(pb, pkt->size + 2); | |
91 put_byte(pb, 256 - 1000000 / enc->sample_rate); | |
92 put_byte(pb, format); | |
93 } | |
94 voc->param_written = 1; | |
95 } else { | |
96 put_byte(pb, VOC_TYPE_VOICE_DATA_CONT); | |
97 put_le24(pb, pkt->size); | |
98 } | |
99 | |
100 put_buffer(pb, pkt->data, pkt->size); | |
101 return 0; | |
102 } | |
103 | |
104 static int voc_write_trailer(AVFormatContext *s) | |
105 { | |
106 put_byte(&s->pb, 0); | |
107 return 0; | |
108 } | |
109 | |
110 AVOutputFormat voc_muxer = { | |
111 "voc", | |
112 "Creative Voice File format", | |
113 "audio/x-voc", | |
114 "voc", | |
115 sizeof(voc_enc_context_t), | |
116 CODEC_ID_PCM_U8, | |
117 CODEC_ID_NONE, | |
118 voc_write_header, | |
119 voc_write_packet, | |
120 voc_write_trailer, | |
121 }; |