Fixed voice message encoding issue that resulted in malformed ogg files causing playback errors on ffmpeg v4

This commit is contained in:
Ilya Laktyushin 2019-08-02 05:28:03 +03:00
parent ee3142966e
commit f3901f6dc4
2 changed files with 48 additions and 52 deletions

View File

@ -178,7 +178,7 @@ static const int encoderPacketSizeInBytes = TGBridgeAudioEncoderSampleRate / 100
if (_assetReader.status == AVAssetReaderStatusCompleted)
{
NSLog(@"finished");
if (_oggWriter != nil && [_oggWriter writeFrame:NULL frameByteCount:0])
if (_oggWriter != nil)
{
dataItemResult = _tempFileItem;
durationResult = [_oggWriter encodedDuration];

View File

@ -557,7 +557,7 @@ final class ManagedAudioRecorderContext {
self.currentPeak = max(Int64(sample), self.currentPeak)
self.currentPeakCount += 1
if self.currentPeakCount == self.peakCompressionFactor {
var compressedPeak = self.currentPeak//Int16(Float(self.currentPeak) / Float(self.peakCompressionFactor))
var compressedPeak = self.currentPeak
withUnsafeBytes(of: &compressedPeak, { buffer in
self.compressedWaveformSamples.append(buffer.bindMemory(to: UInt8.self))
})
@ -592,7 +592,6 @@ final class ManagedAudioRecorderContext {
}
func takeData() -> RecordedAudioData? {
if self.oggWriter.writeFrame(nil, frameByteCount: 0) {
var scaledSamplesMemory = malloc(100 * 2)!
var scaledSamples: UnsafeMutablePointer<Int16> = scaledSamplesMemory.assumingMemoryBound(to: Int16.self)
defer {
@ -640,9 +639,6 @@ final class ManagedAudioRecorderContext {
}
return RecordedAudioData(compressedData: self.dataItem.data(), duration: self.oggWriter.encodedDuration(), waveform: waveform)
} else {
return nil
}
}
}