diff options
author | John Preston <johnprestonmail@gmail.com> | 2023-03-08 13:31:58 +0400 |
---|---|---|
committer | John Preston <johnprestonmail@gmail.com> | 2023-03-08 16:10:36 +0400 |
commit | 9c74c04738d419496d2f9966ad16d33f321bbdca (patch) | |
tree | d6311d837e2cc97d6a9356ed7b726023d56a3d0e /Telegram/SourceFiles/media/audio/media_child_ffmpeg_loader.cpp | |
parent | 0880a83c2c7d06d20f2fb06ce020fac14cbee6d8 (diff) |
Implement audio speed using libavfilter.
Diffstat (limited to 'Telegram/SourceFiles/media/audio/media_child_ffmpeg_loader.cpp')
-rw-r--r-- | Telegram/SourceFiles/media/audio/media_child_ffmpeg_loader.cpp | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/Telegram/SourceFiles/media/audio/media_child_ffmpeg_loader.cpp b/Telegram/SourceFiles/media/audio/media_child_ffmpeg_loader.cpp index 04c338c5d9..1fa8139b25 100644 --- a/Telegram/SourceFiles/media/audio/media_child_ffmpeg_loader.cpp +++ b/Telegram/SourceFiles/media/audio/media_child_ffmpeg_loader.cpp @@ -11,6 +11,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/file_location.h" namespace Media { +namespace { + +using FFmpeg::AvErrorWrap; + +} // namespace ChildFFMpegLoader::ChildFFMpegLoader( std::unique_ptr<ExternalSoundData> &&data) @@ -22,14 +27,13 @@ ChildFFMpegLoader::ChildFFMpegLoader( Expects(_parentData->codec != nullptr); } -bool ChildFFMpegLoader::open(crl::time positionMs) { - return initUsingContext( - _parentData->codec.get(), - _parentData->length, - _parentData->frequency); +bool ChildFFMpegLoader::open(crl::time positionMs, float64 speed) { + const auto sample = (positionMs * samplesFrequency()) / 1000LL; + overrideDuration(sample, _parentData->duration); + return initUsingContext(_parentData->codec.get(), speed); } -AudioPlayerLoader::ReadResult ChildFFMpegLoader::readFromInitialFrame() { +auto ChildFFMpegLoader::readFromInitialFrame() -> ReadResult { if (!_parentData->frame) { return ReadError::Wait; } @@ -58,28 +62,22 @@ auto ChildFFMpegLoader::readMore() -> ReadResult { _eofReached = packet.empty(); if (_eofReached) { avcodec_send_packet(_parentData->codec.get(), nullptr); // drain - return bytes::const_span(); + return ReadError::Retry; } - auto res = avcodec_send_packet( + AvErrorWrap error = avcodec_send_packet( _parentData->codec.get(), &packet.fields()); - if (res < 0) { - char err[AV_ERROR_MAX_STRING_SIZE] = { 0 }; - LOG(("Audio Error: Unable to avcodec_send_packet() file '%1', " - "data size '%2', error %3, %4" - ).arg(_file.name() - ).arg(_data.size() - ).arg(res - ).arg(av_make_error_string(err, sizeof(err), res))); + if (error) { + LogError(u"avcodec_send_packet"_q, error); // There is a sample voice message where skipping such packet // results in a crash (read_access to nullptr) in swr_convert(). - if (res == AVERROR_INVALIDDATA) { - return ReadError::NotYet; // try to skip bad packet + if (error.code() == AVERROR_INVALIDDATA) { + return ReadError::Retry; // try to skip bad packet } return ReadError::Other; } - return bytes::const_span(); + return ReadError::Retry; } void ChildFFMpegLoader::enqueuePackets( |