mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2025-07-23 12:44:19 +00:00
view is now centered and rendering is flipped correctly
This commit is contained in:
parent
f97fe7fce2
commit
72ed023645
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user