Mercurial > hg > svcore
comparison data/fileio/OggVorbisFileReader.cpp @ 1359:1c9bbbb6116a 3.0-integration
Use W64 instead of WAV for decoded files; use Ogg reader in preference to WAV one for Ogg files (WAV reader works, via libsndfile, but doesn't load metadata); fix Ogg reader to use QFile open instead of non-Win32-compatible API; add more encoder tests, audio writer test, midi reader test
author | Chris Cannam |
---|---|
date | Tue, 10 Jan 2017 10:58:25 +0000 |
parents | c380e56c95f5 |
children | ce08318aad83 |
comparison
equal
deleted
inserted
replaced
1358:b7be05d57f0a | 1359:1c9bbbb6116a |
---|---|
38 bool normalised, | 38 bool normalised, |
39 ProgressReporter *reporter) : | 39 ProgressReporter *reporter) : |
40 CodedAudioFileReader(mode, targetRate, normalised), | 40 CodedAudioFileReader(mode, targetRate, normalised), |
41 m_source(source), | 41 m_source(source), |
42 m_path(source.getLocalFilename()), | 42 m_path(source.getLocalFilename()), |
43 m_qfile(0), | |
44 m_ffile(0), | |
45 m_oggz(0), | |
46 m_fishSound(0), | |
43 m_reporter(reporter), | 47 m_reporter(reporter), |
44 m_fileSize(0), | 48 m_fileSize(0), |
45 m_bytesRead(0), | 49 m_bytesRead(0), |
46 m_commentsRead(false), | 50 m_commentsRead(false), |
47 m_cancelled(false), | 51 m_cancelled(false), |
58 | 62 |
59 // SVDEBUG << "OggVorbisFileReader::OggVorbisFileReader(" << m_path << "): now have " << (++instances) << " instances" << endl; | 63 // SVDEBUG << "OggVorbisFileReader::OggVorbisFileReader(" << m_path << "): now have " << (++instances) << " instances" << endl; |
60 | 64 |
61 Profiler profiler("OggVorbisFileReader::OggVorbisFileReader"); | 65 Profiler profiler("OggVorbisFileReader::OggVorbisFileReader"); |
62 | 66 |
63 QFileInfo info(m_path); | 67 // These shenanigans are to avoid using oggz_open(..) with a local |
64 m_fileSize = info.size(); | 68 // codepage on Windows (make sure proper filename encoding is used) |
65 | 69 |
66 if (!(m_oggz = oggz_open(m_path.toLocal8Bit().data(), OGGZ_READ))) { | 70 m_qfile = new QFile(m_path); |
71 if (!m_qfile->open(QIODevice::ReadOnly)) { | |
72 m_error = QString("Failed to open file %1 for reading.").arg(m_path); | |
73 SVDEBUG << "OggVorbisFileReader: " << m_error << endl; | |
74 delete m_qfile; | |
75 m_qfile = 0; | |
76 return; | |
77 } | |
78 | |
79 m_fileSize = m_qfile->size(); | |
80 | |
81 m_ffile = fdopen(dup(m_qfile->handle()), "r"); | |
82 if (!m_ffile) { | |
83 m_error = QString("Failed to open file pointer for file %1").arg(m_path); | |
84 SVDEBUG << "OggVorbisFileReader: " << m_error << endl; | |
85 delete m_qfile; | |
86 m_qfile = 0; | |
87 return; | |
88 } | |
89 | |
90 if (!(m_oggz = oggz_open_stdio(m_ffile, OGGZ_READ))) { | |
67 m_error = QString("File %1 is not an OGG file.").arg(m_path); | 91 m_error = QString("File %1 is not an OGG file.").arg(m_path); |
92 fclose(m_ffile); | |
93 m_ffile = 0; | |
94 delete m_qfile; | |
95 m_qfile = 0; | |
68 return; | 96 return; |
69 } | 97 } |
70 | 98 |
71 FishSoundInfo fsinfo; | 99 FishSoundInfo fsinfo; |
72 m_fishSound = fish_sound_new(FISH_SOUND_DECODE, &fsinfo); | 100 m_fishSound = fish_sound_new(FISH_SOUND_DECODE, &fsinfo); |
112 if (m_decodeThread) { | 140 if (m_decodeThread) { |
113 m_cancelled = true; | 141 m_cancelled = true; |
114 m_decodeThread->wait(); | 142 m_decodeThread->wait(); |
115 delete m_decodeThread; | 143 delete m_decodeThread; |
116 } | 144 } |
145 if (m_qfile) { | |
146 // don't fclose m_ffile; oggz_close did that | |
147 delete m_qfile; | |
148 m_qfile = 0; | |
149 } | |
117 } | 150 } |
118 | 151 |
119 void | 152 void |
120 OggVorbisFileReader::cancelled() | 153 OggVorbisFileReader::cancelled() |
121 { | 154 { |
132 | 165 |
133 while (oggz_read(m_reader->m_oggz, 1024) > 0); | 166 while (oggz_read(m_reader->m_oggz, 1024) > 0); |
134 | 167 |
135 fish_sound_delete(m_reader->m_fishSound); | 168 fish_sound_delete(m_reader->m_fishSound); |
136 m_reader->m_fishSound = 0; | 169 m_reader->m_fishSound = 0; |
170 | |
137 oggz_close(m_reader->m_oggz); | 171 oggz_close(m_reader->m_oggz); |
138 m_reader->m_oggz = 0; | 172 m_reader->m_oggz = 0; |
173 | |
174 // don't fclose m_ffile; oggz_close did that | |
175 | |
176 delete m_reader->m_qfile; | |
177 m_reader->m_qfile = 0; | |
139 | 178 |
140 if (m_reader->isDecodeCacheInitialised()) m_reader->finishDecodeCache(); | 179 if (m_reader->isDecodeCacheInitialised()) m_reader->finishDecodeCache(); |
141 m_reader->m_completion = 100; | 180 m_reader->m_completion = 100; |
142 | 181 |
143 m_reader->endSerialised(); | 182 m_reader->endSerialised(); |