Mercurial > libavformat.hg
annotate vocenc.c @ 5749:dfbaca29e6fd libavformat
handle errors reported by av_get_packet() in Bink demuxer
author | pross |
---|---|
date | Thu, 04 Mar 2010 13:27:53 +0000 |
parents | 3d6e7901bf05 |
children | 536e5527c1e0 |
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 |
2217 | 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
937 | 20 */ |
21 | |
22 #include "voc.h" | |
23 | |
24 | |
25 typedef struct voc_enc_context { | |
26 int param_written; | |
4081 | 27 } VocEncContext; |
937 | 28 |
29 static int voc_write_header(AVFormatContext *s) | |
30 { | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2382
diff
changeset
|
31 ByteIOContext *pb = s->pb; |
937 | 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) | |
2382
863ea27be885
Use AVERROR_PATCHWELCOME instead of AVERROR(ENOTSUP)
ramiro
parents:
2277
diff
changeset
|
37 return AVERROR_PATCHWELCOME; |
937 | 38 |
3764 | 39 put_buffer(pb, ff_voc_magic, sizeof(ff_voc_magic) - 1); |
937 | 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 { | |
4081 | 49 VocEncContext *voc = s->priv_data; |
937 | 50 AVCodecContext *enc = s->streams[0]->codec; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2382
diff
changeset
|
51 ByteIOContext *pb = s->pb; |
937 | 52 |
53 if (!voc->param_written) { | |
1694
bbb1abaa43cb
remove now useless codec_tag setting code in voc muxer
aurel
parents:
1679
diff
changeset
|
54 if (enc->codec_tag > 0xFF) { |
937 | 55 put_byte(pb, VOC_TYPE_NEW_VOICE_DATA); |
56 put_le24(pb, pkt->size + 12); | |
57 put_le32(pb, enc->sample_rate); | |
3908
1d3d17de20ba
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
3766
diff
changeset
|
58 put_byte(pb, enc->bits_per_coded_sample); |
937 | 59 put_byte(pb, enc->channels); |
1694
bbb1abaa43cb
remove now useless codec_tag setting code in voc muxer
aurel
parents:
1679
diff
changeset
|
60 put_le16(pb, enc->codec_tag); |
937 | 61 put_le32(pb, 0); |
62 } else { | |
63 if (s->streams[0]->codec->channels > 1) { | |
64 put_byte(pb, VOC_TYPE_EXTENDED); | |
65 put_le24(pb, 4); | |
66 put_le16(pb, 65536-256000000/(enc->sample_rate*enc->channels)); | |
1694
bbb1abaa43cb
remove now useless codec_tag setting code in voc muxer
aurel
parents:
1679
diff
changeset
|
67 put_byte(pb, enc->codec_tag); |
937 | 68 put_byte(pb, enc->channels - 1); |
69 } | |
70 put_byte(pb, VOC_TYPE_VOICE_DATA); | |
71 put_le24(pb, pkt->size + 2); | |
72 put_byte(pb, 256 - 1000000 / enc->sample_rate); | |
1694
bbb1abaa43cb
remove now useless codec_tag setting code in voc muxer
aurel
parents:
1679
diff
changeset
|
73 put_byte(pb, enc->codec_tag); |
937 | 74 } |
75 voc->param_written = 1; | |
76 } else { | |
77 put_byte(pb, VOC_TYPE_VOICE_DATA_CONT); | |
78 put_le24(pb, pkt->size); | |
79 } | |
80 | |
81 put_buffer(pb, pkt->data, pkt->size); | |
82 return 0; | |
83 } | |
84 | |
85 static int voc_write_trailer(AVFormatContext *s) | |
86 { | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2382
diff
changeset
|
87 put_byte(s->pb, 0); |
937 | 88 return 0; |
89 } | |
90 | |
1169 | 91 AVOutputFormat voc_muxer = { |
937 | 92 "voc", |
3424
7a0230981402
Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents:
2771
diff
changeset
|
93 NULL_IF_CONFIG_SMALL("Creative Voice file format"), |
937 | 94 "audio/x-voc", |
95 "voc", | |
4081 | 96 sizeof(VocEncContext), |
937 | 97 CODEC_ID_PCM_U8, |
98 CODEC_ID_NONE, | |
99 voc_write_header, | |
100 voc_write_packet, | |
101 voc_write_trailer, | |
3766
f062deeedb8d
Change codec_tag type from const struct AVCodecTag ** to const struct AVCodecTag * const *
reimar
parents:
3764
diff
changeset
|
102 .codec_tag=(const AVCodecTag* const []){ff_voc_codec_tags, 0}, |
937 | 103 }; |