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的更多相关文章

  1. 第16月第31天 mongo

    1. 94  brew install  mongodb 95  cd ~ 96  cd Desktop/web/ 97  ls 98  mkdir mongo 99  cd mongo/ 100  ...

  2. 第16月第27天 pip install virtualenv ipython sip brew search

    1. pip install virtualenv virtualenv testvir cd testvir cd Scripts activate pip https://zhuanlan.zhi ...

  3. 第16月第26天 /bin/bash^M: bad interpreter: 没有那个文件或目录

    1. 运行脚本时出现了这样一个错误,打开之后并没有找到所谓的^M,查了之后才知道原来是文件格式的问题,也就是linux和windows之间的不完全兼容...具体细节不管,如果验证: vim test. ...

  4. 第16月第25天 tableView设置UITableViewStyleGrouped顶部有空余高度

    1. 正确的处理方法 1)设置标头的高度为特小值 (不能为零 为零的话苹果会取默认值就无法消除头部间距了) UIView *view = [[UIView alloc]initWithFrame:CG ...

  5. 第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 ...

  6. 第16月第23天 atos

    1. grep --after-context=2 "Binary Images:" *crash xcrun atos -o zhiniao_adhoc_stg1.app.dSY ...

  7. 第16月第17天 contentMode

    1. self.contentMode = UIViewContentModeScaleAspectFill; self.clipsToBounds = YES; http://blog.csdn.n ...

  8. 第16月第15天 glut

    1. https://tokoik.github.io/opengl/libglut.html https://github.com/wistaria/wxtest/tree/master/C htt ...

  9. 第16月第12天 CABasicAnimation 旋转加速

    1. ; double duration = 10.0f; ; i<count; i++) { //旋转动画 CABasicAnimation *anima3 = [CABasicAnimati ...

随机推荐

  1. std::string 字符串替换

    std::string 没有原生的字符串替换函数,需要自己来完成 string& replace_str(string& str, const string& to_repla ...

  2. BZOJ4455 ZJOI2016小星星(容斥原理+树形dp)

    相当于给树上的每个点分配一个编号使父亲和儿子间都有连边. 于是可以考虑树形dp:设f[i][j][k]为i号点的编号为j,其子树中编号集合为k的方案数.转移显然.然而复杂度3n·n3左右,具体我也不知 ...

  3. Linux 下 wordpress 无法安装插件

    修改目录权限mkdir -p wp-content/tmpchown -R www:www  wp-contentchmod -R 777 wp-content 配置修改wp-config.php搜索 ...

  4. HNOI2018题解

    在此处输入标题 标签(空格分隔): 未分类 重做了一遍,本来以为很快的,结果搞了一天... 寻宝游戏 可以发现只有\(\&0\)和\(|1\)会对答案有影响 那么对于每一位,我们只要知道最后一 ...

  5. 洛谷 P2420 让我们异或吧 解题报告

    P2420 让我们异或吧 题目描述 异或是一种神奇的运算,大部分人把它总结成不进位加法. 在生活中-xor运算也很常见.比如,对于一个问题的回答,是为1,否为0.那么: (A是否是男生 )xor( B ...

  6. luogu4269 Snow Boots G (并查集)

    对于某个靴子,如果0代表某个格能走,1代表不能走,那么只要连续的1的个数的最大值>=靴子的步长,那这个靴子就不能用. 那么只要对靴子和格子都按深度排个序,然后从大到小来扫一遍(靴子越来越浅,能走 ...

  7. strace命令,read,write

    strace + 运行的程序,可以查看程序运行的过程中调用的系统函数 read.write函数常常被称为Unbuffered I/O.指的是无用户及缓冲区.但不保证不使用内核缓冲区.

  8. toogle

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. SVN:多版本库环境的搭建

    一. 1,启动SVN sudo svnserve -d -r /home/data/svn/ 其中 -d 表示守护进程, -r 表示在后台执行 /home/data/svn/  为svn的安装目录 2 ...

  10. C# TextBox猜想输入和历史记录输入

    什么是猜想输入 当我们在使用查询应用时,输入某个关键字后文本框下面就会自动弹出跟此关键字相附的词组供我们选择,为我们节省了输入的时间,这就是猜想输入,例如:百度,谷歌,等等,如下图: 如上图所示,使用 ...