Various Fixes

This commit is contained in:
Ilya Laktyushin 2021-07-25 13:01:18 +03:00
parent 1f0646541d
commit c9d4c266dd
10 changed files with 52 additions and 33 deletions

View File

@ -182,12 +182,12 @@ private final class LegacyComponentsGlobalsProviderImpl: NSObject, LegacyCompone
let convertedType: ManagedAudioSessionType
switch type {
case TGAudioSessionTypePlayAndRecord, TGAudioSessionTypePlayAndRecordHeadphones:
convertedType = .record(speaker: false)
convertedType = .recordWithOthers
default:
convertedType = .play
}
let disposable = legacyContext.sharedContext.mediaManager.audioSession.push(audioSessionType: convertedType, once: true, activate: { _ in
}, deactivate: {
}, deactivate: { _ in
interrupted?()
return .complete()
})

View File

@ -515,7 +515,7 @@ private final class AudioPlayerRendererContext {
switch self.audioSession {
case let .manager(manager):
self.audioSessionDisposable.set(manager.push(audioSessionType: self.ambient ? .ambient : (self.playAndRecord ? .playWithPossiblePortOverride : .play), outputMode: self.forceAudioToSpeaker ? .speakerIfNoHeadphones : .system, once: true, manualActivate: { [weak self] control in
self.audioSessionDisposable.set(manager.push(audioSessionType: self.ambient ? .ambient : (self.playAndRecord ? .playWithPossiblePortOverride : .play), outputMode: self.forceAudioToSpeaker ? .speakerIfNoHeadphones : .system, once: self.ambient, manualActivate: { [weak self] control in
audioPlayerRendererQueue.async {
if let strongSelf = self {
strongSelf.audioSessionControl = control
@ -532,13 +532,15 @@ private final class AudioPlayerRendererContext {
}
}
}
}, deactivate: { [weak self] in
}, deactivate: { [weak self] temporary in
return Signal { subscriber in
audioPlayerRendererQueue.async {
if let strongSelf = self {
strongSelf.audioSessionControl = nil
strongSelf.audioPaused()
strongSelf.stop()
if !temporary {
strongSelf.audioPaused()
strongSelf.stop()
}
subscriber.putCompletion()
}
}

View File

@ -233,7 +233,7 @@ public func playSound(context: AccountContext, sound: PeerMessageSound, defaultS
currentPlayer?.play()
}
}
}, deactivate: {
}, deactivate: { _ in
return Signal { subscriber in
Queue.mainQueue().async {
currentPlayer?.stop()

View File

@ -21,6 +21,7 @@ public enum ManagedAudioSessionType: Equatable {
case record(speaker: Bool)
case voiceCall
case videoCall
case recordWithOthers
var isPlay: Bool {
switch self {
@ -38,7 +39,7 @@ private func nativeCategoryForType(_ type: ManagedAudioSessionType, headphones:
return .ambient
case .play:
return .playback
case .record, .voiceCall, .videoCall:
case .record, .recordWithOthers, .voiceCall, .videoCall:
return .playAndRecord
case .playWithPossiblePortOverride:
if headphones {
@ -114,7 +115,7 @@ private final class HolderRecord {
let audioSessionType: ManagedAudioSessionType
let control: ManagedAudioSessionControl
let activate: (ManagedAudioSessionControl) -> Void
let deactivate: () -> Signal<Void, NoError>
let deactivate: (Bool) -> Signal<Void, NoError>
let headsetConnectionStatusChanged: (Bool) -> Void
let availableOutputsChanged: ([AudioSessionOutput], AudioSessionOutput?) -> Void
let once: Bool
@ -122,7 +123,7 @@ private final class HolderRecord {
var active: Bool = false
var deactivatingDisposable: Disposable? = nil
init(id: Int32, audioSessionType: ManagedAudioSessionType, control: ManagedAudioSessionControl, activate: @escaping (ManagedAudioSessionControl) -> Void, deactivate: @escaping () -> Signal<Void, NoError>, headsetConnectionStatusChanged: @escaping (Bool) -> Void, availableOutputsChanged: @escaping ([AudioSessionOutput], AudioSessionOutput?) -> Void, once: Bool, outputMode: AudioSessionOutputMode) {
init(id: Int32, audioSessionType: ManagedAudioSessionType, control: ManagedAudioSessionControl, activate: @escaping (ManagedAudioSessionControl) -> Void, deactivate: @escaping (Bool) -> Signal<Void, NoError>, headsetConnectionStatusChanged: @escaping (Bool) -> Void, availableOutputsChanged: @escaping ([AudioSessionOutput], AudioSessionOutput?) -> Void, once: Bool, outputMode: AudioSessionOutputMode) {
self.id = id
self.audioSessionType = audioSessionType
self.control = control
@ -431,7 +432,7 @@ public final class ManagedAudioSession {
return AVAudioSession.sharedInstance().secondaryAudioShouldBeSilencedHint
}
public func push(audioSessionType: ManagedAudioSessionType, outputMode: AudioSessionOutputMode = .system, once: Bool = false, activate: @escaping (AudioSessionActivationState) -> Void, deactivate: @escaping () -> Signal<Void, NoError>) -> Disposable {
public func push(audioSessionType: ManagedAudioSessionType, outputMode: AudioSessionOutputMode = .system, once: Bool = false, activate: @escaping (AudioSessionActivationState) -> Void, deactivate: @escaping (Bool) -> Signal<Void, NoError>) -> Disposable {
return self.push(audioSessionType: audioSessionType, once: once, manualActivate: { control in
control.setupAndActivate(synchronous: false, { state in
activate(state)
@ -439,7 +440,7 @@ public final class ManagedAudioSession {
}, deactivate: deactivate)
}
public func push(audioSessionType: ManagedAudioSessionType, outputMode: AudioSessionOutputMode = .system, once: Bool = false, activateImmediately: Bool = false, manualActivate: @escaping (ManagedAudioSessionControl) -> Void, deactivate: @escaping () -> Signal<Void, NoError>, headsetConnectionStatusChanged: @escaping (Bool) -> Void = { _ in }, availableOutputsChanged: @escaping ([AudioSessionOutput], AudioSessionOutput?) -> Void = { _, _ in }) -> Disposable {
public func push(audioSessionType: ManagedAudioSessionType, outputMode: AudioSessionOutputMode = .system, once: Bool = false, activateImmediately: Bool = false, manualActivate: @escaping (ManagedAudioSessionControl) -> Void, deactivate: @escaping (Bool) -> Signal<Void, NoError>, headsetConnectionStatusChanged: @escaping (Bool) -> Void = { _ in }, availableOutputsChanged: @escaping ([AudioSessionOutput], AudioSessionOutput?) -> Void = { _, _ in }) -> Disposable {
let id = OSAtomicIncrement32(&self.nextId)
let queue = self.queue
queue.async {
@ -566,9 +567,12 @@ public final class ManagedAudioSession {
}
index += 1
}
let lastIsRecordWithOthers = self.holders.last?.audioSessionType == .recordWithOthers
if !deactivating {
if let activeIndex = activeIndex {
var deactivate = false
var temporary = false
if interruption {
if self.holders[activeIndex].audioSessionType != .voiceCall {
@ -576,7 +580,10 @@ public final class ManagedAudioSession {
}
} else {
if activeIndex != self.holders.count - 1 {
if self.holders[activeIndex].audioSessionType == .voiceCall {
if lastIsRecordWithOthers {
deactivate = true
temporary = true
} else if self.holders[activeIndex].audioSessionType == .voiceCall {
deactivate = false
} else {
deactivate = true
@ -587,7 +594,7 @@ public final class ManagedAudioSession {
if deactivate {
self.holders[activeIndex].active = false
let id = self.holders[activeIndex].id
self.holders[activeIndex].deactivatingDisposable = (self.holders[activeIndex].deactivate()
self.holders[activeIndex].deactivatingDisposable = (self.holders[activeIndex].deactivate(temporary)
|> deliverOn(self.queue)).start(completed: { [weak self] in
guard let strongSelf = self else {
return
@ -726,21 +733,24 @@ public final class ManagedAudioSession {
options.insert(.allowBluetooth)
}
}
case .record, .voiceCall, .videoCall:
case .record, .recordWithOthers, .voiceCall, .videoCall:
options.insert(.allowBluetooth)
}
managedAudioSessionLog("ManagedAudioSession setting active true")
let mode: AVAudioSession.Mode
switch type {
case .voiceCall:
mode = .voiceChat
options.insert(.mixWithOthers)
case .videoCall:
mode = .videoChat
options.insert(.mixWithOthers)
default:
mode = .default
}
switch type {
case .voiceCall:
mode = .voiceChat
options.insert(.mixWithOthers)
case .videoCall:
mode = .videoChat
options.insert(.mixWithOthers)
case .recordWithOthers:
mode = .videoRecording
options.insert(.mixWithOthers)
default:
mode = .default
}
if #available(iOSApplicationExtension 11.0, iOS 11.0, *) {
try AVAudioSession.sharedInstance().setCategory(nativeCategory, mode: mode, policy: .default, options: options)
} else {

View File

@ -391,7 +391,7 @@ public final class PresentationCallImpl: PresentationCall {
}
}
}
}, deactivate: { [weak self] in
}, deactivate: { [weak self] _ in
return Signal { subscriber in
Queue.mainQueue().async {
if let strongSelf = self {

View File

@ -662,7 +662,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
strongSelf.updateSessionState(internalState: strongSelf.internalState, audioSessionControl: control)
}
}
}, deactivate: { [weak self] in
}, deactivate: { [weak self] _ in
return Signal { subscriber in
Queue.mainQueue().async {
if let strongSelf = self {

View File

@ -199,6 +199,9 @@ class ChatMessageInteractiveInstantVideoNode: ASDisplayNode {
break
}
}
if item.message.id.namespace == Namespaces.Message.Local {
notConsumed = true
}
var updatedPlaybackStatus: Signal<FileMediaResourceStatus, NoError>?
if let updatedFile = updatedFile, updatedMedia || updatedMessageId {
@ -917,6 +920,7 @@ class ChatMessageInteractiveInstantVideoNode: ASDisplayNode {
}
}
private var animatedFadeIn = false
func animateFromSnapshot(snapshotView: UIView, transition: CombinedTransition) {
guard let videoFrame = self.videoFrame else {
return
@ -934,9 +938,12 @@ class ChatMessageInteractiveInstantVideoNode: ASDisplayNode {
transition.horizontal.animateTransformScale(node: self, from: 1.0 / scale)
self.dateAndStatusNode.layer.animateAlpha(from: 0.0, to: self.dateAndStatusNode.alpha, duration: 0.15, delay: 0.18)
if let durationNode = self.durationNode {
durationNode.layer.animateAlpha(from: 0.0, to: durationNode.alpha, duration: 0.15, delay: 0.18)
if !self.animatedFadeIn {
self.animatedFadeIn = true
self.dateAndStatusNode.layer.animateAlpha(from: 0.0, to: self.dateAndStatusNode.alpha, duration: 0.15, delay: 0.18)
if let durationNode = self.durationNode {
durationNode.layer.animateAlpha(from: 0.0, to: durationNode.alpha, duration: 0.15, delay: 0.18)
}
}
}
}

View File

@ -402,7 +402,7 @@ final class ManagedAudioRecorderContext {
strongSelf.audioSessionAcquired(headset: state.isHeadsetConnected)
}
}
}, deactivate: { [weak self] in
}, deactivate: { [weak self] _ in
return Signal { subscriber in
queue.async {
if let strongSelf = self {

View File

@ -386,7 +386,7 @@ private final class PlatformVideoContentNode: ASDisplayNode, UniversalVideoConte
self.audioSessionDisposable.set(self.audioSessionManager.push(audioSessionType: .play, activate: { [weak self] _ in
self?.hasAudioSession = true
self?.player.play()
}, deactivate: { [weak self] in
}, deactivate: { [weak self] _ in
self?.hasAudioSession = false
self?.player.pause()
return .complete()

View File

@ -224,7 +224,7 @@ private final class SystemVideoContentNode: ASDisplayNode, UniversalVideoContent
self.audioSessionDisposable.set(self.audioSessionManager.push(audioSessionType: .play, activate: { [weak self] _ in
self?.hasAudioSession = true
self?.player.play()
}, deactivate: { [weak self] in
}, deactivate: { [weak self] _ in
self?.hasAudioSession = false
self?.player.pause()
return .complete()