mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-02 00:17:02 +00:00
Fixed opus encoding completion
This commit is contained in:
parent
41c468c139
commit
b4541f7495
@ -178,7 +178,7 @@ static const int encoderPacketSizeInBytes = TGBridgeAudioEncoderSampleRate / 100
|
|||||||
if (_assetReader.status == AVAssetReaderStatusCompleted)
|
if (_assetReader.status == AVAssetReaderStatusCompleted)
|
||||||
{
|
{
|
||||||
NSLog(@"finished");
|
NSLog(@"finished");
|
||||||
if (_oggWriter != nil)
|
if (_oggWriter != nil && [_oggWriter writeFrame:NULL frameByteCount:0])
|
||||||
{
|
{
|
||||||
dataItemResult = _tempFileItem;
|
dataItemResult = _tempFileItem;
|
||||||
durationResult = [_oggWriter encodedDuration];
|
durationResult = [_oggWriter encodedDuration];
|
||||||
|
@ -592,6 +592,7 @@ final class ManagedAudioRecorderContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func takeData() -> RecordedAudioData? {
|
func takeData() -> RecordedAudioData? {
|
||||||
|
if self.oggWriter.writeFrame(nil, frameByteCount: 0) {
|
||||||
var scaledSamplesMemory = malloc(100 * 2)!
|
var scaledSamplesMemory = malloc(100 * 2)!
|
||||||
var scaledSamples: UnsafeMutablePointer<Int16> = scaledSamplesMemory.assumingMemoryBound(to: Int16.self)
|
var scaledSamples: UnsafeMutablePointer<Int16> = scaledSamplesMemory.assumingMemoryBound(to: Int16.self)
|
||||||
defer {
|
defer {
|
||||||
@ -639,6 +640,9 @@ final class ManagedAudioRecorderContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return RecordedAudioData(compressedData: self.dataItem.data(), duration: self.oggWriter.encodedDuration(), waveform: waveform)
|
return RecordedAudioData(compressedData: self.dataItem.data(), duration: self.oggWriter.encodedDuration(), waveform: waveform)
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,10 +426,12 @@ static inline int writeOggPage(ogg_page *page, TGDataItem *fileItem)
|
|||||||
pages_out++;
|
pages_out++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (framePcmBytes != NULL) {
|
||||||
op.packet = (unsigned char *)_packet;
|
op.packet = (unsigned char *)_packet;
|
||||||
op.bytes = nbBytes;
|
op.bytes = nbBytes;
|
||||||
op.b_o_s = 0;
|
op.b_o_s = 0;
|
||||||
op.granulepos = enc_granulepos;
|
op.granulepos = enc_granulepos;
|
||||||
|
|
||||||
if (op.e_o_s)
|
if (op.e_o_s)
|
||||||
{
|
{
|
||||||
/* We compute the final GP as ceil(len*48k/input_rate). When a resampling
|
/* We compute the final GP as ceil(len*48k/input_rate). When a resampling
|
||||||
@ -441,24 +443,7 @@ static inline int writeOggPage(ogg_page *page, TGDataItem *fileItem)
|
|||||||
op.packetno = 2 + _packetId;
|
op.packetno = 2 + _packetId;
|
||||||
ogg_stream_packetin(&os, &op);
|
ogg_stream_packetin(&os, &op);
|
||||||
last_segments += size_segments;
|
last_segments += size_segments;
|
||||||
|
|
||||||
/* The downside of early reading is if the input is an exact
|
|
||||||
multiple of the frame_size you'll get an extra frame that needs
|
|
||||||
to get cropped off. The downside of late reading is added delay.
|
|
||||||
If your ogg_delay is 120ms or less we'll assume you want the
|
|
||||||
low delay behavior.
|
|
||||||
*/
|
|
||||||
/*if ((!op.e_o_s) && max_ogg_delay > 5760)
|
|
||||||
{
|
|
||||||
nb_samples = inopt.read_samples(inopt.readdata, input, frame_size);
|
|
||||||
total_samples += nb_samples;
|
|
||||||
if (nb_samples < frame_size)
|
|
||||||
eos = 1;
|
|
||||||
if (nb_samples == 0)
|
|
||||||
op.e_o_s = 1;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
nb_samples = -1;*/
|
|
||||||
|
|
||||||
// If the stream is over or we're sure that the delayed flush will fire, go ahead and flush now to avoid adding delay
|
// If the stream is over or we're sure that the delayed flush will fire, go ahead and flush now to avoid adding delay
|
||||||
while ((op.e_o_s || (enc_granulepos + (frame_size * 48000 / coding_rate) - last_granulepos > max_ogg_delay) ||
|
while ((op.e_o_s || (enc_granulepos + (frame_size * 48000 / coding_rate) - last_granulepos > max_ogg_delay) ||
|
||||||
|
Loading…
x
Reference in New Issue
Block a user