mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2026-06-17 14:11:35 +00:00
A little bit of code cleanup
This commit is contained in:
@@ -25,7 +25,7 @@ static NSLock *controllerStreamLock;
|
|||||||
GCController *controller = [GCController controllers][i];
|
GCController *controller = [GCController controllers][i];
|
||||||
|
|
||||||
if (controller != NULL) {
|
if (controller != NULL) {
|
||||||
printf("Controller connected!\n");
|
NSLog(@"Controller connected!");
|
||||||
controller.controllerPausedHandler = ^(GCController *controller) {
|
controller.controllerPausedHandler = ^(GCController *controller) {
|
||||||
// We call LiSendControllerEvent while holding a lock to prevent
|
// We call LiSendControllerEvent while holding a lock to prevent
|
||||||
// multiple simultaneous calls since this function isn't thread safe.
|
// multiple simultaneous calls since this function isn't thread safe.
|
||||||
@@ -117,7 +117,7 @@ static NSLock *controllerStreamLock;
|
|||||||
[ControllerSupport registerControllerCallbacks];
|
[ControllerSupport registerControllerCallbacks];
|
||||||
}];
|
}];
|
||||||
self.disconnectObserver = [[NSNotificationCenter defaultCenter] addObserverForName:GCControllerDidDisconnectNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
|
self.disconnectObserver = [[NSNotificationCenter defaultCenter] addObserverForName:GCControllerDidDisconnectNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
|
||||||
printf("Controller disconnected!\n");
|
NSLog(@"Controller disconnected!");
|
||||||
}];
|
}];
|
||||||
|
|
||||||
[ControllerSupport registerControllerCallbacks];
|
[ControllerSupport registerControllerCallbacks];
|
||||||
|
|||||||
@@ -36,8 +36,9 @@
|
|||||||
|
|
||||||
#define FRAME_START_PREFIX_SIZE 4
|
#define FRAME_START_PREFIX_SIZE 4
|
||||||
#define NALU_START_PREFIX_SIZE 3
|
#define NALU_START_PREFIX_SIZE 3
|
||||||
|
|
||||||
#define NAL_LENGTH_PREFIX_SIZE 4
|
#define NAL_LENGTH_PREFIX_SIZE 4
|
||||||
|
#define NAL_TYPE_SPS 0x7
|
||||||
|
#define NAL_TYPE_PPS 0x8
|
||||||
|
|
||||||
- (void)updateBufferForRange:(CMBlockBufferRef)existingBuffer data:(unsigned char *)data offset:(int)offset length:(int)nalLength
|
- (void)updateBufferForRange:(CMBlockBufferRef)existingBuffer data:(unsigned char *)data offset:(int)offset length:(int)nalLength
|
||||||
{
|
{
|
||||||
@@ -58,7 +59,7 @@
|
|||||||
kCFAllocatorDefault,
|
kCFAllocatorDefault,
|
||||||
NULL, 0, nalLength + 1, 0);
|
NULL, 0, nalLength + 1, 0);
|
||||||
if (status != noErr) {
|
if (status != noErr) {
|
||||||
printf("CMBlockBufferReplaceDataBytes failed: %d\n", (int)status);
|
NSLog(@"CMBlockBufferReplaceDataBytes failed: %d", (int)status);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,18 +69,17 @@
|
|||||||
status = CMBlockBufferReplaceDataBytes(lengthBytes, existingBuffer,
|
status = CMBlockBufferReplaceDataBytes(lengthBytes, existingBuffer,
|
||||||
oldOffset, NAL_LENGTH_PREFIX_SIZE);
|
oldOffset, NAL_LENGTH_PREFIX_SIZE);
|
||||||
if (status != noErr) {
|
if (status != noErr) {
|
||||||
printf("CMBlockBufferReplaceDataBytes failed: %d\n", (int)status);
|
NSLog(@"CMBlockBufferReplaceDataBytes failed: %d", (int)status);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Append a 4 byte buffer to this block for the length prefix
|
// Append a 4 byte buffer to this block for the length prefix
|
||||||
status = CMBlockBufferAppendMemoryBlock(existingBuffer, NULL,
|
status = CMBlockBufferAppendMemoryBlock(existingBuffer, NULL,
|
||||||
NAL_LENGTH_PREFIX_SIZE,
|
NAL_LENGTH_PREFIX_SIZE,
|
||||||
kCFAllocatorDefault, NULL, 0,
|
kCFAllocatorDefault, NULL, 0,
|
||||||
NAL_LENGTH_PREFIX_SIZE, 0);
|
NAL_LENGTH_PREFIX_SIZE, 0);
|
||||||
if (status != noErr) {
|
if (status != noErr) {
|
||||||
printf("CMBlockBufferAppendMemoryBlock failed: %d\n", (int)status);
|
NSLog(@"CMBlockBufferAppendMemoryBlock failed: %d", (int)status);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@
|
|||||||
status = CMBlockBufferReplaceDataBytes(lengthBytes, existingBuffer,
|
status = CMBlockBufferReplaceDataBytes(lengthBytes, existingBuffer,
|
||||||
oldOffset, NAL_LENGTH_PREFIX_SIZE);
|
oldOffset, NAL_LENGTH_PREFIX_SIZE);
|
||||||
if (status != noErr) {
|
if (status != noErr) {
|
||||||
printf("CMBlockBufferReplaceDataBytes failed: %d\n", (int)status);
|
NSLog(@"CMBlockBufferReplaceDataBytes failed: %d", (int)status);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@
|
|||||||
kCFAllocatorNull, // Don't deallocate data on free
|
kCFAllocatorNull, // Don't deallocate data on free
|
||||||
NULL, 0, dataLength, 0);
|
NULL, 0, dataLength, 0);
|
||||||
if (status != noErr) {
|
if (status != noErr) {
|
||||||
printf("CMBlockBufferReplaceDataBytes failed: %d\n", (int)status);
|
NSLog(@"CMBlockBufferReplaceDataBytes failed: %d", (int)status);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,17 +112,16 @@
|
|||||||
unsigned char nalType = data[FRAME_START_PREFIX_SIZE] & 0x1F;
|
unsigned char nalType = data[FRAME_START_PREFIX_SIZE] & 0x1F;
|
||||||
OSStatus status;
|
OSStatus status;
|
||||||
|
|
||||||
if (nalType == 0x7 || nalType == 0x8) {
|
if (nalType == NAL_TYPE_SPS || nalType == NAL_TYPE_PPS) {
|
||||||
if (nalType == 0x7) {
|
if (nalType == NAL_TYPE_SPS) {
|
||||||
printf("Got SPS\n");
|
NSLog(@"Got SPS");
|
||||||
spsData = [NSData dataWithBytes:&data[FRAME_START_PREFIX_SIZE] length:length - FRAME_START_PREFIX_SIZE];
|
spsData = [NSData dataWithBytes:&data[FRAME_START_PREFIX_SIZE] length:length - FRAME_START_PREFIX_SIZE];
|
||||||
waitingForSps = false;
|
waitingForSps = false;
|
||||||
|
|
||||||
// We got a new SPS so wait for a new PPS to match it
|
// We got a new SPS so wait for a new PPS to match it
|
||||||
waitingForPps = true;
|
waitingForPps = true;
|
||||||
}
|
} else if (nalType == NAL_TYPE_PPS) {
|
||||||
else if (nalType == 0x8) {
|
NSLog(@"Got PPS");
|
||||||
printf("Got PPS\n");
|
|
||||||
ppsData = [NSData dataWithBytes:&data[FRAME_START_PREFIX_SIZE] length:length - FRAME_START_PREFIX_SIZE];
|
ppsData = [NSData dataWithBytes:&data[FRAME_START_PREFIX_SIZE] length:length - FRAME_START_PREFIX_SIZE];
|
||||||
waitingForPps = false;
|
waitingForPps = false;
|
||||||
}
|
}
|
||||||
@@ -132,7 +131,7 @@
|
|||||||
const uint8_t* const parameterSetPointers[] = { [spsData bytes], [ppsData bytes] };
|
const uint8_t* const parameterSetPointers[] = { [spsData bytes], [ppsData bytes] };
|
||||||
const size_t parameterSetSizes[] = { [spsData length], [ppsData length] };
|
const size_t parameterSetSizes[] = { [spsData length], [ppsData length] };
|
||||||
|
|
||||||
printf("Constructing new format description\n");
|
NSLog(@"Constructing new format description");
|
||||||
status = CMVideoFormatDescriptionCreateFromH264ParameterSets(kCFAllocatorDefault,
|
status = CMVideoFormatDescriptionCreateFromH264ParameterSets(kCFAllocatorDefault,
|
||||||
2, /* count of parameter sets */
|
2, /* count of parameter sets */
|
||||||
parameterSetPointers,
|
parameterSetPointers,
|
||||||
@@ -140,7 +139,7 @@
|
|||||||
NAL_LENGTH_PREFIX_SIZE,
|
NAL_LENGTH_PREFIX_SIZE,
|
||||||
&formatDesc);
|
&formatDesc);
|
||||||
if (status != noErr) {
|
if (status != noErr) {
|
||||||
printf("Failed to create format description: %d\n", (int)status);
|
NSLog(@"Failed to create format description: %d", (int)status);
|
||||||
formatDesc = NULL;
|
formatDesc = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -169,7 +168,7 @@
|
|||||||
|
|
||||||
status = CMBlockBufferCreateEmpty(NULL, 0, 0, &blockBuffer);
|
status = CMBlockBufferCreateEmpty(NULL, 0, 0, &blockBuffer);
|
||||||
if (status != noErr) {
|
if (status != noErr) {
|
||||||
printf("CMBlockBufferCreateEmpty failed: %d\n", (int)status);
|
NSLog(@"CMBlockBufferCreateEmpty failed: %d", (int)status);
|
||||||
free(data);
|
free(data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -204,7 +203,7 @@
|
|||||||
NULL, 0, NULL,
|
NULL, 0, NULL,
|
||||||
&sampleBuffer);
|
&sampleBuffer);
|
||||||
if (status != noErr) {
|
if (status != noErr) {
|
||||||
printf("CMSampleBufferCreate failed: %d\n", (int)status);
|
NSLog(@"CMSampleBufferCreate failed: %d", (int)status);
|
||||||
CFRelease(blockBuffer);
|
CFRelease(blockBuffer);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -219,8 +218,7 @@
|
|||||||
// P-frame
|
// P-frame
|
||||||
CFDictionarySetValue(dict, kCMSampleAttachmentKey_NotSync, kCFBooleanTrue);
|
CFDictionarySetValue(dict, kCMSampleAttachmentKey_NotSync, kCFBooleanTrue);
|
||||||
CFDictionarySetValue(dict, kCMSampleAttachmentKey_DependsOnOthers, kCFBooleanTrue);
|
CFDictionarySetValue(dict, kCMSampleAttachmentKey_DependsOnOthers, kCFBooleanTrue);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// I-frame
|
// I-frame
|
||||||
CFDictionarySetValue(dict, kCMSampleAttachmentKey_NotSync, kCFBooleanFalse);
|
CFDictionarySetValue(dict, kCMSampleAttachmentKey_NotSync, kCFBooleanFalse);
|
||||||
CFDictionarySetValue(dict, kCMSampleAttachmentKey_DependsOnOthers, kCFBooleanFalse);
|
CFDictionarySetValue(dict, kCMSampleAttachmentKey_DependsOnOthers, kCFBooleanFalse);
|
||||||
|
|||||||
@@ -57,7 +57,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void) connectionStarted {
|
- (void) connectionStarted {
|
||||||
printf("Connection started\n");
|
NSLog(@"Connection started");
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[self.spinner stopAnimating];
|
[self.spinner stopAnimating];
|
||||||
[self.stageLabel setText:@"Waiting for first frame..."];
|
[self.stageLabel setText:@"Waiting for first frame..."];
|
||||||
|
|||||||
Reference in New Issue
Block a user