mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2025-07-23 12:44:19 +00:00
fixed rendering
This commit is contained in:
parent
029d3b0a97
commit
f97fe7fce2
@ -36,15 +36,11 @@
|
||||
<true/>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations~ipad</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
|
@ -23,6 +23,7 @@
|
||||
- (void)StreamButton:(UIButton *)sender
|
||||
{
|
||||
NSLog(@"Stream Button Pressed!");
|
||||
[self performSegueWithIdentifier:@"createStreamFrame" sender:self];
|
||||
}
|
||||
|
||||
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
|
||||
|
@ -10,6 +10,5 @@
|
||||
#import "StreamView.h"
|
||||
|
||||
@interface StreamFrameViewController : UIViewController
|
||||
@property (strong, nonatomic) IBOutlet StreamView *renderView;
|
||||
|
||||
@end
|
||||
|
@ -18,15 +18,21 @@
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
[self.renderView setNeedsDisplay];
|
||||
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.
|
||||
VideoDepacketizer* depacketizer = [[VideoDepacketizer alloc] init];
|
||||
|
||||
NSString* path = [[NSBundle mainBundle] pathForResource:@"notpadded"
|
||||
ofType:@"h264"];
|
||||
NSLog(@"Path: %@", path);
|
||||
[depacketizer readFile:path];
|
||||
VideoDepacketizer* depacketizer = [[VideoDepacketizer alloc] initWithFile:path renderTarget:streamView];
|
||||
NSOperationQueue* opQueue = [[NSOperationQueue alloc] init];
|
||||
[opQueue addOperation:depacketizer];
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -18,19 +18,16 @@
|
||||
CGColorSpaceRef colorSpace;
|
||||
CGContextRef bitmapContext;
|
||||
CGImageRef image;
|
||||
UIImage *uiImage;
|
||||
unsigned char* pixelData;
|
||||
}
|
||||
static bool firstFrame = true;
|
||||
|
||||
-(id)init
|
||||
{
|
||||
NSLog(@"init");
|
||||
return [super init];
|
||||
}
|
||||
|
||||
- (void)awakeFromNib
|
||||
|
||||
- (id)initWithFrame:(CGRect)frame
|
||||
{
|
||||
NSLog(@"awakeFromNib");
|
||||
self = [super initWithFrame:frame];
|
||||
NSLog(@"initWithFrame");
|
||||
// Initialization code
|
||||
width = 1280;
|
||||
height = 720;
|
||||
@ -38,21 +35,18 @@
|
||||
bytesPerRow = (bitsPerComponent / 8) * width * 4;
|
||||
pixelData = malloc(width * height * 4);
|
||||
colorSpace = CGColorSpaceCreateDeviceRGB();
|
||||
bitmapContext = CGBitmapContextCreate(NULL, 1280, 720, 8, 5120, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaNoneSkipLast);
|
||||
image = CGBitmapContextCreateImage(bitmapContext);
|
||||
uiImage = [UIImage imageWithCGImage:image];
|
||||
//VideoRenderer* renderer = [[VideoRenderer alloc]initWithTarget:self];
|
||||
//NSOperationQueue* opQueue = [[NSOperationQueue alloc]init];
|
||||
//[opQueue addOperation:renderer];
|
||||
[self setNeedsDisplay];
|
||||
//bitmapContext = CGBitmapContextCreate(pixelData, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGBitmapByteOrderDefault);
|
||||
//image = CGBitmapContextCreateImage(bitmapContext);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Only override drawRect: if you perform custom drawing.
|
||||
// An empty implementation adversely affects performance during animation.
|
||||
- (void)drawRect:(CGRect)rect
|
||||
{
|
||||
|
||||
NSLog(@"drawRect");
|
||||
|
||||
if (!nv_avc_get_rgb_frame(pixelData, width*height*4))
|
||||
@ -60,10 +54,31 @@
|
||||
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();
|
||||
|
||||
CGContextDrawImage(context, CGRectMake(0, 0, 1280, 720), image);
|
||||
|
||||
CGContextTranslateCTM(context, 0, rect.size.width);
|
||||
CGContextScaleCTM(context, (float)width / self.frame.size.width, (float)height / -self.frame.size.height);
|
||||
|
||||
CGContextDrawImage(context, rect, image);
|
||||
|
||||
CGImageRelease(image);
|
||||
|
||||
[super drawRect:rect];
|
||||
}
|
||||
|
||||
|
@ -9,11 +9,13 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "VideoDecoder.h"
|
||||
|
||||
@interface VideoDepacketizer : NSObject <NSStreamDelegate>
|
||||
@interface VideoDepacketizer : NSOperation <NSStreamDelegate>
|
||||
@property uint8_t* byteBuffer;
|
||||
@property unsigned int offset;
|
||||
@property VideoDecoder* decoder;
|
||||
@property NSString* file;
|
||||
@property UIView* target;
|
||||
|
||||
- (void) readFile:(NSString*) file;
|
||||
- (id) initWithFile:(NSString*) file renderTarget:(UIView*)renderTarget;
|
||||
|
||||
@end
|
||||
|
@ -11,10 +11,18 @@
|
||||
@implementation VideoDepacketizer
|
||||
static int BUFFER_LENGTH = 131072;
|
||||
|
||||
- (void) readFile:(NSString*) file
|
||||
- (id)initWithFile:(NSString *)file renderTarget:(UIView*)renderTarget
|
||||
{
|
||||
self = [super init];
|
||||
self.file = file;
|
||||
self.target = renderTarget;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)main
|
||||
{
|
||||
NSLog(@"Allocating input stream\n");
|
||||
NSInputStream* inStream = [[NSInputStream alloc] initWithFileAtPath:file];
|
||||
NSInputStream* inStream = [[NSInputStream alloc] initWithFileAtPath:self.file];
|
||||
NSLog(@"Allocating byteBuffer");
|
||||
self.byteBuffer = malloc(BUFFER_LENGTH);
|
||||
NSLog(@"byte pointer: %p", self.byteBuffer);
|
||||
@ -39,21 +47,20 @@ static int BUFFER_LENGTH = 131072;
|
||||
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++) {
|
||||
self.offset++;
|
||||
if (self.byteBuffer[i] == 0 && self.byteBuffer[i+1] == 0
|
||||
&& self.byteBuffer[i+2] == 0 && self.byteBuffer[i+3] == 1)
|
||||
{
|
||||
NSLog(@"i: %d", i);
|
||||
|
||||
if (firstStart)
|
||||
{
|
||||
// decode the first i-1 bytes
|
||||
[self.decoder decode:self.byteBuffer length:i-1];
|
||||
[self.decoder decode:self.byteBuffer length:i];
|
||||
[self renderFrame];
|
||||
[inStream setProperty:[[NSNumber alloc] initWithInt:self.offset-4] forKey:NSStreamFileCurrentOffsetKey];
|
||||
self.offset -= 4;
|
||||
self.offset -= 1;
|
||||
|
||||
break;
|
||||
} else
|
||||
{
|
||||
@ -67,6 +74,12 @@ static int BUFFER_LENGTH = 131072;
|
||||
NSLog(@"No Buffer!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
- (void) renderFrame
|
||||
{
|
||||
[self.target performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:NULL waitUntilDone:FALSE];
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -21,8 +21,6 @@
|
||||
}
|
||||
}*/
|
||||
int decStat = nv_avc_decode(buffer, length);
|
||||
NSLog(@"Decode Status: %d", decStat);
|
||||
|
||||
}
|
||||
|
||||
- (id) init
|
||||
@ -125,23 +123,7 @@ int nv_avc_init(int width, int height, int perf_lvl, int thread_count) {
|
||||
decoder_ctx->height = height;
|
||||
decoder_ctx->pix_fmt = PIX_FMT_YUV420P;
|
||||
|
||||
// Little-endian makes the AV_PIX_FMT constants look wierd
|
||||
if (perf_lvl & NATIVE_COLOR_RGB0) {
|
||||
render_pix_fmt = AV_PIX_FMT_0BGR;
|
||||
}
|
||||
else if (perf_lvl & NATIVE_COLOR_0RGB) {
|
||||
render_pix_fmt = AV_PIX_FMT_BGR0;
|
||||
}
|
||||
else if (perf_lvl & NATIVE_COLOR_RGBA) {
|
||||
render_pix_fmt = AV_PIX_FMT_ABGR;
|
||||
}
|
||||
else if (perf_lvl & NATIVE_COLOR_ARGB) {
|
||||
render_pix_fmt = AV_PIX_FMT_BGRA;
|
||||
}
|
||||
else {
|
||||
// Default
|
||||
render_pix_fmt = AV_PIX_FMT_ABGR;
|
||||
}
|
||||
render_pix_fmt = AV_PIX_FMT_RGBA;
|
||||
|
||||
err = avcodec_open2(decoder_ctx, decoder, NULL);
|
||||
if (err < 0) {
|
||||
|
@ -12,18 +12,18 @@
|
||||
<viewControllerLayoutGuide type="top" id="9ZL-gP-cfY"/>
|
||||
<viewControllerLayoutGuide type="bottom" id="Shd-7C-CVq"/>
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="ugc-rC-3gm">
|
||||
<rect key="frame" x="0.0" y="0.0" width="768" height="1024"/>
|
||||
<view key="view" contentMode="scaleToFill" horizontalHuggingPriority="222" id="ugc-rC-3gm">
|
||||
<rect key="frame" x="0.0" y="0.0" width="1024" height="768"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<subviews>
|
||||
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Geforce PC Host" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="iC2-gT-zgS">
|
||||
<rect key="frame" x="20" y="107" width="728" height="30"/>
|
||||
<rect key="frame" x="20" y="107" width="984" height="30"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="22"/>
|
||||
<textInputTraits key="textInputTraits"/>
|
||||
</textField>
|
||||
<pickerView contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="rnA-uG-hAA">
|
||||
<rect key="frame" x="0.0" y="211" width="768" height="216"/>
|
||||
<rect key="frame" x="0.0" y="211" width="1024" height="216"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
|
||||
<connections>
|
||||
<outlet property="dataSource" destination="wb7-af-jn8" id="25E-op-oh6"/>
|
||||
@ -31,7 +31,7 @@
|
||||
</connections>
|
||||
</pickerView>
|
||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="taW-Um-zc6" userLabel="Start Stream Btn">
|
||||
<rect key="frame" x="189" y="435" width="391" height="141"/>
|
||||
<rect key="frame" x="317" y="421" width="391" height="141"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="26"/>
|
||||
<state key="normal" title="Start Streaming Steam!">
|
||||
@ -39,13 +39,10 @@
|
||||
</state>
|
||||
<connections>
|
||||
<action selector="StreamButton:" destination="wb7-af-jn8" eventType="touchUpInside" id="u2m-8A-Tor"/>
|
||||
<segue destination="OIm-0n-i9v" kind="popover" popoverAnchorView="taW-Um-zc6" id="RqQ-bq-Vkc">
|
||||
<popoverArrowDirection key="popoverArrowDirection" up="YES" down="YES" left="YES" right="YES"/>
|
||||
</segue>
|
||||
</connections>
|
||||
</button>
|
||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="0Nz-KX-Du4" userLabel="Pair Btn">
|
||||
<rect key="frame" x="311" y="604" width="147" height="36"/>
|
||||
<rect key="frame" x="439" y="595" width="147" height="36"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="26"/>
|
||||
<state key="normal" title="Pair with PC">
|
||||
@ -57,14 +54,17 @@
|
||||
</button>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
|
||||
<simulatedOrientationMetrics key="simulatedOrientationMetrics" orientation="landscapeRight"/>
|
||||
</view>
|
||||
<simulatedOrientationMetrics key="simulatedOrientationMetrics" orientation="landscapeRight"/>
|
||||
<connections>
|
||||
<outlet property="StreamConfigs" destination="rnA-uG-hAA" id="LPP-jQ-5eW"/>
|
||||
<segue destination="OIm-0n-i9v" kind="modal" identifier="createStreamFrame" modalPresentationStyle="fullScreen" id="MOD-9A-3Sk"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="ZYl-Xu-QyD" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="109" y="-320"/>
|
||||
<point key="canvasLocation" x="179" y="-318"/>
|
||||
</scene>
|
||||
<!--Stream Frame View Controller-->
|
||||
<scene sceneID="RuD-qk-7nb">
|
||||
@ -74,15 +74,18 @@
|
||||
<viewControllerLayoutGuide type="top" id="NG3-N1-D4k"/>
|
||||
<viewControllerLayoutGuide type="bottom" id="3MH-n6-BSR"/>
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="VPm-Ae-rc4" userLabel="RenderView" customClass="StreamView">
|
||||
<rect key="frame" x="0.0" y="0.0" width="768" height="1024"/>
|
||||
<view key="view" contentMode="scaleToFill" id="VPm-Ae-rc4" userLabel="RenderView">
|
||||
<rect key="frame" x="0.0" y="0.0" width="1024" height="768"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
|
||||
<color key="backgroundColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<simulatedOrientationMetrics key="simulatedOrientationMetrics" orientation="landscapeRight"/>
|
||||
</view>
|
||||
<navigationItem key="navigationItem" id="aB9-My-tz5"/>
|
||||
<connections>
|
||||
<outlet property="renderView" destination="VPm-Ae-rc4" id="Xf2-AW-9Cg"/>
|
||||
</connections>
|
||||
<navigationItem key="navigationItem" id="G20-tf-3L9"/>
|
||||
<nil key="simulatedStatusBarMetrics"/>
|
||||
<nil key="simulatedTopBarMetrics"/>
|
||||
<nil key="simulatedBottomBarMetrics"/>
|
||||
<simulatedOrientationMetrics key="simulatedOrientationMetrics" orientation="landscapeRight"/>
|
||||
<simulatedScreenMetrics key="simulatedDestinationMetrics"/>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="hON-k2-Efa" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
|
Loading…
x
Reference in New Issue
Block a user