Merge pull request #1761 from bhuroc:qtkit-video-file-2.4
authorRoman Donchenko <roman.donchenko@itseez.com>
Wed, 20 Nov 2013 09:36:37 +0000 (13:36 +0400)
committerOpenCV Buildbot <buildbot@opencv.org>
Wed, 20 Nov 2013 09:36:37 +0000 (13:36 +0400)
modules/highgui/src/cap_qtkit.mm

index ef7b42a..6b91597 100644 (file)
@@ -179,6 +179,7 @@ private:
     int changedPos;
 
     int started;
+    QTTime endOfMovie;
 };
 
 
@@ -673,6 +674,8 @@ CvCaptureFile::CvCaptureFile(const char* filename) {
         return;
     }
 
+    [mCaptureSession gotoEnd];
+    endOfMovie = [mCaptureSession currentTime];
 
     [mCaptureSession gotoBeginning];
 
@@ -709,6 +712,11 @@ int CvCaptureFile::didStart() {
 bool CvCaptureFile::grabFrame() {
     NSAutoreleasePool* localpool = [[NSAutoreleasePool alloc] init];
     double t1 = getProperty(CV_CAP_PROP_POS_MSEC);
+
+    QTTime curTime;
+    curTime = [mCaptureSession currentTime];
+    bool isEnd=(QTTimeCompare(curTime,endOfMovie) == NSOrderedSame);
+
     [mCaptureSession stepForward];
     double t2 = getProperty(CV_CAP_PROP_POS_MSEC);
     if (t2>t1 && !changedPos) {
@@ -718,7 +726,7 @@ bool CvCaptureFile::grabFrame() {
     }
     changedPos = 0;
     [localpool drain];
-    return 1;
+    return !isEnd;
 }