annotate mp3.c @ 1960:c0289552590f libavformat

Change the vhook code to send real timestamps to the filters instead of the current time of day, which is useless, and which the filters could just as easily query for themselves. patch by Bobby Bingham, uhmmmm gmail com
author diego
date Thu, 29 Mar 2007 05:24:35 +0000
parents 5d72afc6c8aa
children 1a3c9056982a
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(p->buf_size < ID3_HEADER_SIZE)
1107
921c8af78310 probe for mpeg audio
mru
parents: 896
diff changeset
256 return 0;
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 if(id3_match(p->buf))
1469
5789e36270ce fix missdetection of mpeg-ps (ps2_interdite.mpg)
michael
parents: 1433
diff changeset
259 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
260
1308
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
261 max_frames = 0;
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
262 buf = p->buf;
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
263 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
264
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
265 for(; buf < end; buf++) {
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
266 buf2 = buf;
1107
921c8af78310 probe for mpeg audio
mru
parents: 896
diff changeset
267
1312
24f1d6a50117 10l typo
michael
parents: 1308
diff changeset
268 for(frames = 0; buf2 < end; frames++) {
1308
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
269 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
270 fsize = mpa_decode_header(&avctx, header, &sample_rate);
1308
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
271 if(fsize < 0)
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
272 break;
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
273 buf2 += fsize;
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
274 }
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
275 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
276 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
277 first_frames= frames;
1308
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
278 }
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
279 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
280 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
281 else if(max_frames>=1) return 1;
1308
866d43ed0a67 allow ffmpeg to read mp3s beginning with partial frames
gpoirier
parents: 1169
diff changeset
282 else return 0;
1107
921c8af78310 probe for mpeg audio
mru
parents: 896
diff changeset
283 }
921c8af78310 probe for mpeg audio
mru
parents: 896
diff changeset
284
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
285 static int mp3_read_header(AVFormatContext *s,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
286 AVFormatParameters *ap)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
287 {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
288 AVStream *st;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
289 uint8_t buf[ID3_TAG_SIZE];
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
290 int len, ret, filesize;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
291
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
292 st = av_new_stream(s, 0);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
293 if (!st)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
294 return AVERROR_NOMEM;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
295
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 814
diff changeset
296 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
297 st->codec->codec_id = CODEC_ID_MP3;
307
5552d3761ec0 added parsing
bellard
parents: 277
diff changeset
298 st->need_parsing = 1;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
299
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
300 /* try to get the TAG */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
301 if (!url_is_streamed(&s->pb)) {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
302 /* 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
303 filesize = url_fsize(&s->pb);
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
304 if (filesize > 128) {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
305 url_fseek(&s->pb, filesize - 128, SEEK_SET);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
306 ret = get_buffer(&s->pb, buf, ID3_TAG_SIZE);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
307 if (ret == ID3_TAG_SIZE) {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
308 id3_parse_tag(s, buf);
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 url_fseek(&s->pb, 0, SEEK_SET);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
311 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
312 }
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 /* if ID3 header found, skip it */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
315 ret = get_buffer(&s->pb, buf, ID3_HEADER_SIZE);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
316 if (ret != ID3_HEADER_SIZE)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
317 return -1;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
318 if (id3_match(buf)) {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
319 /* skip ID3 header */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
320 len = ((buf[6] & 0x7f) << 21) |
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
321 ((buf[7] & 0x7f) << 14) |
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
322 ((buf[8] & 0x7f) << 7) |
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
323 (buf[9] & 0x7f);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
324 url_fskip(&s->pb, len);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
325 } else {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
326 url_fseek(&s->pb, 0, SEEK_SET);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
327 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
328
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
329 /* the parameters will be extracted from the compressed bitstream */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
330 return 0;
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
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
333 #define MP3_PACKET_SIZE 1024
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_read_packet(AVFormatContext *s, AVPacket *pkt)
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 int ret, size;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
338 // AVStream *st = s->streams[0];
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
339
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
340 size= MP3_PACKET_SIZE;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
341
775
c5077fdab490 AVPacket.pos
michael
parents: 764
diff changeset
342 ret= av_get_packet(&s->pb, pkt, size);
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
343
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
344 pkt->stream_index = 0;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
345 if (ret <= 0) {
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 468
diff changeset
346 return AVERROR_IO;
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
347 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
348 /* 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
349 packet */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
350 pkt->size = ret;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
351 return ret;
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
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
354 static int mp3_read_close(AVFormatContext *s)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
355 {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
356 return 0;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
357 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
358
858
66cc656ea404 Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents: 820
diff changeset
359 #ifdef CONFIG_MUXERS
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
360 /* simple formats */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
361 static int mp3_write_header(struct AVFormatContext *s)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
362 {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
363 return 0;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
364 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
365
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 307
diff changeset
366 static int mp3_write_packet(struct AVFormatContext *s, AVPacket *pkt)
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
367 {
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 307
diff changeset
368 put_buffer(&s->pb, pkt->data, pkt->size);
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
369 put_flush_packet(&s->pb);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
370 return 0;
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
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
373 static int mp3_write_trailer(struct AVFormatContext *s)
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
374 {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
375 uint8_t buf[ID3_TAG_SIZE];
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 /* write the id3 header */
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
378 if (s->title[0] != '\0') {
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
379 id3_create_tag(s, buf);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
380 put_buffer(&s->pb, buf, ID3_TAG_SIZE);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
381 put_flush_packet(&s->pb);
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
382 }
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
383 return 0;
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
384 }
858
66cc656ea404 Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents: 820
diff changeset
385 #endif //CONFIG_MUXERS
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
386
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
387 #ifdef CONFIG_MP3_DEMUXER
1167
d89d7ef290da give AVInput/OutputFormat structs consistent names
mru
parents: 1107
diff changeset
388 AVInputFormat mp3_demuxer = {
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
389 "mp3",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
390 "MPEG audio",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
391 0,
1107
921c8af78310 probe for mpeg audio
mru
parents: 896
diff changeset
392 mp3_read_probe,
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
393 mp3_read_header,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
394 mp3_read_packet,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
395 mp3_read_close,
1756
5d72afc6c8aa better generic index building and seeking code
michael
parents: 1622
diff changeset
396 .flags= AVFMT_GENERIC_INDEX,
814
731af78f150d .m1v and .m2a (feature req #1178960)
michael
parents: 775
diff changeset
397 .extensions = "mp2,mp3,m2a", /* XXX: use probe */
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
398 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
399 #endif
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
400 #ifdef CONFIG_MP2_MUXER
1167
d89d7ef290da give AVInput/OutputFormat structs consistent names
mru
parents: 1107
diff changeset
401 AVOutputFormat mp2_muxer = {
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
402 "mp2",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
403 "MPEG audio layer 2",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
404 "audio/x-mpeg",
1622
ac2a299df031 variable renaming: mp3lame --> libmp3lame
diego
parents: 1469
diff changeset
405 #ifdef CONFIG_LIBMP3LAME
814
731af78f150d .m1v and .m2a (feature req #1178960)
michael
parents: 775
diff changeset
406 "mp2,m2a",
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
407 #else
814
731af78f150d .m1v and .m2a (feature req #1178960)
michael
parents: 775
diff changeset
408 "mp2,mp3,m2a",
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
409 #endif
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
410 0,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
411 CODEC_ID_MP2,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
412 0,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
413 mp3_write_header,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
414 mp3_write_packet,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
415 mp3_write_trailer,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
416 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
417 #endif
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
418 #ifdef CONFIG_MP3_MUXER
1167
d89d7ef290da give AVInput/OutputFormat structs consistent names
mru
parents: 1107
diff changeset
419 AVOutputFormat mp3_muxer = {
234
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 "MPEG audio layer 3",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
422 "audio/x-mpeg",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
423 "mp3",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
424 0,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
425 CODEC_ID_MP3,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
426 0,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
427 mp3_write_header,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
428 mp3_write_packet,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
429 mp3_write_trailer,
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
430 };
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
431 #endif