mirror of
https://github.com/signalapp/libsignal.git
synced 2026-05-02 04:27:22 +02:00
This MP4 format "sanitizer" currently only transforms (when necessary) outgoing media on iOS, Android, or Desktop to make it suitable for streaming playback by the recepient. In the future, it will validate and be able to either repair or reject outbound AND inbound media, to prevent malformed media from being fed to third party or OS media players. An generic io module was added to the libsignal rust bridge containing the InputStream trait, modeled loosely after Java's InputStream, which calls back into the client language to perform reads or skips. This infrastructure could potentially also be for any other future large data inputs to libsignal functions.
39 lines
1.5 KiB
Swift
39 lines
1.5 KiB
Swift
//
|
|
// Copyright 2023 Signal Messenger, LLC.
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
//
|
|
|
|
import Foundation
|
|
import SignalFfi
|
|
|
|
internal func withInputStream<Result>(_ stream: SignalInputStream, _ body: (UnsafePointer<SignalFfi.SignalInputStream>) throws -> Result) throws -> Result {
|
|
func ffiShimRead(stream_ctx: UnsafeMutableRawPointer?,
|
|
pBuf: UnsafeMutablePointer<UInt8>?,
|
|
bufLen: UInt,
|
|
pAmountRead: UnsafeMutablePointer<UInt>?) -> Int32 {
|
|
let streamContext = stream_ctx!.assumingMemoryBound(to: ErrorHandlingContext<SignalInputStream>.self)
|
|
return streamContext.pointee.catchCallbackErrors { stream in
|
|
let buf = UnsafeMutableRawBufferPointer(start: pBuf, count: Int(bufLen))
|
|
let amountRead = try stream.read(into: buf)
|
|
pAmountRead!.pointee = amountRead
|
|
return 0
|
|
}
|
|
}
|
|
|
|
func ffiShimSkip(stream_ctx: UnsafeMutableRawPointer?, amount: UInt64) -> Int32 {
|
|
let streamContext = stream_ctx!.assumingMemoryBound(to: ErrorHandlingContext<SignalInputStream>.self)
|
|
return streamContext.pointee.catchCallbackErrors { stream in
|
|
try stream.skip(by: amount)
|
|
return 0
|
|
}
|
|
}
|
|
|
|
return try rethrowCallbackErrors(stream) {
|
|
var ffiStream = SignalFfi.SignalInputStream(
|
|
ctx: $0,
|
|
read: ffiShimRead as SignalRead,
|
|
skip: ffiShimSkip as SignalSkip)
|
|
return try body(&ffiStream)
|
|
}
|
|
}
|