Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
... | ... |
@@ -509,7 +509,7 @@ library: |
509 | 509 |
@tab Used on the Nintendo GameCube. |
510 | 510 |
@item Tiertex Limited SEQ @tab @tab X |
511 | 511 |
@tab Tiertex .seq files used in the DOS CD-ROM version of the game Flashback. |
512 |
-@item True Audio @tab @tab X |
|
512 |
+@item True Audio @tab X @tab X |
|
513 | 513 |
@item VAG @tab @tab X |
514 | 514 |
@tab Audio format used in many Sony PS2 games. |
515 | 515 |
@item VC-1 test bitstream @tab X @tab X |
... | ... |
@@ -471,6 +471,7 @@ OBJS-$(CONFIG_TMV_DEMUXER) += tmv.o |
471 | 471 |
OBJS-$(CONFIG_TRUEHD_DEMUXER) += rawdec.o mlpdec.o |
472 | 472 |
OBJS-$(CONFIG_TRUEHD_MUXER) += rawenc.o |
473 | 473 |
OBJS-$(CONFIG_TTA_DEMUXER) += tta.o apetag.o img2.o |
474 |
+OBJS-$(CONFIG_TTA_MUXER) += ttaenc.o apetag.o img2.o |
|
474 | 475 |
OBJS-$(CONFIG_TTY_DEMUXER) += tty.o sauce.o |
475 | 476 |
OBJS-$(CONFIG_TXD_DEMUXER) += txd.o |
476 | 477 |
OBJS-$(CONFIG_UNCODEDFRAMECRC_MUXER) += uncodedframecrcenc.o framehash.o |
... | ... |
@@ -311,7 +311,7 @@ void av_register_all(void) |
311 | 311 |
REGISTER_MUXER (MKVTIMESTAMP_V2, mkvtimestamp_v2); |
312 | 312 |
REGISTER_DEMUXER (TMV, tmv); |
313 | 313 |
REGISTER_MUXDEMUX(TRUEHD, truehd); |
314 |
- REGISTER_DEMUXER (TTA, tta); |
|
314 |
+ REGISTER_MUXDEMUX(TTA, tta); |
|
315 | 315 |
REGISTER_DEMUXER (TXD, txd); |
316 | 316 |
REGISTER_DEMUXER (TTY, tty); |
317 | 317 |
REGISTER_MUXER (UNCODEDFRAMECRC, uncodedframecrc); |
318 | 318 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,149 @@ |
0 |
+/* |
|
1 |
+ * True Audio (TTA) muxer |
|
2 |
+ * Copyright (c) 2016 James Almer |
|
3 |
+ * |
|
4 |
+ * This file is part of FFmpeg. |
|
5 |
+ * |
|
6 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
7 |
+ * modify it under the terms of the GNU Lesser General Public |
|
8 |
+ * License as published by the Free Software Foundation; either |
|
9 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
10 |
+ * |
|
11 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
12 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 |
+ * Lesser General Public License for more details. |
|
15 |
+ * |
|
16 |
+ * You should have received a copy of the GNU Lesser General Public |
|
17 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
18 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
19 |
+ */ |
|
20 |
+ |
|
21 |
+#include "libavutil/crc.h" |
|
22 |
+#include "libavutil/intreadwrite.h" |
|
23 |
+ |
|
24 |
+#include "apetag.h" |
|
25 |
+#include "avformat.h" |
|
26 |
+#include "avio_internal.h" |
|
27 |
+#include "internal.h" |
|
28 |
+ |
|
29 |
+typedef struct TTAMuxContext { |
|
30 |
+ AVIOContext *seek_table; |
|
31 |
+ AVIOContext *data; |
|
32 |
+ uint32_t nb_samples; |
|
33 |
+ int frame_size; |
|
34 |
+ int last_frame; |
|
35 |
+} TTAMuxContext; |
|
36 |
+ |
|
37 |
+static int tta_write_header(AVFormatContext *s) |
|
38 |
+{ |
|
39 |
+ TTAMuxContext *tta = s->priv_data; |
|
40 |
+ AVCodecParameters *par = s->streams[0]->codecpar; |
|
41 |
+ int ret; |
|
42 |
+ |
|
43 |
+ if (s->nb_streams != 1) { |
|
44 |
+ av_log(s, AV_LOG_ERROR, "Only one stream is supported\n"); |
|
45 |
+ return AVERROR(EINVAL); |
|
46 |
+ } |
|
47 |
+ if (par->codec_id != AV_CODEC_ID_TTA) { |
|
48 |
+ av_log(s, AV_LOG_ERROR, "Unsupported codec\n"); |
|
49 |
+ return AVERROR(EINVAL); |
|
50 |
+ } |
|
51 |
+ if (par->extradata && par->extradata_size < 22) { |
|
52 |
+ av_log(s, AV_LOG_ERROR, "Invalid TTA extradata\n"); |
|
53 |
+ return AVERROR_INVALIDDATA; |
|
54 |
+ } |
|
55 |
+ |
|
56 |
+ if ((ret = avio_open_dyn_buf(&tta->seek_table)) < 0) |
|
57 |
+ return ret; |
|
58 |
+ if ((ret = avio_open_dyn_buf(&tta->data)) < 0) { |
|
59 |
+ ffio_free_dyn_buf(&tta->seek_table); |
|
60 |
+ return ret; |
|
61 |
+ } |
|
62 |
+ |
|
63 |
+ /* Ignore most extradata information if present. It can be innacurate |
|
64 |
+ if for example remuxing from Matroska */ |
|
65 |
+ ffio_init_checksum(s->pb, ff_crcEDB88320_update, UINT32_MAX); |
|
66 |
+ ffio_init_checksum(tta->seek_table, ff_crcEDB88320_update, UINT32_MAX); |
|
67 |
+ avio_write(s->pb, "TTA1", 4); |
|
68 |
+ avio_wl16(s->pb, par->extradata ? AV_RL16(par->extradata + 4) : 1); |
|
69 |
+ avio_wl16(s->pb, par->channels); |
|
70 |
+ avio_wl16(s->pb, par->bits_per_raw_sample); |
|
71 |
+ avio_wl32(s->pb, par->sample_rate); |
|
72 |
+ /* Prevent overflow */ |
|
73 |
+ if (par->sample_rate > 0x7FFFFFu) { |
|
74 |
+ av_log(s, AV_LOG_ERROR, "Sample rate too large\n"); |
|
75 |
+ return AVERROR(EINVAL); |
|
76 |
+ } |
|
77 |
+ tta->frame_size = par->sample_rate * 256 / 245; |
|
78 |
+ avpriv_set_pts_info(s->streams[0], 64, 1, par->sample_rate); |
|
79 |
+ |
|
80 |
+ return 0; |
|
81 |
+} |
|
82 |
+ |
|
83 |
+static int tta_write_packet(AVFormatContext *s, AVPacket *pkt) |
|
84 |
+{ |
|
85 |
+ TTAMuxContext *tta = s->priv_data; |
|
86 |
+ |
|
87 |
+ avio_write(tta->data, pkt->data, pkt->size); |
|
88 |
+ avio_wl32(tta->seek_table, pkt->size); |
|
89 |
+ tta->nb_samples += pkt->duration; |
|
90 |
+ |
|
91 |
+ if (tta->frame_size != pkt->duration) { |
|
92 |
+ if (tta->last_frame) { |
|
93 |
+ /* Two frames with a different duration than the default frame |
|
94 |
+ size means the TTA stream comes from a faulty container, and |
|
95 |
+ there's no way the last frame duration will be correct. */ |
|
96 |
+ av_log(s, AV_LOG_ERROR, "Invalid frame durations\n"); |
|
97 |
+ |
|
98 |
+ return AVERROR_INVALIDDATA; |
|
99 |
+ } |
|
100 |
+ /* First frame with a different duration than the default frame size. |
|
101 |
+ Assume it's the last frame in the stream and continue. */ |
|
102 |
+ tta->last_frame++; |
|
103 |
+ } |
|
104 |
+ |
|
105 |
+ return 0; |
|
106 |
+} |
|
107 |
+ |
|
108 |
+static int tta_write_trailer(AVFormatContext *s) |
|
109 |
+{ |
|
110 |
+ TTAMuxContext *tta = s->priv_data; |
|
111 |
+ uint8_t *ptr; |
|
112 |
+ unsigned int crc; |
|
113 |
+ int size; |
|
114 |
+ |
|
115 |
+ avio_wl32(s->pb, tta->nb_samples); |
|
116 |
+ crc = ffio_get_checksum(s->pb) ^ UINT32_MAX; |
|
117 |
+ avio_wl32(s->pb, crc); |
|
118 |
+ |
|
119 |
+ /* Write Seek table */ |
|
120 |
+ crc = ffio_get_checksum(tta->seek_table) ^ UINT32_MAX; |
|
121 |
+ avio_wl32(tta->seek_table, crc); |
|
122 |
+ size = avio_close_dyn_buf(tta->seek_table, &ptr); |
|
123 |
+ avio_write(s->pb, ptr, size); |
|
124 |
+ av_free(ptr); |
|
125 |
+ |
|
126 |
+ /* Write audio data */ |
|
127 |
+ size = avio_close_dyn_buf(tta->data, &ptr); |
|
128 |
+ avio_write(s->pb, ptr, size); |
|
129 |
+ av_free(ptr); |
|
130 |
+ |
|
131 |
+ ff_ape_write_tag(s); |
|
132 |
+ avio_flush(s->pb); |
|
133 |
+ |
|
134 |
+ return 0; |
|
135 |
+} |
|
136 |
+ |
|
137 |
+AVOutputFormat ff_tta_muxer = { |
|
138 |
+ .name = "tta", |
|
139 |
+ .long_name = NULL_IF_CONFIG_SMALL("TTA (True Audio)"), |
|
140 |
+ .mime_type = "audio/x-tta", |
|
141 |
+ .extensions = "tta", |
|
142 |
+ .priv_data_size = sizeof(TTAMuxContext), |
|
143 |
+ .audio_codec = AV_CODEC_ID_TTA, |
|
144 |
+ .video_codec = AV_CODEC_ID_NONE, |
|
145 |
+ .write_header = tta_write_header, |
|
146 |
+ .write_packet = tta_write_packet, |
|
147 |
+ .write_trailer = tta_write_trailer, |
|
148 |
+}; |
... | ... |
@@ -32,7 +32,7 @@ |
32 | 32 |
// Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium) |
33 | 33 |
// Also please add any ticket numbers that you belive might be affected here |
34 | 34 |
#define LIBAVFORMAT_VERSION_MAJOR 57 |
35 |
-#define LIBAVFORMAT_VERSION_MINOR 44 |
|
35 |
+#define LIBAVFORMAT_VERSION_MINOR 45 |
|
36 | 36 |
#define LIBAVFORMAT_VERSION_MICRO 100 |
37 | 37 |
|
38 | 38 |
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ |
... | ... |
@@ -154,8 +154,8 @@ FATE_ACODEC-$(call ENCDEC, WAVPACK, WV) += fate-acodec-wavpack |
154 | 154 |
fate-acodec-wavpack: FMT = wv |
155 | 155 |
fate-acodec-wavpack: CODEC = wavpack -compression_level 1 |
156 | 156 |
|
157 |
-FATE_ACODEC-$(call ENCDEC, TTA, MATROSKA) += fate-acodec-tta |
|
158 |
-fate-acodec-tta: FMT = matroska |
|
157 |
+FATE_ACODEC-$(call ENCDEC, TTA, TTA) += fate-acodec-tta |
|
158 |
+fate-acodec-tta: FMT = tta |
|
159 | 159 |
|
160 | 160 |
FATE_ACODEC += $(FATE_ACODEC-yes) |
161 | 161 |
|
... | ... |
@@ -15,6 +15,7 @@ FATE_LAVF-$(call ENCDEC, GIF, IMAGE2) += gif |
15 | 15 |
FATE_LAVF-$(call ENCDEC2, MPEG2VIDEO, PCM_S16LE, GXF) += gxf |
16 | 16 |
FATE_LAVF-$(call ENCDEC, PCM_S16LE, IRCAM) += ircam |
17 | 17 |
FATE_LAVF-$(call ENCDEC, MJPEG, IMAGE2) += jpg |
18 |
+FATE_LAVF-$(call ENCMUX, TTA, MATROSKA_AUDIO) += mka |
|
18 | 19 |
FATE_LAVF-$(call ENCDEC2, MPEG4, MP2, MATROSKA) += mkv |
19 | 20 |
FATE_LAVF-$(call ENCDEC, ADPCM_YAMAHA, MMF) += mmf |
20 | 21 |
FATE_LAVF-$(call ENCDEC2, MPEG4, PCM_ALAW, MOV) += mov ismv |
... | ... |
@@ -44,6 +45,7 @@ FATE_LAVF-$(call ENCDEC, FLV, SWF) += swf |
44 | 44 |
FATE_LAVF-$(call ENCDEC, TARGA, IMAGE2) += tga |
45 | 45 |
FATE_LAVF-$(call ENCDEC, TIFF, IMAGE2) += tiff |
46 | 46 |
FATE_LAVF-$(call ENCDEC2, MPEG2VIDEO, MP2, MPEGTS) += ts |
47 |
+FATE_LAVF-$(call ENCDEC, TTA, TTA) += tta |
|
47 | 48 |
FATE_LAVF-$(call ENCDEC, PCM_U8, VOC) += voc |
48 | 49 |
FATE_LAVF-$(call ENCDEC, PCM_S16LE, VOC) += voc_s16 |
49 | 50 |
FATE_LAVF-$(call ENCDEC, PCM_S16LE, WAV) += wav |
... | ... |
@@ -145,6 +145,10 @@ if [ -n "$do_nut" ] ; then |
145 | 145 |
do_lavf nut "" "-acodec mp2 -ab 64k -ar 44100 -threads 1" |
146 | 146 |
fi |
147 | 147 |
|
148 |
+if [ -n "$do_mka" ] ; then |
|
149 |
+do_audio_only mka "" "-c:a tta" |
|
150 |
+fi |
|
151 |
+ |
|
148 | 152 |
if [ -n "$do_mkv" ] ; then |
149 | 153 |
do_lavf mkv "" "-acodec mp2 -ab 64k -vcodec mpeg4 \ |
150 | 154 |
-attach ${raw_src%/*}/00.pgm -metadata:s:t mimetype=image/x-portable-greymap -threads 1" |
... | ... |
@@ -350,6 +354,10 @@ if [ -n "$do_sox" ] ; then |
350 | 350 |
do_audio_only sox |
351 | 351 |
fi |
352 | 352 |
|
353 |
+if [ -n "$do_tta" ] ; then |
|
354 |
+do_audio_only tta |
|
355 |
+fi |
|
356 |
+ |
|
353 | 357 |
if [ -n "$do_caf" ] ; then |
354 | 358 |
do_audio_only caf |
355 | 359 |
fi |
... | ... |
@@ -1,4 +1,4 @@ |
1 |
-6c260836d7a32e4bd714453a3546c0d5 *tests/data/fate/acodec-tta.matroska |
|
2 |
-331148 tests/data/fate/acodec-tta.matroska |
|
1 |
+847d065f082ac94825728b5f1af853eb *tests/data/fate/acodec-tta.tta |
|
2 |
+330583 tests/data/fate/acodec-tta.tta |
|
3 | 3 |
95e54b261530a1bcf6de6fe3b21dc5f6 *tests/data/fate/acodec-tta.out.wav |
4 | 4 |
stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 |