annotate mp3.c @ 1312:24f1d6a50117 libavformat

10l typo
author michael
date Tue, 12 Sep 2006 14:16:48 +0000
parents 866d43ed0a67
children 9eeb01383e30
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
1 /*
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
2 * MP3 encoder and decoder
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
3 * Copyright (c) 2003 Fabrice Bellard.
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
4 *
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
9 *
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
13 * Lesser General Public License for more details.
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
14 *
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 885
diff changeset
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
18 */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
19 #include "avformat.h"
1308
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
20 #include "mpegaudio.h"
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
21
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
22 #define ID3_HEADER_SIZE 10
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
23 #define ID3_TAG_SIZE 128
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
24
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
25 #define ID3_GENRE_MAX 125
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
26
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
27 static const char *id3_genre_str[ID3_GENRE_MAX + 1] = {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
28 [0] = "Blues",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
29 [1] = "Classic Rock",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
30 [2] = "Country",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
31 [3] = "Dance",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
32 [4] = "Disco",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
33 [5] = "Funk",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
34 [6] = "Grunge",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
35 [7] = "Hip-Hop",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
36 [8] = "Jazz",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
37 [9] = "Metal",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
38 [10] = "New Age",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
39 [11] = "Oldies",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
40 [12] = "Other",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
41 [13] = "Pop",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
42 [14] = "R&B",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
43 [15] = "Rap",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
44 [16] = "Reggae",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
45 [17] = "Rock",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
46 [18] = "Techno",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
47 [19] = "Industrial",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
48 [20] = "Alternative",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
49 [21] = "Ska",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
50 [22] = "Death Metal",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
51 [23] = "Pranks",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
52 [24] = "Soundtrack",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
53 [25] = "Euro-Techno",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
54 [26] = "Ambient",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
55 [27] = "Trip-Hop",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
56 [28] = "Vocal",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
57 [29] = "Jazz+Funk",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
58 [30] = "Fusion",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
59 [31] = "Trance",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
60 [32] = "Classical",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
61 [33] = "Instrumental",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
62 [34] = "Acid",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
63 [35] = "House",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
64 [36] = "Game",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
65 [37] = "Sound Clip",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
66 [38] = "Gospel",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
67 [39] = "Noise",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
68 [40] = "AlternRock",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
69 [41] = "Bass",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
70 [42] = "Soul",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
71 [43] = "Punk",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
72 [44] = "Space",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
73 [45] = "Meditative",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
74 [46] = "Instrumental Pop",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
75 [47] = "Instrumental Rock",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
76 [48] = "Ethnic",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
77 [49] = "Gothic",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
78 [50] = "Darkwave",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
79 [51] = "Techno-Industrial",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
80 [52] = "Electronic",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
81 [53] = "Pop-Folk",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
82 [54] = "Eurodance",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
83 [55] = "Dream",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
84 [56] = "Southern Rock",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
85 [57] = "Comedy",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
86 [58] = "Cult",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
87 [59] = "Gangsta",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
88 [60] = "Top 40",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
89 [61] = "Christian Rap",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
90 [62] = "Pop/Funk",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
91 [63] = "Jungle",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
92 [64] = "Native American",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
93 [65] = "Cabaret",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
94 [66] = "New Wave",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
95 [67] = "Psychadelic",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
96 [68] = "Rave",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
97 [69] = "Showtunes",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
98 [70] = "Trailer",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
99 [71] = "Lo-Fi",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
100 [72] = "Tribal",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
101 [73] = "Acid Punk",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
102 [74] = "Acid Jazz",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
103 [75] = "Polka",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
104 [76] = "Retro",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
105 [77] = "Musical",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
106 [78] = "Rock & Roll",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
107 [79] = "Hard Rock",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
108 [80] = "Folk",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
109 [81] = "Folk-Rock",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
110 [82] = "National Folk",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
111 [83] = "Swing",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
112 [84] = "Fast Fusion",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
113 [85] = "Bebob",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
114 [86] = "Latin",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
115 [87] = "Revival",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
116 [88] = "Celtic",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
117 [89] = "Bluegrass",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
118 [90] = "Avantgarde",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
119 [91] = "Gothic Rock",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
120 [92] = "Progressive Rock",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
121 [93] = "Psychedelic Rock",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
122 [94] = "Symphonic Rock",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
123 [95] = "Slow Rock",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
124 [96] = "Big Band",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
125 [97] = "Chorus",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
126 [98] = "Easy Listening",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
127 [99] = "Acoustic",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
128 [100] = "Humour",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
129 [101] = "Speech",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
130 [102] = "Chanson",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
131 [103] = "Opera",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
132 [104] = "Chamber Music",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
133 [105] = "Sonata",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
134 [106] = "Symphony",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
135 [107] = "Booty Bass",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
136 [108] = "Primus",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
137 [109] = "Porn Groove",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
138 [110] = "Satire",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
139 [111] = "Slow Jam",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
140 [112] = "Club",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
141 [113] = "Tango",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
142 [114] = "Samba",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
143 [115] = "Folklore",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
144 [116] = "Ballad",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
145 [117] = "Power Ballad",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
146 [118] = "Rhythmic Soul",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
147 [119] = "Freestyle",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
148 [120] = "Duet",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
149 [121] = "Punk Rock",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
150 [122] = "Drum Solo",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
151 [123] = "A capella",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
152 [124] = "Euro-House",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
153 [125] = "Dance Hall",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
154 };
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
155
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
156 /* buf must be ID3_HEADER_SIZE byte long */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
157 static int id3_match(const uint8_t *buf)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
158 {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
159 return (buf[0] == 'I' &&
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
160 buf[1] == 'D' &&
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
161 buf[2] == '3' &&
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
162 buf[3] != 0xff &&
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
163 buf[4] != 0xff &&
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
164 (buf[6] & 0x80) == 0 &&
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
165 (buf[7] & 0x80) == 0 &&
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
166 (buf[8] & 0x80) == 0 &&
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
167 (buf[9] & 0x80) == 0);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
168 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
169
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
170 static void id3_get_string(char *str, int str_size,
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
171 const uint8_t *buf, int buf_size)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
172 {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
173 int i, c;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
174 char *q;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
175
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
176 q = str;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
177 for(i = 0; i < buf_size; i++) {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
178 c = buf[i];
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
179 if (c == '\0')
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
180 break;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
181 if ((q - str) >= str_size - 1)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
182 break;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
183 *q++ = c;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
184 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
185 *q = '\0';
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
186 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
187
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
188 /* 'buf' must be ID3_TAG_SIZE byte long */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
189 static int id3_parse_tag(AVFormatContext *s, const uint8_t *buf)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
190 {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
191 char str[5];
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
192 int genre;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
193
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
194 if (!(buf[0] == 'T' &&
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
195 buf[1] == 'A' &&
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
196 buf[2] == 'G'))
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
197 return -1;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
198 id3_get_string(s->title, sizeof(s->title), buf + 3, 30);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
199 id3_get_string(s->author, sizeof(s->author), buf + 33, 30);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
200 id3_get_string(s->album, sizeof(s->album), buf + 63, 30);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
201 id3_get_string(str, sizeof(str), buf + 93, 4);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
202 s->year = atoi(str);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
203 id3_get_string(s->comment, sizeof(s->comment), buf + 97, 30);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
204 if (buf[125] == 0 && buf[126] != 0)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
205 s->track = buf[126];
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
206 genre = buf[127];
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
207 if (genre <= ID3_GENRE_MAX)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
208 pstrcpy(s->genre, sizeof(s->genre), id3_genre_str[genre]);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
209 return 0;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
210 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
211
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
212 static void id3_create_tag(AVFormatContext *s, uint8_t *buf)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
213 {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
214 int v, i;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
215
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
216 memset(buf, 0, ID3_TAG_SIZE); /* fail safe */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
217 buf[0] = 'T';
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
218 buf[1] = 'A';
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
219 buf[2] = 'G';
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
220 strncpy(buf + 3, s->title, 30);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
221 strncpy(buf + 33, s->author, 30);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
222 strncpy(buf + 63, s->album, 30);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
223 v = s->year;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
224 if (v > 0) {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
225 for(i = 0;i < 4; i++) {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
226 buf[96 - i] = '0' + (v % 10);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
227 v = v / 10;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
228 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
229 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
230 strncpy(buf + 97, s->comment, 30);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
231 if (s->track != 0) {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
232 buf[125] = 0;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
233 buf[126] = s->track;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
234 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
235 for(i = 0; i <= ID3_GENRE_MAX; i++) {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
236 if (!strcasecmp(s->genre, id3_genre_str[i])) {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
237 buf[127] = i;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
238 break;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
239 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
240 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
241 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
242
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
243 /* mp3 read */
1107
921c8af78310 probe for mpeg audio
mru
parents: 896
diff changeset
244
921c8af78310 probe for mpeg audio
mru
parents: 896
diff changeset
245 static int mp3_read_probe(AVProbeData *p)
921c8af78310 probe for mpeg audio
mru
parents: 896
diff changeset
246 {
1308
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
247 int max_frames;
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
248 int fsize, frames;
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
249 uint32_t header;
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
250 uint8_t *buf, *buf2, *end;
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
251 AVCodecContext avctx;
1107
921c8af78310 probe for mpeg audio
mru
parents: 896
diff changeset
252
1308
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
253 if(p->buf_size < ID3_HEADER_SIZE)
1107
921c8af78310 probe for mpeg audio
mru
parents: 896
diff changeset
254 return 0;
921c8af78310 probe for mpeg audio
mru
parents: 896
diff changeset
255
1308
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
256 if(id3_match(p->buf))
1107
921c8af78310 probe for mpeg audio
mru
parents: 896
diff changeset
257 return AVPROBE_SCORE_MAX;
921c8af78310 probe for mpeg audio
mru
parents: 896
diff changeset
258
1308
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
259 max_frames = 0;
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
260 buf = p->buf;
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
261 end = buf + FFMIN(4096, p->buf_size - sizeof(uint32_t));
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
262
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
263 for(; buf < end; buf++) {
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
264 buf2 = buf;
1107
921c8af78310 probe for mpeg audio
mru
parents: 896
diff changeset
265
1312
24f1d6a50117 10l typo
michael
parents: 1308
diff changeset
266 for(frames = 0; buf2 < end; frames++) {
1308
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
267 header = (buf2[0] << 24) | (buf2[1] << 16) | (buf2[2] << 8) | buf2[3];
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
268 fsize = mpa_decode_header(&avctx, header);
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
269 if(fsize < 0)
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
270 break;
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
271 buf2 += fsize;
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
272 }
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
273 max_frames = FFMAX(max_frames, frames);
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
274 }
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
275 if (max_frames>=3) return AVPROBE_SCORE_MAX/2+1;
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
276 else if(max_frames==2) return AVPROBE_SCORE_MAX/4;
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
277 else if(max_frames==1) return 1;
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
278 else return 0;
1107
921c8af78310 probe for mpeg audio
mru
parents: 896
diff changeset
279 }
921c8af78310 probe for mpeg audio
mru
parents: 896
diff changeset
280
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
281 static int mp3_read_header(AVFormatContext *s,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
282 AVFormatParameters *ap)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
283 {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
284 AVStream *st;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
285 uint8_t buf[ID3_TAG_SIZE];
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
286 int len, ret, filesize;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
287
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
288 st = av_new_stream(s, 0);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
289 if (!st)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
290 return AVERROR_NOMEM;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
291
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 814
diff changeset
292 st->codec->codec_type = CODEC_TYPE_AUDIO;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 814
diff changeset
293 st->codec->codec_id = CODEC_ID_MP3;
307
5552d3761ec0 added parsing
bellard
parents: 277
diff changeset
294 st->need_parsing = 1;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
295
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
296 /* try to get the TAG */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
297 if (!url_is_streamed(&s->pb)) {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
298 /* XXX: change that */
764
cdb845a57ae4 drop most url_fileno() calls (allows to use ByteIOContext directly in caller apps instead of URLProtocol)
aurel
parents: 482
diff changeset
299 filesize = url_fsize(&s->pb);
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
300 if (filesize > 128) {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
301 url_fseek(&s->pb, filesize - 128, SEEK_SET);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
302 ret = get_buffer(&s->pb, buf, ID3_TAG_SIZE);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
303 if (ret == ID3_TAG_SIZE) {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
304 id3_parse_tag(s, buf);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
305 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
306 url_fseek(&s->pb, 0, SEEK_SET);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
307 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
308 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
309
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
310 /* if ID3 header found, skip it */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
311 ret = get_buffer(&s->pb, buf, ID3_HEADER_SIZE);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
312 if (ret != ID3_HEADER_SIZE)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
313 return -1;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
314 if (id3_match(buf)) {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
315 /* skip ID3 header */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
316 len = ((buf[6] & 0x7f) << 21) |
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
317 ((buf[7] & 0x7f) << 14) |
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
318 ((buf[8] & 0x7f) << 7) |
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
319 (buf[9] & 0x7f);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
320 url_fskip(&s->pb, len);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
321 } else {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
322 url_fseek(&s->pb, 0, SEEK_SET);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
323 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
324
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
325 /* the parameters will be extracted from the compressed bitstream */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
326 return 0;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
327 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
328
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
329 #define MP3_PACKET_SIZE 1024
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
330
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
331 static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
332 {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
333 int ret, size;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
334 // AVStream *st = s->streams[0];
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
335
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
336 size= MP3_PACKET_SIZE;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
337
775
c5077fdab490 AVPacket.pos
michael
parents: 764
diff changeset
338 ret= av_get_packet(&s->pb, pkt, size);
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
339
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
340 pkt->stream_index = 0;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
341 if (ret <= 0) {
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 468
diff changeset
342 return AVERROR_IO;
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
343 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
344 /* note: we need to modify the packet size here to handle the last
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
345 packet */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
346 pkt->size = ret;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
347 return ret;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
348 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
349
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
350 static int mp3_read_close(AVFormatContext *s)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
351 {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
352 return 0;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
353 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
354
858
66cc656ea404 Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents: 820
diff changeset
355 #ifdef CONFIG_MUXERS
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
356 /* simple formats */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
357 static int mp3_write_header(struct AVFormatContext *s)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
358 {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
359 return 0;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
360 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
361
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 307
diff changeset
362 static int mp3_write_packet(struct AVFormatContext *s, AVPacket *pkt)
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
363 {
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 307
diff changeset
364 put_buffer(&s->pb, pkt->data, pkt->size);
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
365 put_flush_packet(&s->pb);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
366 return 0;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
367 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
368
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
369 static int mp3_write_trailer(struct AVFormatContext *s)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
370 {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
371 uint8_t buf[ID3_TAG_SIZE];
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
372
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
373 /* write the id3 header */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
374 if (s->title[0] != '\0') {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
375 id3_create_tag(s, buf);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
376 put_buffer(&s->pb, buf, ID3_TAG_SIZE);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
377 put_flush_packet(&s->pb);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
378 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
379 return 0;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
380 }
858
66cc656ea404 Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents: 820
diff changeset
381 #endif //CONFIG_MUXERS
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
382
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
383 #ifdef CONFIG_MP3_DEMUXER
1167
d89d7ef290da give AVInput/OutputFormat structs consistent names
mru
parents: 1107
diff changeset
384 AVInputFormat mp3_demuxer = {
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
385 "mp3",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
386 "MPEG audio",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
387 0,
1107
921c8af78310 probe for mpeg audio
mru
parents: 896
diff changeset
388 mp3_read_probe,
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
389 mp3_read_header,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
390 mp3_read_packet,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
391 mp3_read_close,
814
731af78f150d .m1v and .m2a (feature req #1178960)
michael
parents: 775
diff changeset
392 .extensions = "mp2,mp3,m2a", /* XXX: use probe */
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
393 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
394 #endif
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
395 #ifdef CONFIG_MP2_MUXER
1167
d89d7ef290da give AVInput/OutputFormat structs consistent names
mru
parents: 1107
diff changeset
396 AVOutputFormat mp2_muxer = {
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
397 "mp2",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
398 "MPEG audio layer 2",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
399 "audio/x-mpeg",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
400 #ifdef CONFIG_MP3LAME
814
731af78f150d .m1v and .m2a (feature req #1178960)
michael
parents: 775
diff changeset
401 "mp2,m2a",
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
402 #else
814
731af78f150d .m1v and .m2a (feature req #1178960)
michael
parents: 775
diff changeset
403 "mp2,mp3,m2a",
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
404 #endif
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
405 0,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
406 CODEC_ID_MP2,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
407 0,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
408 mp3_write_header,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
409 mp3_write_packet,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
410 mp3_write_trailer,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
411 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
412 #endif
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
413 #ifdef CONFIG_MP3_MUXER
1167
d89d7ef290da give AVInput/OutputFormat structs consistent names
mru
parents: 1107
diff changeset
414 AVOutputFormat mp3_muxer = {
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
415 "mp3",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
416 "MPEG audio layer 3",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
417 "audio/x-mpeg",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
418 "mp3",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
419 0,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
420 CODEC_ID_MP3,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
421 0,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
422 mp3_write_header,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
423 mp3_write_packet,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
424 mp3_write_trailer,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
425 };
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
426 #endif