riff.c
Go to the documentation of this file.
1 /*
2  * RIFF common functions and data
3  * Copyright (c) 2000 Fabrice Bellard
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
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  *
12  * FFmpeg is distributed in the hope that it will be useful,
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
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "libavutil/mathematics.h"
23 #include "libavcodec/avcodec.h"
24 #include "avformat.h"
25 #include "avio_internal.h"
26 #include "riff.h"
27 #include "libavcodec/bytestream.h"
28 #include "libavutil/avassert.h"
29 
30 /* Note: when encoding, the first matching tag is used, so order is
31  important if multiple tags possible for a given codec.
32  Note also that this list is used for more than just riff, other
33  files use it as well.
34 */
36  { AV_CODEC_ID_H264, MKTAG('H', '2', '6', '4') },
37  { AV_CODEC_ID_H264, MKTAG('h', '2', '6', '4') },
38  { AV_CODEC_ID_H264, MKTAG('X', '2', '6', '4') },
39  { AV_CODEC_ID_H264, MKTAG('x', '2', '6', '4') },
40  { AV_CODEC_ID_H264, MKTAG('a', 'v', 'c', '1') },
41  { AV_CODEC_ID_H264, MKTAG('D', 'A', 'V', 'C') },
42  { AV_CODEC_ID_H264, MKTAG('S', 'M', 'V', '2') },
43  { AV_CODEC_ID_H264, MKTAG('V', 'S', 'S', 'H') },
44  { AV_CODEC_ID_H264, MKTAG('Q', '2', '6', '4') }, /* QNAP surveillance system */
45  { AV_CODEC_ID_H264, MKTAG('V', '2', '6', '4') },
46  { AV_CODEC_ID_H263, MKTAG('H', '2', '6', '3') },
47  { AV_CODEC_ID_H263, MKTAG('X', '2', '6', '3') },
48  { AV_CODEC_ID_H263, MKTAG('T', '2', '6', '3') },
49  { AV_CODEC_ID_H263, MKTAG('L', '2', '6', '3') },
50  { AV_CODEC_ID_H263, MKTAG('V', 'X', '1', 'K') },
51  { AV_CODEC_ID_H263, MKTAG('Z', 'y', 'G', 'o') },
52  { AV_CODEC_ID_H263, MKTAG('M', '2', '6', '3') },
53  { AV_CODEC_ID_H263, MKTAG('l', 's', 'v', 'm') },
54  { AV_CODEC_ID_H263P, MKTAG('H', '2', '6', '3') },
55  { AV_CODEC_ID_H263I, MKTAG('I', '2', '6', '3') }, /* intel h263 */
56  { AV_CODEC_ID_H261, MKTAG('H', '2', '6', '1') },
57  { AV_CODEC_ID_H263, MKTAG('U', '2', '6', '3') },
58  { AV_CODEC_ID_MPEG4, MKTAG('F', 'M', 'P', '4') },
59  { AV_CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', 'X') },
60  { AV_CODEC_ID_MPEG4, MKTAG('D', 'X', '5', '0') },
61  { AV_CODEC_ID_MPEG4, MKTAG('X', 'V', 'I', 'D') },
62  { AV_CODEC_ID_MPEG4, MKTAG('M', 'P', '4', 'S') },
63  { AV_CODEC_ID_MPEG4, MKTAG('M', '4', 'S', '2') },
64  { AV_CODEC_ID_MPEG4, MKTAG( 4 , 0 , 0 , 0 ) }, /* some broken avi use this */
65  { AV_CODEC_ID_MPEG4, MKTAG('Z', 'M', 'P', '4') }, /* some broken avi use this */
66  { AV_CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', '1') },
67  { AV_CODEC_ID_MPEG4, MKTAG('B', 'L', 'Z', '0') },
68  { AV_CODEC_ID_MPEG4, MKTAG('m', 'p', '4', 'v') },
69  { AV_CODEC_ID_MPEG4, MKTAG('U', 'M', 'P', '4') },
70  { AV_CODEC_ID_MPEG4, MKTAG('W', 'V', '1', 'F') },
71  { AV_CODEC_ID_MPEG4, MKTAG('S', 'E', 'D', 'G') },
72  { AV_CODEC_ID_MPEG4, MKTAG('R', 'M', 'P', '4') },
73  { AV_CODEC_ID_MPEG4, MKTAG('3', 'I', 'V', '2') },
74  { AV_CODEC_ID_MPEG4, MKTAG('W', 'A', 'W', 'V') }, /* WaWv MPEG-4 Video Codec */
75  { AV_CODEC_ID_MPEG4, MKTAG('F', 'F', 'D', 'S') },
76  { AV_CODEC_ID_MPEG4, MKTAG('F', 'V', 'F', 'W') },
77  { AV_CODEC_ID_MPEG4, MKTAG('D', 'C', 'O', 'D') },
78  { AV_CODEC_ID_MPEG4, MKTAG('M', 'V', 'X', 'M') },
79  { AV_CODEC_ID_MPEG4, MKTAG('P', 'M', '4', 'V') },
80  { AV_CODEC_ID_MPEG4, MKTAG('S', 'M', 'P', '4') },
81  { AV_CODEC_ID_MPEG4, MKTAG('D', 'X', 'G', 'M') },
82  { AV_CODEC_ID_MPEG4, MKTAG('V', 'I', 'D', 'M') },
83  { AV_CODEC_ID_MPEG4, MKTAG('M', '4', 'T', '3') },
84  { AV_CODEC_ID_MPEG4, MKTAG('G', 'E', 'O', 'X') },
85  { AV_CODEC_ID_MPEG4, MKTAG('H', 'D', 'X', '4') }, /* flipped video */
86  { AV_CODEC_ID_MPEG4, MKTAG('D', 'M', 'K', '2') },
87  { AV_CODEC_ID_MPEG4, MKTAG('D', 'I', 'G', 'I') },
88  { AV_CODEC_ID_MPEG4, MKTAG('I', 'N', 'M', 'C') },
89  { AV_CODEC_ID_MPEG4, MKTAG('E', 'P', 'H', 'V') }, /* Ephv MPEG-4 */
90  { AV_CODEC_ID_MPEG4, MKTAG('E', 'M', '4', 'A') },
91  { AV_CODEC_ID_MPEG4, MKTAG('M', '4', 'C', 'C') }, /* Divio MPEG-4 */
92  { AV_CODEC_ID_MPEG4, MKTAG('S', 'N', '4', '0') },
93  { AV_CODEC_ID_MPEG4, MKTAG('V', 'S', 'P', 'X') },
94  { AV_CODEC_ID_MPEG4, MKTAG('U', 'L', 'D', 'X') },
95  { AV_CODEC_ID_MPEG4, MKTAG('G', 'E', 'O', 'V') },
96  { AV_CODEC_ID_MPEG4, MKTAG('S', 'I', 'P', 'P') }, /* Samsung SHR-6040 */
97  { AV_CODEC_ID_MPEG4, MKTAG('S', 'M', '4', 'V') },
98  { AV_CODEC_ID_MPEG4, MKTAG('X', 'V', 'I', 'X') },
99  { AV_CODEC_ID_MPEG4, MKTAG('D', 'r', 'e', 'X') },
100  { AV_CODEC_ID_MPEG4, MKTAG('Q', 'M', 'P', '4') }, /* QNAP Systems */
101  { AV_CODEC_ID_MPEG4, MKTAG('P', 'L', 'V', '1') }, /* Pelco DVR MPEG-4 */
102  { AV_CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', '4', '3') },
103  { AV_CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '3') },
104  { AV_CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', 'G', '3') },
105  { AV_CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '5') },
106  { AV_CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '6') },
107  { AV_CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '4') },
108  { AV_CODEC_ID_MSMPEG4V3, MKTAG('D', 'V', 'X', '3') },
109  { AV_CODEC_ID_MSMPEG4V3, MKTAG('A', 'P', '4', '1') },
110  { AV_CODEC_ID_MSMPEG4V3, MKTAG('C', 'O', 'L', '1') },
111  { AV_CODEC_ID_MSMPEG4V3, MKTAG('C', 'O', 'L', '0') },
112  { AV_CODEC_ID_MSMPEG4V2, MKTAG('M', 'P', '4', '2') },
113  { AV_CODEC_ID_MSMPEG4V2, MKTAG('D', 'I', 'V', '2') },
114  { AV_CODEC_ID_MSMPEG4V1, MKTAG('M', 'P', 'G', '4') },
115  { AV_CODEC_ID_MSMPEG4V1, MKTAG('M', 'P', '4', '1') },
116  { AV_CODEC_ID_WMV1, MKTAG('W', 'M', 'V', '1') },
117  { AV_CODEC_ID_WMV2, MKTAG('W', 'M', 'V', '2') },
118  { AV_CODEC_ID_WMV2, MKTAG('G', 'X', 'V', 'E') },
119  { AV_CODEC_ID_DVVIDEO, MKTAG('d', 'v', 's', 'd') },
120  { AV_CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'h', 'd') },
121  { AV_CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'h', '1') },
122  { AV_CODEC_ID_DVVIDEO, MKTAG('d', 'v', 's', 'l') },
123  { AV_CODEC_ID_DVVIDEO, MKTAG('d', 'v', '2', '5') },
124  { AV_CODEC_ID_DVVIDEO, MKTAG('d', 'v', '5', '0') },
125  { AV_CODEC_ID_DVVIDEO, MKTAG('c', 'd', 'v', 'c') }, /* Canopus DV */
126  { AV_CODEC_ID_DVVIDEO, MKTAG('C', 'D', 'V', 'H') }, /* Canopus DV */
127  { AV_CODEC_ID_DVVIDEO, MKTAG('C', 'D', 'V', '5') }, /* Canopus DV */
128  { AV_CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', ' ') },
129  { AV_CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', 's') },
130  { AV_CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'h', '1') },
131  { AV_CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'i', 's') },
132  { AV_CODEC_ID_DVVIDEO, MKTAG('p', 'd', 'v', 'c') },
133  { AV_CODEC_ID_DVVIDEO, MKTAG('S', 'L', '2', '5') },
134  { AV_CODEC_ID_DVVIDEO, MKTAG('S', 'L', 'D', 'V') },
135  { AV_CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'g', '1') },
136  { AV_CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'g', '2') },
137  { AV_CODEC_ID_MPEG2VIDEO, MKTAG('m', 'p', 'g', '2') },
138  { AV_CODEC_ID_MPEG2VIDEO, MKTAG('M', 'P', 'E', 'G') },
139  { AV_CODEC_ID_MPEG1VIDEO, MKTAG('P', 'I', 'M', '1') },
140  { AV_CODEC_ID_MPEG2VIDEO, MKTAG('P', 'I', 'M', '2') },
141  { AV_CODEC_ID_MPEG1VIDEO, MKTAG('V', 'C', 'R', '2') },
142  { AV_CODEC_ID_MPEG1VIDEO, MKTAG( 1 , 0 , 0 , 16) },
143  { AV_CODEC_ID_MPEG2VIDEO, MKTAG( 2 , 0 , 0 , 16) },
144  { AV_CODEC_ID_MPEG4, MKTAG( 4 , 0 , 0 , 16) },
145  { AV_CODEC_ID_MPEG2VIDEO, MKTAG('D', 'V', 'R', ' ') },
146  { AV_CODEC_ID_MPEG2VIDEO, MKTAG('M', 'M', 'E', 'S') },
147  { AV_CODEC_ID_MPEG2VIDEO, MKTAG('L', 'M', 'P', '2') }, /* Lead MPEG2 in avi */
148  { AV_CODEC_ID_MPEG2VIDEO, MKTAG('s', 'l', 'i', 'f') },
149  { AV_CODEC_ID_MPEG2VIDEO, MKTAG('E', 'M', '2', 'V') },
150  { AV_CODEC_ID_MPEG2VIDEO, MKTAG('M', '7', '0', '1') }, /* Matrox MPEG2 intra-only */
151  { AV_CODEC_ID_MPEG2VIDEO, MKTAG('m', 'p', 'g', 'v') },
152  { AV_CODEC_ID_MPEG1VIDEO, MKTAG('B', 'W', '1', '0') },
153  { AV_CODEC_ID_MPEG1VIDEO, MKTAG('X', 'M', 'P', 'G') }, /* Xing MPEG intra only */
154  { AV_CODEC_ID_MJPEG, MKTAG('M', 'J', 'P', 'G') },
155  { AV_CODEC_ID_MJPEG, MKTAG('L', 'J', 'P', 'G') },
156  { AV_CODEC_ID_MJPEG, MKTAG('d', 'm', 'b', '1') },
157  { AV_CODEC_ID_MJPEG, MKTAG('m', 'j', 'p', 'a') },
158  { AV_CODEC_ID_LJPEG, MKTAG('L', 'J', 'P', 'G') },
159  { AV_CODEC_ID_MJPEG, MKTAG('J', 'P', 'G', 'L') }, /* Pegasus lossless JPEG */
160  { AV_CODEC_ID_JPEGLS, MKTAG('M', 'J', 'L', 'S') }, /* JPEG-LS custom FOURCC for avi - encoder */
161  { AV_CODEC_ID_JPEGLS, MKTAG('M', 'J', 'P', 'G') },
162  { AV_CODEC_ID_MJPEG, MKTAG('M', 'J', 'L', 'S') }, /* JPEG-LS custom FOURCC for avi - decoder */
163  { AV_CODEC_ID_MJPEG, MKTAG('j', 'p', 'e', 'g') },
164  { AV_CODEC_ID_MJPEG, MKTAG('I', 'J', 'P', 'G') },
165  { AV_CODEC_ID_AVRN, MKTAG('A', 'V', 'R', 'n') },
166  { AV_CODEC_ID_MJPEG, MKTAG('A', 'C', 'D', 'V') },
167  { AV_CODEC_ID_MJPEG, MKTAG('Q', 'I', 'V', 'G') },
168  { AV_CODEC_ID_MJPEG, MKTAG('S', 'L', 'M', 'J') }, /* SL M-JPEG */
169  { AV_CODEC_ID_MJPEG, MKTAG('C', 'J', 'P', 'G') }, /* Creative Webcam JPEG */
170  { AV_CODEC_ID_MJPEG, MKTAG('I', 'J', 'L', 'V') }, /* Intel JPEG Library Video Codec */
171  { AV_CODEC_ID_MJPEG, MKTAG('M', 'V', 'J', 'P') }, /* Midvid JPEG Video Codec */
172  { AV_CODEC_ID_MJPEG, MKTAG('A', 'V', 'I', '1') },
173  { AV_CODEC_ID_MJPEG, MKTAG('A', 'V', 'I', '2') },
174  { AV_CODEC_ID_MJPEG, MKTAG('M', 'T', 'S', 'J') },
175  { AV_CODEC_ID_MJPEG, MKTAG('Z', 'J', 'P', 'G') }, /* Paradigm Matrix M-JPEG Codec */
176  { AV_CODEC_ID_MJPEG, MKTAG('M', 'M', 'J', 'P') },
177  { AV_CODEC_ID_HUFFYUV, MKTAG('H', 'F', 'Y', 'U') },
178  { AV_CODEC_ID_FFVHUFF, MKTAG('F', 'F', 'V', 'H') },
179  { AV_CODEC_ID_CYUV, MKTAG('C', 'Y', 'U', 'V') },
180  { AV_CODEC_ID_RAWVIDEO, MKTAG( 0 , 0 , 0 , 0 ) },
181  { AV_CODEC_ID_RAWVIDEO, MKTAG( 3 , 0 , 0 , 0 ) },
182  { AV_CODEC_ID_RAWVIDEO, MKTAG('I', '4', '2', '0') },
183  { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', 'U', 'Y', '2') },
184  { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '4', '2', '2') },
185  { AV_CODEC_ID_RAWVIDEO, MKTAG('V', '4', '2', '2') },
186  { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', 'U', 'N', 'V') },
187  { AV_CODEC_ID_RAWVIDEO, MKTAG('U', 'Y', 'N', 'V') },
188  { AV_CODEC_ID_RAWVIDEO, MKTAG('U', 'Y', 'N', 'Y') },
189  { AV_CODEC_ID_RAWVIDEO, MKTAG('u', 'y', 'v', '1') },
190  { AV_CODEC_ID_RAWVIDEO, MKTAG('2', 'V', 'u', '1') },
191  { AV_CODEC_ID_RAWVIDEO, MKTAG('2', 'v', 'u', 'y') },
192  { AV_CODEC_ID_RAWVIDEO, MKTAG('y', 'u', 'v', 's') },
193  { AV_CODEC_ID_RAWVIDEO, MKTAG('y', 'u', 'v', '2') },
194  { AV_CODEC_ID_RAWVIDEO, MKTAG('P', '4', '2', '2') },
195  { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', '1', '2') },
196  { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', '1', '6') },
197  { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', '2', '4') },
198  { AV_CODEC_ID_RAWVIDEO, MKTAG('U', 'Y', 'V', 'Y') },
199  { AV_CODEC_ID_RAWVIDEO, MKTAG('V', 'Y', 'U', 'Y') },
200  { AV_CODEC_ID_RAWVIDEO, MKTAG('I', 'Y', 'U', 'V') },
201  { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '8', '0', '0') },
202  { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '8', ' ', ' ') },
203  { AV_CODEC_ID_RAWVIDEO, MKTAG('H', 'D', 'Y', 'C') },
204  { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', 'U', '9') },
205  { AV_CODEC_ID_RAWVIDEO, MKTAG('V', 'D', 'T', 'Z') }, /* SoftLab-NSK VideoTizer */
206  { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '4', '1', '1') },
207  { AV_CODEC_ID_RAWVIDEO, MKTAG('N', 'V', '1', '2') },
208  { AV_CODEC_ID_RAWVIDEO, MKTAG('N', 'V', '2', '1') },
209  { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '4', '1', 'B') },
210  { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '4', '2', 'B') },
211  { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', 'U', 'V', '9') },
212  { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', 'U', '9') },
213  { AV_CODEC_ID_RAWVIDEO, MKTAG('a', 'u', 'v', '2') },
214  { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', 'Y', 'U') },
215  { AV_CODEC_ID_FRWU, MKTAG('F', 'R', 'W', 'U') },
216  { AV_CODEC_ID_R10K, MKTAG('R', '1', '0', 'k') },
217  { AV_CODEC_ID_R210, MKTAG('r', '2', '1', '0') },
218  { AV_CODEC_ID_V210, MKTAG('v', '2', '1', '0') },
219  { AV_CODEC_ID_V308, MKTAG('v', '3', '0', '8') },
220  { AV_CODEC_ID_V408, MKTAG('v', '4', '0', '8') },
221  { AV_CODEC_ID_AYUV, MKTAG('A', 'Y', 'U', 'V') },
222  { AV_CODEC_ID_V410, MKTAG('v', '4', '1', '0') },
223  { AV_CODEC_ID_YUV4, MKTAG('y', 'u', 'v', '4') },
224  { AV_CODEC_ID_INDEO3, MKTAG('I', 'V', '3', '1') },
225  { AV_CODEC_ID_INDEO3, MKTAG('I', 'V', '3', '2') },
226  { AV_CODEC_ID_INDEO4, MKTAG('I', 'V', '4', '1') },
227  { AV_CODEC_ID_INDEO5, MKTAG('I', 'V', '5', '0') },
228  { AV_CODEC_ID_VP3, MKTAG('V', 'P', '3', '1') },
229  { AV_CODEC_ID_VP3, MKTAG('V', 'P', '3', '0') },
230  { AV_CODEC_ID_VP5, MKTAG('V', 'P', '5', '0') },
231  { AV_CODEC_ID_VP6, MKTAG('V', 'P', '6', '0') },
232  { AV_CODEC_ID_VP6, MKTAG('V', 'P', '6', '1') },
233  { AV_CODEC_ID_VP6, MKTAG('V', 'P', '6', '2') },
234  { AV_CODEC_ID_VP6F, MKTAG('V', 'P', '6', 'F') },
235  { AV_CODEC_ID_VP6F, MKTAG('F', 'L', 'V', '4') },
236  { AV_CODEC_ID_VP8, MKTAG('V', 'P', '8', '0') },
237  { AV_CODEC_ID_ASV1, MKTAG('A', 'S', 'V', '1') },
238  { AV_CODEC_ID_ASV2, MKTAG('A', 'S', 'V', '2') },
239  { AV_CODEC_ID_VCR1, MKTAG('V', 'C', 'R', '1') },
240  { AV_CODEC_ID_FFV1, MKTAG('F', 'F', 'V', '1') },
241  { AV_CODEC_ID_XAN_WC4, MKTAG('X', 'x', 'a', 'n') },
242  { AV_CODEC_ID_MIMIC, MKTAG('L', 'M', '2', '0') },
243  { AV_CODEC_ID_MSRLE, MKTAG('m', 'r', 'l', 'e') },
244  { AV_CODEC_ID_MSRLE, MKTAG( 1 , 0 , 0 , 0 ) },
245  { AV_CODEC_ID_MSRLE, MKTAG( 2 , 0 , 0 , 0 ) },
246  { AV_CODEC_ID_MSVIDEO1, MKTAG('M', 'S', 'V', 'C') },
247  { AV_CODEC_ID_MSVIDEO1, MKTAG('m', 's', 'v', 'c') },
248  { AV_CODEC_ID_MSVIDEO1, MKTAG('C', 'R', 'A', 'M') },
249  { AV_CODEC_ID_MSVIDEO1, MKTAG('c', 'r', 'a', 'm') },
250  { AV_CODEC_ID_MSVIDEO1, MKTAG('W', 'H', 'A', 'M') },
251  { AV_CODEC_ID_MSVIDEO1, MKTAG('w', 'h', 'a', 'm') },
252  { AV_CODEC_ID_CINEPAK, MKTAG('c', 'v', 'i', 'd') },
253  { AV_CODEC_ID_TRUEMOTION1, MKTAG('D', 'U', 'C', 'K') },
254  { AV_CODEC_ID_TRUEMOTION1, MKTAG('P', 'V', 'E', 'Z') },
255  { AV_CODEC_ID_MSZH, MKTAG('M', 'S', 'Z', 'H') },
256  { AV_CODEC_ID_ZLIB, MKTAG('Z', 'L', 'I', 'B') },
257  { AV_CODEC_ID_SNOW, MKTAG('S', 'N', 'O', 'W') },
258  { AV_CODEC_ID_4XM, MKTAG('4', 'X', 'M', 'V') },
259  { AV_CODEC_ID_FLV1, MKTAG('F', 'L', 'V', '1') },
260  { AV_CODEC_ID_FLV1, MKTAG('S', '2', '6', '3') },
261  { AV_CODEC_ID_FLASHSV, MKTAG('F', 'S', 'V', '1') },
262  { AV_CODEC_ID_SVQ1, MKTAG('s', 'v', 'q', '1') },
263  { AV_CODEC_ID_TSCC, MKTAG('t', 's', 'c', 'c') },
264  { AV_CODEC_ID_ULTI, MKTAG('U', 'L', 'T', 'I') },
265  { AV_CODEC_ID_VIXL, MKTAG('V', 'I', 'X', 'L') },
266  { AV_CODEC_ID_QPEG, MKTAG('Q', 'P', 'E', 'G') },
267  { AV_CODEC_ID_QPEG, MKTAG('Q', '1', '.', '0') },
268  { AV_CODEC_ID_QPEG, MKTAG('Q', '1', '.', '1') },
269  { AV_CODEC_ID_WMV3, MKTAG('W', 'M', 'V', '3') },
270  { AV_CODEC_ID_WMV3IMAGE, MKTAG('W', 'M', 'V', 'P') },
271  { AV_CODEC_ID_VC1, MKTAG('W', 'V', 'C', '1') },
272  { AV_CODEC_ID_VC1, MKTAG('W', 'M', 'V', 'A') },
273  { AV_CODEC_ID_VC1IMAGE, MKTAG('W', 'V', 'P', '2') },
274  { AV_CODEC_ID_LOCO, MKTAG('L', 'O', 'C', 'O') },
275  { AV_CODEC_ID_WNV1, MKTAG('W', 'N', 'V', '1') },
276  { AV_CODEC_ID_WNV1, MKTAG('Y', 'U', 'V', '8') },
277  { AV_CODEC_ID_AASC, MKTAG('A', 'A', 'S', '4') },
278  { AV_CODEC_ID_AASC, MKTAG('A', 'A', 'S', 'C') },
279  { AV_CODEC_ID_INDEO2, MKTAG('R', 'T', '2', '1') },
280  { AV_CODEC_ID_FRAPS, MKTAG('F', 'P', 'S', '1') },
281  { AV_CODEC_ID_THEORA, MKTAG('t', 'h', 'e', 'o') },
282  { AV_CODEC_ID_TRUEMOTION2, MKTAG('T', 'M', '2', '0') },
283  { AV_CODEC_ID_CSCD, MKTAG('C', 'S', 'C', 'D') },
284  { AV_CODEC_ID_ZMBV, MKTAG('Z', 'M', 'B', 'V') },
285  { AV_CODEC_ID_KMVC, MKTAG('K', 'M', 'V', 'C') },
286  { AV_CODEC_ID_CAVS, MKTAG('C', 'A', 'V', 'S') },
287  { AV_CODEC_ID_JPEG2000, MKTAG('m', 'j', 'p', '2') },
288  { AV_CODEC_ID_JPEG2000, MKTAG('M', 'J', '2', 'C') },
289  { AV_CODEC_ID_JPEG2000, MKTAG('L', 'J', '2', 'C') },
290  { AV_CODEC_ID_JPEG2000, MKTAG('L', 'J', '2', 'K') },
291  { AV_CODEC_ID_JPEG2000, MKTAG('I', 'P', 'J', '2') },
292  { AV_CODEC_ID_VMNC, MKTAG('V', 'M', 'n', 'c') },
293  { AV_CODEC_ID_TARGA, MKTAG('t', 'g', 'a', ' ') },
294  { AV_CODEC_ID_PNG, MKTAG('M', 'P', 'N', 'G') },
295  { AV_CODEC_ID_PNG, MKTAG('P', 'N', 'G', '1') },
296  { AV_CODEC_ID_CLJR, MKTAG('C', 'L', 'J', 'R') },
297  { AV_CODEC_ID_DIRAC, MKTAG('d', 'r', 'a', 'c') },
298  { AV_CODEC_ID_RPZA, MKTAG('a', 'z', 'p', 'r') },
299  { AV_CODEC_ID_RPZA, MKTAG('R', 'P', 'Z', 'A') },
300  { AV_CODEC_ID_RPZA, MKTAG('r', 'p', 'z', 'a') },
301  { AV_CODEC_ID_SP5X, MKTAG('S', 'P', '5', '4') },
302  { AV_CODEC_ID_AURA, MKTAG('A', 'U', 'R', 'A') },
303  { AV_CODEC_ID_AURA2, MKTAG('A', 'U', 'R', '2') },
304  { AV_CODEC_ID_DPX, MKTAG('d', 'p', 'x', ' ') },
305  { AV_CODEC_ID_KGV1, MKTAG('K', 'G', 'V', '1') },
306  { AV_CODEC_ID_LAGARITH, MKTAG('L', 'A', 'G', 'S') },
307  { AV_CODEC_ID_G2M, MKTAG('G', '2', 'M', '2') },
308  { AV_CODEC_ID_G2M, MKTAG('G', '2', 'M', '3') },
309  { AV_CODEC_ID_G2M, MKTAG('G', '2', 'M', '4') },
310  { AV_CODEC_ID_AMV, MKTAG('A', 'M', 'V', 'F') },
311  { AV_CODEC_ID_UTVIDEO, MKTAG('U', 'L', 'R', 'A') },
312  { AV_CODEC_ID_UTVIDEO, MKTAG('U', 'L', 'R', 'G') },
313  { AV_CODEC_ID_UTVIDEO, MKTAG('U', 'L', 'Y', '0') },
314  { AV_CODEC_ID_UTVIDEO, MKTAG('U', 'L', 'Y', '2') },
315  { AV_CODEC_ID_VBLE, MKTAG('V', 'B', 'L', 'E') },
316  { AV_CODEC_ID_ESCAPE130, MKTAG('E', '1', '3', '0') },
317  { AV_CODEC_ID_DXTORY, MKTAG('x', 't', 'o', 'r') },
318  { AV_CODEC_ID_ZEROCODEC, MKTAG('Z', 'E', 'C', 'O') },
319  { AV_CODEC_ID_Y41P, MKTAG('Y', '4', '1', 'P') },
320  { AV_CODEC_ID_FLIC, MKTAG('A', 'F', 'L', 'C') },
321  { AV_CODEC_ID_EXR, MKTAG('e', 'x', 'r', ' ') },
322  { AV_CODEC_ID_MSS1, MKTAG('M', 'S', 'S', '1') },
323  { AV_CODEC_ID_MSA1, MKTAG('M', 'S', 'A', '1') },
324  { AV_CODEC_ID_TSCC2, MKTAG('T', 'S', 'C', '2') },
325  { AV_CODEC_ID_MTS2, MKTAG('M', 'T', 'S', '2') },
326  { AV_CODEC_ID_CLLC, MKTAG('C', 'L', 'L', 'C') },
327  { AV_CODEC_ID_MSS2, MKTAG('M', 'S', 'S', '2') },
328  { AV_CODEC_ID_SVQ3, MKTAG('S', 'V', 'Q', '3') },
329  { AV_CODEC_ID_012V, MKTAG('0', '1', '2', 'v') },
330  { AV_CODEC_ID_012V, MKTAG('a', '1', '2', 'v') },
331  { AV_CODEC_ID_NONE, 0 }
332 };
333 
335  { AV_CODEC_ID_PCM_S16LE, 0x0001 },
336  { AV_CODEC_ID_PCM_U8, 0x0001 }, /* must come after s16le in this list */
337  { AV_CODEC_ID_PCM_S24LE, 0x0001 },
338  { AV_CODEC_ID_PCM_S32LE, 0x0001 },
339  { AV_CODEC_ID_ADPCM_MS, 0x0002 },
340  { AV_CODEC_ID_PCM_F32LE, 0x0003 },
341  { AV_CODEC_ID_PCM_F64LE, 0x0003 }, /* must come after f32le in this list */
342  { AV_CODEC_ID_PCM_ALAW, 0x0006 },
343  { AV_CODEC_ID_PCM_MULAW, 0x0007 },
344  { AV_CODEC_ID_WMAVOICE, 0x000A },
345  { AV_CODEC_ID_ADPCM_IMA_OKI, 0x0010 },
346  { AV_CODEC_ID_ADPCM_IMA_WAV, 0x0011 },
347  { AV_CODEC_ID_PCM_ZORK, 0x0011 }, /* must come after adpcm_ima_wav in this list */
348  { AV_CODEC_ID_ADPCM_IMA_OKI, 0x0017 },
349  { AV_CODEC_ID_ADPCM_YAMAHA, 0x0020 },
350  { AV_CODEC_ID_TRUESPEECH, 0x0022 },
351  { AV_CODEC_ID_GSM_MS, 0x0031 },
352  { AV_CODEC_ID_AMR_NB, 0x0038 }, /* rogue format number */
353  { AV_CODEC_ID_G723_1, 0x0042 },
354  { AV_CODEC_ID_ADPCM_G726, 0x0045 },
355  { AV_CODEC_ID_MP2, 0x0050 },
356  { AV_CODEC_ID_MP3, 0x0055 },
357  { AV_CODEC_ID_AMR_NB, 0x0057 },
358  { AV_CODEC_ID_AMR_WB, 0x0058 },
359  { AV_CODEC_ID_ADPCM_IMA_DK4, 0x0061 }, /* rogue format number */
360  { AV_CODEC_ID_ADPCM_IMA_DK3, 0x0062 }, /* rogue format number */
361  { AV_CODEC_ID_ADPCM_IMA_WAV, 0x0069 },
362  { AV_CODEC_ID_VOXWARE, 0x0075 },
363  { AV_CODEC_ID_AAC, 0x00ff },
364  { AV_CODEC_ID_SIPR, 0x0130 },
365  { AV_CODEC_ID_WMAV1, 0x0160 },
366  { AV_CODEC_ID_WMAV2, 0x0161 },
367  { AV_CODEC_ID_WMAPRO, 0x0162 },
368  { AV_CODEC_ID_WMALOSSLESS, 0x0163 },
369  { AV_CODEC_ID_ADPCM_CT, 0x0200 },
370  { AV_CODEC_ID_ATRAC3, 0x0270 },
371  { AV_CODEC_ID_ADPCM_G722, 0x028F },
372  { AV_CODEC_ID_IMC, 0x0401 },
373  { AV_CODEC_ID_IAC, 0x0402 },
374  { AV_CODEC_ID_GSM_MS, 0x1500 },
375  { AV_CODEC_ID_TRUESPEECH, 0x1501 },
376  { AV_CODEC_ID_AAC, 0x1600 }, /* ADTS AAC */
377  { AV_CODEC_ID_AAC_LATM, 0x1602 },
378  { AV_CODEC_ID_AC3, 0x2000 },
379  { AV_CODEC_ID_DTS, 0x2001 },
380  { AV_CODEC_ID_SONIC, 0x2048 },
381  { AV_CODEC_ID_SONIC_LS, 0x2048 },
382  { AV_CODEC_ID_PCM_MULAW, 0x6c75 },
383  { AV_CODEC_ID_AAC, 0x706d },
384  { AV_CODEC_ID_AAC, 0x4143 },
385  { AV_CODEC_ID_G723_1, 0xA100 },
386  { AV_CODEC_ID_AAC, 0xA106 },
387  { AV_CODEC_ID_SPEEX, 0xA109 },
388  { AV_CODEC_ID_FLAC, 0xF1AC },
389  { AV_CODEC_ID_ADPCM_SWF, ('S'<<8)+'F' },
390  { AV_CODEC_ID_VORBIS, ('V'<<8)+'o' }, //HACK/FIXME, does vorbis in WAV/AVI have an (in)official id?
391  { AV_CODEC_ID_NONE, 0 },
392 };
393 
395  {AV_CODEC_ID_AC3, {0x2C,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA}},
396  {AV_CODEC_ID_ATRAC3P, {0xBF,0xAA,0x23,0xE9,0x58,0xCB,0x71,0x44,0xA1,0x19,0xFF,0xFA,0x01,0xE4,0xCE,0x62}},
397  {AV_CODEC_ID_EAC3, {0xAF,0x87,0xFB,0xA7,0x02,0x2D,0xFB,0x42,0xA4,0xD4,0x05,0xCD,0x93,0x84,0x3B,0xDD}},
398  {AV_CODEC_ID_MP2, {0x2B,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA}},
400 };
401 
403  { "IART", "artist" },
404  { "ICMT", "comment" },
405  { "ICOP", "copyright" },
406  { "ICRD", "date" },
407  { "IGNR", "genre" },
408  { "ILNG", "language" },
409  { "INAM", "title" },
410  { "IPRD", "album" },
411  { "IPRT", "track" },
412  { "ISFT", "encoder" },
413  { "ISMP", "timecode" },
414  { "ITCH", "encoded_by"},
415  { 0 },
416 };
417 
418 #if CONFIG_MUXERS
419 int64_t ff_start_tag(AVIOContext *pb, const char *tag)
420 {
421  ffio_wfourcc(pb, tag);
422  avio_wl32(pb, 0);
423  return avio_tell(pb);
424 }
425 
426 void ff_end_tag(AVIOContext *pb, int64_t start)
427 {
428  int64_t pos;
429 
430  av_assert0((start&1) == 0);
431 
432  pos = avio_tell(pb);
433  if (pos & 1)
434  avio_w8(pb, 0);
435  avio_seek(pb, start - 4, SEEK_SET);
436  avio_wl32(pb, (uint32_t)(pos - start));
437  avio_seek(pb, FFALIGN(pos, 2), SEEK_SET);
438 }
439 
440 /* WAVEFORMATEX header */
441 /* returns the size or -1 on error */
443 {
444  int bps, blkalign, bytespersec, frame_size;
445  int hdrsize = 18;
446  int waveformatextensible;
447  uint8_t temp[256];
448  uint8_t *riff_extradata= temp;
449  uint8_t *riff_extradata_start= temp;
450 
451  if(!enc->codec_tag || enc->codec_tag > 0xffff)
452  return -1;
453 
454  /* We use the known constant frame size for the codec if known, otherwise
455  fallback to using AVCodecContext.frame_size, which is not as reliable
456  for indicating packet duration */
457  frame_size = av_get_audio_frame_duration(enc, 0);
458  if (!frame_size)
459  frame_size = enc->frame_size;
460 
461  waveformatextensible = (enc->channels > 2 && enc->channel_layout)
462  || enc->sample_rate > 48000
463  || av_get_bits_per_sample(enc->codec_id) > 16;
464 
465  if (waveformatextensible) {
466  avio_wl16(pb, 0xfffe);
467  } else {
468  avio_wl16(pb, enc->codec_tag);
469  }
470  avio_wl16(pb, enc->channels);
471  avio_wl32(pb, enc->sample_rate);
472  if (enc->codec_id == AV_CODEC_ID_ATRAC3 ||
473  enc->codec_id == AV_CODEC_ID_G723_1 ||
474  enc->codec_id == AV_CODEC_ID_GSM_MS ||
475  enc->codec_id == AV_CODEC_ID_MP2 ||
476  enc->codec_id == AV_CODEC_ID_MP3) {
477  bps = 0;
478  } else {
479  if (!(bps = av_get_bits_per_sample(enc->codec_id))) {
480  if (enc->bits_per_coded_sample)
481  bps = enc->bits_per_coded_sample;
482  else
483  bps = 16; // default to 16
484  }
485  }
486  if(bps != enc->bits_per_coded_sample && enc->bits_per_coded_sample){
487  av_log(enc, AV_LOG_WARNING, "requested bits_per_coded_sample (%d) and actually stored (%d) differ\n", enc->bits_per_coded_sample, bps);
488  }
489 
490  if (enc->codec_id == AV_CODEC_ID_MP2 || enc->codec_id == AV_CODEC_ID_MP3) {
491  /* this is wrong, but it seems many demuxers do not work if this is set
492  correctly */
493  blkalign = frame_size;
494  //blkalign = 144 * enc->bit_rate/enc->sample_rate;
495  } else if (enc->codec_id == AV_CODEC_ID_AC3) {
496  blkalign = 3840; //maximum bytes per frame
497  } else if (enc->codec_id == AV_CODEC_ID_AAC) {
498  blkalign = 768 * enc->channels; //maximum bytes per frame
499  } else if (enc->codec_id == AV_CODEC_ID_G723_1) {
500  blkalign = 24;
501  } else if (enc->block_align != 0) { /* specified by the codec */
502  blkalign = enc->block_align;
503  } else
504  blkalign = bps * enc->channels / av_gcd(8, bps);
505  if (enc->codec_id == AV_CODEC_ID_PCM_U8 ||
511  bytespersec = enc->sample_rate * blkalign;
512  } else if (enc->codec_id == AV_CODEC_ID_G723_1) {
513  bytespersec = 800;
514  } else {
515  bytespersec = enc->bit_rate / 8;
516  }
517  avio_wl32(pb, bytespersec); /* bytes per second */
518  avio_wl16(pb, blkalign); /* block align */
519  avio_wl16(pb, bps); /* bits per sample */
520  if (enc->codec_id == AV_CODEC_ID_MP3) {
521  hdrsize += 12;
522  bytestream_put_le16(&riff_extradata, 1); /* wID */
523  bytestream_put_le32(&riff_extradata, 2); /* fdwFlags */
524  bytestream_put_le16(&riff_extradata, 1152); /* nBlockSize */
525  bytestream_put_le16(&riff_extradata, 1); /* nFramesPerBlock */
526  bytestream_put_le16(&riff_extradata, 1393); /* nCodecDelay */
527  } else if (enc->codec_id == AV_CODEC_ID_MP2) {
528  hdrsize += 22;
529  bytestream_put_le16(&riff_extradata, 2); /* fwHeadLayer */
530  bytestream_put_le32(&riff_extradata, enc->bit_rate); /* dwHeadBitrate */
531  bytestream_put_le16(&riff_extradata, enc->channels == 2 ? 1 : 8); /* fwHeadMode */
532  bytestream_put_le16(&riff_extradata, 0); /* fwHeadModeExt */
533  bytestream_put_le16(&riff_extradata, 1); /* wHeadEmphasis */
534  bytestream_put_le16(&riff_extradata, 16); /* fwHeadFlags */
535  bytestream_put_le32(&riff_extradata, 0); /* dwPTSLow */
536  bytestream_put_le32(&riff_extradata, 0); /* dwPTSHigh */
537  } else if (enc->codec_id == AV_CODEC_ID_G723_1) {
538  hdrsize += 20;
539  bytestream_put_le32(&riff_extradata, 0x9ace0002); /* extradata needed for msacm g723.1 codec */
540  bytestream_put_le32(&riff_extradata, 0xaea2f732);
541  bytestream_put_le16(&riff_extradata, 0xacde);
542  } else if (enc->codec_id == AV_CODEC_ID_GSM_MS || enc->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV) {
543  hdrsize += 2;
544  bytestream_put_le16(&riff_extradata, frame_size); /* wSamplesPerBlock */
545  } else if(enc->extradata_size){
546  riff_extradata_start= enc->extradata;
547  riff_extradata= enc->extradata + enc->extradata_size;
548  hdrsize += enc->extradata_size;
549  }
550  if(waveformatextensible) { /* write WAVEFORMATEXTENSIBLE extensions */
551  hdrsize += 22;
552  avio_wl16(pb, riff_extradata - riff_extradata_start + 22); /* 22 is WAVEFORMATEXTENSIBLE size */
553  avio_wl16(pb, bps); /* ValidBitsPerSample || SamplesPerBlock || Reserved */
554  avio_wl32(pb, enc->channel_layout); /* dwChannelMask */
555  avio_wl32(pb, enc->codec_tag); /* GUID + next 3 */
556  avio_wl32(pb, 0x00100000);
557  avio_wl32(pb, 0xAA000080);
558  avio_wl32(pb, 0x719B3800);
559  } else {
560  avio_wl16(pb, riff_extradata - riff_extradata_start); /* cbSize */
561  }
562  avio_write(pb, riff_extradata_start, riff_extradata - riff_extradata_start);
563  if(hdrsize&1){
564  hdrsize++;
565  avio_w8(pb, 0);
566  }
567 
568  return hdrsize;
569 }
570 
571 /* BITMAPINFOHEADER header */
572 void ff_put_bmp_header(AVIOContext *pb, AVCodecContext *enc, const AVCodecTag *tags, int for_asf)
573 {
574  avio_wl32(pb, 40 + enc->extradata_size); /* size */
575  avio_wl32(pb, enc->width);
576  //We always store RGB TopDown
577  avio_wl32(pb, enc->codec_tag ? enc->height : -enc->height);
578  avio_wl16(pb, 1); /* planes */
579 
580  avio_wl16(pb, enc->bits_per_coded_sample ? enc->bits_per_coded_sample : 24); /* depth */
581  /* compression type */
582  avio_wl32(pb, enc->codec_tag);
583  avio_wl32(pb, (enc->width * enc->height * (enc->bits_per_coded_sample ? enc->bits_per_coded_sample : 24)+7) / 8);
584  avio_wl32(pb, 0);
585  avio_wl32(pb, 0);
586  avio_wl32(pb, 0);
587  avio_wl32(pb, 0);
588 
589  avio_write(pb, enc->extradata, enc->extradata_size);
590 
591  if (!for_asf && enc->extradata_size & 1)
592  avio_w8(pb, 0);
593 }
594 
595 void ff_parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssize, int *au_scale)
596 {
597  int gcd;
598  int audio_frame_size;
599 
600  /* We use the known constant frame size for the codec if known, otherwise
601  fallback to using AVCodecContext.frame_size, which is not as reliable
602  for indicating packet duration */
603  audio_frame_size = av_get_audio_frame_duration(stream, 0);
604  if (!audio_frame_size)
605  audio_frame_size = stream->frame_size;
606 
607  *au_ssize= stream->block_align;
608  if (audio_frame_size && stream->sample_rate) {
609  *au_scale = audio_frame_size;
610  *au_rate= stream->sample_rate;
611  }else if(stream->codec_type == AVMEDIA_TYPE_VIDEO ||
612  stream->codec_type == AVMEDIA_TYPE_DATA ||
613  stream->codec_type == AVMEDIA_TYPE_SUBTITLE){
614  *au_scale= stream->time_base.num;
615  *au_rate = stream->time_base.den;
616  }else{
617  *au_scale= stream->block_align ? stream->block_align*8 : 8;
618  *au_rate = stream->bit_rate ? stream->bit_rate : 8*stream->sample_rate;
619  }
620  gcd= av_gcd(*au_scale, *au_rate);
621  *au_scale /= gcd;
622  *au_rate /= gcd;
623 }
624 
625 void ff_riff_write_info_tag(AVIOContext *pb, const char *tag, const char *str)
626 {
627  int len = strlen(str);
628  if (len > 0) {
629  len++;
630  ffio_wfourcc(pb, tag);
631  avio_wl32(pb, len);
632  avio_put_str(pb, str);
633  if (len & 1)
634  avio_w8(pb, 0);
635  }
636 }
637 
638 static const char riff_tags[][5] = {
639  "IARL", "IART", "ICMS", "ICMT", "ICOP", "ICRD", "ICRP", "IDIM", "IDPI",
640  "IENG", "IGNR", "IKEY", "ILGT", "ILNG", "IMED", "INAM", "IPLT", "IPRD",
641  "IPRT", "ISBJ", "ISFT", "ISHP", "ISMP", "ISRC", "ISRF", "ITCH",
642  {0}
643 };
644 
645 static int riff_has_valid_tags(AVFormatContext *s)
646 {
647  int i;
648 
649  for (i = 0; *riff_tags[i]; i++) {
650  if (av_dict_get(s->metadata, riff_tags[i], NULL, AV_DICT_MATCH_CASE))
651  return 1;
652  }
653 
654  return 0;
655 }
656 
658 {
659  AVIOContext *pb = s->pb;
660  int i;
661  int64_t list_pos;
663 
664  ff_metadata_conv(&s->metadata, ff_riff_info_conv, NULL);
665 
666  /* writing empty LIST is not nice and may cause problems */
667  if (!riff_has_valid_tags(s))
668  return;
669 
670  list_pos = ff_start_tag(pb, "LIST");
671  ffio_wfourcc(pb, "INFO");
672  for (i = 0; *riff_tags[i]; i++) {
673  if ((t = av_dict_get(s->metadata, riff_tags[i], NULL, AV_DICT_MATCH_CASE)))
674  ff_riff_write_info_tag(s->pb, t->key, t->value);
675  }
676  ff_end_tag(pb, list_pos);
677 }
678 #endif //CONFIG_MUXERS
679 
680 #if CONFIG_DEMUXERS
681 /* We could be given one of the three possible structures here:
682  * WAVEFORMAT, PCMWAVEFORMAT or WAVEFORMATEX. Each structure
683  * is an expansion of the previous one with the fields added
684  * at the bottom. PCMWAVEFORMAT adds 'WORD wBitsPerSample' and
685  * WAVEFORMATEX adds 'WORD cbSize' and basically makes itself
686  * an openended structure.
687  */
688 int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size)
689 {
690  int id;
691 
692  id = avio_rl16(pb);
694  codec->channels = avio_rl16(pb);
695  codec->sample_rate = avio_rl32(pb);
696  codec->bit_rate = avio_rl32(pb) * 8;
697  codec->block_align = avio_rl16(pb);
698  if (size == 14) { /* We're dealing with plain vanilla WAVEFORMAT */
699  codec->bits_per_coded_sample = 8;
700  }else
701  codec->bits_per_coded_sample = avio_rl16(pb);
702  if (id == 0xFFFE) {
703  codec->codec_tag = 0;
704  } else {
705  codec->codec_tag = id;
707  }
708  if (size >= 18) { /* We're obviously dealing with WAVEFORMATEX */
709  int cbSize = avio_rl16(pb); /* cbSize */
710  size -= 18;
711  cbSize = FFMIN(size, cbSize);
712  if (cbSize >= 22 && id == 0xfffe) { /* WAVEFORMATEXTENSIBLE */
713  ff_asf_guid subformat;
714  int bps = avio_rl16(pb);
715  if (bps)
716  codec->bits_per_coded_sample = bps;
717  codec->channel_layout = avio_rl32(pb); /* dwChannelMask */
718  ff_get_guid(pb, &subformat);
719  if (!memcmp(subformat + 4, (const uint8_t[]){FF_MEDIASUBTYPE_BASE_GUID}, 12)) {
720  codec->codec_tag = AV_RL32(subformat);
722  } else {
723  codec->codec_id = ff_codec_guid_get_id(ff_codec_wav_guids, subformat);
724  if (!codec->codec_id)
725  av_log(codec, AV_LOG_WARNING, "unknown subformat:"FF_PRI_GUID"\n", FF_ARG_GUID(subformat));
726  }
727  cbSize -= 22;
728  size -= 22;
729  }
730  codec->extradata_size = cbSize;
731  if (cbSize > 0) {
732  av_free(codec->extradata);
734  if (!codec->extradata)
735  return AVERROR(ENOMEM);
736  avio_read(pb, codec->extradata, codec->extradata_size);
737  size -= cbSize;
738  }
739 
740  /* It is possible for the chunk to contain garbage at the end */
741  if (size > 0)
742  avio_skip(pb, size);
743  }
744  if (codec->codec_id == AV_CODEC_ID_AAC_LATM) {
745  /* channels and sample_rate values are those prior to applying SBR and/or PS */
746  codec->channels = 0;
747  codec->sample_rate = 0;
748  }
749  /* override bits_per_coded_sample for G.726 */
750  if (codec->codec_id == AV_CODEC_ID_ADPCM_G726 && codec->sample_rate)
751  codec->bits_per_coded_sample = codec->bit_rate / codec->sample_rate;
752 
753  return 0;
754 }
755 
756 
757 enum AVCodecID ff_wav_codec_get_id(unsigned int tag, int bps)
758 {
759  enum AVCodecID id;
760  id = ff_codec_get_id(ff_codec_wav_tags, tag);
761  if (id <= 0)
762  return id;
763 
764  if (id == AV_CODEC_ID_PCM_S16LE)
765  id = ff_get_pcm_codec_id(bps, 0, 0, ~1);
766  else if (id == AV_CODEC_ID_PCM_F32LE)
767  id = ff_get_pcm_codec_id(bps, 1, 0, 0);
768 
769  if (id == AV_CODEC_ID_ADPCM_IMA_WAV && bps == 8)
771  return id;
772 }
773 
774 int ff_get_bmp_header(AVIOContext *pb, AVStream *st, unsigned *esize)
775 {
776  int tag1;
777  if(esize) *esize = avio_rl32(pb);
778  else avio_rl32(pb);
779  st->codec->width = avio_rl32(pb);
780  st->codec->height = (int32_t)avio_rl32(pb);
781  avio_rl16(pb); /* planes */
782  st->codec->bits_per_coded_sample= avio_rl16(pb); /* depth */
783  tag1 = avio_rl32(pb);
784  avio_rl32(pb); /* ImageSize */
785  avio_rl32(pb); /* XPelsPerMeter */
786  avio_rl32(pb); /* YPelsPerMeter */
787  avio_rl32(pb); /* ClrUsed */
788  avio_rl32(pb); /* ClrImportant */
789  return tag1;
790 }
791 
793 {
794  av_assert0(sizeof(*g) == 16); //compiler will optimize this out
795  if (avio_read(s, *g, sizeof(*g)) < (int)sizeof(*g))
796  memset(*g, 0, sizeof(*g));
797 }
798 
799 enum AVCodecID ff_codec_guid_get_id(const AVCodecGuid *guids, ff_asf_guid guid)
800 {
801  int i;
802  for (i = 0; guids[i].id != AV_CODEC_ID_NONE; i++) {
803  if (!ff_guidcmp(guids[i].guid, guid))
804  return guids[i].id;
805  }
806  return AV_CODEC_ID_NONE;
807 }
808 
809 int ff_read_riff_info(AVFormatContext *s, int64_t size)
810 {
811  int64_t start, end, cur;
812  AVIOContext *pb = s->pb;
813 
814  start = avio_tell(pb);
815  end = start + size;
816 
817  while ((cur = avio_tell(pb)) >= 0 && cur <= end - 8 /* = tag + size */) {
818  uint32_t chunk_code;
819  int64_t chunk_size;
820  char key[5] = {0};
821  char *value;
822 
823  chunk_code = avio_rl32(pb);
824  chunk_size = avio_rl32(pb);
825  if (url_feof(pb)) {
826  if (chunk_code || chunk_size) {
827  av_log(s, AV_LOG_WARNING, "INFO subchunk truncated\n");
828  return AVERROR_INVALIDDATA;
829  }
830  break;
831  }
832  if (chunk_size > end || end - chunk_size < cur || chunk_size == UINT_MAX) {
833  avio_seek(pb, -9, SEEK_CUR);
834  chunk_code = avio_rl32(pb);
835  chunk_size = avio_rl32(pb);
836  if (chunk_size > end || end - chunk_size < cur || chunk_size == UINT_MAX) {
837  av_log(s, AV_LOG_WARNING, "too big INFO subchunk\n");
838  return AVERROR_INVALIDDATA;
839  }
840  }
841 
842  chunk_size += (chunk_size & 1);
843 
844  if (!chunk_code) {
845  if (chunk_size)
846  avio_skip(pb, chunk_size);
847  continue;
848  }
849 
850  value = av_mallocz(chunk_size + 1);
851  if (!value) {
852  av_log(s, AV_LOG_ERROR, "out of memory, unable to read INFO tag\n");
853  return AVERROR(ENOMEM);
854  }
855 
856  AV_WL32(key, chunk_code);
857 
858  if (avio_read(pb, value, chunk_size) != chunk_size) {
859  av_log(s, AV_LOG_WARNING, "premature end of file while reading INFO tag\n");
860  }
861 
862  av_dict_set(&s->metadata, key, value, AV_DICT_DONT_STRDUP_VAL);
863  }
864 
865  return 0;
866 }
867 #endif // CONFIG_DEMUXERS
int ff_read_riff_info(AVFormatContext *s, int64_t size)
Definition: start.py:1
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:367
const char * s
Definition: avisynth_c.h:668
Bytestream IO Context.
Definition: avio.h:68
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
void ff_end_tag(AVIOContext *pb, int64_t start)
int64_t ff_start_tag(AVIOContext *pb, const char *tag)
enum AVCodecID id
Definition: mxfenc.c:89
enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
void ff_parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssize, int *au_scale)
else temp
Definition: vf_mcdeint.c:148
#define FF_ARG_GUID(g)
Definition: riff.h:65
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:154
enum AVCodecID id
Definition: riff.h:76
int num
numerator
Definition: rational.h:44
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:199
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:256
AVDictionaryEntry * av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:39
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
#define FFALIGN(x, a)
Definition: common.h:63
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
const AVCodecGuid ff_codec_wav_guids[]
Definition: riff.c:394
Format I/O context.
Definition: avformat.h:944
#define AV_WL32(p, darg)
Definition: intreadwrite.h:282
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:291
uint8_t
#define FF_MEDIASUBTYPE_BASE_GUID
Definition: riff.h:84
Opaque data information usually continuous.
Definition: avutil.h:145
end end
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
uint32_t tag
Definition: movenc.c:894
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:248
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:173
static av_always_inline void ffio_wfourcc(AVIOContext *pb, const uint8_t *s)
Definition: avio_internal.h:50
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:478
static const uint8_t frame_size[4]
Definition: g723_1_data.h:58
AVCodecID
Identify the syntax and semantics of the bitstream.
int ff_get_bmp_header(AVIOContext *pb, AVStream *st, unsigned *esize)
Read BITMAPINFOHEADER structure and set AVStream codec width, height and bits_per_encoded_sample fiel...
#define AV_DICT_MATCH_CASE
Definition: dict.h:67
AVDictionary * metadata
Definition: avformat.h:1092
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:183
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:579
int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size)
void ff_riff_write_info_tag(AVIOContext *pb, const char *tag, const char *str)
Write a single RIFF info tag.
preferred ID for decoding MPEG audio layer 1, 2 or 3
simple assert() macros that are a bit more flexible than ISO C assert().
int64_t av_gcd(int64_t a, int64_t b)
Return the greatest common divisor of a and b.
Definition: mathematics.c:55
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
const AVCodecTag ff_codec_wav_tags[]
Definition: riff.c:334
external API header
int size
uint64_t channel_layout
Audio channel layout.
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:662
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
FFT buffer for g
Definition: stft_peak.m:17
int bit_rate
the average bitrate
#define FFMIN(a, b)
Definition: common.h:58
const AVCodecTag ff_codec_bmp_tags[]
Definition: riff.c:35
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that&#39;s been allocated with av_malloc() and chilren.
Definition: dict.h:72
int width
picture width / height.
t
Definition: genspecsines3.m:6
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
int32_t
#define AV_RL32
int url_feof(AVIOContext *s)
feof() equivalent for AVIOContext.
Definition: aviobuf.c:280
preferred ID for MPEG-1/2 video decoding
int avio_put_str(AVIOContext *s, const char *str)
Write a NULL-terminated string.
Definition: aviobuf.c:307
uint8_t ff_asf_guid[16]
Definition: riff.h:59
Stream structure.
Definition: avformat.h:643
int frame_size
Number of samples per channel in an audio frame.
NULL
Definition: eval.c:55
enum AVMediaType codec_type
enum AVCodecID codec_id
int sample_rate
samples per second
AVIOContext * pb
I/O context.
Definition: avformat.h:977
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:151
main external API structure.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> (&#39;D&#39;<<24) + (&#39;C&#39;<<16) + (&#39;B&#39;<<8) + &#39;A&#39;).
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:62
void ff_riff_write_info(AVFormatContext *s)
Write all recognized RIFF tags from s->metadata.
double value
Definition: eval.c:82
synthesis window for stochastic i
enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int be, int sflags)
Select a PCM codec based on the given parameters.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
Return audio frame duration.
void ff_put_bmp_header(AVIOContext *pb, AVCodecContext *enc, const AVCodecTag *tags, int for_asf)
const AVMetadataConv ff_riff_info_conv[]
Definition: riff.c:402
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:563
Main libavformat public API header.
enum AVCodecID ff_codec_guid_get_id(const AVCodecGuid *guids, ff_asf_guid guid)
enum AVCodecID ff_wav_codec_get_id(unsigned int tag, int bps)
#define FF_PRI_GUID
Definition: riff.h:63
int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc)
char * key
Definition: dict.h:81
int den
denominator
Definition: rational.h:45
unsigned bps
Definition: movenc.c:895
void ff_get_guid(AVIOContext *s, ff_asf_guid *g)
void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv, const AVMetadataConv *s_conv)
char * value
Definition: dict.h:82
int len
int channels
number of audio channels
void INT64 start
Definition: avisynth_c.h:594
#define MKTAG(a, b, c, d)
Definition: common.h:282
static av_always_inline int ff_guidcmp(const void *g1, const void *g2)
Definition: riff.h:68