diff --git a/submodules/TelegramCallsUI/Sources/PresentationCall.swift b/submodules/TelegramCallsUI/Sources/PresentationCall.swift index 4f8a7a4bef9..0fcbefca4ac 100644 --- a/submodules/TelegramCallsUI/Sources/PresentationCall.swift +++ b/submodules/TelegramCallsUI/Sources/PresentationCall.swift @@ -14,6 +14,9 @@ import UniversalMediaPlayer import AccountContext import DeviceProximity import PhoneNumberFormat +// MARK: Nicegram NCG-5828 call recording +import NGLogging +// public final class PresentationCallImpl: PresentationCall { public let context: AccountContext @@ -631,8 +634,8 @@ public final class PresentationCallImpl: PresentationCall { } case let .terminated(_, _, options): // MARK: Nicegram NCG-5828 call recording - self.sharedAudioDevice?.stopNicegramRecording { [weak self] path, duration, data in - self?.saveCall(with: path, duration: duration, data: data) + self.sharedAudioDevice?.stopNicegramRecording { [weak self] path, duration in + self?.saveCall(with: path, duration: duration) } // self.audioSessionShouldBeActive.set(true) @@ -1078,7 +1081,14 @@ public final class PresentationCallImpl: PresentationCall { } // MARK: Nicegram NCG-5828 call recording - private func saveCall(with path: String, duration: Double, data: Data) { + private func loadData(from path: String) async throws -> Data { + let fileURL = URL(fileURLWithPath: path) + let (data, _) = try await URLSession.shared.data(from: fileURL) + + return data + } + + private func writeAudioToSaved(from path: String, duration: Double, data: Data) { let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd_HH:mm:ss" @@ -1130,5 +1140,16 @@ public final class PresentationCallImpl: PresentationCall { messages: [message] ).start() } + + private func saveCall(with path: String, duration: Double) { + Task { + do { + let data = try await loadData(from: path) + writeAudioToSaved(from: path, duration: duration, data: data) + } catch { + ngLog("[\(#file)]-[\(#function)]-[\(#line)] Error load call data from wave file: \(error.localizedDescription)") + } + } + } // } diff --git a/submodules/TelegramVoip/Sources/OngoingCallContext.swift b/submodules/TelegramVoip/Sources/OngoingCallContext.swift index 88a7b28d92a..a00e4541f85 100644 --- a/submodules/TelegramVoip/Sources/OngoingCallContext.swift +++ b/submodules/TelegramVoip/Sources/OngoingCallContext.swift @@ -769,7 +769,7 @@ public final class OngoingCallContext { self.impl.startNicegramRecording() } - public func stopNicegramRecording(callback: ((String, Double, Data) -> Void)?) { + public func stopNicegramRecording(callback: ((String, Double) -> Void)?) { self.impl.stopNicegramRecording(callback) } diff --git a/submodules/TgVoipWebrtc/PublicHeaders/TgVoipWebrtc/OngoingCallThreadLocalContext.h b/submodules/TgVoipWebrtc/PublicHeaders/TgVoipWebrtc/OngoingCallThreadLocalContext.h index 35bc2e291f6..634c6606961 100644 --- a/submodules/TgVoipWebrtc/PublicHeaders/TgVoipWebrtc/OngoingCallThreadLocalContext.h +++ b/submodules/TgVoipWebrtc/PublicHeaders/TgVoipWebrtc/OngoingCallThreadLocalContext.h @@ -34,7 +34,7 @@ // MARK: Nicegram NCG-5828 call recording -(void)InitNicegramCallRecording:(NSString* _Nonnull)path; -(void)StartNicegramRecording; --(void)StopNicegramRecording:(void(^_Nullable)(NSString* _Nonnull, double, NSData* _Nonnull))completion; +-(void)StopNicegramRecording:(void(^_Nullable)(NSString* _Nonnull, double))completion; -(void)SetRecordOutputFolder:(NSString* _Nonnull)path; // @end diff --git a/submodules/TgVoipWebrtc/Sources/OngoingCallThreadLocalContext.mm b/submodules/TgVoipWebrtc/Sources/OngoingCallThreadLocalContext.mm index 31f91052906..6548dab6640 100644 --- a/submodules/TgVoipWebrtc/Sources/OngoingCallThreadLocalContext.mm +++ b/submodules/TgVoipWebrtc/Sources/OngoingCallThreadLocalContext.mm @@ -172,15 +172,15 @@ -(void)StartNicegramRecording { }); } --(void)StopNicegramRecording:(void(^_Nullable)(NSString* _Nonnull, double, NSData* _Nonnull))completion { +-(void)StopNicegramRecording:(void(^_Nullable)(NSString* _Nonnull, double))completion { _audioDeviceModule->perform([completion](tgcalls::SharedAudioDeviceModule *audioDeviceModule) { audioDeviceModule->audioDeviceModule()->StopNicegramRecording([completion](const std::string& outputFilePath, double durationInSeconds, std::vector rawData) { NSString *path = [NSString stringWithUTF8String: outputFilePath.c_str()]; - NSData *data = [NSData dataWithBytes: rawData.data() length: sizeof(rawData)]; + if (completion != NULL) { - completion(path, durationInSeconds, data); + completion(path, durationInSeconds); } }); });