annotate mp3.c @ 2006:2f0154760e5f libavformat

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