第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 ...
随机推荐
- Java之枚举类范例
代码如下: package catf.component.http.model; /** * @Auther:gongxingrui * @Date:2018-04-17 * @Description ...
- python之Map函数
# map()函数使用举例 # 功能:map()接受一个函数f和一个或多个list,将f依次作用在list的每个元素,得到一个新的列表 # 语法:map(方法名,列表,[列表2]) # 注意:map( ...
- SQL Server 公用表表达式(CTE)实现递归
公用表表达式简介: 公用表表达式 (CTE) 可以认为是在单个 SELECT.INSERT.UPDATE.DELETE 或 CREATE VIEW 语句的执行范围内定义的临时结果集.CTE 与派生表类 ...
- 画caffe训练loss曲线
Linux下操作 1. 将loss值存储到lossInf.txt中 fName1='loss.txt' cat loss.log | grep "solver.cpp:218] Iterat ...
- IBM推出新一代云计算技术来解决多云管理
IBM 云计算论坛在南京举行,推出了一项全新的开放式技术,使用户能够更加便捷地跨不同云计算基础架构来管理.迁移和整合应用. IBM 多云管理解决方案(Multicloud Manager)控制面板 据 ...
- 最小费用最大流spfa
#include <iostream> #include <cstring> #include <cstdio> #include <queue> #d ...
- day7 笔记
二进制-----> ASCLL :只能存英文和拉丁字符.-----> gb2312 :只有6700来个中文字符,1980年-----> gbk1.0 :存了2w多字符 ,1995年- ...
- MT【30】椭圆的第二定义解题
问题:上式表示的区域是怎样的? 解答:利用椭圆第二定义易知当取等号时为椭圆,又令$y$趋向于$+\infty$时不等号不成立,故可以判断为椭圆内部区域. 评:利用mathmatics软件容易得到
- copy elison & RVO & NRVO
蓝色的博文 To summarize, RVO is a compiler optimization technique, while std::move is just an rvalue cast ...
- 自学Python1.6-Centos内英文语法切换
自学Python之路 自学Python1.6-Centos内中英文语法切换 测试采用是官方Centos7.0系统 1.添加中文输入法 打开设置---区域和语言--->在输入源最下面有一个 + 号 ...