Mercurial > hg > svcore
comparison data/fileio/MP3FileReader.cpp @ 1364:b812df0351d9 3.0-integration
Fix (I think) crash on exit on Windows having loaded an mp3
author | Chris Cannam |
---|---|
date | Thu, 12 Jan 2017 17:29:59 +0000 |
parents | 97deefd38060 |
children | cc62d7862203 |
comparison
equal
deleted
inserted
replaced
1363:39271c98cbdd | 1364:b812df0351d9 |
---|---|
28 | 28 |
29 #include <cstdlib> | 29 #include <cstdlib> |
30 | 30 |
31 #ifdef HAVE_ID3TAG | 31 #ifdef HAVE_ID3TAG |
32 #include <id3tag.h> | 32 #include <id3tag.h> |
33 #endif | |
34 | |
35 #ifdef _WIN32 | |
36 #include <io.h> | |
37 #include <fcntl.h> | |
38 #else | |
39 #include <fcntl.h> | |
40 #include <unistd.h> | |
33 #endif | 41 #endif |
34 | 42 |
35 #include <QFileInfo> | 43 #include <QFileInfo> |
36 | 44 |
37 #include <QTextCodec> | 45 #include <QTextCodec> |
174 { | 182 { |
175 m_title = ""; | 183 m_title = ""; |
176 | 184 |
177 #ifdef HAVE_ID3TAG | 185 #ifdef HAVE_ID3TAG |
178 | 186 |
179 id3_file *file = id3_file_fdopen(fd, ID3_FILE_MODE_READONLY); | 187 #ifdef _WIN32 |
188 int id3fd = _dup(fd); | |
189 #else | |
190 int id3fd = dup(fd); | |
191 #endif | |
192 | |
193 id3_file *file = id3_file_fdopen(id3fd, ID3_FILE_MODE_READONLY); | |
180 if (!file) return; | 194 if (!file) return; |
181 | 195 |
182 // We can do this a lot more elegantly, but we'll leave that for | 196 // We can do this a lot more elegantly, but we'll leave that for |
183 // when we implement support for more than just the one tag! | 197 // when we implement support for more than just the one tag! |
184 | 198 |
185 id3_tag *tag = id3_file_tag(file); | 199 id3_tag *tag = id3_file_tag(file); |
186 if (!tag) { | 200 if (!tag) { |
187 SVDEBUG << "MP3FileReader::loadTags: No ID3 tag found" << endl; | 201 SVDEBUG << "MP3FileReader::loadTags: No ID3 tag found" << endl; |
188 id3_file_close(file); | 202 id3_file_close(file); // also closes our dup'd fd |
189 return; | 203 return; |
190 } | 204 } |
191 | 205 |
192 m_title = loadTag(tag, "TIT2"); // work title | 206 m_title = loadTag(tag, "TIT2"); // work title |
193 if (m_title == "") m_title = loadTag(tag, "TIT1"); | 207 if (m_title == "") m_title = loadTag(tag, "TIT1"); |
204 m_tags[tag->frames[i]->id] = value; | 218 m_tags[tag->frames[i]->id] = value; |
205 } | 219 } |
206 } | 220 } |
207 } | 221 } |
208 | 222 |
209 // We don't id3_file_close(file) because that closes the fd, which | 223 id3_file_close(file); // also closes our dup'd fd |
210 // was only lent to us | |
211 | 224 |
212 #else | 225 #else |
213 SVDEBUG << "MP3FileReader::loadTags: ID3 tag support not compiled in" << endl; | 226 SVDEBUG << "MP3FileReader::loadTags: ID3 tag support not compiled in" << endl; |
214 #endif | 227 #endif |
215 } | 228 } |