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. python之pygal:掷一个骰子统计次数并以直方图形式显示

    源码如下: # pygal包:生成可缩放的矢量图形文件,可自适应不同尺寸的屏幕显示 # 安装:python -m pip intall pygal-2.4.0-py2.py3-none-any.whl ...

  2. codeforces624A

    Save Luke CodeForces - 624A Luke Skywalker got locked up in a rubbish shredder between two presses. ...

  3. lvs逻辑卷详解

    管理磁盘空间对系统管理员来说是一件重要的日常工作.一旦磁盘空间耗尽就需要进行一系列耗时而又复杂的任务,以提升磁盘分区中可用的磁盘空间.它也需要系统离线才能处理.通常这种任务会涉及到安装一个新的硬盘.引 ...

  4. BZOJ3724 PA2014Final Krolestwo(欧拉回路+构造)

    如果没有长度为偶数的限制,新建一个点向所有奇点连边,跑欧拉回路即可,显然此时一定存在欧拉回路,因为所有点度数都为偶数. 考虑长度为偶数的限制,将每个点拆成两个点放进一个二分图里,那么每条原图中的边在二 ...

  5. hdu 3949 XOR (线性基)

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=3949 题意: 给出n个数,从中任意取几个数字异或,求第k小的异或和 思路: 线性基求第k小异或和,因为题 ...

  6. Hard Rock

    Ilya is a frontman of the most famous rock band on Earth. Band decided to make the most awesome musi ...

  7. 自学Aruba5.1.1-基于时间的Role定义

    点击返回:自学Aruba之路 自学Aruba5.1.1-基于时间的Role定义 可以配置一条rule是基于时间来做限制 具体配置时间(Time ranges)步骤如下: 1 建立一个绝对时间范围,命令 ...

  8. Android 判定手机是否root

    Android获取手机root的状态 package com.app.demo; import java.io.File; import android.app.Activity; import an ...

  9. awk实例

    AWK-F 以XX为分割df -lh | grep boot | awk '{print $5}' | awk -F '%' '{print $1}'grep "bash" /et ...

  10. JavaScript -- throw、try 和 catch

    try 语句测试代码块的错误. catch 语句处理错误. throw 语句创建自定义错误. 很想java哦. <!DOCTYPE html> <html> <head& ...