第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 ...
随机推荐
- Django-website 程序案例系列-3 URL详解
django参考资料:http://docs.30c.org/djangobook2/index.html urls.py是django中控制接收前端的参数指定函数去执行逻辑 第一种 函数的方式 ur ...
- BZOJ1563 NOI2009诗人小G(动态规划+决策单调性)
设f[i]为前i行的最小不协调度,转移枚举这一行从哪开始,显然有f[i]=min{f[j]+abs(s[i]-s[j]+i-j-1-m)p}.大胆猜想有决策单调性就好了.证明看起来很麻烦,从略.注意需 ...
- day14 闭包
闭包的概念 必须要有函数嵌套,内部函数调用外部函数的变量 简单的例子 此种方法会导致每次使用内部函数inner的时候需要不断的调用外部函数. 结果导致外部函数的变量不断的被调用被释放,比较低效,相当于 ...
- python numpy 数组拼接
我就写一下我遇到的,更多具体的请看Python之Numpy数组拼接,组合,连接 >>> aarray([0, 1, 2], [3, 4, 5], [6, 7, ...
- 有标号的DAG计数(FFT)
有标号的DAG计数系列 有标号的DAG计数I 题意 给定一正整数\(n\),对\(n\)个点有标号的有向无环图(可以不连通)进行计数,输出答案\(mod \ 10007\)的结果.\(n\le 500 ...
- 【转】cJSON 源码阅读笔记
前言 cjson 的代码只有 1000+ 行, 而且只是简单的几个函数的调用. 而且 cjson 还有很多不完善的地方, 推荐大家看完之后自己实现一个 封装好的功能完善的 cjson 程序. json ...
- elasticsearch 安装、配置
elasticsearch:基于java开发,基于RESTful web 接口,提供分布式多用户能力的全文搜索引擎. elasticsearch 安装: 1. java SE Development ...
- SDL源码阅读笔记(1) 基本模块
write by 九天雁翎(JTianLing) -- blog.csdn.net/vagrxie 前言 对于大牛来说,写关于阅读源码的文章都会叫源码剖析或者深入浅出啥的,对于我,自己阅读阅读源码,写 ...
- 几个面试经典算法题Java解答
题目一: public class testClockwiseOutput { //顺时针打印一个矩阵 @Test public void test(){ int[][] num = new int[ ...
- C# 类&结构体&枚举
类: class Lei //要和static void Main(string[] args)平级: { public int lei_int; //public是关键字,代表访问权限,这里是公 ...