| 110 | } |
| 111 | |
| 112 | std::unique_ptr<ImportFileHandle> PCMImportPlugin::Open( |
| 113 | const FilePath &filename, AudacityProject*) |
| 114 | { |
| 115 | SF_INFO info; |
| 116 | wxFile f; // will be closed when it goes out of scope |
| 117 | SFFile file; |
| 118 | |
| 119 | memset(&info, 0, sizeof(info)); |
| 120 | |
| 121 | |
| 122 | #ifdef __WXGTK__ |
| 123 | if (filename.Lower().EndsWith(wxT("mp3"))) { |
| 124 | // There is a bug in libsndfile where mp3s with duplicated metadata tags |
| 125 | // will crash libsndfile and thus audacity. |
| 126 | // We have patched the lib-src version of libsndfile, but |
| 127 | // for linux the user can build against the system libsndfile which |
| 128 | // still has this bug. |
| 129 | // This happens in sf_open_fd, which is the very first point of |
| 130 | // interaction with libsndfile, so the only workaround is to hardcode |
| 131 | // ImportPCM to not handle .mp3. Of course, this will still fail for mp3s |
| 132 | // that are mislabeled with a .wav or other extension. |
| 133 | // So, in the future we may want to write a simple parser to detect mp3s here. |
| 134 | return NULL; |
| 135 | } |
| 136 | #endif |
| 137 | |
| 138 | |
| 139 | if (f.Open(filename)) { |
| 140 | // Even though there is an sf_open() that takes a filename, use the one that |
| 141 | // takes a file descriptor since wxWidgets can open a file with a Unicode name and |
| 142 | // libsndfile can't (under Windows). |
| 143 | file.reset(SFCall<SNDFILE*>(sf_open_fd, f.fd(), SFM_READ, &info, TRUE)); |
| 144 | } |
| 145 | |
| 146 | // The file descriptor is now owned by "file", so we must tell "f" to leave |
| 147 | // it alone. The file descriptor is closed by the destructor of file even if an error |
| 148 | // occurs. |
| 149 | f.Detach(); |
| 150 | |
| 151 | if (!file) { |
| 152 | // TODO: Handle error |
| 153 | //char str[1000]; |
| 154 | //sf_error_str((SNDFILE *)NULL, str, 1000); |
| 155 | |
| 156 | return nullptr; |
| 157 | } else if (file && |
| 158 | (info.format & SF_FORMAT_TYPEMASK) == SF_FORMAT_OGG) { |
| 159 | // mchinen 15.1.2012 - disallowing libsndfile to handle |
| 160 | // ogg files because seeking is broken at this date (very slow, |
| 161 | // seeks from beginning of file each seek). |
| 162 | // This was said by Erik (libsndfile maintainer). |
| 163 | // Note that this won't apply to our local libsndfile, so only |
| 164 | // linux builds that use --with-libsndfile=system are affected, |
| 165 | // as our local libsndfile doesn't do OGG. |
| 166 | // In particular ubuntu 10.10 and 11.04 are known to be affected |
| 167 | // When the bug is fixed, we can check version to avoid only |
| 168 | // the broken builds. |
| 169 |
no test coverage detected