Mercurial > libavformat.hg
annotate vocenc.c @ 1575:003fede0eb67 libavformat
RFC 3&4 stage: FFmpeg style aint't my style
- Tabs are 4 width
- No tabs allowed
author | gpoirier |
---|---|
date | Tue, 12 Dec 2006 22:32:08 +0000 |
parents | 6dc55143f99f |
children | 71078c1009c4 |
rev | line source |
---|---|
937 | 1 /* |
1535 | 2 * Creative Voice File muxer. |
937 | 3 * Copyright (c) 2006 Aurelien Jacobs <aurel@gnuage.org> |
4 * | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1172
diff
changeset
|
5 * This file is part of FFmpeg. |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1172
diff
changeset
|
6 * |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1172
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
937 | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1172
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
937 | 11 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1172
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
937 | 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 | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1172
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
937 | 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
20 */ | |
21 | |
22 #include "voc.h" | |
23 | |
24 | |
25 typedef struct voc_enc_context { | |
26 int param_written; | |
27 } voc_enc_context_t; | |
28 | |
29 static int voc_write_header(AVFormatContext *s) | |
30 { | |
31 ByteIOContext *pb = &s->pb; | |
32 const int header_size = 26; | |
33 const int version = 0x0114; | |
34 | |
35 if (s->nb_streams != 1 | |
36 || s->streams[0]->codec->codec_type != CODEC_TYPE_AUDIO) | |
37 return AVERROR_NOTSUPP; | |
38 | |
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); | |
43 | |
44 return 0; | |
45 } | |
46 | |
47 static int voc_write_packet(AVFormatContext *s, AVPacket *pkt) | |
48 { | |
49 voc_enc_context_t *voc = s->priv_data; | |
50 AVCodecContext *enc = s->streams[0]->codec; | |
51 ByteIOContext *pb = &s->pb; | |
52 | |
53 if (!voc->param_written) { | |
54 int format = codec_get_tag(voc_codec_tags, enc->codec_id); | |
55 | |
56 if (format > 0xFF) { | |
57 put_byte(pb, VOC_TYPE_NEW_VOICE_DATA); | |
58 put_le24(pb, pkt->size + 12); | |
59 put_le32(pb, enc->sample_rate); | |
60 put_byte(pb, enc->bits_per_sample); | |
61 put_byte(pb, enc->channels); | |
62 put_le16(pb, format); | |
63 put_le32(pb, 0); | |
64 } else { | |
65 if (s->streams[0]->codec->channels > 1) { | |
66 put_byte(pb, VOC_TYPE_EXTENDED); | |
67 put_le24(pb, 4); | |
68 put_le16(pb, 65536-256000000/(enc->sample_rate*enc->channels)); | |
69 put_byte(pb, format); | |
70 put_byte(pb, enc->channels - 1); | |
71 } | |
72 put_byte(pb, VOC_TYPE_VOICE_DATA); | |
73 put_le24(pb, pkt->size + 2); | |
74 put_byte(pb, 256 - 1000000 / enc->sample_rate); | |
75 put_byte(pb, format); | |
76 } | |
77 voc->param_written = 1; | |
78 } else { | |
79 put_byte(pb, VOC_TYPE_VOICE_DATA_CONT); | |
80 put_le24(pb, pkt->size); | |
81 } | |
82 | |
83 put_buffer(pb, pkt->data, pkt->size); | |
84 return 0; | |
85 } | |
86 | |
87 static int voc_write_trailer(AVFormatContext *s) | |
88 { | |
89 put_byte(&s->pb, 0); | |
90 return 0; | |
91 } | |
92 | |
1169 | 93 AVOutputFormat voc_muxer = { |
937 | 94 "voc", |
95 "Creative Voice File format", | |
96 "audio/x-voc", | |
97 "voc", | |
98 sizeof(voc_enc_context_t), | |
99 CODEC_ID_PCM_U8, | |
100 CODEC_ID_NONE, | |
101 voc_write_header, | |
102 voc_write_packet, | |
103 voc_write_trailer, | |
104 }; |