diff --git a/Limelight/Stream/StreamManager.m b/Limelight/Stream/StreamManager.m index c924027..06967b6 100644 --- a/Limelight/Stream/StreamManager.m +++ b/Limelight/Stream/StreamManager.m @@ -88,10 +88,13 @@ _config.appVersion = appversion; _config.gfeVersion = gfeVersion; - VideoDecoderRenderer* renderer = [[VideoDecoderRenderer alloc]initWithView:_renderView]; - _connection = [[Connection alloc] initWithConfig:_config renderer:renderer connectionCallbacks:_callbacks]; - NSOperationQueue* opQueue = [[NSOperationQueue alloc] init]; - [opQueue addOperation:_connection]; + // Initializing the renderer must be done on the main thread + dispatch_async(dispatch_get_main_queue(), ^{ + VideoDecoderRenderer* renderer = [[VideoDecoderRenderer alloc] initWithView:self->_renderView]; + self->_connection = [[Connection alloc] initWithConfig:self->_config renderer:renderer connectionCallbacks:self->_callbacks]; + NSOperationQueue* opQueue = [[NSOperationQueue alloc] init]; + [opQueue addOperation:self->_connection]; + }); } - (void) stopStream diff --git a/Limelight/Stream/VideoDecoderRenderer.m b/Limelight/Stream/VideoDecoderRenderer.m index 151b251..ac95e9b 100644 --- a/Limelight/Stream/VideoDecoderRenderer.m +++ b/Limelight/Stream/VideoDecoderRenderer.m @@ -33,6 +33,10 @@ displayLayer.position = CGPointMake(CGRectGetMidX(_view.bounds), CGRectGetMidY(_view.bounds)); displayLayer.videoGravity = AVLayerVideoGravityResizeAspect; + // Hide the layer until we get an IDR frame. This ensures we + // can see the loading progress label as the stream is starting. + displayLayer.hidden = YES; + if (oldLayer != nil) { // Switch out the old display layer with the new one [_view.layer replaceSublayer:oldLayer with:displayLayer]; @@ -349,8 +353,12 @@ // Enqueue video samples on the main thread dispatch_async(dispatch_get_main_queue(), ^{ + // Enqueue the next frame [self->displayLayer enqueueSampleBuffer:sampleBuffer]; + // Ensure the layer is visible now + self->displayLayer.hidden = NO; + // Dereference the buffers CFRelease(blockBuffer); CFRelease(sampleBuffer);