mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2026-04-20 23:40:17 +00:00
added simple depacketizer and test h264 file
This commit is contained in:
19
Limelight-iOS/Video/VideoDepacketizer.h
Normal file
19
Limelight-iOS/Video/VideoDepacketizer.h
Normal file
@@ -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 <Foundation/Foundation.h>
|
||||
#import "VideoDecoder.h"
|
||||
|
||||
@interface VideoDepacketizer : NSObject <NSStreamDelegate>
|
||||
@property uint8_t* byteBuffer;
|
||||
@property unsigned int offset;
|
||||
@property VideoDecoder* decoder;
|
||||
|
||||
- (void) readFile:(NSString*) file;
|
||||
|
||||
@end
|
||||
89
Limelight-iOS/Video/VideoDepacketizer.m
Normal file
89
Limelight-iOS/Video/VideoDepacketizer.m
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user