comparison data/fileio/QuickTimeFileReader.cpp @ 285:20028c634494

* change some QStrings to std::strings etc
author Chris Cannam
date Thu, 09 Aug 2007 16:29:29 +0000
parents e2fdcf9d35c5
children 92e8dbde73cd
comparison
equal deleted inserted replaced
284:41d64b873d87 285:20028c634494
46 Movie movie; 46 Movie movie;
47 size_t blockSize; 47 size_t blockSize;
48 }; 48 };
49 49
50 50
51 QuickTimeFileReader::QuickTimeFileReader(QString path, 51 QuickTimeFileReader::QuickTimeFileReader(std::string path,
52 DecodeMode decodeMode, 52 DecodeMode decodeMode,
53 CacheMode mode) : 53 CacheMode mode) :
54 CodedAudioFileReader(mode), 54 CodedAudioFileReader(mode),
55 m_path(path), 55 m_path(path),
56 m_d(new D), 56 m_d(new D),
72 #ifdef WIN32 72 #ifdef WIN32
73 InitializeQTML(0); // FIXME should check QT version 73 InitializeQTML(0); // FIXME should check QT version
74 #else 74 #else
75 m_d->err = Gestalt(gestaltQuickTime,&QTversion); 75 m_d->err = Gestalt(gestaltQuickTime,&QTversion);
76 if ((m_d->err != noErr) || (QTversion < 0x07000000)) { 76 if ((m_d->err != noErr) || (QTversion < 0x07000000)) {
77 m_error = QString("Failed to find compatible version of QuickTime (version 7 or above required)"); 77 setError("Failed to find compatible version of QuickTime (version 7 or above required)");
78 return; 78 return;
79 } 79 }
80 #endif 80 #endif
81 81
82 EnterMovies(); 82 EnterMovies();
98 // m_d->err = QTNewDataReferenceFromURLCFString 98 // m_d->err = QTNewDataReferenceFromURLCFString
99 m_d->err = QTNewDataReferenceFromCFURL 99 m_d->err = QTNewDataReferenceFromCFURL
100 (url, 0, &dataRef, &dataRefType); 100 (url, 0, &dataRef, &dataRefType);
101 101
102 if (m_d->err) { 102 if (m_d->err) {
103 m_error = QString("Error creating data reference for QuickTime decoder: code %1").arg(m_d->err); 103 setError("Error creating data reference for QuickTime decoder", m_d->err);
104 return; 104 return;
105 } 105 }
106 106
107 short fileID = movieInDataForkResID; 107 short fileID = movieInDataForkResID;
108 short flags = 0; 108 short flags = 0;
109 m_d->err = NewMovieFromDataRef 109 m_d->err = NewMovieFromDataRef
110 (&m_d->movie, flags, &fileID, dataRef, dataRefType); 110 (&m_d->movie, flags, &fileID, dataRef, dataRefType);
111 111
112 DisposeHandle(dataRef); 112 DisposeHandle(dataRef);
113 if (m_d->err) { 113 if (m_d->err) {
114 m_error = QString("Error creating new movie for QuickTime decoder: code %1").arg(m_d->err); 114 setError("Error creating new movie for QuickTime decoder", m_d->err);
115 return; 115 return;
116 } 116 }
117 117
118 Boolean isProtected = 0; 118 Boolean isProtected = 0;
119 Track aTrack = GetMovieIndTrackType 119 Track aTrack = GetMovieIndTrackType
138 } else { 138 } else {
139 m_d->err = 1; 139 m_d->err = 1;
140 } 140 }
141 141
142 if (m_d->err && m_d->err != kQTPropertyNotSupportedErr) { 142 if (m_d->err && m_d->err != kQTPropertyNotSupportedErr) {
143 m_error = QString("Error checking for DRM in QuickTime decoder: code %1").arg(m_d->err); 143 setError("Error checking for DRM in QuickTime decoder", m_d->err);
144 return; 144 return;
145 } else if (!m_d->err && isProtected) { 145 } else if (!m_d->err && isProtected) {
146 m_error = QString("File is protected with DRM"); 146 setError("File is protected with DRM");
147 return; 147 return;
148 } else if (m_d->err == kQTPropertyNotSupportedErr && !isProtected) { 148 } else if (m_d->err == kQTPropertyNotSupportedErr && !isProtected) {
149 std::cerr << "QuickTime: File is not protected with DRM" << std::endl; 149 std::cerr << "QuickTime: File is not protected with DRM" << std::endl;
150 } 150 }
151 151
152 if (m_d->movie) { 152 if (m_d->movie) {
153 SetMovieActive(m_d->movie, TRUE); 153 SetMovieActive(m_d->movie, TRUE);
154 m_d->err = GetMoviesError(); 154 m_d->err = GetMoviesError();
155 if (m_d->err) { 155 if (m_d->err) {
156 m_error = QString("Error in QuickTime decoder activation: code %1").arg(m_d->err); 156 setError("Error in QuickTime decoder activation", m_d->err);
157 return; 157 return;
158 } 158 }
159 } else { 159 } else {
160 m_error = QString("Error in QuickTime decoder: Movie object not valid"); 160 setError("Error in QuickTime decoder: Movie object not valid");
161 return; 161 return;
162 } 162 }
163 163
164 m_d->err = MovieAudioExtractionBegin 164 m_d->err = MovieAudioExtractionBegin
165 (m_d->movie, 0, &m_d->extractionSessionRef); 165 (m_d->movie, 0, &m_d->extractionSessionRef);
166 if (m_d->err) { 166 if (m_d->err) {
167 m_error = QString("Error in QuickTime decoder extraction init: code %1").arg(m_d->err); 167 setError("Error in QuickTime decoder extraction init", m_d->err);
168 return; 168 return;
169 } 169 }
170 170
171 m_d->err = MovieAudioExtractionGetProperty 171 m_d->err = MovieAudioExtractionGetProperty
172 (m_d->extractionSessionRef, 172 (m_d->extractionSessionRef,
174 sizeof(m_d->asbd), 174 sizeof(m_d->asbd),
175 &m_d->asbd, 175 &m_d->asbd,
176 nil); 176 nil);
177 177
178 if (m_d->err) { 178 if (m_d->err) {
179 m_error = QString("Error in QuickTime decoder property get: code %1").arg(m_d->err); 179 setError("Error in QuickTime decoder property get", m_d->err);
180 return; 180 return;
181 } 181 }
182 182
183 m_channelCount = m_d->asbd.mChannelsPerFrame; 183 m_channelCount = m_d->asbd.mChannelsPerFrame;
184 m_sampleRate = m_d->asbd.mSampleRate; 184 m_sampleRate = m_d->asbd.mSampleRate;
199 kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription, 199 kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
200 sizeof(m_d->asbd), 200 sizeof(m_d->asbd),
201 &m_d->asbd); 201 &m_d->asbd);
202 202
203 if (m_d->err) { 203 if (m_d->err) {
204 m_error = QString("Error in QuickTime decoder property set: code %1").arg(m_d->err); 204 setError("Error in QuickTime decoder property set", m_d->err);
205 return; 205 return;
206 } 206 }
207 207
208 m_d->buffer.mNumberBuffers = 1; 208 m_d->buffer.mNumberBuffers = 1;
209 m_d->buffer.mBuffers[0].mNumberChannels = m_channelCount; 209 m_d->buffer.mBuffers[0].mNumberChannels = m_channelCount;
215 initialiseDecodeCache(); 215 initialiseDecodeCache();
216 216
217 if (decodeMode == DecodeAtOnce) { 217 if (decodeMode == DecodeAtOnce) {
218 218
219 m_progress = new QProgressDialog 219 m_progress = new QProgressDialog
220 (QObject::tr("Decoding %1...").arg(QFileInfo(path).fileName()), 220 (QObject::tr("Decoding %1...").arg(QFileInfo(path.c_str()).fileName()),
221 QObject::tr("Stop"), 0, 100); 221 QObject::tr("Stop"), 0, 100);
222 m_progress->hide(); 222 m_progress->hide();
223 223
224 while (1) { 224 while (1) {
225 225
227 UInt32 extractionFlags = 0; 227 UInt32 extractionFlags = 0;
228 m_d->err = MovieAudioExtractionFillBuffer 228 m_d->err = MovieAudioExtractionFillBuffer
229 (m_d->extractionSessionRef, &framesRead, &m_d->buffer, 229 (m_d->extractionSessionRef, &framesRead, &m_d->buffer,
230 &extractionFlags); 230 &extractionFlags);
231 if (m_d->err) { 231 if (m_d->err) {
232 m_error = QString("Error in QuickTime decoding: code %1") 232 setError("Error in QuickTime decoding", m_d->err);
233 .arg(m_d->err);
234 break; 233 break;
235 } 234 }
236 235
237 // std::cerr << "Read " << framesRead << " frames (block size " << m_d->blockSize << ")" << std::endl; 236 // std::cerr << "Read " << framesRead << " frames (block size " << m_d->blockSize << ")" << std::endl;
238 237
248 247
249 finishDecodeCache(); 248 finishDecodeCache();
250 249
251 m_d->err = MovieAudioExtractionEnd(m_d->extractionSessionRef); 250 m_d->err = MovieAudioExtractionEnd(m_d->extractionSessionRef);
252 if (m_d->err) { 251 if (m_d->err) {
253 m_error = QString("Error ending QuickTime extraction session: code %1").arg(m_d->err); 252 setError("Error ending QuickTime extraction session", m_d->err);
254 } 253 }
255 254
256 m_completion = 100; 255 m_completion = 100;
257 256
258 delete m_progress; 257 delete m_progress;
263 m_decodeThread = new DecodeThread(this); 262 m_decodeThread = new DecodeThread(this);
264 m_decodeThread->start(); 263 m_decodeThread->start();
265 } 264 }
266 } 265 }
267 266
268 std::cerr << "QuickTimeFileReader::QuickTimeFileReader: frame count is now " << getFrameCount() << ", error is \"\"" << m_error.toStdString() << "\"" << std::endl; 267 std::cerr << "QuickTimeFileReader::QuickTimeFileReader: frame count is now " << getFrameCount() << ", error is \"\"" << m_error << "\"" << std::endl;
269 } 268 }
270 269
271 QuickTimeFileReader::~QuickTimeFileReader() 270 QuickTimeFileReader::~QuickTimeFileReader()
272 { 271 {
273 std::cerr << "QuickTimeFileReader::~QuickTimeFileReader" << std::endl; 272 std::cerr << "QuickTimeFileReader::~QuickTimeFileReader" << std::endl;
294 UInt32 extractionFlags = 0; 293 UInt32 extractionFlags = 0;
295 m_reader->m_d->err = MovieAudioExtractionFillBuffer 294 m_reader->m_d->err = MovieAudioExtractionFillBuffer
296 (m_reader->m_d->extractionSessionRef, &framesRead, 295 (m_reader->m_d->extractionSessionRef, &framesRead,
297 &m_reader->m_d->buffer, &extractionFlags); 296 &m_reader->m_d->buffer, &extractionFlags);
298 if (m_reader->m_d->err) { 297 if (m_reader->m_d->err) {
299 m_reader->m_error = QString("Error in QuickTime decoding: code %1") 298 m_reader->setError("Error in QuickTime decoding",
300 .arg(m_reader->m_d->err); 299 m_reader->m_d->err);
301 break; 300 break;
302 } 301 }
303 302
304 m_reader->m_frameCount += framesRead; 303 m_reader->m_frameCount += framesRead;
305 304
313 312
314 m_reader->finishDecodeCache(); 313 m_reader->finishDecodeCache();
315 314
316 m_reader->m_d->err = MovieAudioExtractionEnd(m_reader->m_d->extractionSessionRef); 315 m_reader->m_d->err = MovieAudioExtractionEnd(m_reader->m_d->extractionSessionRef);
317 if (m_reader->m_d->err) { 316 if (m_reader->m_d->err) {
318 m_reader->m_error = QString("Error ending QuickTime extraction session: code %1").arg(m_reader->m_d->err); 317 m_reader->setError("Error ending QuickTime extraction session", m_reader->m_d->err);
319 } 318 }
320 319
321 m_reader->m_completion = 100; 320 m_reader->m_completion = 100;
322 } 321 }
323 322
324 void 323 void
325 QuickTimeFileReader::getSupportedExtensions(std::set<QString> &extensions) 324 QuickTimeFileReader::getSupportedExtensions(std::set<std::string> &extensions)
326 { 325 {
327 extensions.insert("aiff"); 326 extensions.insert("aiff");
328 extensions.insert("au"); 327 extensions.insert("au");
329 extensions.insert("avi"); 328 extensions.insert("avi");
330 extensions.insert("m4a"); 329 extensions.insert("m4a");