diff --git a/Limelight-iOS.xcodeproj/project.pbxproj b/Limelight-iOS.xcodeproj/project.pbxproj index b228523..8538caa 100644 --- a/Limelight-iOS.xcodeproj/project.pbxproj +++ b/Limelight-iOS.xcodeproj/project.pbxproj @@ -10,6 +10,8 @@ FBC18AE3188A2AB500D5D34E /* MainFrame.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FBC18AE2188A2AB500D5D34E /* MainFrame.storyboard */; }; FBC18B2B188A3B9100D5D34E /* MainFrameViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = FBC18B2A188A3B9100D5D34E /* MainFrameViewController.m */; }; FBC18B2F188A4E0500D5D34E /* VideoDepacketizer.m in Sources */ = {isa = PBXBuildFile; fileRef = FBC18B2E188A4E0500D5D34E /* VideoDepacketizer.m */; }; + FBC18B32188A5A1100D5D34E /* VideoDecoder.m in Sources */ = {isa = PBXBuildFile; fileRef = FBC18B31188A5A1100D5D34E /* VideoDecoder.m */; }; + FBC18B34188A5D6700D5D34E /* notpadded.h264 in Resources */ = {isa = PBXBuildFile; fileRef = FBC18B33188A5D6700D5D34E /* notpadded.h264 */; }; FBF6AE75188A274100B50578 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FBF6AE74188A274100B50578 /* Foundation.framework */; }; FBF6AE77188A274100B50578 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FBF6AE76188A274100B50578 /* CoreGraphics.framework */; }; FBF6AE79188A274100B50578 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FBF6AE78188A274100B50578 /* UIKit.framework */; }; @@ -43,6 +45,9 @@ FBC18B2A188A3B9100D5D34E /* MainFrameViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MainFrameViewController.m; sourceTree = ""; }; FBC18B2D188A4E0500D5D34E /* VideoDepacketizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VideoDepacketizer.h; path = Video/VideoDepacketizer.h; sourceTree = ""; }; FBC18B2E188A4E0500D5D34E /* VideoDepacketizer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VideoDepacketizer.m; path = Video/VideoDepacketizer.m; sourceTree = ""; }; + FBC18B30188A5A1100D5D34E /* VideoDecoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VideoDecoder.h; sourceTree = ""; }; + FBC18B31188A5A1100D5D34E /* VideoDecoder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VideoDecoder.m; sourceTree = ""; }; + FBC18B33188A5D6700D5D34E /* notpadded.h264 */ = {isa = PBXFileReference; lastKnownFileType = file; path = notpadded.h264; sourceTree = ""; }; FBF6AE71188A274100B50578 /* Limelight-iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Limelight-iOS.app"; sourceTree = BUILT_PRODUCTS_DIR; }; FBF6AE74188A274100B50578 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; FBF6AE76188A274100B50578 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; @@ -94,6 +99,8 @@ children = ( FBC18B2D188A4E0500D5D34E /* VideoDepacketizer.h */, FBC18B2E188A4E0500D5D34E /* VideoDepacketizer.m */, + FBC18B30188A5A1100D5D34E /* VideoDecoder.h */, + FBC18B31188A5A1100D5D34E /* VideoDecoder.m */, ); name = Video; sourceTree = ""; @@ -148,6 +155,7 @@ FBF6AE7D188A274100B50578 /* Supporting Files */ = { isa = PBXGroup; children = ( + FBC18B33188A5D6700D5D34E /* notpadded.h264 */, FBF6AE7E188A274100B50578 /* Limelight-iOS-Info.plist */, FBF6AE7F188A274100B50578 /* InfoPlist.strings */, FBF6AE82188A274100B50578 /* main.m */, @@ -255,6 +263,7 @@ FBC18AE3188A2AB500D5D34E /* MainFrame.storyboard in Resources */, FBF6AE81188A274100B50578 /* InfoPlist.strings in Resources */, FBF6AE8C188A274100B50578 /* Images.xcassets in Resources */, + FBC18B34188A5D6700D5D34E /* notpadded.h264 in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -275,6 +284,7 @@ files = ( FBC18B2F188A4E0500D5D34E /* VideoDepacketizer.m in Sources */, FBF6AE87188A274100B50578 /* AppDelegate.m in Sources */, + FBC18B32188A5A1100D5D34E /* VideoDecoder.m in Sources */, FBF6AE8A188A274100B50578 /* Limelight_iOS.xcdatamodeld in Sources */, FBF6AE83188A274100B50578 /* main.m in Sources */, FBC18B2B188A3B9100D5D34E /* MainFrameViewController.m in Sources */, @@ -338,6 +348,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; + DSTROOT = "/tmp/$(PROJECT_NAME).dst"; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; @@ -354,6 +365,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 7.0; ONLY_ACTIVE_ARCH = YES; + PRODUCT_NAME = Limelight; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; }; @@ -378,6 +390,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = YES; + DSTROOT = "/tmp/$(PROJECT_NAME).dst"; ENABLE_NS_ASSERTIONS = NO; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; @@ -387,6 +400,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 7.0; + PRODUCT_NAME = Limelight; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; diff --git a/Limelight-iOS/MainFrameViewController.m b/Limelight-iOS/MainFrameViewController.m index c5620c7..36eac4a 100644 --- a/Limelight-iOS/MainFrameViewController.m +++ b/Limelight-iOS/MainFrameViewController.m @@ -7,6 +7,7 @@ // #import "MainFrameViewController.h" +#import "VideoDepacketizer.h" @interface MainFrameViewController () @@ -22,6 +23,12 @@ - (void)StreamButton:(UIButton *)sender { NSLog(@"Stream Button Pressed!"); + VideoDepacketizer* depacketizer = [[VideoDepacketizer alloc] init]; + + NSString* path = [[NSBundle mainBundle] pathForResource:@"notpadded" + ofType:@"h264"]; + NSLog(@"Path: %@", path); + [depacketizer readFile:path]; } - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component diff --git a/Limelight-iOS/Video/VideoDepacketizer.h b/Limelight-iOS/Video/VideoDepacketizer.h new file mode 100644 index 0000000..451e3b3 --- /dev/null +++ b/Limelight-iOS/Video/VideoDepacketizer.h @@ -0,0 +1,19 @@ +// +// VideoDepacketizer.h +// Limelight-iOS +// +// Created by Diego Waxemberg on 1/18/14. +// Copyright (c) 2014 Diego Waxemberg. All rights reserved. +// + +#import +#import "VideoDecoder.h" + +@interface VideoDepacketizer : NSObject +@property uint8_t* byteBuffer; +@property unsigned int offset; +@property VideoDecoder* decoder; + +- (void) readFile:(NSString*) file; + +@end diff --git a/Limelight-iOS/Video/VideoDepacketizer.m b/Limelight-iOS/Video/VideoDepacketizer.m new file mode 100644 index 0000000..b972889 --- /dev/null +++ b/Limelight-iOS/Video/VideoDepacketizer.m @@ -0,0 +1,89 @@ +// +// VideoDepacketizer.m +// Limelight-iOS +// +// Created by Diego Waxemberg on 1/18/14. +// Copyright (c) 2014 Diego Waxemberg. All rights reserved. +// + +#import "VideoDepacketizer.h" + +@implementation VideoDepacketizer +static int BUFFER_LENGTH = 131072; + +- (void) readFile:(NSString*) file +{ + NSLog(@"Allocating input stream\n"); + NSInputStream* inStream = [[NSInputStream alloc] initWithFileAtPath:file]; + NSLog(@"Allocating byteBuffer"); + self.byteBuffer = malloc(BUFFER_LENGTH); + NSLog(@"byte pointer: %p", self.byteBuffer); + [inStream setDelegate:self]; + + NSLog(@"Allocating decoder"); + self.decoder = [[VideoDecoder alloc]init]; + NSLog(@"old self pointer: %p", self); + + [inStream open]; + while ([inStream streamStatus] != NSStreamStatusOpen) { + NSLog(@"stream status: %d", [inStream streamStatus]); + sleep(1); + } + while ([inStream streamStatus] != NSStreamStatusAtEnd) + { + unsigned int len = 0; + NSLog(@"Reading File\n"); + NSLog(@"stream pointer: %p", inStream); + NSLog(@"self pointer: %p", self); + NSLog(@"byte buffer pointer: %p", self.byteBuffer); + len = [(NSInputStream *)inStream read:self.byteBuffer maxLength:BUFFER_LENGTH]; + if (len) + { + NSLog(@"len: %u\n", len); + BOOL firstStart = false; + for (int i = 0; i < len - 4; i++) { + if (self.byteBuffer[i] == 0 && self.byteBuffer[i+1] == 0 + && self.byteBuffer[i+2] == 0 && self.byteBuffer[i+3] == 1) + { + NSLog(@"i: %d", i); + self.offset++; + if (firstStart) + { + // decode the first i-1 bytes + [self.decoder decode:self.byteBuffer length:i-1]; + [inStream setProperty:[[NSNumber alloc] initWithInt:self.offset-4] forKey:NSStreamFileCurrentOffsetKey]; + self.offset -= 4; + } else + { + firstStart = true; + } + } + } + } + else + { + NSLog(@"No Buffer!"); + } + } + + +} + +- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode +{ + switch (eventCode) + { + case NSStreamEventHasBytesAvailable: + { + break; + } + default: + { + NSLog(@"eventCode: %u", eventCode); + } + + } +} + + +@end diff --git a/Limelight-iOS/VideoDecoder.h b/Limelight-iOS/VideoDecoder.h new file mode 100644 index 0000000..b2e208c --- /dev/null +++ b/Limelight-iOS/VideoDecoder.h @@ -0,0 +1,13 @@ +// +// VideoDecoder.h +// Limelight-iOS +// +// Created by Diego Waxemberg on 1/18/14. +// Copyright (c) 2014 Diego Waxemberg. All rights reserved. +// + +#import + +@interface VideoDecoder : NSObject +- (void) decode:(uint8_t*)buffer length:(unsigned int)length; +@end diff --git a/Limelight-iOS/VideoDecoder.m b/Limelight-iOS/VideoDecoder.m new file mode 100644 index 0000000..6d3b195 --- /dev/null +++ b/Limelight-iOS/VideoDecoder.m @@ -0,0 +1,23 @@ +// +// VideoDecoder.m +// Limelight-iOS +// +// Created by Diego Waxemberg on 1/18/14. +// Copyright (c) 2014 Diego Waxemberg. All rights reserved. +// + +#import "VideoDecoder.h" + +@implementation VideoDecoder +- (void)decode:(uint8_t *)buffer length:(unsigned int)length +{ + for (int i = 0; i < length; i++) { + printf("%02x ", buffer[i]); + if (i != 0 && i % 16 == 0) { + NSLog(@""); + } + } + + +} +@end diff --git a/Limelight-iOS/notpadded.h264 b/Limelight-iOS/notpadded.h264 new file mode 100644 index 0000000..8607070 Binary files /dev/null and b/Limelight-iOS/notpadded.h264 differ