Skip to content

Commit ba1f7a3

Browse files
authored
Merge pull request LaiFengiOS#4 from LaiFengiOS/master
update to last version
2 parents 519b685 + b109289 commit ba1f7a3

File tree

10 files changed

+63
-51
lines changed

10 files changed

+63
-51
lines changed

LFLiveKit.podspec

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Pod::Spec.new do |s|
33

44
s.name = "LFLiveKit"
5-
s.version = "1.6.3"
5+
s.version = "1.7.1"
66
s.summary = "LaiFeng ios Live. LFLiveKit."
77
s.homepage = "https://github.com/chenliming777"
88
s.license = { :type => "MIT", :file => "LICENSE" }
@@ -21,5 +21,6 @@ Pod::Spec.new do |s|
2121
s.dependency "CocoaAsyncSocket", "~> 7.4.1"
2222
s.dependency 'LMGPUImage', '~> 0.1.9'
2323
s.dependency "pili-librtmp", "~> 1.0.2"
24+
s.dependency "YYDispatchQueuePool"
2425

2526
end
Binary file not shown.

LFLiveKit/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.6.3</string>
18+
<string>1.7.1</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

LFLiveKit/LFLiveSession.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ - (LFVideoCapture*)videoCaptureSource{
282282
- (id<LFStreamSocket>)socket{
283283
if(!_socket){
284284
if(self.liveType == LFLiveRTMP){
285-
_socket = [[LFStreamRtmpSocket alloc] initWithStream:self.streamInfo];
285+
_socket = [[LFStreamRtmpSocket alloc] initWithStream:self.streamInfo videoSize:self.videoConfiguration.videoSize reconnectInterval:self.reconnectInterval reconnectCount:self.reconnectCount];
286286
}else if(self.liveType == LFLiveFLV){
287287
_socket = [[LFStreamTcpSocket alloc] initWithStream:self.streamInfo videoSize:self.videoConfiguration.videoSize reconnectInterval:self.reconnectInterval reconnectCount:self.reconnectCount];
288288
}

LFLiveKit/capture/LFAudioCapture.m

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ - (instancetype)initWithAudioConfiguration:(LFLiveAudioConfiguration *)configura
3232
self.taskQueue = dispatch_queue_create("com.youku.Laifeng.audioCapture.Queue", NULL);
3333

3434
AVAudioSession *session = [AVAudioSession sharedInstance];
35-
[session setActive:YES withOptions:kAudioSessionSetActiveFlag_NotifyOthersOnDeactivation error:nil];
35+
[session setActive:YES error:nil];
3636

3737
[[NSNotificationCenter defaultCenter] addObserver: self
3838
selector: @selector(handleRouteChange:)
@@ -45,7 +45,7 @@ - (instancetype)initWithAudioConfiguration:(LFLiveAudioConfiguration *)configura
4545

4646
NSError *error = nil;
4747

48-
[session setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker | AVAudioSessionCategoryOptionMixWithOthers error:nil];
48+
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
4949

5050
[session setMode:AVAudioSessionModeVideoRecording error:&error];
5151

@@ -169,6 +169,7 @@ - (void)handleRouteChange:(NSNotification *)notification {
169169
break;
170170
}
171171
NSLog(@"handleRouteChange reason is %@",seccReason);
172+
172173
AVAudioSessionPortDescription *input = [[session.currentRoute.inputs count]?session.currentRoute.inputs:nil objectAtIndex:0];
173174
if (input.portType == AVAudioSessionPortHeadsetMic) {
174175

LFLiveKit/upload/LFStreamRtmpSocket.m

+48-41
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@
88

99
#import "LFStreamRtmpSocket.h"
1010
#import "rtmp.h"
11+
#import "YYDispatchQueuePool.h"
1112

1213
static const NSInteger RetryTimesBreaken = 20;///< 重连1分钟 3秒一次 一共20次
1314
static const NSInteger RetryTimesMargin = 3;
1415

16+
static dispatch_queue_t YYRtmpSendQueue() {
17+
YYDispatchQueuePool *pool = [[YYDispatchQueuePool alloc] initWithName:@"com.youku.laifeng.rtmpsendQueue" queueCount:1 qos:NSQualityOfServiceDefault];
18+
dispatch_queue_t queue = [pool queue];
19+
return queue;
20+
}
21+
#define RTMP_RECEIVE_TIMEOUT 2
1522
#define DATA_ITEMS_MAX_COUNT 100
1623
#define RTMP_DATA_RESERVE_SIZE 400
1724
#define RTMP_HEAD_SIZE (sizeof(RTMPPacket)+RTMP_MAX_HEADER_SIZE)
@@ -46,7 +53,6 @@ @interface LFStreamRtmpSocket ()<LFStreamingBufferDelegate>
4653
@property (nonatomic, weak) id<LFStreamSocketDelegate> delegate;
4754
@property (nonatomic, strong) LFLiveStreamInfo *stream;
4855
@property (nonatomic, strong) LFStreamingBuffer *buffer;
49-
@property (nonatomic, strong) dispatch_queue_t socketQueue;
5056
@property (nonatomic, strong) LFLiveDebug *debugInfo;
5157
//错误信息
5258
@property (nonatomic, assign) RTMPError error;
@@ -83,32 +89,41 @@ - (nullable instancetype)initWithStream:(nullable LFLiveStreamInfo*)stream video
8389
}
8490

8591
- (void) start{
86-
dispatch_async(self.socketQueue, ^{
87-
if(!_stream) return;
88-
if(_isConnecting) return;
89-
if(_rtmp != NULL) return;
90-
self.debugInfo.streamId = self.stream.streamId;
91-
self.debugInfo.uploadUrl = self.stream.url;
92-
self.debugInfo.isRtmp = YES;
93-
[self clean];
94-
[self RTMP264_Connect:(char*)[_stream.url cStringUsingEncoding:NSASCIIStringEncoding]];
92+
dispatch_async(YYRtmpSendQueue(), ^{
93+
[self _start];
9594
});
9695
}
9796

97+
- (void)_start{
98+
if(!_stream) return;
99+
if(_isConnecting) return;
100+
if(_rtmp != NULL) return;
101+
self.debugInfo.streamId = self.stream.streamId;
102+
self.debugInfo.uploadUrl = self.stream.url;
103+
self.debugInfo.isRtmp = YES;
104+
[self clean];
105+
[self RTMP264_Connect:(char*)[_stream.url cStringUsingEncoding:NSASCIIStringEncoding]];
106+
}
107+
98108
- (void) stop{
99-
dispatch_async(self.socketQueue, ^{
100-
if(_rtmp != NULL){
101-
PILI_RTMP_Close(_rtmp, &_error);
102-
PILI_RTMP_Free(_rtmp);
103-
_rtmp = NULL;
104-
}
109+
dispatch_async(YYRtmpSendQueue(), ^{
110+
[self _stop];
105111
});
106112
}
107113

114+
- (void)_stop{
115+
if(self.delegate && [self.delegate respondsToSelector:@selector(socketStatus:status:)]){
116+
[self.delegate socketStatus:self status:LFLiveStop];
117+
}
118+
if(_rtmp != NULL){
119+
PILI_RTMP_Close(_rtmp, &_error);
120+
PILI_RTMP_Free(_rtmp);
121+
_rtmp = NULL;
122+
}
123+
}
124+
108125
- (void) sendFrame:(LFFrame*)frame{
109-
__weak typeof(self) _self = self;
110-
dispatch_async(self.socketQueue, ^{
111-
__strong typeof(_self) self = _self;
126+
dispatch_async(YYRtmpSendQueue(), ^{
112127
if(!frame) return;
113128
[self.buffer appendObject:frame];
114129
[self sendFrame];
@@ -209,6 +224,7 @@ -(NSInteger) RTMP264_Connect:(char *)push_url{
209224
_rtmp->m_connCallback = ConnectionTimeCallback;
210225
_rtmp->m_userData = (__bridge void*)self;
211226
_rtmp->m_msgCounter = 1;
227+
_rtmp->Link.timeout = RTMP_RECEIVE_TIMEOUT;
212228
//设置可写,即发布流,这个函数必须在连接前使用,否则无效
213229
PILI_RTMP_EnableWrite(_rtmp);
214230

@@ -398,7 +414,10 @@ - (NSInteger)RtmpPacketSend:(PILI_RTMPPacket*)packet{
398414
int success = PILI_RTMP_SendPacket(_rtmp,packet,0,&_error);
399415
if(success){
400416
self.isSending = NO;
401-
[self sendFrame];
417+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
418+
[self sendFrame];
419+
});
420+
402421
}
403422
return success;
404423
}
@@ -438,30 +457,24 @@ - (void)sendAudio:(LFFrame*)frame {
438457

439458
// 断线重连
440459
-(void) reconnect {
441-
_isReconnecting = NO;
442-
if(_isConnected) return;
443-
if(_rtmp){
444-
PILI_RTMP_ReconnectStream(_rtmp, 0, &_error);
445-
}else{
446-
[self stop];
447-
[self start];
448-
}
460+
dispatch_async(YYRtmpSendQueue(), ^{
461+
_isReconnecting = NO;
462+
if(_isConnected) return;
463+
464+
[self _stop];
465+
[self _start];
466+
});
449467
}
450468

451469
#pragma mark -- CallBack
452470
void RTMPErrorCallback(RTMPError *error, void *userData){
453471
LFStreamRtmpSocket *socket = (__bridge LFStreamRtmpSocket*)userData;
454-
if(error->code == RTMPErrorSocketClosedByPeer){
455-
[socket stop];
456-
if(socket.delegate && [socket.delegate respondsToSelector:@selector(socketStatus:status:)]){
457-
[socket.delegate socketStatus:socket status:LFLiveError];
458-
}
459-
}else{
472+
if(error->code < 0){
460473
if(socket.retryTimes4netWorkBreaken++ < socket.reconnectCount && !socket.isReconnecting){
461474
socket.isConnected = NO;
462475
socket.isConnecting = NO;
463476
socket.isReconnecting = YES;
464-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(socket.reconnectInterval * NSEC_PER_SEC)), socket.socketQueue, ^{
477+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(socket.reconnectInterval * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
465478
[socket reconnect];
466479
});
467480
}else if(socket.retryTimes4netWorkBreaken >= socket.reconnectCount){
@@ -480,12 +493,6 @@ void ConnectionTimeCallback(PILI_CONNECTION_TIME* conn_time, void *userData){
480493
}
481494

482495
#pragma mark -- Getter Setter
483-
- (dispatch_queue_t)socketQueue{
484-
if(!_socketQueue){
485-
_socketQueue = dispatch_queue_create("com.youku.LaiFeng.live.socketQueue", NULL);
486-
}
487-
return _socketQueue;
488-
}
489496

490497
- (LFStreamingBuffer*)buffer{
491498
if(!_buffer){

LFLiveKitDemo/LFLiveKitDemo/LFLivePreview.m

+5-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ - (void)requestAccessForVideo{
5959
}
6060
case AVAuthorizationStatusAuthorized:{
6161
// 已经开启授权,可继续
62-
[_self.session setRunning:YES];
62+
dispatch_async(dispatch_get_main_queue(), ^{
63+
[_self.session setRunning:YES];
64+
});
6365
break;
6466
}
6567
case AVAuthorizationStatusDenied:
@@ -218,7 +220,7 @@ - (LFLiveSession*)session{
218220
*/
219221

220222

221-
_session.running = YES;
223+
_session.delegate = self;
222224
_session.preView = self;
223225
}
224226
return _session;
@@ -310,7 +312,7 @@ - (UIButton*)startLiveButton{
310312
if(_self.startLiveButton.selected){
311313
[_self.startLiveButton setTitle:@"结束直播" forState:UIControlStateNormal];
312314
LFLiveStreamInfo *stream = [LFLiveStreamInfo new];
313-
stream.url = @"rtmp://30.96.179.95:1935/live/1234";
315+
stream.url = @"rtmp://live.hkstv.hk.lxdns.com:1935/live/stream789";
314316
//stream.url = @"rtmp://daniulive.com:1935/live/stream2399";
315317
[_self.session startLive:stream];
316318
}else{

LFLiveKitDemo/Podfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ platform :ios,'8.0'
33

44
target "LFLiveKitDemo" do
55

6-
pod 'LFLiveKit', '~> 1.5.2'
6+
pod 'LFLiveKit', '~> 1.7.1'
7+
pod 'YYDispatchQueuePool'
78

89
end

Podfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ target "LFLiveKit" do
66
pod 'CocoaAsyncSocket', '~> 7.4.1'
77
pod 'pili-librtmp', '~> 1.0.2'
88
pod 'LMGPUImage', '~> 0.1.9'
9-
9+
pod 'YYDispatchQueuePool'
1010
end

0 commit comments

Comments
 (0)