当前位置: 首页 > news >正文

自己如何做电影网站/网络推广员是什么

自己如何做电影网站,网络推广员是什么,宜春做网站,wordpress更新很慢iphone视频聊天代码实现 分类: iphone开发 2011-05-19 11:59 3714人阅读 评论(8) 收藏 举报 聊天iphonesessionoutputimageinput视频聊天从摄像头中取得缓冲数据,转换成NSData,通过网络发送,接收端取得NSData后把NSData转换成图…

iphone视频聊天代码实现

分类: iphone开发 3714人阅读 评论(8) 收藏 举报
聊天iphonesessionoutputimageinput

视频聊天从摄像头中取得缓冲数据,转换成NSData,通过网络发送,接收端取得NSData后把NSData转换成图像,双方不停的收发数据,播放图像,就形成了视频聊天。废话不多说,直接上代码:

首先创建视频输入输出:

NSError *error = nil;
    
    // Setup the video input
    AVCaptureDevice *videoDevice = [self getFrontCamera];//[AVCaptureDevice defaultDeviceWithMediaType: AVMediaTypeVideo];
    // Create a device input with the device and add it to the session.
    AVCaptureDeviceInput *videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error];
    // Setup the video output
    _videoOutput = [[AVCaptureVideoDataOutput alloc] init];
    _videoOutput.alwaysDiscardsLateVideoFrames = NO;
    _videoOutput.videoSettings =
    [NSDictionary dictionaryWithObject:
     [NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey];     
    
    
    // Create the session
    _capSession = [[AVCaptureSession alloc] init];
    [_capSession addInput:videoInput];
    //[_capSession addInput:audioInput];
    [_capSession addOutput:_videoOutput];
    //[_capSession addOutput:_audioOutput];
    
    _capSession.sessionPreset = AVCaptureSessionPresetLow;     
    
    // Setup the queue
    dispatch_queue_t queue = dispatch_queue_create("MyQueue", NULL);
    [_videoOutput setSampleBufferDelegate:self queue:queue];
    [_audioOutput setSampleBufferDelegate:self queue:queue];
    dispatch_release(queue);
    [_capSession startRunning];

通过AVCaptureVideoDataOutputSampleBufferDelegate 代理 取得摄像头数据

#pragma mark AVCaptureSession delegate
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
       fromConnection:(AVCaptureConnection *)connection
{
    
    NSData *data = [NSData dataWithBytes:&sampleBuffer length:malloc_size(sampleBuffer)];
    [self recieveVideoFromData:data];
}

收到数据后转换成图像

- (void)recieveVideoFromData:(NSData *)data{
    CMSampleBufferRef sampleBuffer;
    [data getBytes:&sampleBuffer length:sizeof(sampleBuffer)];
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    
    CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
    CVPixelBufferLockBaseAddress(imageBuffer,0);
    uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(imageBuffer);
    size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
    size_t width = CVPixelBufferGetWidth(imageBuffer);
    size_t height = CVPixelBufferGetHeight(imageBuffer);
    
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGContextRef newContext = CGBitmapContextCreate(baseAddress,
                                                    width, height, 8, bytesPerRow, colorSpace,
                                                    kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
    CGImageRef newImage = CGBitmapContextCreateImage(newContext);
    
    CGContextRelease(newContext);
    CGColorSpaceRelease(colorSpace);
    
    UIImage *image= [UIImage imageWithCGImage:newImage scale:1.0
                                  orientation:UIImageOrientationRight];
    
    CGImageRelease(newImage);
    [self.imageView performSelectorOnMainThread:@selector(setImage:)
                                withObject:image waitUntilDone:YES];
    CVPixelBufferUnlockBaseAddress(imageBuffer,0);
    
    [pool drain];
    
}

http://www.jmfq.cn/news/4930561.html

相关文章:

  • 定制化开发是什么意思/网站seo搜索引擎优化教程
  • 网站建设合同服务范围/哪里可以建网站
  • 公司网站做地图地址/网站模板免费下载
  • 上海闵行网站制作公司/今日国内重大新闻事件
  • 湖南网站建设小公司排名/重庆疫情最新消息
  • 变色龙app制作平台/站内seo内容优化包括
  • 电子商务网站规书/疫情最新消息今天公布
  • 网站开发公司怎么能接到单子/网络营销策略有哪几种
  • 肇庆 网站建设 域联/推广赚钱一个2元
  • 邢台做移动网站价格表/找百度
  • 做网站多少宽带够/百度热搜榜
  • 19年做网站还能赚钱/软文营销常用的方式
  • 开发和发布网站的主要流程/企业建站系统模板
  • 百度手机模板网站/360收录入口
  • 广州企业网站设计方案/网络营销有哪些推广方法
  • 什么是网页和网站/百度店铺免费入驻
  • 珠海市网站开发公司电话/网站优化的主要内容
  • 网站上的用户注册怎么做的/制作电商网站
  • 网站建设组织/网站seo检测
  • 专做实习生招聘的网站/网站为什么要seo?
  • 怎样与知名网站做友情链接/百度快速排名化
  • 电子商务网站推广实训心得/整站排名优化公司
  • 淳安县建设局网站/怎样在百度上发布免费广告
  • 百度推广代理商名单/全网优化哪家好
  • 十里堡网站建设/seo软文推广
  • 沈阳app开发公司哪家好/河南网站优化公司哪家好
  • 网站开展营销的思路和方法/项目推广方案
  • 网站开发流程注意事项/佛山seo代理计费
  • flash做的小动画视频网站/友情链接你会回来感谢我
  • 网站开发证书要求/视频推广一条多少钱