From 1b98870b4141e59b86dae49c16de2644da90ca1d Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Thu, 23 Oct 2014 22:35:59 -0400 Subject: [PATCH] Fix missing video issue --- Limelight/Stream/VideoDecoderRenderer.m | 41 ++++++++++--------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/Limelight/Stream/VideoDecoderRenderer.m b/Limelight/Stream/VideoDecoderRenderer.m index be79694..c8f10c0 100644 --- a/Limelight/Stream/VideoDecoderRenderer.m +++ b/Limelight/Stream/VideoDecoderRenderer.m @@ -10,10 +10,9 @@ @implementation VideoDecoderRenderer { AVSampleBufferDisplayLayer* displayLayer; - Boolean waitingForSps, waitingForPpsA, waitingForPpsB; + Boolean waitingForSps, waitingForPps; - NSData *spsData, *ppsDataA, *ppsDataB; - unsigned char ppsDataAFirstByte; + NSData *spsData, *ppsData; CMVideoFormatDescriptionRef formatDesc; } @@ -30,8 +29,7 @@ // We need some parameter sets before we can properly start decoding frames waitingForSps = true; - waitingForPpsA = true; - waitingForPpsB = true; + waitingForPps = true; return self; } @@ -114,34 +112,27 @@ unsigned char nalType = data[FRAME_START_PREFIX_SIZE] & 0x1F; OSStatus status; - if (formatDesc == NULL && (nalType == 0x7 || nalType == 0x8)) { - if (waitingForSps && nalType == 0x7) { + if (nalType == 0x7 || nalType == 0x8) { + if (nalType == 0x7) { printf("Got SPS\n"); spsData = [NSData dataWithBytes:&data[FRAME_START_PREFIX_SIZE] length:length - FRAME_START_PREFIX_SIZE]; waitingForSps = false; + + // We got a new SPS so wait for a new PPS to match it + waitingForPps = true; } - // Nvidia's stream has 2 PPS NALUs so we'll wait for both of them - else if ((waitingForPpsA || waitingForPpsB) && nalType == 0x8) { - // Read the NALU's PPS index to figure out which PPS this is - if (waitingForPpsA) { - printf("Got PPS 1\n"); - ppsDataA = [NSData dataWithBytes:&data[FRAME_START_PREFIX_SIZE] length:length - FRAME_START_PREFIX_SIZE]; - waitingForPpsA = false; - ppsDataAFirstByte = data[FRAME_START_PREFIX_SIZE + 1]; - } - else if (data[FRAME_START_PREFIX_SIZE + 1] != ppsDataAFirstByte) { - printf("Got PPS 2\n"); - ppsDataA = [NSData dataWithBytes:&data[FRAME_START_PREFIX_SIZE] length:length - FRAME_START_PREFIX_SIZE]; - waitingForPpsB = false; - } + else if (nalType == 0x8) { + printf("Got PPS\n"); + ppsData = [NSData dataWithBytes:&data[FRAME_START_PREFIX_SIZE] length:length - FRAME_START_PREFIX_SIZE]; + waitingForPps = false; } // See if we've got all the parameter sets we need - if (!waitingForSps && !waitingForPpsA && !waitingForPpsB) { - const uint8_t* const parameterSetPointers[] = { [spsData bytes], [ppsDataA bytes], [ppsDataB bytes] }; - const size_t parameterSetSizes[] = { [spsData length], [ppsDataA length], [ppsDataB length] }; + if (!waitingForSps && !waitingForPps) { + const uint8_t* const parameterSetPointers[] = { [spsData bytes], [ppsData bytes] }; + const size_t parameterSetSizes[] = { [spsData length], [ppsData length] }; - printf("Constructing format description\n"); + printf("Constructing new format description\n"); status = CMVideoFormatDescriptionCreateFromH264ParameterSets(kCFAllocatorDefault, 2, /* count of parameter sets */ parameterSetPointers,