Commit d7b85468 authored by Alexandre Lision's avatar Alexandre Lision

video: disconnect preview

lambda registered for frameUpdated was still alive after closing the window.
It was consuming frames, preventing the call to get them.
It's a limitation of our implementetation: there is only one possible receiver
of frameUpdated for a given renderer.

Tuleap: #130
Change-Id: Ic8f5b8efea60e3409c77e4510320e3eba11fe21d
parent 0e66aea4
...@@ -99,17 +99,12 @@ QMetaObject::Connection previewStopped; ...@@ -99,17 +99,12 @@ QMetaObject::Connection previewStopped;
} }
// check if preview has to be started/stopped by this controller
self.shouldHandlePreview = !Video::PreviewManager::instance().isPreviewing();
[previewView setWantsLayer:YES]; [previewView setWantsLayer:YES];
[previewView setLayer:[CALayer layer]]; [previewView setLayer:[CALayer layer]];
[previewView.layer setBackgroundColor:[NSColor blackColor].CGColor]; [previewView.layer setBackgroundColor:[NSColor blackColor].CGColor];
[previewView.layer setContentsGravity:kCAGravityResizeAspect]; [previewView.layer setContentsGravity:kCAGravityResizeAspect];
[previewView.layer setFrame:previewView.frame]; [previewView.layer setFrame:previewView.frame];
[previewView.layer setBounds:previewView.frame]; [previewView.layer setBounds:previewView.frame];
[self connectPreviewSignals];
} }
- (IBAction)chooseDevice:(id)sender { - (IBAction)chooseDevice:(id)sender {
...@@ -135,32 +130,33 @@ QMetaObject::Connection previewStopped; ...@@ -135,32 +130,33 @@ QMetaObject::Connection previewStopped;
QObject::disconnect(frameUpdated); QObject::disconnect(frameUpdated);
QObject::disconnect(previewStopped); QObject::disconnect(previewStopped);
QObject::disconnect(previewStarted); QObject::disconnect(previewStarted);
previewStarted = QObject::connect(&Video::PreviewManager::instance(), previewStarted = QObject::connect(&Video::PreviewManager::instance(),
&Video::PreviewManager::previewStarted, &Video::PreviewManager::previewStarted,
[=](Video::Renderer* renderer) { [=](Video::Renderer* renderer) {
NSLog(@"Preview started"); NSLog(@"Preview started");
QObject::disconnect(frameUpdated); QObject::disconnect(frameUpdated);
frameUpdated = QObject::connect(renderer, frameUpdated = QObject::connect(renderer,
&Video::Renderer::frameUpdated, &Video::Renderer::frameUpdated,
[=]() { [=]() {
[self renderer:Video::PreviewManager::instance().previewRenderer() renderFrameForView:previewView]; [self renderer:Video::PreviewManager::instance().previewRenderer() renderFrameForView:previewView];
}); });
}); });
previewStopped = QObject::connect(&Video::PreviewManager::instance(), previewStopped = QObject::connect(&Video::PreviewManager::instance(),
&Video::PreviewManager::previewStopped, &Video::PreviewManager::previewStopped,
[=](Video::Renderer* renderer) { [=](Video::Renderer* renderer) {
NSLog(@"Preview stopped"); NSLog(@"Preview stopped");
QObject::disconnect(frameUpdated); QObject::disconnect(frameUpdated);
[previewView.layer setContents:nil]; [previewView.layer setContents:nil];
}); });
frameUpdated = QObject::connect(Video::PreviewManager::instance().previewRenderer(), frameUpdated = QObject::connect(Video::PreviewManager::instance().previewRenderer(),
&Video::Renderer::frameUpdated, &Video::Renderer::frameUpdated,
[=]() { [=]() {
[self renderer:Video::PreviewManager::instance().previewRenderer() [self renderer:Video::PreviewManager::instance().previewRenderer()
renderFrameForView:previewView]; renderFrameForView:previewView];
}); });
} }
-(void) renderer: (Video::Renderer*)renderer renderFrameForView:(NSView*) view -(void) renderer: (Video::Renderer*)renderer renderFrameForView:(NSView*) view
...@@ -197,6 +193,10 @@ QMetaObject::Connection previewStopped; ...@@ -197,6 +193,10 @@ QMetaObject::Connection previewStopped;
- (void) viewWillAppear - (void) viewWillAppear
{ {
// check if preview has to be started/stopped by this controller
self.shouldHandlePreview = !Video::PreviewManager::instance().previewRenderer()->isRendering();
[self connectPreviewSignals];
if (self.shouldHandlePreview) { if (self.shouldHandlePreview) {
Video::PreviewManager::instance().startPreview(); Video::PreviewManager::instance().startPreview();
} }
...@@ -204,6 +204,9 @@ QMetaObject::Connection previewStopped; ...@@ -204,6 +204,9 @@ QMetaObject::Connection previewStopped;
- (void)viewWillDisappear - (void)viewWillDisappear
{ {
QObject::disconnect(frameUpdated);
QObject::disconnect(previewStopped);
QObject::disconnect(previewStarted);
if (self.shouldHandlePreview) { if (self.shouldHandlePreview) {
Video::PreviewManager::instance().stopPreview(); Video::PreviewManager::instance().stopPreview();
} }
......
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