Commit fa916616 by suolong

解决agora盘路推流问题

parent e2fa0bda
......@@ -49,10 +49,44 @@ NSString * const kLiveLinkMicRoleDidChanged = @"linkMicRoleChange";
@property (nonatomic, assign) BOOL hasCancelPerssionAlert;
// 进频道成功后暂存旁路参数,等待本地媒体真正发布再启动 RTMP。
@property (nonatomic, copy, nullable) NSString *pendingRtmpUrl;
@property (nonatomic, copy, nullable) NSString *pendingRtmpChannelId;
@property (nonatomic, assign) BOOL hasJoinedForRtmp;
@property (nonatomic, assign) BOOL hasPublishedLocalMedia;
@property (nonatomic, assign) BOOL hasStartedRtmp;
@end
@implementation FUSAgoraHelper
- (void)fus_resetPendingRtmpWithChannelId:(NSString *)channelId {
self.pendingRtmpUrl = nil;
self.pendingRtmpChannelId = channelId;
self.hasJoinedForRtmp = NO;
self.hasPublishedLocalMedia = NO;
self.hasStartedRtmp = NO;
}
// joinSuccess 不保证本地音视频轨道已经发布,过早启动旁路可能向 CDN 推送空流。
- (void)fus_tryStartPendingRtmp {
if (self.hasStartedRtmp || !self.hasJoinedForRtmp || !self.hasPublishedLocalMedia) {
return;
}
if (self.pendingRtmpUrl.length == 0 ||
self.pendingRtmpChannelId.integerValue != self.currentChannelId) {
return;
}
self.hasStartedRtmp = YES;
NSInteger result = [self.agoraEngine startRtmpStreamWithoutTranscoding:self.pendingRtmpUrl];
FUSLogInfo(@"[AgoraRtmpTrace] start requested after media published result=%ld channel=%@ uid=%ld",
(long)result, self.pendingRtmpChannelId, (long)self.uid);
if (result != 0) {
self.hasStartedRtmp = NO;
}
}
+ (instancetype)shareInstance {
......@@ -288,6 +322,7 @@ NSString * const kLiveLinkMicRoleDidChanged = @"linkMicRoleChange";
return;
}
self.myselfIsOnMic = YES;
[self fus_resetPendingRtmpWithChannelId:channelId];
dispatch_async(dispatch_get_main_queue(), ^{
[FUSLiveHelper fus_showOBSLoadingView];
});
......@@ -322,7 +357,12 @@ NSString * const kLiveLinkMicRoleDidChanged = @"linkMicRoleChange";
// 如果不是连麦房
// [weakSelf.captureHelper fus_pauseCapture];
// [weakSelf.captureHelper fus_pauseAudioCapture];
[weakSelf.agoraEngine startRtmpStreamWithoutTranscoding:[FUSLiveHelper shareInstance].streamView.pushView.streamUrl];
weakSelf.pendingRtmpUrl = [FUSLiveHelper shareInstance].streamView.pushView.streamUrl;
weakSelf.pendingRtmpChannelId = channel;
weakSelf.hasJoinedForRtmp = YES;
FUSLogInfo(@"[AgoraRtmpTrace] join succeeded, waiting for local media channel=%@ uid=%ld",
channel, (long)uid);
[weakSelf fus_tryStartPendingRtmp];
}
FUSLogDebug(@"pp===加入频道成功 %@", channel);
......@@ -402,6 +442,11 @@ NSString * const kLiveLinkMicRoleDidChanged = @"linkMicRoleChange";
- (void)fus_stopRTCStreamingWithCompletion:(void(^)(void))completion
{
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(delayUpdateToSpeakerPlay) object:nil];
self.pendingRtmpUrl = nil;
self.pendingRtmpChannelId = nil;
self.hasJoinedForRtmp = NO;
self.hasPublishedLocalMedia = NO;
self.hasStartedRtmp = NO;
if (!_agoraEngine || !_myselfIsOnMic) {
self.isJoining = NO;
return;
......@@ -1275,6 +1320,35 @@ NSString * const kLiveLinkMicRoleDidChanged = @"linkMicRoleChange";
}
- (void)rtcEngine:(AgoraRtcEngineKit *)engine
didVideoPublishStateChange:(NSString *)channelId
sourceType:(AgoraVideoSourceType)sourceType
oldState:(AgoraStreamPublishState)oldState
newState:(AgoraStreamPublishState)newState
elapseSinceLastState:(int)elapseSinceLastState {
FUSLogInfo(@"[AgoraRtmpTrace] video publish state channel=%@ source=%ld old=%ld new=%ld elapsed=%dms",
channelId, (long)sourceType, (long)oldState, (long)newState, elapseSinceLastState);
if (newState == AgoraStreamPublishStatePublished &&
channelId.integerValue == self.currentChannelId) {
self.hasPublishedLocalMedia = YES;
[self fus_tryStartPendingRtmp];
}
}
- (void)rtcEngine:(AgoraRtcEngineKit *)engine
didAudioPublishStateChange:(NSString *)channelId
oldState:(AgoraStreamPublishState)oldState
newState:(AgoraStreamPublishState)newState
elapseSinceLastState:(int)elapseSinceLastState {
FUSLogInfo(@"[AgoraRtmpTrace] audio publish state channel=%@ old=%ld new=%ld elapsed=%dms",
channelId, (long)oldState, (long)newState, elapseSinceLastState);
if (newState == AgoraStreamPublishStatePublished &&
channelId.integerValue == self.currentChannelId) {
self.hasPublishedLocalMedia = YES;
[self fus_tryStartPendingRtmp];
}
}
/** The status of publishing a stream in CDN live.
@param engine AgoraRtcEngineKit object.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment