Commit 775f2164 authored by Felix Paul Kühne's avatar Felix Paul Kühne

Clean up the code a bit, turning to be half as laggy as the previous code, but...

Clean up the code a bit, turning to be half as laggy as the previous code, but it will need to be properly fixed.

Additionally, we are a good citizen now, since we actually quit our session instead of just releasing it. This takes a couple of secs though.
parent fbbabab3
...@@ -104,8 +104,7 @@ vlc_module_end(); ...@@ -104,8 +104,7 @@ vlc_module_end();
@synchronized (self) { @synchronized (self) {
imageBufferToRelease = currentImageBuffer; imageBufferToRelease = currentImageBuffer;
currentImageBuffer = videoFrame; currentImageBuffer = videoFrame;
/* FIXME: is it the right PTS? */ currentPts = [sampleBuffer presentationTime].timeValue;
currentPts = [sampleBuffer presentationTime].timeValue / [sampleBuffer presentationTime].timeScale;
} }
CVBufferRelease(imageBufferToRelease); CVBufferRelease(imageBufferToRelease);
} }
...@@ -118,12 +117,13 @@ vlc_module_end(); ...@@ -118,12 +117,13 @@ vlc_module_end();
if(!currentImageBuffer) return 0; if(!currentImageBuffer) return 0;
imageBuffer = CVBufferRetain(currentImageBuffer); imageBuffer = CVBufferRetain(currentImageBuffer);
pts = currentPts; pts = currentPts;
}
CVPixelBufferLockBaseAddress(imageBuffer, 0); CVPixelBufferLockBaseAddress(imageBuffer, 0);
void * pixels = CVPixelBufferGetBaseAddress(imageBuffer); void * pixels = CVPixelBufferGetBaseAddress(imageBuffer);
memcpy( buffer, pixels, CVPixelBufferGetBytesPerRow(imageBuffer) * CVPixelBufferGetHeight(imageBuffer) ); memcpy( buffer, pixels, CVPixelBufferGetBytesPerRow(imageBuffer) * CVPixelBufferGetHeight(imageBuffer) );
CVPixelBufferUnlockBaseAddress(imageBuffer, 0); CVPixelBufferUnlockBaseAddress(imageBuffer, 0);
}
CVBufferRelease(imageBuffer); CVBufferRelease(imageBuffer);
...@@ -137,10 +137,11 @@ vlc_module_end(); ...@@ -137,10 +137,11 @@ vlc_module_end();
*****************************************************************************/ *****************************************************************************/
struct demux_sys_t { struct demux_sys_t {
QTCaptureSession * session; QTCaptureSession * session;
VLCDecompressedVideoOutput * output; QTCaptureDevice * device;
int height, width; VLCDecompressedVideoOutput * output;
es_out_id_t * p_es_video; int height, width;
es_out_id_t * p_es_video;
}; };
...@@ -185,62 +186,73 @@ static int Open( vlc_object_t *p_this ) ...@@ -185,62 +186,73 @@ static int Open( vlc_object_t *p_this )
/* Only when selected */ /* Only when selected */
if( *p_demux->psz_access == '\0' ) if( *p_demux->psz_access == '\0' )
return VLC_EGENERIC; return VLC_EGENERIC;
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
/* Set up p_demux */
p_demux->pf_demux = Demux;
p_demux->pf_control = Control;
p_demux->info.i_update = 0;
p_demux->info.i_title = 0;
p_demux->info.i_seekpoint = 0;
p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
if( !p_sys ) return VLC_ENOMEM;
memset( p_sys, 0, sizeof( demux_sys_t ) );
memset( &fmt, 0, sizeof( es_format_t ) );
msg_Dbg( p_demux, "QTCapture Probed" ); msg_Dbg( p_demux, "QTCapture Probed" );
QTCaptureDeviceInput * input = nil; QTCaptureDeviceInput * input = nil;
QTCaptureSession * session = nil;
VLCDecompressedVideoOutput * output = nil;
QTCaptureDevice * device = [QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeVideo]; p_sys->device = [QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeVideo];
if( !device ) if( !p_sys->device )
{ {
msg_Err( p_demux, "Can't open any Video device" ); msg_Err( p_demux, "Can't find any Video device" );
goto error; goto error;
} }
if( ![device open: nil /* FIXME */] ) if( ![p_sys->device open: nil /* FIXME */] )
{ {
msg_Err( p_demux, "Can't open any Video device" ); msg_Err( p_demux, "Can't open any Video device" );
goto error; goto error;
} }
input = [[QTCaptureDeviceInput alloc] initWithDevice: device]; input = [[QTCaptureDeviceInput alloc] initWithDevice: p_sys->device];
if( !device ) if( !p_sys->device )
{ {
msg_Err( p_demux, "Can't create a capture session" ); msg_Err( p_demux, "Can't create a capture session" );
goto error; goto error;
} }
output = [[VLCDecompressedVideoOutput alloc] init]; p_sys->output = [[VLCDecompressedVideoOutput alloc] init];
/* Hack - This will lower CPU consumption for some reason */ /* Hack - This will lower CPU consumption for some reason */
[output setPixelBufferAttributes: [NSDictionary dictionaryWithObjectsAndKeys: [p_sys->output setPixelBufferAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:480], kCVPixelBufferHeightKey, [NSNumber numberWithInt:480], kCVPixelBufferHeightKey,
[NSNumber numberWithInt:640], kCVPixelBufferWidthKey, nil]]; [NSNumber numberWithInt:640], kCVPixelBufferWidthKey, nil]];
session = [[QTCaptureSession alloc] init]; p_sys->session = [[QTCaptureSession alloc] init];
bool ret = [session addInput:input error:nil /* FIXME */]; bool ret = [p_sys->session addInput:input error:nil /* FIXME */];
if( !ret ) if( !ret )
{ {
msg_Err( p_demux, "Can't add the video device as input" ); msg_Err( p_demux, "Can't add the video device as input" );
goto error; goto error;
} }
ret = [session addOutput:output error:nil /* FIXME */]; ret = [p_sys->session addOutput:p_sys->output error:nil /* FIXME */];
if( !ret ) if( !ret )
{ {
msg_Err( p_demux, "Can't get any output output" ); msg_Err( p_demux, "Can't get any output output" );
goto error; goto error;
} }
[session startRunning]; [p_sys->session startRunning];
int qtchroma = [[[device formatDescriptions] objectAtIndex: 0] formatType]; /* FIXME */ int qtchroma = [[[p_sys->device formatDescriptions] objectAtIndex: 0] formatType]; /* FIXME */
int chroma = qtchroma_to_fourcc( qtchroma ); int chroma = qtchroma_to_fourcc( qtchroma );
if( !chroma ) if( !chroma )
{ {
...@@ -250,22 +262,9 @@ static int Open( vlc_object_t *p_this ) ...@@ -250,22 +262,9 @@ static int Open( vlc_object_t *p_this )
/* Now we can init */ /* Now we can init */
/* Set up p_demux */
p_demux->pf_demux = Demux;
p_demux->pf_control = Control;
p_demux->info.i_update = 0;
p_demux->info.i_title = 0;
p_demux->info.i_seekpoint = 0;
p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
if( !p_sys ) return VLC_ENOMEM;
memset( p_sys, 0, sizeof( demux_sys_t ) );
memset( &fmt, 0, sizeof( es_format_t ) );
es_format_Init( &fmt, VIDEO_ES, chroma ); es_format_Init( &fmt, VIDEO_ES, chroma );
NSSize size = [[device attributeForKey:QTFormatDescriptionVideoEncodedPixelsSizeAttribute] sizeValue]; NSSize size = [[p_sys->device attributeForKey:QTFormatDescriptionVideoEncodedPixelsSizeAttribute] sizeValue];
p_sys->width = fmt.video.i_width = 640;/* size.width; FIXME */ p_sys->width = fmt.video.i_width = 640;/* size.width; FIXME */
p_sys->height = fmt.video.i_height = 480;/* size.height; FIXME */ p_sys->height = fmt.video.i_height = 480;/* size.height; FIXME */
...@@ -274,12 +273,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -274,12 +273,7 @@ static int Open( vlc_object_t *p_this )
p_sys->p_es_video = es_out_Add( p_demux->out, &fmt ); p_sys->p_es_video = es_out_Add( p_demux->out, &fmt );
p_sys->output = [output retain];
p_sys->session = [session retain];
[input release]; [input release];
[output release];
[session release];
[pool release]; [pool release];
msg_Dbg( p_demux, "QTCapture: We have a video device ready!" ); msg_Dbg( p_demux, "QTCapture: We have a video device ready!" );
...@@ -287,9 +281,9 @@ static int Open( vlc_object_t *p_this ) ...@@ -287,9 +281,9 @@ static int Open( vlc_object_t *p_this )
return VLC_SUCCESS; return VLC_SUCCESS;
error: error:
[input release]; [input release];
[session release]; [p_sys->device release];
[input release]; [p_sys->output release];
[output release]; [p_sys->session release];
[pool release]; [pool release];
free( p_sys ); free( p_sys );
...@@ -306,8 +300,11 @@ static void Close( vlc_object_t *p_this ) ...@@ -306,8 +300,11 @@ static void Close( vlc_object_t *p_this )
demux_t *p_demux = (demux_t*)p_this; demux_t *p_demux = (demux_t*)p_this;
demux_sys_t *p_sys = p_demux->p_sys; demux_sys_t *p_sys = p_demux->p_sys;
[p_sys->session stopRunning];
[p_sys->output release]; [p_sys->output release];
[p_sys->session release]; [p_sys->session release];
[p_sys->device release];
free( p_sys ); free( p_sys );
[pool release]; [pool release];
...@@ -332,7 +329,9 @@ static int Demux( demux_t *p_demux ) ...@@ -332,7 +329,9 @@ static int Demux( demux_t *p_demux )
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
@synchronized (p_sys->output) {
p_block->i_pts = [p_sys->output copyCurrentFrameToBuffer: p_block->p_buffer]; p_block->i_pts = [p_sys->output copyCurrentFrameToBuffer: p_block->p_buffer];
}
if( !p_block->i_pts ) if( !p_block->i_pts )
{ {
......
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