第16月第5天 performSelector afterDelay cancel dispatch_semaphore_wait
1.
//不延时,可能会导致界面黑屏并卡住一会
[self performSelector:@selector(startScan) withObject:nil afterDelay:0.3];
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[NSObject cancelPreviousPerformRequestsWithTarget:self];
[self stopScan];
2.ZXCapture
_captureQueue = dispatch_queue_create("com.zxing.captureQueue", NULL);
[_output setSampleBufferDelegate:self queue:_captureQueue];
3.gcd 生产者 消费者
http://blog.csdn.net/jeffasd/article/details/50495977
//
// ViewController.m
// tick01
//
// Created by temp on 2018/1/5.
// Copyright © 2018年 temp. All rights reserved.
// #import "ViewController.h" #define WS(weakSelf) __weak __typeof(&*self)weakSelf = self; @interface ViewController ()
{
dispatch_queue_t _dispatchQueue; dispatch_semaphore_t sem; } @property (readwrite) BOOL playing;
@property (weak, nonatomic) IBOutlet UIButton *playBtn; @end @implementation ViewController - (void)dealloc
{
_dispatchQueue = nil; NSLog(@"111--- ViewController dealloc");
} - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. _dispatchQueue = dispatch_queue_create("KxMovie", DISPATCH_QUEUE_SERIAL);
sem = dispatch_semaphore_create(); } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} - (void)viewWillDisappear
{
[self pause];
} #pragma mark - 播放与暂停
- (IBAction)playAndpauseAction:(id)sender
{
if (self.playing){
[self state];
}
else{
//[_activityIndicatorView startAnimating];
[self play];
[_playBtn setImage:[UIImage imageNamed:@"playback_pause"] forState:UIControlStateNormal];
}
} - (void)state
{
if (self.playing){
[_playBtn setImage:[UIImage imageNamed:@"playback_play"] forState:UIControlStateNormal];
// [_activityIndicatorView stopAnimating];
[self pause];
}
} - (void) pause
{
if (!self.playing)
return;
self.playing = NO;
// [self enableAudio:NO];
// [self updatePlayButton];
} #pragma mark - play
-(void) play
{
if (self.playing)
return; self.playing = YES; [self asyncDecodeFrames];
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ [self tick]; }); WS(weakSelf);
dispatch_async(dispatch_get_global_queue(, ), ^{ while () {
__strong ViewController *strongSelf = weakSelf;
{
if (!strongSelf.playing)
return;
} NSLog(@"111--- dispatch_semaphore_wait");
if (dispatch_semaphore_wait(sem, dispatch_time(DISPATCH_TIME_NOW, *NSEC_PER_SEC))) {
continue;
}
[strongSelf tick];
} });
} - (void) tick
{
CGFloat interval = ; if (self.playing) {
[self asyncDecodeFrames]; NSLog(@"111--- tick"); }
} - (void) asyncDecodeFrames
{ WS(weakSelf); dispatch_async(_dispatchQueue, ^{
__strong ViewController *strongSelf = weakSelf;
{
if (!strongSelf.playing)
return;
} NSLog(@"111---do some thing...");
[NSThread sleepForTimeInterval:]; if (!dispatch_semaphore_signal(sem))
{
// sleep(1); //wait for a while
// continue;
NSLog(@"111--- signal fail");
} //通知成功 });
} @end
gpuimage
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{
if (!self.captureSession.isRunning)
{
return;
}
else if (captureOutput == audioOutput)
{
[self processAudioSampleBuffer:sampleBuffer];
}
else
{
if (dispatch_semaphore_wait(frameRenderingSemaphore, DISPATCH_TIME_NOW) != )
{
return;
} CFRetain(sampleBuffer);
runAsynchronouslyOnVideoProcessingQueue(^{
//Feature Detection Hook.
if (self.delegate)
{
[self.delegate willOutputSampleBuffer:sampleBuffer];
} [self processVideoSampleBuffer:sampleBuffer]; CFRelease(sampleBuffer);
dispatch_semaphore_signal(frameRenderingSemaphore);
});
}
}
第16月第5天 performSelector afterDelay cancel dispatch_semaphore_wait的更多相关文章
- 第16月第31天 mongo
1. 94 brew install mongodb 95 cd ~ 96 cd Desktop/web/ 97 ls 98 mkdir mongo 99 cd mongo/ 100 ...
- 第16月第27天 pip install virtualenv ipython sip brew search
1. pip install virtualenv virtualenv testvir cd testvir cd Scripts activate pip https://zhuanlan.zhi ...
- 第16月第26天 /bin/bash^M: bad interpreter: 没有那个文件或目录
1. 运行脚本时出现了这样一个错误,打开之后并没有找到所谓的^M,查了之后才知道原来是文件格式的问题,也就是linux和windows之间的不完全兼容...具体细节不管,如果验证: vim test. ...
- 第16月第25天 tableView设置UITableViewStyleGrouped顶部有空余高度
1. 正确的处理方法 1)设置标头的高度为特小值 (不能为零 为零的话苹果会取默认值就无法消除头部间距了) UIView *view = [[UIView alloc]initWithFrame:CG ...
- 第16月第24天 find iconv sublime utf-8
1. find . -type f -exec echo {} \; find src -type f -exec sh -c "iconv -f GB18030 -t UTF8 {} &g ...
- 第16月第23天 atos
1. grep --after-context=2 "Binary Images:" *crash xcrun atos -o zhiniao_adhoc_stg1.app.dSY ...
- 第16月第17天 contentMode
1. self.contentMode = UIViewContentModeScaleAspectFill; self.clipsToBounds = YES; http://blog.csdn.n ...
- 第16月第15天 glut
1. https://tokoik.github.io/opengl/libglut.html https://github.com/wistaria/wxtest/tree/master/C htt ...
- 第16月第12天 CABasicAnimation 旋转加速
1. ; double duration = 10.0f; ; i<count; i++) { //旋转动画 CABasicAnimation *anima3 = [CABasicAnimati ...
随机推荐
- linux下拷贝文件夹的时候排除其中的一些目录
http://blog.csdn.net/wind19/article/details/8960574 使用find cd /usr find ./tmp/ | grep -v tmp/dirc | ...
- ZJOI2019 Day1游记
退役吧垃圾 考的再烂还是要把自己捡起来 如果不想让自己的OI生涯就到这里止步的话 就给我滚去拿剩下的300分吧 浙江省前十六,学校前五,day1比别人差一百多分.如果这样还能进省队的话,我就成为传说了 ...
- BZOJ2001 HNOI2010城市建设(线段树分治+LCT)
一个很显然的思路是把边按时间段拆开线段树分治一下,用lct维护MST.理论上复杂度是O((M+Q)logNlogQ),实际常数爆炸T成狗.正解写不动了. #include<iostream> ...
- Sublime Text3配置及控制台乱码[cmd杀死进程乱码/编译文件乱码]解决方法
[NodeJs] 1.安装 http://nodejs.cn/download/ 2.安装过程省略(因为已经安装过了) 和平时安装软件没区别 3.配置环境 计算机--->属性-->高级系统 ...
- Codeforces 1106F Lunar New Year and a Recursive Sequence | BSGS/exgcd/矩阵乘法
我诈尸啦! 高三退役选手好不容易抛弃天利和金考卷打场CF,结果打得和shi一样--还因为queue太长而unrated了!一个学期不敲代码实在是忘干净了-- 没分该没分,考题还是要订正的 =v= 欢迎 ...
- Azure Powershell script检测登陆并部署ARM Template
本文简单提供了一个Azure powershell脚本,能实现如下功能 Azure (China)账户是否已经登陆了,如果没登陆,会提示你登陆. 要创建的资源组是否存在,存在的话不再创建,直接部署te ...
- JavaScript表格插件库
DataTables https://datatables.net/ Handsontable https://handsontable.com/ JsGrid http://js-grid.com/ ...
- apigateway-kong(五)集群搭建部署
kong 集群将使得系统通过增加更多机器,从而实现水平扩展,承接更多的请求流量.它们将共享同样的配置且使用同一个数据库.kong 集群中的的所有节点都连接同一个数据库. 你需要在 kong 集群的上一 ...
- pyglet----画一个矩形
这里列出一种在窗口Window中画图的程序框架.......... #-*- coding:utf-8 -*- from pyglet.gl import * def draw_rect(x, y, ...
- 利用bootstrap-datetimepicker实日历插件
由于项目中需要获取一个时间值,手动输入的话比较Low,这里引用了bootstrap-datetimepicker模块来实现. 1.首先,下载该模块并引用.(官网:http://www.bootcss. ...