pcm: support 24-bit/32-bit little-endian planar
[libav.git] / libavformat / nut.c
CommitLineData
874abace
MN
1/*
2 * nut
3 * Copyright (c) 2004-2007 Michael Niedermayer
4 *
2912e87a 5 * This file is part of Libav.
874abace 6 *
2912e87a 7 * Libav is free software; you can redistribute it and/or
874abace
MN
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
2912e87a 12 * Libav is distributed in the hope that it will be useful,
874abace
MN
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
2912e87a 18 * License along with Libav; if not, write to the Free Software
874abace
MN
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
0ebcdf5c 22#include "libavutil/mathematics.h"
245976da 23#include "libavutil/tree.h"
874abace 24#include "nut.h"
1bd442c2 25#include "riff.h"
80b39e1c 26#include "internal.h"
874abace 27
1326621c 28const AVCodecTag ff_nut_subtitle_tags[] = {
72e228b2
LB
29 { AV_CODEC_ID_TEXT, MKTAG('U', 'T', 'F', '8') },
30 { AV_CODEC_ID_SSA, MKTAG('S', 'S', 'A', 0) },
31 { AV_CODEC_ID_DVD_SUBTITLE, MKTAG('D', 'V', 'D', 'S') },
32 { AV_CODEC_ID_DVB_SUBTITLE, MKTAG('D', 'V', 'B', 'S') },
33 { AV_CODEC_ID_NONE, 0 }
1326621c
MN
34};
35
d4bff9f1 36const AVCodecTag ff_nut_data_tags[] = {
72e228b2
LB
37 { AV_CODEC_ID_TEXT, MKTAG('U', 'T', 'F', '8') },
38 { AV_CODEC_ID_NONE, 0 }
d4bff9f1
LB
39};
40
2e01def0 41const AVCodecTag ff_nut_video_tags[] = {
72e228b2
LB
42 { AV_CODEC_ID_VP9, MKTAG('V', 'P', '9', '0') },
43 { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 15) },
44 { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 15) },
45 { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 16) },
46 { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 16) },
47 { AV_CODEC_ID_RAWVIDEO, MKTAG(15, 'B', 'G', 'R') },
48 { AV_CODEC_ID_RAWVIDEO, MKTAG(15, 'R', 'G', 'B') },
49 { AV_CODEC_ID_RAWVIDEO, MKTAG(16, 'B', 'G', 'R') },
50 { AV_CODEC_ID_RAWVIDEO, MKTAG(16, 'R', 'G', 'B') },
51 { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 12) },
52 { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 12) },
53 { AV_CODEC_ID_RAWVIDEO, MKTAG(12, 'B', 'G', 'R') },
54 { AV_CODEC_ID_RAWVIDEO, MKTAG(12, 'R', 'G', 'B') },
55 { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 'A') },
56 { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 'A') },
57 { AV_CODEC_ID_RAWVIDEO, MKTAG('A', 'B', 'G', 'R') },
58 { AV_CODEC_ID_RAWVIDEO, MKTAG('A', 'R', 'G', 'B') },
59 { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 24) },
60 { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 24) },
61 { AV_CODEC_ID_RAWVIDEO, MKTAG('4', '1', '1', 'P') },
62 { AV_CODEC_ID_RAWVIDEO, MKTAG('4', '2', '2', 'P') },
63 { AV_CODEC_ID_RAWVIDEO, MKTAG('4', '2', '2', 'P') },
64 { AV_CODEC_ID_RAWVIDEO, MKTAG('4', '4', '0', 'P') },
65 { AV_CODEC_ID_RAWVIDEO, MKTAG('4', '4', '0', 'P') },
66 { AV_CODEC_ID_RAWVIDEO, MKTAG('4', '4', '4', 'P') },
67 { AV_CODEC_ID_RAWVIDEO, MKTAG('4', '4', '4', 'P') },
68 { AV_CODEC_ID_RAWVIDEO, MKTAG('B', '1', 'W', '0') },
69 { AV_CODEC_ID_RAWVIDEO, MKTAG('B', '0', 'W', '1') },
70 { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 8) },
71 { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 8) },
72 { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 4) },
73 { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 4) },
74 { AV_CODEC_ID_RAWVIDEO, MKTAG('B', '4', 'B', 'Y') },
75 { AV_CODEC_ID_RAWVIDEO, MKTAG('R', '4', 'B', 'Y') },
76 { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 48) },
77 { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 48) },
78 { AV_CODEC_ID_RAWVIDEO, MKTAG(48, 'B', 'G', 'R') },
79 { AV_CODEC_ID_RAWVIDEO, MKTAG(48, 'R', 'G', 'B') },
80 { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 11, 10) },
81 { AV_CODEC_ID_RAWVIDEO, MKTAG(10, 11, '3', 'Y') },
82 { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 10, 10) },
83 { AV_CODEC_ID_RAWVIDEO, MKTAG(10, 10, '3', 'Y') },
84 { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 0, 10) },
85 { AV_CODEC_ID_RAWVIDEO, MKTAG(10, 0, '3', 'Y') },
86 { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '1', 0, 16) },
87 { AV_CODEC_ID_RAWVIDEO, MKTAG(16, 0, '1', 'Y') },
88 { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 11, 16) },
89 { AV_CODEC_ID_RAWVIDEO, MKTAG(16, 11, '3', 'Y') },
90 { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 10, 16) },
91 { AV_CODEC_ID_RAWVIDEO, MKTAG(16, 10, '3', 'Y') },
92 { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 0, 16) },
93 { AV_CODEC_ID_RAWVIDEO, MKTAG(16, 0, '3', 'Y') },
94 { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '4', 11, 8) },
95 { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '2', 0, 8) },
96
97 { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '1', 0, 9) },
98 { AV_CODEC_ID_RAWVIDEO, MKTAG(9, 0, '1', 'Y') },
99 { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '4', 11, 9) },
100 { AV_CODEC_ID_RAWVIDEO, MKTAG(9, 11, '4', 'Y') },
101 { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '4', 10, 9) },
102 { AV_CODEC_ID_RAWVIDEO, MKTAG(9, 10, '4', 'Y') },
103 { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '4', 0, 9) },
104 { AV_CODEC_ID_RAWVIDEO, MKTAG(9, 0, '4', 'Y') },
105
106 { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '1', 0, 10) },
107 { AV_CODEC_ID_RAWVIDEO, MKTAG(10, 0, '1', 'Y') },
108 { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '4', 11, 10) },
109 { AV_CODEC_ID_RAWVIDEO, MKTAG(10, 11, '4', 'Y') },
110 { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '4', 10, 10) },
111 { AV_CODEC_ID_RAWVIDEO, MKTAG(10, 10, '4', 'Y') },
112 { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '4', 0, 10) },
113 { AV_CODEC_ID_RAWVIDEO, MKTAG(10, 0, '4', 'Y') },
114
115 { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '1', 0, 16) },
116 { AV_CODEC_ID_RAWVIDEO, MKTAG(16, 0, '1', 'Y') },
117 { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '4', 11, 16) },
118 { AV_CODEC_ID_RAWVIDEO, MKTAG(16, 11, '4', 'Y') },
119 { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '4', 10, 16) },
120 { AV_CODEC_ID_RAWVIDEO, MKTAG(16, 10, '4', 'Y') },
121 { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '4', 0, 16) },
122 { AV_CODEC_ID_RAWVIDEO, MKTAG(16, 0, '4', 'Y') },
123
124 { AV_CODEC_ID_NONE, 0 }
2e01def0
SS
125};
126
92281850
LB
127const AVCodecTag ff_nut_audio_tags[] = {
128 { AV_CODEC_ID_PCM_ALAW, MKTAG('A', 'L', 'A', 'W') },
129 { AV_CODEC_ID_PCM_MULAW, MKTAG('U', 'L', 'A', 'W') },
72e228b2
LB
130 { AV_CODEC_ID_PCM_F32BE, MKTAG(32, 'D', 'F', 'P') },
131 { AV_CODEC_ID_PCM_F32LE, MKTAG('P', 'F', 'D', 32) },
132 { AV_CODEC_ID_PCM_F64BE, MKTAG(64, 'D', 'F', 'P') },
133 { AV_CODEC_ID_PCM_F64LE, MKTAG('P', 'F', 'D', 64) },
134 { AV_CODEC_ID_PCM_S16BE, MKTAG(16, 'D', 'S', 'P') },
135 { AV_CODEC_ID_PCM_S16LE, MKTAG('P', 'S', 'D', 16) },
136 { AV_CODEC_ID_PCM_S24BE, MKTAG(24, 'D', 'S', 'P') },
137 { AV_CODEC_ID_PCM_S24LE, MKTAG('P', 'S', 'D', 24) },
138 { AV_CODEC_ID_PCM_S32BE, MKTAG(32, 'D', 'S', 'P') },
139 { AV_CODEC_ID_PCM_S32LE, MKTAG('P', 'S', 'D', 32) },
140 { AV_CODEC_ID_PCM_S8, MKTAG('P', 'S', 'D', 8) },
141 { AV_CODEC_ID_PCM_U16BE, MKTAG(16, 'D', 'U', 'P') },
142 { AV_CODEC_ID_PCM_U16LE, MKTAG('P', 'U', 'D', 16) },
143 { AV_CODEC_ID_PCM_U24BE, MKTAG(24, 'D', 'U', 'P') },
144 { AV_CODEC_ID_PCM_U24LE, MKTAG('P', 'U', 'D', 24) },
145 { AV_CODEC_ID_PCM_U32BE, MKTAG(32, 'D', 'U', 'P') },
146 { AV_CODEC_ID_PCM_U32LE, MKTAG('P', 'U', 'D', 32) },
147 { AV_CODEC_ID_PCM_U8, MKTAG('P', 'U', 'D', 8) },
148 { AV_CODEC_ID_PCM_S16LE_PLANAR, MKTAG('P', 'S', 'P', 16) },
7e52080c
PM
149 { AV_CODEC_ID_PCM_S24LE_PLANAR, MKTAG('P', 'S', 'P', 24) },
150 { AV_CODEC_ID_PCM_S32LE_PLANAR, MKTAG('P', 'S', 'P', 32) },
cdaa1f84 151 { AV_CODEC_ID_MP3, MKTAG('M', 'P', '3', ' ') },
72e228b2 152 { AV_CODEC_ID_NONE, 0 }
92281850
LB
153};
154
1bd442c2 155const AVCodecTag * const ff_nut_codec_tags[] = {
92281850 156 ff_nut_video_tags, ff_nut_audio_tags, ff_nut_subtitle_tags,
d4bff9f1 157 ff_codec_bmp_tags, ff_codec_wav_tags, ff_nut_data_tags, 0
1bd442c2
LB
158};
159
72e228b2
LB
160void ff_nut_reset_ts(NUTContext *nut, AVRational time_base, int64_t val)
161{
874abace 162 int i;
72e228b2
LB
163 for (i = 0; i < nut->avf->nb_streams; i++)
164 nut->stream[i].last_pts =
165 av_rescale_rnd(val,
166 time_base.num * (int64_t)nut->stream[i].time_base->den,
167 time_base.den * (int64_t)nut->stream[i].time_base->num,
168 AV_ROUND_DOWN);
874abace 169}
f13ea4e0 170
72e228b2
LB
171int64_t ff_lsb2full(StreamContext *stream, int64_t lsb)
172{
173 int64_t mask = (1 << stream->msb_pts_shift) - 1;
174 int64_t delta = stream->last_pts - mask / 2;
175 return ((lsb - delta) & mask) + delta;
f13ea4e0
MN
176}
177
72e228b2
LB
178int ff_nut_sp_pos_cmp(const Syncpoint *a, const Syncpoint *b)
179{
47a1ae1b 180 return ((a->pos - b->pos) >> 32) - ((b->pos - a->pos) >> 32);
4a3b5fe1
MN
181}
182
72e228b2
LB
183int ff_nut_sp_pts_cmp(const Syncpoint *a, const Syncpoint *b)
184{
47a1ae1b 185 return ((a->ts - b->ts) >> 32) - ((b->ts - a->ts) >> 32);
4a3b5fe1
MN
186}
187
72e228b2
LB
188void ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts)
189{
190 Syncpoint *sp = av_mallocz(sizeof(Syncpoint));
e002e329 191 struct AVTreeNode *node = av_tree_node_alloc();
4a3b5fe1 192
72e228b2
LB
193 sp->pos = pos;
194 sp->back_ptr = back_ptr;
195 sp->ts = ts;
f990f6e3 196 av_tree_insert(&nut->syncpoints, sp, (void *) ff_nut_sp_pos_cmp, &node);
72e228b2 197 if (node) {
4a3b5fe1 198 av_free(sp);
6e8b982b
MN
199 av_free(node);
200 }
4a3b5fe1 201}
90c2295b 202
59856b98 203static int enu_free(void *opaque, void *elem)
4b83fc0f
VS
204{
205 av_free(elem);
59856b98 206 return 0;
4b83fc0f
VS
207}
208
209void ff_nut_free_sp(NUTContext *nut)
210{
211 av_tree_enumerate(nut->syncpoints, NULL, NULL, enu_free);
212 av_tree_destroy(nut->syncpoints);
213}
214
90c2295b 215const Dispositions ff_nut_dispositions[] = {
72e228b2
LB
216 { "default", AV_DISPOSITION_DEFAULT },
217 { "dub", AV_DISPOSITION_DUB },
218 { "original", AV_DISPOSITION_ORIGINAL },
219 { "comment", AV_DISPOSITION_COMMENT },
220 { "lyrics", AV_DISPOSITION_LYRICS },
221 { "karaoke", AV_DISPOSITION_KARAOKE },
222 { "", 0 }
90c2295b
ES
223};
224
43382b5f
AK
225const AVMetadataConv ff_nut_metadata_conv[] = {
226 { "Author", "artist" },
227 { "X-CreationTime", "date" },
228 { "CreationTime", "date" },
229 { "SourceFilename", "filename" },
230 { "X-Language", "language" },
231 { "X-Disposition", "disposition" },
232 { "X-Replaces", "replaces" },
233 { "X-Depends", "depends" },
234 { "X-Uses", "uses" },
235 { "X-UsesFont", "usesfont" },
236 { 0 },
237};