Add a hack as a possible workaround for #372

This commit is contained in:
Cameron Gutman
2019-09-14 11:49:09 -07:00
parent 73197e4378
commit 409b262a4f
3 changed files with 38 additions and 5 deletions

View File

@@ -48,10 +48,15 @@ static VideoDecoderRenderer* renderer;
int DrDecoderSetup(int videoFormat, int width, int height, int redrawRate, void* context, int drFlags)
{
[renderer setupWithVideoFormat:videoFormat];
[renderer setupWithVideoFormat:videoFormat refreshRate:redrawRate];
return 0;
}
void DrCleanup(void)
{
[renderer cleanup];
}
int DrSubmitDecodeUnit(PDECODE_UNIT decodeUnit)
{
int offset = 0;
@@ -380,6 +385,7 @@ void ClConnectionStatusUpdate(int status)
LiInitializeVideoCallbacks(&_drCallbacks);
_drCallbacks.setup = DrDecoderSetup;
_drCallbacks.cleanup = DrCleanup;
_drCallbacks.submitDecodeUnit = DrSubmitDecodeUnit;
// RFI doesn't work properly with HEVC on iOS 11 with an iPhone SE (at least)

View File

@@ -12,7 +12,9 @@
- (id)initWithView:(OSView*)view;
- (void)setupWithVideoFormat:(int)videoFormat;
- (void)setupWithVideoFormat:(int)videoFormat refreshRate:(int)refreshRate;
- (void)cleanup;
- (void)updateBufferForRange:(CMBlockBufferRef)existingBuffer data:(unsigned char *)data offset:(int)offset length:(int)nalLength;

View File

@@ -20,6 +20,8 @@
NSData *spsData, *ppsData, *vpsData;
CMVideoFormatDescriptionRef formatDesc;
CADisplayLink* _displayLink;
}
- (void)reinitializeDisplayLayer
@@ -70,12 +72,33 @@
return self;
}
- (void)setupWithVideoFormat:(int)videoFormat
- (void)setupWithVideoFormat:(int)videoFormat refreshRate:(int)refreshRate
{
self->videoFormat = videoFormat;
#if !TARGET_OS_IPHONE
_view.codec = videoFormat;
#endif
if (refreshRate > 60) {
// HACK: We seem to just get 60 Hz screen updates even with a 120 FPS stream if
// we don't set preferredFramesPerSecond somewhere. Since we're a UIKit view, we
// have to use CADisplayLink for that. See https://github.com/moonlight-stream/moonlight-ios/issues/372
_displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkCallback:)];
if (@available(iOS 10.0, tvOS 10.0, *)) {
_displayLink.preferredFramesPerSecond = refreshRate;
}
[_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
}
}
- (void)displayLinkCallback:(CADisplayLink *)sender
{
// No-op - rendering done in submitDecodeBuffer
}
- (void)cleanup
{
[_displayLink invalidate];
}
#define FRAME_START_PREFIX_SIZE 4
@@ -356,8 +379,10 @@
// Enqueue the next frame
[self->displayLayer enqueueSampleBuffer:sampleBuffer];
// Ensure the layer is visible now
self->displayLayer.hidden = NO;
if ([self isNalReferencePicture:nalType]) {
// Ensure the layer is visible now
self->displayLayer.hidden = NO;
}
// Dereference the buffers
CFRelease(blockBuffer);