- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
NSString * url = @"
rtsp://192.168.199.121:8554/h264ESVideoTest";
NSString * appName = @"test";
dispatch_async(dispatch_get_global_queue(0,0), ^{
[mixTest test:url appName:appName];
});
dispatch_async(dispatch_get_main_queue(), ^{
//主线程
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(getNewFrame:) name:@"getYUVData" object:nil];
});
}
- (void)getNewFrame:(NSNotification *)notification {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSDictionary *dataDic = notification.userInfo;
NSValue *frameSize = [dataDic valueForKey:@"frameSize"];
NSData *frameData = [dataDic valueForKey:@"frameData"];
struct Frame frame;
[frameSize getValue:&frame];
UInt8 *videoFrame = (UInt8 *)[frameData bytes];
CGRect videoSize = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width);
self.glView = [[OpenGLView20 alloc]initWithFrame:videoSize];
[self.view addSubview:self.glView];
[self.glView setVideoSize:352 height:288];
dispatch_async(dispatch_get_main_queue(), ^{
[self.glView displayYUV420pData:videoFrame width:352 height:288];
});
NSLog(@"!!!!!!!!!!!!!!!!!!!!!!!!");
});
}
mixTest的静态方法是循环的,并且每个循环会让nsnotification发出一个通知,main队列中就收到这个通知,然后去执行getNewFrame的内容,可是这样不能够接收一帧播放一帧呀