annotate mp3.c @ 355:46029c682234 libavformat

seeking stuff adaptively change middle position selection algo for seeking, this avoids some ugly worstcases of the interpolated variant avoid backward search for mpeg where possible, its 17 times slower then forward according to my benchmark
author michael
date Sat, 17 Jan 2004 20:26:44 +0000
parents 5552d3761ec0
children 60f897e8dd2d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
1 /*
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
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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"
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
20
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
21 #define ID3_HEADER_SIZE 10
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
22 #define ID3_TAG_SIZE 128
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
23
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
24 #define ID3_GENRE_MAX 125
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
25
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
26 static const char *id3_genre_str[ID3_GENRE_MAX + 1] = {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
27 [0] = "Blues",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
28 [1] = "Classic Rock",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
29 [2] = "Country",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
30 [3] = "Dance",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
31 [4] = "Disco",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
32 [5] = "Funk",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
33 [6] = "Grunge",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
34 [7] = "Hip-Hop",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
35 [8] = "Jazz",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
36 [9] = "Metal",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
37 [10] = "New Age",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
38 [11] = "Oldies",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
39 [12] = "Other",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
40 [13] = "Pop",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
41 [14] = "R&B",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
42 [15] = "Rap",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
43 [16] = "Reggae",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
44 [17] = "Rock",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
45 [18] = "Techno",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
46 [19] = "Industrial",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
47 [20] = "Alternative",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
48 [21] = "Ska",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
49 [22] = "Death Metal",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
50 [23] = "Pranks",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
51 [24] = "Soundtrack",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
52 [25] = "Euro-Techno",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
53 [26] = "Ambient",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
54 [27] = "Trip-Hop",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
55 [28] = "Vocal",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
56 [29] = "Jazz+Funk",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
57 [30] = "Fusion",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
58 [31] = "Trance",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
59 [32] = "Classical",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
60 [33] = "Instrumental",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
61 [34] = "Acid",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
62 [35] = "House",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
63 [36] = "Game",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
64 [37] = "Sound Clip",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
65 [38] = "Gospel",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
66 [39] = "Noise",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
67 [40] = "AlternRock",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
68 [41] = "Bass",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
69 [42] = "Soul",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
70 [43] = "Punk",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
71 [44] = "Space",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
72 [45] = "Meditative",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
73 [46] = "Instrumental Pop",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
74 [47] = "Instrumental Rock",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
75 [48] = "Ethnic",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
76 [49] = "Gothic",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
77 [50] = "Darkwave",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
78 [51] = "Techno-Industrial",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
79 [52] = "Electronic",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
80 [53] = "Pop-Folk",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
81 [54] = "Eurodance",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
82 [55] = "Dream",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
83 [56] = "Southern Rock",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
84 [57] = "Comedy",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
85 [58] = "Cult",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
86 [59] = "Gangsta",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
87 [60] = "Top 40",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
88 [61] = "Christian Rap",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
89 [62] = "Pop/Funk",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
90 [63] = "Jungle",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
91 [64] = "Native American",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
92 [65] = "Cabaret",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
93 [66] = "New Wave",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
94 [67] = "Psychadelic",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
95 [68] = "Rave",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
96 [69] = "Showtunes",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
97 [70] = "Trailer",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
98 [71] = "Lo-Fi",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
99 [72] = "Tribal",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
100 [73] = "Acid Punk",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
101 [74] = "Acid Jazz",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
102 [75] = "Polka",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
103 [76] = "Retro",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
104 [77] = "Musical",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
105 [78] = "Rock & Roll",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
106 [79] = "Hard Rock",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
107 [80] = "Folk",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
108 [81] = "Folk-Rock",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
109 [82] = "National Folk",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
110 [83] = "Swing",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
111 [84] = "Fast Fusion",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
112 [85] = "Bebob",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
113 [86] = "Latin",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
114 [87] = "Revival",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
115 [88] = "Celtic",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
116 [89] = "Bluegrass",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
117 [90] = "Avantgarde",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
118 [91] = "Gothic Rock",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
119 [92] = "Progressive Rock",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
120 [93] = "Psychedelic Rock",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
121 [94] = "Symphonic Rock",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
122 [95] = "Slow Rock",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
123 [96] = "Big Band",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
124 [97] = "Chorus",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
125 [98] = "Easy Listening",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
126 [99] = "Acoustic",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
127 [100] = "Humour",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
128 [101] = "Speech",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
129 [102] = "Chanson",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
130 [103] = "Opera",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
131 [104] = "Chamber Music",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
132 [105] = "Sonata",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
133 [106] = "Symphony",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
134 [107] = "Booty Bass",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
135 [108] = "Primus",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
136 [109] = "Porn Groove",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
137 [110] = "Satire",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
138 [111] = "Slow Jam",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
139 [112] = "Club",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
140 [113] = "Tango",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
141 [114] = "Samba",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
142 [115] = "Folklore",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
143 [116] = "Ballad",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
144 [117] = "Power Ballad",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
145 [118] = "Rhythmic Soul",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
146 [119] = "Freestyle",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
147 [120] = "Duet",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
148 [121] = "Punk Rock",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
149 [122] = "Drum Solo",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
150 [123] = "A capella",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
151 [124] = "Euro-House",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
152 [125] = "Dance Hall",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
153 };
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 /* buf must be ID3_HEADER_SIZE byte long */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
156 static int id3_match(const uint8_t *buf)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
157 {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
158 return (buf[0] == 'I' &&
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
159 buf[1] == 'D' &&
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
160 buf[2] == '3' &&
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
161 buf[3] != 0xff &&
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
162 buf[4] != 0xff &&
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
163 (buf[6] & 0x80) == 0 &&
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
164 (buf[7] & 0x80) == 0 &&
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
165 (buf[8] & 0x80) == 0 &&
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
166 (buf[9] & 0x80) == 0);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
167 }
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 static void id3_get_string(char *str, int str_size,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
170 const uint8_t *buf, int buf_size)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
171 {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
172 int i, c;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
173 char *q;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
174
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
175 q = str;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
176 for(i = 0; i < buf_size; i++) {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
177 c = buf[i];
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
178 if (c == '\0')
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
179 break;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
180 if ((q - str) >= str_size - 1)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
181 break;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
182 *q++ = c;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
183 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
184 *q = '\0';
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
185 }
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 /* 'buf' must be ID3_TAG_SIZE byte long */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
188 static int id3_parse_tag(AVFormatContext *s, const uint8_t *buf)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
189 {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
190 char str[5];
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
191 int genre;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
192
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
193 if (!(buf[0] == 'T' &&
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
194 buf[1] == 'A' &&
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
195 buf[2] == 'G'))
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
196 return -1;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
197 id3_get_string(s->title, sizeof(s->title), buf + 3, 30);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
198 id3_get_string(s->author, sizeof(s->author), buf + 33, 30);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
199 id3_get_string(s->album, sizeof(s->album), buf + 63, 30);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
200 id3_get_string(str, sizeof(str), buf + 93, 4);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
201 s->year = atoi(str);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
202 id3_get_string(s->comment, sizeof(s->comment), buf + 97, 30);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
203 if (buf[125] == 0 && buf[126] != 0)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
204 s->track = buf[126];
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
205 genre = buf[127];
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
206 if (genre <= ID3_GENRE_MAX)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
207 pstrcpy(s->genre, sizeof(s->genre), id3_genre_str[genre]);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
208 return 0;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
209 }
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 static void id3_create_tag(AVFormatContext *s, uint8_t *buf)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
212 {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
213 int v, i;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
214
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
215 memset(buf, 0, ID3_TAG_SIZE); /* fail safe */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
216 buf[0] = 'T';
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
217 buf[1] = 'A';
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
218 buf[2] = 'G';
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
219 strncpy(buf + 3, s->title, 30);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
220 strncpy(buf + 33, s->author, 30);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
221 strncpy(buf + 63, s->album, 30);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
222 v = s->year;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
223 if (v > 0) {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
224 for(i = 0;i < 4; i++) {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
225 buf[96 - i] = '0' + (v % 10);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
226 v = v / 10;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
227 }
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 strncpy(buf + 97, s->comment, 30);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
230 if (s->track != 0) {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
231 buf[125] = 0;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
232 buf[126] = s->track;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
233 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
234 for(i = 0; i <= ID3_GENRE_MAX; i++) {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
235 if (!strcasecmp(s->genre, id3_genre_str[i])) {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
236 buf[127] = i;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
237 break;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
238 }
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 /* mp3 read */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
243 static int mp3_read_header(AVFormatContext *s,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
244 AVFormatParameters *ap)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
245 {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
246 AVStream *st;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
247 uint8_t buf[ID3_TAG_SIZE];
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
248 int len, ret, filesize;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
249
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
250 st = av_new_stream(s, 0);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
251 if (!st)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
252 return AVERROR_NOMEM;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
253
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
254 st->codec.codec_type = CODEC_TYPE_AUDIO;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
255 st->codec.codec_id = CODEC_ID_MP3;
307
5552d3761ec0 added parsing
bellard
parents: 277
diff changeset
256 st->need_parsing = 1;
5552d3761ec0 added parsing
bellard
parents: 277
diff changeset
257
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
258 /* try to get the TAG */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
259 if (!url_is_streamed(&s->pb)) {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
260 /* XXX: change that */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
261 filesize = url_filesize(url_fileno(&s->pb));
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
262 if (filesize > 128) {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
263 url_fseek(&s->pb, filesize - 128, SEEK_SET);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
264 ret = get_buffer(&s->pb, buf, ID3_TAG_SIZE);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
265 if (ret == ID3_TAG_SIZE) {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
266 id3_parse_tag(s, buf);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
267 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
268 url_fseek(&s->pb, 0, SEEK_SET);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
269 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
270 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
271
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
272 /* if ID3 header found, skip it */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
273 ret = get_buffer(&s->pb, buf, ID3_HEADER_SIZE);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
274 if (ret != ID3_HEADER_SIZE)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
275 return -1;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
276 if (id3_match(buf)) {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
277 /* skip ID3 header */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
278 len = ((buf[6] & 0x7f) << 21) |
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
279 ((buf[7] & 0x7f) << 14) |
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
280 ((buf[8] & 0x7f) << 7) |
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
281 (buf[9] & 0x7f);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
282 url_fskip(&s->pb, len);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
283 } else {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
284 url_fseek(&s->pb, 0, SEEK_SET);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
285 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
286
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
287 /* the parameters will be extracted from the compressed bitstream */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
288 return 0;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
289 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
290
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
291 #define MP3_PACKET_SIZE 1024
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
292
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
293 static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
294 {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
295 int ret, size;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
296 // AVStream *st = s->streams[0];
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
297
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
298 size= MP3_PACKET_SIZE;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
299
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
300 if (av_new_packet(pkt, size) < 0)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
301 return -EIO;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
302
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
303 pkt->stream_index = 0;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
304 ret = get_buffer(&s->pb, pkt->data, size);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
305 if (ret <= 0) {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
306 av_free_packet(pkt);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
307 return -EIO;
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 /* 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
310 packet */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
311 pkt->size = ret;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
312 return ret;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
313 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
314
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
315 static int mp3_read_close(AVFormatContext *s)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
316 {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
317 return 0;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
318 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
319
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 241
diff changeset
320 #ifdef CONFIG_ENCODERS
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
321 /* simple formats */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
322 static int mp3_write_header(struct AVFormatContext *s)
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 return 0;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
325 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
326
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
327 static int mp3_write_packet(struct AVFormatContext *s, int stream_index,
241
3d92f793fd67 64 bit pts for writing - more const usage
bellard
parents: 234
diff changeset
328 const uint8_t *buf, int size, int64_t pts)
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
329 {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
330 put_buffer(&s->pb, buf, size);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
331 put_flush_packet(&s->pb);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
332 return 0;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
333 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
334
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
335 static int mp3_write_trailer(struct AVFormatContext *s)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
336 {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
337 uint8_t buf[ID3_TAG_SIZE];
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
338
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
339 /* write the id3 header */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
340 if (s->title[0] != '\0') {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
341 id3_create_tag(s, buf);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
342 put_buffer(&s->pb, buf, ID3_TAG_SIZE);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
343 put_flush_packet(&s->pb);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
344 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
345 return 0;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
346 }
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 241
diff changeset
347 #endif //CONFIG_ENCODERS
234
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 AVInputFormat mp3_iformat = {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
350 "mp3",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
351 "MPEG audio",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
352 0,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
353 NULL,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
354 mp3_read_header,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
355 mp3_read_packet,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
356 mp3_read_close,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
357 .extensions = "mp2,mp3", /* XXX: use probe */
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
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 241
diff changeset
360 #ifdef CONFIG_ENCODERS
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
361 AVOutputFormat mp2_oformat = {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
362 "mp2",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
363 "MPEG audio layer 2",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
364 "audio/x-mpeg",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
365 #ifdef CONFIG_MP3LAME
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
366 "mp2",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
367 #else
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
368 "mp2,mp3",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
369 #endif
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
370 0,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
371 CODEC_ID_MP2,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
372 0,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
373 mp3_write_header,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
374 mp3_write_packet,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
375 mp3_write_trailer,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
376 };
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
377
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
378 #ifdef CONFIG_MP3LAME
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
379 AVOutputFormat mp3_oformat = {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
380 "mp3",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
381 "MPEG audio layer 3",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
382 "audio/x-mpeg",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
383 "mp3",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
384 0,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
385 CODEC_ID_MP3,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
386 0,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
387 mp3_write_header,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
388 mp3_write_packet,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
389 mp3_write_trailer,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
390 };
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
391 #endif
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 241
diff changeset
392 #endif //CONFIG_ENCODERS
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
393
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
394 int mp3_init(void)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
395 {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
396 av_register_input_format(&mp3_iformat);
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 241
diff changeset
397 #ifdef CONFIG_ENCODERS
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
398 av_register_output_format(&mp2_oformat);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
399 #ifdef CONFIG_MP3LAME
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
400 av_register_output_format(&mp3_oformat);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
401 #endif
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 241
diff changeset
402 #endif //CONFIG_ENCODERS
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
403 return 0;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
404 }