From 72ed023645e4a8f1d6dc79013e3534d177f22cd6 Mon Sep 17 00:00:00 2001 From: Diego Waxemberg Date: Sat, 18 Jan 2014 21:39:29 -0500 Subject: [PATCH] view is now centered and rendering is flipped correctly --- Limelight-iOS/StreamFrameViewController.m | 17 ++++++++++--- Limelight-iOS/StreamView.m | 30 ++++++----------------- Limelight-iOS/Video/VideoDepacketizer.m | 24 +++++------------- 3 files changed, 28 insertions(+), 43 deletions(-) diff --git a/Limelight-iOS/StreamFrameViewController.m b/Limelight-iOS/StreamFrameViewController.m index 4ddcd80..222226f 100644 --- a/Limelight-iOS/StreamFrameViewController.m +++ b/Limelight-iOS/StreamFrameViewController.m @@ -18,14 +18,25 @@ - (void)viewDidLoad { [super viewDidLoad]; + StreamView* streamView = [[StreamView alloc] initWithFrame:self.view.frame]; streamView.backgroundColor = [UIColor blackColor]; [self.view addSubview:streamView]; - [streamView setNeedsDisplay]; - - // Do any additional setup after loading the view. + + + + CGAffineTransform transform = CGAffineTransformMakeTranslation((streamView.frame.size.height/2) - (streamView.frame.size.width/2), (streamView.frame.size.width/2) - (streamView.frame.size.height/2)); + transform = CGAffineTransformRotate(transform, M_PI_2); + transform = CGAffineTransformScale(transform, -1, -1); + streamView.transform = transform; + + // Repositions and resizes the view. + CGRect contentRect = CGRectMake(0,0, self.view.frame.size.width, self.view.frame.size.height); + streamView.bounds = contentRect; + + // Do any additional setup after loading the view. NSString* path = [[NSBundle mainBundle] pathForResource:@"notpadded" ofType:@"h264"]; NSLog(@"Path: %@", path); diff --git a/Limelight-iOS/StreamView.m b/Limelight-iOS/StreamView.m index c764a22..f38c336 100644 --- a/Limelight-iOS/StreamView.m +++ b/Limelight-iOS/StreamView.m @@ -27,17 +27,16 @@ static bool firstFrame = true; - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; - NSLog(@"initWithFrame"); + // Initialization code + width = 1280; height = 720; bitsPerComponent = 8; bytesPerRow = (bitsPerComponent / 8) * width * 4; pixelData = malloc(width * height * 4); colorSpace = CGColorSpaceCreateDeviceRGB(); - //bitmapContext = CGBitmapContextCreate(pixelData, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGBitmapByteOrderDefault); - //image = CGBitmapContextCreateImage(bitmapContext); - + return self; } @@ -47,34 +46,21 @@ static bool firstFrame = true; // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { - NSLog(@"drawRect"); if (!nv_avc_get_rgb_frame(pixelData, width*height*4)) { + NSLog(@"failed to decode frame!"); return; } - if (firstFrame) { - - NSData *data = [[NSData alloc] initWithBytes:pixelData length:(width*height*4)]; - NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); - NSString *documentsDirectory = [paths objectAtIndex:0]; - NSString *appFile = [documentsDirectory stringByAppendingPathComponent:@"MyFile"]; - [data writeToFile:appFile atomically:YES]; - NSLog(@"writing data to: %@",documentsDirectory); - - firstFrame = false; - } - bitmapContext = CGBitmapContextCreate(pixelData, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast); image = CGBitmapContextCreateImage(bitmapContext); - + ; struct CGContext* context = UIGraphicsGetCurrentContext(); - - CGContextTranslateCTM(context, 0, rect.size.width); - CGContextScaleCTM(context, (float)width / self.frame.size.width, (float)height / -self.frame.size.height); - + + CGContextRotateCTM(context, -M_PI_2); + CGContextScaleCTM(context, -(float)self.frame.size.width/self.frame.size.height, (float)self.frame.size.height/self.frame.size.width); CGContextDrawImage(context, rect, image); CGImageRelease(image); diff --git a/Limelight-iOS/Video/VideoDepacketizer.m b/Limelight-iOS/Video/VideoDepacketizer.m index 2b6dfc7..be20270 100644 --- a/Limelight-iOS/Video/VideoDepacketizer.m +++ b/Limelight-iOS/Video/VideoDepacketizer.m @@ -21,16 +21,10 @@ static int BUFFER_LENGTH = 131072; - (void)main { - NSLog(@"Allocating input stream\n"); NSInputStream* inStream = [[NSInputStream alloc] initWithFileAtPath:self.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) { @@ -40,10 +34,7 @@ static int BUFFER_LENGTH = 131072; 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) { @@ -55,9 +46,11 @@ static int BUFFER_LENGTH = 131072; { if (firstStart) { - // decode the first i-1 bytes + // decode the first i-1 bytes and render a frame [self.decoder decode:self.byteBuffer length:i]; - [self renderFrame]; + [self.target performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:NULL waitUntilDone:FALSE]; + + // move offset back to beginning of start sequence [inStream setProperty:[[NSNumber alloc] initWithInt:self.offset-4] forKey:NSStreamFileCurrentOffsetKey]; self.offset -= 1; @@ -77,9 +70,4 @@ static int BUFFER_LENGTH = 131072; } -- (void) renderFrame -{ - [self.target performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:NULL waitUntilDone:FALSE]; -} - @end