Mercurial > libavformat.hg
annotate tta.c @ 2001:1a3c9056982a libavformat
allocate 32 extra bytes at the end of the probe buffer and remove most probe buf_size checks
author | michael |
---|---|
date | Sun, 08 Apr 2007 11:34:15 +0000 |
parents | 363dcd1e64e0 |
children | d3c1ef5b9a2f |
rev | line source |
---|---|
948
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
1 /* |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
2 * TTA demuxer |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
3 * Copyright (c) 2006 Alex Beregszaszi |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
4 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1281
diff
changeset
|
5 * This file is part of FFmpeg. |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1281
diff
changeset
|
6 * |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1281
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
948
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
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:
1281
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
948
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
11 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1281
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
948
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
16 * |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
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:
1281
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
1187 | 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
948
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
20 */ |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
21 #include "avformat.h" |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
22 #include "bitstream.h" |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
23 |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
24 typedef struct { |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
25 int totalframes, currentframe; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
26 uint32_t *seektable; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
27 } TTAContext; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
28 |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
29 static int tta_probe(AVProbeData *p) |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
30 { |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
31 const uint8_t *d = p->buf; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
32 if (d[0] == 'T' && d[1] == 'T' && d[2] == 'A' && d[3] == '1') |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
33 return 80; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
34 return 0; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
35 } |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
36 |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
37 static int tta_read_header(AVFormatContext *s, AVFormatParameters *ap) |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
38 { |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
39 TTAContext *c = s->priv_data; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
40 AVStream *st; |
1969 | 41 int i, channels, bps, samplerate, datalen, framelen; |
948
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
42 |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
43 if (get_le32(&s->pb) != ff_get_fourcc("TTA1")) |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
44 return -1; // not tta file |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
45 |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
46 url_fskip(&s->pb, 2); // FIXME: flags |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
47 channels = get_le16(&s->pb); |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
48 bps = get_le16(&s->pb); |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
49 samplerate = get_le32(&s->pb); |
1079 | 50 if(samplerate <= 0 || samplerate > 1000000){ |
51 av_log(s, AV_LOG_ERROR, "nonsense samplerate\n"); | |
52 return -1; | |
53 } | |
54 | |
948
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
55 datalen = get_le32(&s->pb); |
1079 | 56 if(datalen < 0){ |
57 av_log(s, AV_LOG_ERROR, "nonsense datalen\n"); | |
58 return -1; | |
59 } | |
60 | |
948
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
61 url_fskip(&s->pb, 4); // header crc |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
62 |
1968
170e151f1d9e
10^10l to the idiot who designed this format and didnt even realize what number he used
michael
parents:
1358
diff
changeset
|
63 framelen = samplerate*256/245; |
948
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
64 c->totalframes = datalen / framelen + ((datalen % framelen) ? 1 : 0); |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
65 c->currentframe = 0; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
66 |
1079 | 67 if(c->totalframes >= UINT_MAX/sizeof(uint32_t)){ |
68 av_log(s, AV_LOG_ERROR, "totalframes too large\n"); | |
69 return -1; | |
70 } | |
948
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
71 c->seektable = av_mallocz(sizeof(uint32_t)*c->totalframes); |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
72 if (!c->seektable) |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
73 return AVERROR_NOMEM; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
74 |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
75 for (i = 0; i < c->totalframes; i++) |
1971 | 76 c->seektable[i] = get_le32(&s->pb); |
948
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
77 url_fskip(&s->pb, 4); // seektable crc |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
78 |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
79 st = av_new_stream(s, 0); |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
80 // av_set_pts_info(st, 32, 1, 1000); |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
81 if (!st) |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
82 return AVERROR_NOMEM; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
83 st->codec->codec_type = CODEC_TYPE_AUDIO; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
84 st->codec->codec_id = CODEC_ID_TTA; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
85 st->codec->channels = channels; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
86 st->codec->sample_rate = samplerate; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
87 st->codec->bits_per_sample = bps; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
88 |
1969 | 89 st->codec->extradata_size = url_ftell(&s->pb); |
1079 | 90 if(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)st->codec->extradata_size){ |
91 //this check is redundant as get_buffer should fail | |
92 av_log(s, AV_LOG_ERROR, "extradata_size too large\n"); | |
93 return -1; | |
94 } | |
957
99a7f76a8954
10l, allocate bitbuffer with regard to the padding size
alex
parents:
948
diff
changeset
|
95 st->codec->extradata = av_mallocz(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE); |
1969 | 96 url_fseek(&s->pb, 0, SEEK_SET); |
948
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
97 get_buffer(&s->pb, st->codec->extradata, st->codec->extradata_size); |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
98 |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
99 return 0; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
100 } |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
101 |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
102 static int tta_read_packet(AVFormatContext *s, AVPacket *pkt) |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
103 { |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
104 TTAContext *c = s->priv_data; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
105 int ret, size; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
106 |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
107 // FIXME! |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
108 if (c->currentframe > c->totalframes) |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
109 size = 0; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
110 else |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
111 size = c->seektable[c->currentframe]; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
112 |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
113 c->currentframe++; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
114 |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
115 if (av_new_packet(pkt, size) < 0) |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
116 return AVERROR_IO; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
117 |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
118 pkt->pos = url_ftell(&s->pb); |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
119 pkt->stream_index = 0; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
120 ret = get_buffer(&s->pb, pkt->data, size); |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
121 if (ret <= 0) { |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
122 av_free_packet(pkt); |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
123 return AVERROR_IO; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
124 } |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
125 pkt->size = ret; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
126 // av_log(s, AV_LOG_INFO, "TTA packet #%d desired size: %d read size: %d at pos %d\n", |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
127 // c->currentframe, size, ret, pkt->pos); |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
128 return 0; //ret; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
129 } |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
130 |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
131 static int tta_read_close(AVFormatContext *s) |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
132 { |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
133 TTAContext *c = s->priv_data; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
134 if (c->seektable) |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
135 av_free(c->seektable); |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
136 return 0; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
137 } |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
138 |
1167 | 139 AVInputFormat tta_demuxer = { |
948
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
140 "tta", |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
141 "true-audio", |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
142 sizeof(TTAContext), |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
143 tta_probe, |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
144 tta_read_header, |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
145 tta_read_packet, |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
146 tta_read_close, |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
147 .extensions = "tta", |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
148 }; |