Mercurial > hg > svcore
comparison data/fileio/QuickTimeFileReader.cpp @ 290:92e8dbde73cd
* Revert revision 713. We do like QStrings after all.
author | Chris Cannam |
---|---|
date | Fri, 24 Aug 2007 11:41:48 +0000 |
parents | 20028c634494 |
children | 42e6c8360df1 |
comparison
equal
deleted
inserted
replaced
289:3020904de772 | 290:92e8dbde73cd |
---|---|
46 Movie movie; | 46 Movie movie; |
47 size_t blockSize; | 47 size_t blockSize; |
48 }; | 48 }; |
49 | 49 |
50 | 50 |
51 QuickTimeFileReader::QuickTimeFileReader(std::string path, | 51 QuickTimeFileReader::QuickTimeFileReader(QString 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 setError("Failed to find compatible version of QuickTime (version 7 or above required)"); | 77 m_error = QString("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 setError("Error creating data reference for QuickTime decoder", m_d->err); | 103 m_error = QString("Error creating data reference for QuickTime decoder: code %1").arg(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 setError("Error creating new movie for QuickTime decoder", m_d->err); | 114 m_error = QString("Error creating new movie for QuickTime decoder: code %1").arg(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 setError("Error checking for DRM in QuickTime decoder", m_d->err); | 143 m_error = QString("Error checking for DRM in QuickTime decoder: code %1").arg(m_d->err); |
144 return; | 144 return; |
145 } else if (!m_d->err && isProtected) { | 145 } else if (!m_d->err && isProtected) { |
146 setError("File is protected with DRM"); | 146 m_error = QString("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 setError("Error in QuickTime decoder activation", m_d->err); | 156 m_error = QString("Error in QuickTime decoder activation: code %1").arg(m_d->err); |
157 return; | 157 return; |
158 } | 158 } |
159 } else { | 159 } else { |
160 setError("Error in QuickTime decoder: Movie object not valid"); | 160 m_error = QString("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 setError("Error in QuickTime decoder extraction init", m_d->err); | 167 m_error = QString("Error in QuickTime decoder extraction init: code %1").arg(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 setError("Error in QuickTime decoder property get", m_d->err); | 179 m_error = QString("Error in QuickTime decoder property get: code %1").arg(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 setError("Error in QuickTime decoder property set", m_d->err); | 204 m_error = QString("Error in QuickTime decoder property set: code %1").arg(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.c_str()).fileName()), | 220 (QObject::tr("Decoding %1...").arg(QFileInfo(path).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 setError("Error in QuickTime decoding", m_d->err); | 232 m_error = QString("Error in QuickTime decoding: code %1") |
233 .arg(m_d->err); | |
233 break; | 234 break; |
234 } | 235 } |
235 | 236 |
236 // std::cerr << "Read " << framesRead << " frames (block size " << m_d->blockSize << ")" << std::endl; | 237 // std::cerr << "Read " << framesRead << " frames (block size " << m_d->blockSize << ")" << std::endl; |
237 | 238 |
247 | 248 |
248 finishDecodeCache(); | 249 finishDecodeCache(); |
249 | 250 |
250 m_d->err = MovieAudioExtractionEnd(m_d->extractionSessionRef); | 251 m_d->err = MovieAudioExtractionEnd(m_d->extractionSessionRef); |
251 if (m_d->err) { | 252 if (m_d->err) { |
252 setError("Error ending QuickTime extraction session", m_d->err); | 253 m_error = QString("Error ending QuickTime extraction session: code %1").arg(m_d->err); |
253 } | 254 } |
254 | 255 |
255 m_completion = 100; | 256 m_completion = 100; |
256 | 257 |
257 delete m_progress; | 258 delete m_progress; |
262 m_decodeThread = new DecodeThread(this); | 263 m_decodeThread = new DecodeThread(this); |
263 m_decodeThread->start(); | 264 m_decodeThread->start(); |
264 } | 265 } |
265 } | 266 } |
266 | 267 |
267 std::cerr << "QuickTimeFileReader::QuickTimeFileReader: frame count is now " << getFrameCount() << ", error is \"\"" << m_error << "\"" << std::endl; | 268 std::cerr << "QuickTimeFileReader::QuickTimeFileReader: frame count is now " << getFrameCount() << ", error is \"\"" << m_error.toStdString() << "\"" << std::endl; |
268 } | 269 } |
269 | 270 |
270 QuickTimeFileReader::~QuickTimeFileReader() | 271 QuickTimeFileReader::~QuickTimeFileReader() |
271 { | 272 { |
272 std::cerr << "QuickTimeFileReader::~QuickTimeFileReader" << std::endl; | 273 std::cerr << "QuickTimeFileReader::~QuickTimeFileReader" << std::endl; |
293 UInt32 extractionFlags = 0; | 294 UInt32 extractionFlags = 0; |
294 m_reader->m_d->err = MovieAudioExtractionFillBuffer | 295 m_reader->m_d->err = MovieAudioExtractionFillBuffer |
295 (m_reader->m_d->extractionSessionRef, &framesRead, | 296 (m_reader->m_d->extractionSessionRef, &framesRead, |
296 &m_reader->m_d->buffer, &extractionFlags); | 297 &m_reader->m_d->buffer, &extractionFlags); |
297 if (m_reader->m_d->err) { | 298 if (m_reader->m_d->err) { |
298 m_reader->setError("Error in QuickTime decoding", | 299 m_reader->m_error = QString("Error in QuickTime decoding: code %1") |
299 m_reader->m_d->err); | 300 .arg(m_reader->m_d->err); |
300 break; | 301 break; |
301 } | 302 } |
302 | 303 |
303 m_reader->m_frameCount += framesRead; | 304 m_reader->m_frameCount += framesRead; |
304 | 305 |
312 | 313 |
313 m_reader->finishDecodeCache(); | 314 m_reader->finishDecodeCache(); |
314 | 315 |
315 m_reader->m_d->err = MovieAudioExtractionEnd(m_reader->m_d->extractionSessionRef); | 316 m_reader->m_d->err = MovieAudioExtractionEnd(m_reader->m_d->extractionSessionRef); |
316 if (m_reader->m_d->err) { | 317 if (m_reader->m_d->err) { |
317 m_reader->setError("Error ending QuickTime extraction session", m_reader->m_d->err); | 318 m_reader->m_error = QString("Error ending QuickTime extraction session: code %1").arg(m_reader->m_d->err); |
318 } | 319 } |
319 | 320 |
320 m_reader->m_completion = 100; | 321 m_reader->m_completion = 100; |
321 } | 322 } |
322 | 323 |
323 void | 324 void |
324 QuickTimeFileReader::getSupportedExtensions(std::set<std::string> &extensions) | 325 QuickTimeFileReader::getSupportedExtensions(std::set<QString> &extensions) |
325 { | 326 { |
326 extensions.insert("aiff"); | 327 extensions.insert("aiff"); |
327 extensions.insert("au"); | 328 extensions.insert("au"); |
328 extensions.insert("avi"); | 329 extensions.insert("avi"); |
329 extensions.insert("m4a"); | 330 extensions.insert("m4a"); |