comparison data/fileio/OggVorbisFileReader.cpp @ 1527:710e6250a401 zoom

Merge from default branch
author Chris Cannam
date Mon, 17 Sep 2018 13:51:14 +0100
parents ce08318aad83
children 70e172e6cc59
comparison
equal deleted inserted replaced
1324:d4a28d1479a8 1527:710e6250a401
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);
67 m_error = QString("File %1 is not an OGG file.").arg(m_path); 71 if (!m_qfile->open(QIODevice::ReadOnly)) {
68 return; 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()), "rb");
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))) {
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;
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);
73 101
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();
170 return 0; 209 return 0;
171 } 210 }
172 211
173 int 212 int
174 OggVorbisFileReader::acceptFrames(FishSound *fs, float **frames, long nframes, 213 OggVorbisFileReader::acceptFrames(FishSound *fs, float **frames, long nframes,
175 void *data) 214 void *data)
176 { 215 {
177 OggVorbisFileReader *reader = (OggVorbisFileReader *)data; 216 OggVorbisFileReader *reader = (OggVorbisFileReader *)data;
178 217
179 if (!reader->m_commentsRead) { 218 if (!reader->m_commentsRead) {
180 const FishSoundComment *comment; 219 const FishSoundComment *comment;
194 } 233 }
195 reader->m_commentsRead = true; 234 reader->m_commentsRead = true;
196 } 235 }
197 236
198 if (reader->m_channelCount == 0) { 237 if (reader->m_channelCount == 0) {
199 FishSoundInfo fsinfo; 238 FishSoundInfo fsinfo;
200 fish_sound_command(fs, FISH_SOUND_GET_INFO, 239 fish_sound_command(fs, FISH_SOUND_GET_INFO,
201 &fsinfo, sizeof(FishSoundInfo)); 240 &fsinfo, sizeof(FishSoundInfo));
202 reader->m_fileRate = fsinfo.samplerate; 241 reader->m_fileRate = fsinfo.samplerate;
203 reader->m_channelCount = fsinfo.channels; 242 reader->m_channelCount = fsinfo.channels;
204 reader->initialiseDecodeCache(); 243 reader->initialiseDecodeCache();
205 } 244 }
206 245
207 if (nframes > 0) { 246 if (nframes > 0) {
208 reader->addSamplesToDecodeCache(frames, nframes); 247 reader->addSamplesToDecodeCache(frames, nframes);