Skip to content

Commit

Permalink
update to v2.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ksysdkci committed Sep 13, 2017
1 parent d2f301b commit 833893c
Show file tree
Hide file tree
Showing 120 changed files with 10,661 additions and 7,817 deletions.
4 changes: 2 additions & 2 deletions demo/KSYLiveDemo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>2.6.1</string>
<string>2.7.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>2.6.1.2</string>
<string>2.7.0.1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
Expand Down
2 changes: 1 addition & 1 deletion demo/KSYLiveDemo/KSYDemoUI/KSYBgmView.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ -(id)init{
_bgmPath = _bgmSel.filePath;
_cnt = _bgmSel.fileList.count;
_loopType = [self addSegCtrlWithItems:@[@"单曲播放", @"单曲循环", @"随机播放",@"循环播放"]];
_loopType.selectedSegmentIndex = 4;
_loopType.selectedSegmentIndex = 3;
_progressBar = [[KSYProgressView alloc] init];
[self addSubview:_progressBar];
if (_cnt == 0) {
Expand Down
5 changes: 4 additions & 1 deletion demo/KSYLiveDemo/KSYDemoUI/KSYBgpStreamerVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ - (void)onSelectFile{
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo {
if(image == nil) {
[picker dismissViewControllerAnimated:YES completion:nil];
return;
}
_streamState.hidden = NO;
captureBtn.hidden = NO;
streamBtn.hidden = NO;
Expand All @@ -167,7 +171,6 @@ -(void)imagePickerController:(UIImagePickerController *)picker
}else{
_kit.previewDimension = _kit.bgPic.outputImageSize;
}
image = nil;
//推流过程中切换图片
if (_capFlag == 0) {
_capFlag = 1;
Expand Down
101 changes: 40 additions & 61 deletions demo/KSYLiveDemo/KSYDemoUI/KSYBrushStreamerVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,45 @@
#import "KSYDrawingView.h"
#import <libksygpulive/KSYGPUBrushStreamerKit.h>


@interface KSYBrushStreamerVC (){
UIButton *drawBtn;//画图按钮
UIButton *drawDelBtn;//删图按钮
UIButton *_drawBtn;//启动/停止 画图按钮
}
@property KSYGPUBrushStreamerKit *brushKit;
@property KSYDrawingView *drawView;
@property NSTimer *nsTimer;
@property BOOL drawRefresh; //是否刷新画图图层
@property CGRect drawViewRect;
@end

@implementation KSYBrushStreamerVC
- (void)setupUI{
[super setupUI];
_nsTimer = [NSTimer scheduledTimerWithTimeInterval:0.1
target:self
selector:@selector(onTimer:)
userInfo:nil
repeats:YES];
_drawRefresh = NO;
_drawViewRect = CGRectMake(0, 0.15*self.view.frame.size.height, self.view.frame.size.width, 0.75*self.view.frame.size.height);
_brushKit.drawPicRect = CGRectMake(0.0, 0.15, 1.0, 0.75);

//draw view
drawBtn = [self.ctrlView addButton:@"画图"];
drawDelBtn = [self.ctrlView addButton:@"删图"];
self.ctrlView.yPos = 50;
[self.ctrlView putRow:@[drawBtn, drawDelBtn, [UIView new]]];

self.profilePicker.hidden = YES;
}

- (void)viewDidLoad {
_brushKit = [[KSYGPUBrushStreamerKit alloc] initWithDefaultCfg];
self.kit = _brushKit;
_brushKit.drawPicRect = CGRectMake(0.0, 0.15, 1.0, 0.75);
[super viewDidLoad];
}
- (void)setupUI{
[super setupUI];
_drawBtn = [self.ctrlView addButton:@"启动画板"];
[_drawBtn setTitle:@"清除画板" forState: UIControlStateSelected ];
_drawView = [[KSYDrawingView alloc] init];
[_drawView.layer setBorderColor:[[UIColor blueColor] CGColor]];
[_drawView.layer setBorderWidth:2.0f];
[self.view addSubview:_drawView];
_drawView.hidden = YES;
self.profilePicker.hidden = YES;
}

- (void)layoutUI{
[super layoutUI];
if (self.ctrlView == nil || _drawBtn == nil) {
return;
}
self.ctrlView.yPos = 55;
[self.ctrlView putRow:@[_drawBtn, [UIView new]]];
int hgt = self.view.frame.size.height;
int wdt = self.view.frame.size.width;
_drawView.frame = CGRectMake(0, 0.15*hgt, wdt, 0.75*hgt);
}

- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
Expand All @@ -60,53 +62,30 @@ - (void)viewWillAppear:(BOOL)animated{

- (void)onBtn:(UIButton *)btn{
[super onBtn:btn];
if (btn == drawBtn){
//画图
[self onDraw];
}else if (btn == drawDelBtn){
//删图
[self onDrawDel];
}
}

- (void)onDraw{
if (!_drawRefresh){
_drawRefresh = YES;
_drawView = [[KSYDrawingView alloc] initDraw:_drawViewRect];
_drawView.frame = _drawViewRect;
[_drawView.layer setBorderColor:[[UIColor blueColor] CGColor]];
[_drawView.layer setBorderWidth:2.0f];
[self.view addSubview:_drawView];
}
}

- (void)onDrawDel{
if (_drawRefresh){
_drawRefresh = NO;
[_brushKit removeDrawLayer];
[_drawView removeFromSuperview];
if (btn == _drawBtn){
_drawBtn.selected = !_drawBtn.selected;
if (_drawBtn.selected) { // 启动画板
_brushKit.drawPic = [[KSYGPUViewCapture alloc] initWithView:_drawView];
[_brushKit.drawPic start];
_drawView.hidden = NO;
}
else { //停止画板
[_brushKit.drawPic stop];
_brushKit.drawPic = nil;
_drawView.hidden = YES;
[_drawView clearAllPath];
}
}
}

- (void)onQuit{
[super onQuit];
[self onDrawDel];
_brushKit = nil;
}

- (BOOL)shouldAutorotate{
return NO;
}

- (void)onTimer:(NSTimer *)theTimer{
[self updateDrawView];
}

//刷新画笔view
- (void) updateDrawView{
if(_drawRefresh){
_brushKit.drawPic = [[GPUImageUIElement alloc] initWithView:_drawView];
}
}

@end

1 change: 1 addition & 0 deletions demo/KSYLiveDemo/KSYDemoUI/KSYPresetCfgVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ - (void)viewDidLoad {
}
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self layoutUI];
}

Expand Down
5 changes: 4 additions & 1 deletion demo/KSYLiveDemo/KSYDemoUI/KSYQRCode.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,14 @@ - (UIImage *)createNonInterpolatedUIImageFormCIImage:(CIImage *)image withSize:(
CGContextSetInterpolationQuality(bitmapRef, kCGInterpolationNone);
CGContextScaleCTM(bitmapRef, scale, scale);
CGContextDrawImage(bitmapRef, extent, bitmapImage);
CGColorSpaceRelease(cs);
// 2.保存bitmap到图片
CGImageRef scaledImage = CGBitmapContextCreateImage(bitmapRef);
CGContextRelease(bitmapRef);
CGImageRelease(bitmapImage);
return [UIImage imageWithCGImage:scaledImage];
UIImage * img = [UIImage imageWithCGImage:scaledImage];
CGImageRelease(scaledImage);
return img;
}
- (UIButton*)addButton:(NSString*)title{
//添加一个按钮
Expand Down
3 changes: 3 additions & 0 deletions demo/KSYLiveDemo/KSYDemoUI/KSYStateLableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ typedef struct _StreamState {
int uploadKByte; // 上传的字节数(KB)
int encodedFrames;// 编码的视频帧数
int droppedVFrames; // 丢弃的视频帧数
int capFrames;
} StreamState;
@class KSYStreamerBase;

Expand All @@ -38,6 +39,8 @@ typedef struct _StreamState {
@property int fpsRaiseCnt;
//帧率下调事件发生次数
@property int fpsDropCnt;
// 采集的帧数
@property int capFrames;

// 将推流状态信息清0
- (void) initStreamStat;
Expand Down
6 changes: 5 additions & 1 deletion demo/KSYLiveDemo/KSYDemoUI/KSYStateLableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,20 @@ - (void) updateState:(KSYStreamerBase*)str {
curState.uploadKByte = [str uploadedKByte];
curState.encodedFrames = [str encodedFrames];
curState.droppedVFrames = [str droppedVideoFrames];
curState.capFrames = _capFrames;

StreamState deltaS = {0};
deltaS.timeSecond = curState.timeSecond -_lastStD.timeSecond ;
deltaS.uploadKByte = curState.uploadKByte -_lastStD.uploadKByte ;
deltaS.encodedFrames = curState.encodedFrames -_lastStD.encodedFrames ;
deltaS.droppedVFrames= curState.droppedVFrames-_lastStD.droppedVFrames;
deltaS.capFrames = curState.capFrames -_lastStD.capFrames;

_lastStD = curState;

double realTKbps = deltaS.uploadKByte*8 / deltaS.timeSecond;
double encFps = deltaS.encodedFrames / deltaS.timeSecond;
double capFps = deltaS.capFrames / deltaS.timeSecond;
double dropPercent = deltaS.droppedVFrames * 100.0 /MAX(curState.encodedFrames, 1);

NSString* liveTime =[KSYUIVC timeFormatted: (int)(curState.timeSecond-_startTime) ] ;
Expand All @@ -73,7 +77,7 @@ - (void) updateState:(KSYStreamerBase*)str {
playUrl = [NSString stringWithFormat:@"拉流地址:%@\n",playUrl];
}
NSString* statekbps = [NSString stringWithFormat:@"实时码率(kbps)%4.1f\tA%4.1f\tV%4.1f\n", realTKbps, [str encodeAKbps], [str encodeVKbps] ];
NSString* statefps = [NSString stringWithFormat:@"实时帧率(fps)%2.1f\t总上传:%@\n", encFps, uploadDateSize ];
NSString* statefps = [NSString stringWithFormat:@"实时帧率(fps)%2.1f %2.1f\t总上传:%@\n", encFps, capFps, uploadDateSize ];
NSString* videoqosinfo = [NSString stringWithFormat:@"视频缓冲 %d B %d ms %d packets \n",
info->videoBufferDataSize, info->videoBufferTimeLength, info->videoBufferPackets];
NSString* audioqosinfo = [NSString stringWithFormat:@"音频缓冲 %d B %d ms %d packets \n",
Expand Down
16 changes: 11 additions & 5 deletions demo/KSYLiveDemo/KSYDemoUI/KSYStreamerVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ @interface KSYStreamerVC () <UIImagePickerControllerDelegate
#endif
YYImageDecoder * _animateDecoder;
int _animateIdx;
CADisplayLink *_displayLink;

NSTimeInterval _dlTime;
NSLock *_dlLock;
GPUImagePicture *_logoPicure;
UIImageOrientation _logoOrientation;
CADisplayLink *_displayLink;
}

@end

@implementation KSYStreamerVC
Expand Down Expand Up @@ -159,6 +161,7 @@ - (void)addSubViews{
_ksyBgmView.onSegCtrlBlock = ^(id sender) {
[selfWeak onBgmCtrSle:sender];
};
[selfWeak onBgmCtrSle:_ksyBgmView.loopType];
_ksyBgmView.progressBar.dragingSliderCallback = ^(float progress) {
[selfWeak.kit.bgmPlayer seekToProgress:progress];
};
Expand Down Expand Up @@ -302,7 +305,10 @@ - (void) setupAnimateLogo:(NSString*)path {
_animateIdx = 0;
_dlTime = 0;
if(!_displayLink){
_displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkCallBack:)];
KSYWeakProxy *proxy = [KSYWeakProxy proxyWithTarget:self];
SEL dpCB = @selector(displayLinkCallBack:);
_displayLink = [CADisplayLink displayLinkWithTarget:proxy
selector:dpCB];
[_displayLink addToRunLoop:[NSRunLoop currentRunLoop]
forMode:NSRunLoopCommonModes];
}
Expand Down Expand Up @@ -359,7 +365,9 @@ - (void) setCaptureCfg {
_kit.gpuOutputPixelFormat = [self.presetCfgView gpuOutputPixelFmt];
_kit.capturePixelFormat = [self.presetCfgView gpuOutputPixelFmt];
_kit.aCapDev.noiseSuppressionLevel = self.audioView.noiseSuppress;
weakObj(self);
_kit.videoProcessingCallback = ^(CMSampleBufferRef buf){
selfWeak.ctrlView.lblStat.capFrames += 1; // 统计预览帧率(实际使用时不需要)
// 在此处添加自定义图像处理, 直接修改buf中的图像数据会传递到观众端
// 或复制图像数据之后再做其他处理, 则观众端仍然看到处理前的图像
};
Expand Down Expand Up @@ -1130,7 +1138,6 @@ -(void)deleteFile:(NSString *)file{
*/
- (CGPoint)convertToPointOfInterestFromViewCoordinates:(CGPoint)viewCoordinates
{
CGPoint pointOfInterest = CGPointMake(.5f, .5f);
CGSize frameSize = self.view.frame.size;
CGSize apertureSize = [_kit captureDimension];
CGPoint point = viewCoordinates;
Expand Down Expand Up @@ -1158,8 +1165,7 @@ - (CGPoint)convertToPointOfInterestFromViewCoordinates:(CGPoint)viewCoordinates
yc = 1.f - (point.x / x2);
}
}
pointOfInterest = CGPointMake(xc, yc);
return pointOfInterest;
return CGPointMake(xc, yc);
}

//设置摄像头对焦位置
Expand Down
3 changes: 1 addition & 2 deletions demo/KSYLiveDemo/KSYLiveVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -375,14 +375,13 @@ - (IBAction)onBtn:(id)sender {
}
else if(sender == _buttonDone){
UIViewController* vc = nil;
NSString * urlStr = _currentSelectUrl;
NSURL *url = [NSURL URLWithString:_currentSelectUrl];
NSString *scheme = [url scheme];
if( ![scheme isEqualToString:@"rtmp"] &&
![scheme isEqualToString:@"http"] &&
![scheme isEqualToString:@"https"] &&
![scheme isEqualToString:@"rtsp"]) {
urlStr = [NSString stringWithFormat:@"%@%s%@", NSHomeDirectory(), "/Documents/",_currentSelectUrl];
NSString * urlStr = [NSString stringWithFormat:@"%@%s%@", NSHomeDirectory(), "/Documents/",_currentSelectUrl];
url = [NSURL URLWithString:urlStr];
}
if (_selectMenuRow >= 0 && _selectMenuRow < _controllers.count) {
Expand Down
12 changes: 12 additions & 0 deletions demo/KSYLiveDemo/KSYPlayerDemo/KSYAVWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ typedef NS_ENUM(NSInteger, KSYAVWriterStatus) {
KSYAVWriter_Status_OK,
///停止中状态
KSYAVWriter_Status_Stoping,
// 暂停
KSYAVWriter_Status_Pause,
};

/**
Expand Down Expand Up @@ -56,6 +58,9 @@ typedef NS_ENUM(NSInteger, KSYAVWriterMetaType) {
//开始写入
-(void)startRecord;

//开始写入(新版--暂停后重新开始录制时,不删除已录制的视频)
-(void)startRecordDeleteRecordedVideo:(BOOL)isDelete;

//接收视频sampleBuffer
-(void)processVideoSampleBuffer:(CMSampleBufferRef)sampleBuffer;

Expand All @@ -65,5 +70,12 @@ typedef NS_ENUM(NSInteger, KSYAVWriterMetaType) {
//停止写入
-(void)stopRecord;

// 暂停写入
- (void)stopRecordPause:(BOOL)pause;

// 将录制的视频存入相册
- (void)saveVideoToPhotosAlbumWithResultBlock:(void(^)(NSError *error))resultBlock;

- (void)cancelRecorde;

@end
Loading

0 comments on commit 833893c

Please sign in to comment.