#include <vlc_interface.h>
#import <QTKit/QTKit.h>
+#import <CoreAudio/CoreAudio.h>
/*****************************************************************************
* Local prototypes
{
CVImageBufferRef currentImageBuffer;
mtime_t currentPts;
+ mtime_t previousPts;
}
- (id)init;
- (void)outputVideoFrame:(CVImageBufferRef)videoFrame withSampleBuffer:(QTSampleBuffer *)sampleBuffer fromConnection:(QTCaptureConnection *)connection;
{
currentImageBuffer = nil;
currentPts = 0;
+ previousPts = 0;
}
return self;
}
{
imageBufferToRelease = currentImageBuffer;
currentImageBuffer = videoFrame;
- currentPts = 1000000L / [sampleBuffer presentationTime].timeScale * [sampleBuffer presentationTime].timeValue;
+ currentPts = (mtime_t)(1000000L / [sampleBuffer presentationTime].timeScale * [sampleBuffer presentationTime].timeValue);
+
+ /* Try to use hosttime of the sample if available, because iSight Pts seems broken */
+ NSNumber *hosttime = (NSNumber *)[sampleBuffer attributeForKey:QTSampleBufferHostTimeAttribute];
+ if( hosttime ) currentPts = (mtime_t)AudioConvertHostTimeToNanos([hosttime unsignedLongLongValue])/1000;
}
CVBufferRelease(imageBufferToRelease);
}
CVImageBufferRef imageBuffer;
mtime_t pts;
- if(!currentImageBuffer)
+ if(!currentImageBuffer || currentPts == previousPts )
return 0;
@synchronized (self)
{
imageBuffer = CVBufferRetain(currentImageBuffer);
- pts = currentPts;
+ pts = previousPts = currentPts;
CVPixelBufferLockBaseAddress(imageBuffer, 0);
void * pixels = CVPixelBufferGetBaseAddress(imageBuffer);
demux_t *p_demux = (demux_t*)p_this;
demux_sys_t *p_sys = p_demux->p_sys;
- [p_sys->session stopRunning];
- [p_sys->output release];
- [p_sys->session release];
- [p_sys->device release];
+ /* Hack: if libvlc was killed, main interface thread was,
+ * and poor QTKit needs it, so don't tell him.
+ * Else we dead lock. */
+ if( vlc_object_alive(p_this->p_libvlc))
+ {
+ [p_sys->session stopRunning];
+ [p_sys->output release];
+ [p_sys->session release];
+ }
free( p_sys );
[pool release];
/* Nothing to display yet, just forget */
block_Release( p_block );
[pool release];
+ msleep( 10000 );
return 1;
}