第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 ...
随机推荐
- React的组件间通信
一.React的单向数据流 React是单向数据流,数据主要从父节点传递到子节点(通过props).如果顶层(父级)的某个props改变了,React会重渲染所有的子节点.这通常被称为“自顶向下”或“ ...
- Nginx PRECONTENT try_files指令
L:61 try_fiels指令 syntax : try_files file ... uri;=code //可以是多个文件 context : server,location; locatio ...
- Nginx PREACCESS阶段 如何限制每个客户端每秒处理请求数
L:56 limit_req_zone $binary_remote_addr zone=one:10m rate=2r/m;#以用户IP作为key 开辟共享内存10M 并且限制每分钟2个请求 rat ...
- Code POJ - 1780(栈模拟dfs)
题意: 就是数位哈密顿回路 解析: 是就算了...尼玛还不能直接用dfs,得手动开栈模拟dfs emm...看了老大半天才看的一知半解 #include <iostream> #inclu ...
- day30 __hash__ 计算哈希值
hash() # __hash__哈希的时候会根据内存地址进行哈希,因为地址不同所以哈希的值也不同,哪怕是完全一样子的属性得出的哈希值也不一样因此存在需要某些时刻期望属性相同得出相同哈希值可以控制对象 ...
- BZOJ2839 : 集合计数 (广义容斥定理)
题目 一个有 \(N\) 个 元素的集合有 \(2^N\) 个不同子集(包含空集), 现在要在这 \(2^N\) 个集合中取出若干集合(至少一个), 使得它们的交集的元素个数为 \(K\) ,求取法的 ...
- (python爬取小故事网并写入mysql)
前言: 这是一篇来自整理EVERNOTE的笔记所产生的小博客,实现功能主要为用广度优先算法爬取小故事网,爬满100个链接并写入mysql,虽然CS作为双学位已经修习了三年多了,但不仅理论知识一般,动手 ...
- [学习笔记&教程] 信号, 集合, 多项式, 以及各种卷积性变换 (FFT,NTT,FWT,FMT)
目录 信号, 集合, 多项式, 以及卷积性变换 卷积 卷积性变换 傅里叶变换与信号 引入: 信号分析 变换的基础: 复数 傅里叶变换 离散傅里叶变换 FFT 与多项式 \(n\) 次单位复根 消去引理 ...
- JNative 传递参数bug
下载JNative网址:http://sourceforge.net/projects/jnative/files/jnative/ 下载JNative版本:JNative_1.4RC3_bin.zi ...
- 强大log
http://lovelease.iteye.com/blog/1886907 import java.io.BufferedReader; import java.io.File; import j ...