Commit 114579c3 authored by Bo Hu's avatar Bo Hu

Added proper testing of the end of quicktime video files.

CvCaptureFile::grabFrame() always returns 1 regardless, which causes
dead loop when relying on the return value of VideoCapture::read().
parent 296f76a1
...@@ -179,6 +179,7 @@ private: ...@@ -179,6 +179,7 @@ private:
int changedPos; int changedPos;
int started; int started;
QTTime endOfMovie;
}; };
...@@ -673,6 +674,8 @@ CvCaptureFile::CvCaptureFile(const char* filename) { ...@@ -673,6 +674,8 @@ CvCaptureFile::CvCaptureFile(const char* filename) {
return; return;
} }
[mCaptureSession gotoEnd];
endOfMovie = [mCaptureSession currentTime];
[mCaptureSession gotoBeginning]; [mCaptureSession gotoBeginning];
...@@ -709,6 +712,11 @@ int CvCaptureFile::didStart() { ...@@ -709,6 +712,11 @@ int CvCaptureFile::didStart() {
bool CvCaptureFile::grabFrame() { bool CvCaptureFile::grabFrame() {
NSAutoreleasePool* localpool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool* localpool = [[NSAutoreleasePool alloc] init];
double t1 = getProperty(CV_CAP_PROP_POS_MSEC); double t1 = getProperty(CV_CAP_PROP_POS_MSEC);
QTTime curTime;
curTime = [mCaptureSession currentTime];
bool isEnd=(QTTimeCompare(curTime,endOfMovie) == NSOrderedSame);
[mCaptureSession stepForward]; [mCaptureSession stepForward];
double t2 = getProperty(CV_CAP_PROP_POS_MSEC); double t2 = getProperty(CV_CAP_PROP_POS_MSEC);
if (t2>t1 && !changedPos) { if (t2>t1 && !changedPos) {
...@@ -718,7 +726,7 @@ bool CvCaptureFile::grabFrame() { ...@@ -718,7 +726,7 @@ bool CvCaptureFile::grabFrame() {
} }
changedPos = 0; changedPos = 0;
[localpool drain]; [localpool drain];
return 1; return !isEnd;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment