Mercurial > libavformat.hg
annotate tta.c @ 5108:44a0fab134a9 libavformat
Replace WORDS_BIGENDIAN with HAVE_BIGENDIAN
author | mru |
---|---|
date | Sun, 26 Jul 2009 12:20:04 +0000 |
parents | 304a0ea063f0 |
children | af08ed2b60b8 |
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 |
2217 | 19 * Foundation, Inc., 51 Franklin Street, 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 */ |
3286 | 21 |
4872 | 22 #include "libavcodec/get_bits.h" |
948
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
23 #include "avformat.h" |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
24 |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
25 typedef struct { |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
26 int totalframes, currentframe; |
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; |
2031
d3c1ef5b9a2f
Change from using a seek table internal to the TTA demuxer to using the standard lavf index.
conrad
parents:
2001
diff
changeset
|
42 uint64_t framepos; |
948
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
43 |
4243 | 44 if (get_le32(s->pb) != AV_RL32("TTA1")) |
948
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
45 return -1; // not tta file |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
46 |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2375
diff
changeset
|
47 url_fskip(s->pb, 2); // FIXME: flags |
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2375
diff
changeset
|
48 channels = get_le16(s->pb); |
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2375
diff
changeset
|
49 bps = get_le16(s->pb); |
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2375
diff
changeset
|
50 samplerate = get_le32(s->pb); |
1079 | 51 if(samplerate <= 0 || samplerate > 1000000){ |
52 av_log(s, AV_LOG_ERROR, "nonsense samplerate\n"); | |
53 return -1; | |
54 } | |
55 | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2375
diff
changeset
|
56 datalen = get_le32(s->pb); |
1079 | 57 if(datalen < 0){ |
58 av_log(s, AV_LOG_ERROR, "nonsense datalen\n"); | |
59 return -1; | |
60 } | |
61 | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2375
diff
changeset
|
62 url_fskip(s->pb, 4); // header crc |
948
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
63 |
1968
170e151f1d9e
10^10l to the idiot who designed this format and didnt even realize what number he used
michael
parents:
1358
diff
changeset
|
64 framelen = samplerate*256/245; |
948
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
65 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
|
66 c->currentframe = 0; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
67 |
1079 | 68 if(c->totalframes >= UINT_MAX/sizeof(uint32_t)){ |
69 av_log(s, AV_LOG_ERROR, "totalframes too large\n"); | |
70 return -1; | |
71 } | |
2031
d3c1ef5b9a2f
Change from using a seek table internal to the TTA demuxer to using the standard lavf index.
conrad
parents:
2001
diff
changeset
|
72 |
d3c1ef5b9a2f
Change from using a seek table internal to the TTA demuxer to using the standard lavf index.
conrad
parents:
2001
diff
changeset
|
73 st = av_new_stream(s, 0); |
d3c1ef5b9a2f
Change from using a seek table internal to the TTA demuxer to using the standard lavf index.
conrad
parents:
2001
diff
changeset
|
74 if (!st) |
2273
7eb456c4ed8a
Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents:
2217
diff
changeset
|
75 return AVERROR(ENOMEM); |
948
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
76 |
2031
d3c1ef5b9a2f
Change from using a seek table internal to the TTA demuxer to using the standard lavf index.
conrad
parents:
2001
diff
changeset
|
77 av_set_pts_info(st, 64, 1, samplerate); |
d3c1ef5b9a2f
Change from using a seek table internal to the TTA demuxer to using the standard lavf index.
conrad
parents:
2001
diff
changeset
|
78 st->start_time = 0; |
d3c1ef5b9a2f
Change from using a seek table internal to the TTA demuxer to using the standard lavf index.
conrad
parents:
2001
diff
changeset
|
79 st->duration = datalen; |
d3c1ef5b9a2f
Change from using a seek table internal to the TTA demuxer to using the standard lavf index.
conrad
parents:
2001
diff
changeset
|
80 |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2375
diff
changeset
|
81 framepos = url_ftell(s->pb) + 4*c->totalframes + 4; |
2031
d3c1ef5b9a2f
Change from using a seek table internal to the TTA demuxer to using the standard lavf index.
conrad
parents:
2001
diff
changeset
|
82 |
d3c1ef5b9a2f
Change from using a seek table internal to the TTA demuxer to using the standard lavf index.
conrad
parents:
2001
diff
changeset
|
83 for (i = 0; i < c->totalframes; i++) { |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2375
diff
changeset
|
84 uint32_t size = get_le32(s->pb); |
2031
d3c1ef5b9a2f
Change from using a seek table internal to the TTA demuxer to using the standard lavf index.
conrad
parents:
2001
diff
changeset
|
85 av_add_index_entry(st, framepos, i*framelen, size, 0, AVINDEX_KEYFRAME); |
d3c1ef5b9a2f
Change from using a seek table internal to the TTA demuxer to using the standard lavf index.
conrad
parents:
2001
diff
changeset
|
86 framepos += size; |
d3c1ef5b9a2f
Change from using a seek table internal to the TTA demuxer to using the standard lavf index.
conrad
parents:
2001
diff
changeset
|
87 } |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2375
diff
changeset
|
88 url_fskip(s->pb, 4); // seektable crc |
948
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
89 |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
90 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
|
91 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
|
92 st->codec->channels = channels; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
93 st->codec->sample_rate = samplerate; |
3908
1d3d17de20ba
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
3424
diff
changeset
|
94 st->codec->bits_per_coded_sample = bps; |
948
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
95 |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2375
diff
changeset
|
96 st->codec->extradata_size = url_ftell(s->pb); |
1079 | 97 if(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)st->codec->extradata_size){ |
98 //this check is redundant as get_buffer should fail | |
99 av_log(s, AV_LOG_ERROR, "extradata_size too large\n"); | |
100 return -1; | |
101 } | |
957
99a7f76a8954
10l, allocate bitbuffer with regard to the padding size
alex
parents:
948
diff
changeset
|
102 st->codec->extradata = av_mallocz(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE); |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2375
diff
changeset
|
103 url_fseek(s->pb, 0, SEEK_SET); |
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2375
diff
changeset
|
104 get_buffer(s->pb, st->codec->extradata, st->codec->extradata_size); |
948
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
105 |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
106 return 0; |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
107 } |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
108 |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
109 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
|
110 { |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
111 TTAContext *c = s->priv_data; |
2031
d3c1ef5b9a2f
Change from using a seek table internal to the TTA demuxer to using the standard lavf index.
conrad
parents:
2001
diff
changeset
|
112 AVStream *st = s->streams[0]; |
2375 | 113 int size, ret; |
948
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 // FIXME! |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
116 if (c->currentframe > c->totalframes) |
2031
d3c1ef5b9a2f
Change from using a seek table internal to the TTA demuxer to using the standard lavf index.
conrad
parents:
2001
diff
changeset
|
117 return -1; |
948
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
118 |
2375 | 119 size = st->index_entries[c->currentframe].size; |
948
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
120 |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2375
diff
changeset
|
121 ret = av_get_packet(s->pb, pkt, size); |
2375 | 122 pkt->dts = st->index_entries[c->currentframe++].timestamp; |
123 return ret; | |
948
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 |
2041 | 126 static int tta_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) |
127 { | |
128 TTAContext *c = s->priv_data; | |
129 AVStream *st = s->streams[stream_index]; | |
130 int index = av_index_search_timestamp(st, timestamp, flags); | |
131 if (index < 0) | |
132 return -1; | |
133 | |
134 c->currentframe = index; | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2375
diff
changeset
|
135 url_fseek(s->pb, st->index_entries[index].pos, SEEK_SET); |
2041 | 136 |
137 return 0; | |
138 } | |
139 | |
1167 | 140 AVInputFormat tta_demuxer = { |
948
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
141 "tta", |
3424
7a0230981402
Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents:
3286
diff
changeset
|
142 NULL_IF_CONFIG_SMALL("True Audio"), |
948
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
143 sizeof(TTAContext), |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
144 tta_probe, |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
145 tta_read_header, |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
146 tta_read_packet, |
2031
d3c1ef5b9a2f
Change from using a seek table internal to the TTA demuxer to using the standard lavf index.
conrad
parents:
2001
diff
changeset
|
147 NULL, |
2041 | 148 tta_read_seek, |
948
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
149 .extensions = "tta", |
1e766711e6c8
tta demuxer, also usable for moving tta audio data into an other container
alex
parents:
diff
changeset
|
150 }; |