From 5f5770dd46491133b135a71fc2d4f92d13107ade Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 1 Mar 2017 10:31:36 +0300 Subject: [PATCH] Support special seek whence for ffmpeg. AVSEEK_SIZE is passed as a whence when ffmpeg needs just data size. --- Telegram/SourceFiles/media/media_audio_capture.cpp | 4 ++++ Telegram/SourceFiles/media/media_audio_ffmpeg_loader.cpp | 8 ++++++++ Telegram/SourceFiles/media/media_clip_ffmpeg.cpp | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/Telegram/SourceFiles/media/media_audio_capture.cpp b/Telegram/SourceFiles/media/media_audio_capture.cpp index 3f520e60a9..643b92659b 100644 --- a/Telegram/SourceFiles/media/media_audio_capture.cpp +++ b/Telegram/SourceFiles/media/media_audio_capture.cpp @@ -157,6 +157,10 @@ struct Instance::Inner::Private { case SEEK_SET: newPos = offset; break; case SEEK_CUR: newPos = l->dataPos + offset; break; case SEEK_END: newPos = l->data.size() + offset; break; + case AVSEEK_SIZE: { + // Special whence for determining filesize without any seek. + return l->data.size(); + } break; } if (newPos < 0) { return -1; diff --git a/Telegram/SourceFiles/media/media_audio_ffmpeg_loader.cpp b/Telegram/SourceFiles/media/media_audio_ffmpeg_loader.cpp index 69fafd00cc..0ca1105805 100644 --- a/Telegram/SourceFiles/media/media_audio_ffmpeg_loader.cpp +++ b/Telegram/SourceFiles/media/media_audio_ffmpeg_loader.cpp @@ -109,6 +109,10 @@ int64_t AbstractFFMpegLoader::_seek_data(void *opaque, int64_t offset, int whenc case SEEK_SET: newPos = offset; break; case SEEK_CUR: newPos = l->dataPos + offset; break; case SEEK_END: newPos = l->data.size() + offset; break; + case AVSEEK_SIZE: { + // Special whence for determining filesize without any seek. + return l->data.size(); + } break; } if (newPos < 0 || newPos > l->data.size()) { return -1; @@ -129,6 +133,10 @@ int64_t AbstractFFMpegLoader::_seek_file(void *opaque, int64_t offset, int whenc case SEEK_SET: return l->f.seek(offset) ? l->f.pos() : -1; case SEEK_CUR: return l->f.seek(l->f.pos() + offset) ? l->f.pos() : -1; case SEEK_END: return l->f.seek(l->f.size() + offset) ? l->f.pos() : -1; + case AVSEEK_SIZE: { + // Special whence for determining filesize without any seek. + return l->f.size(); + } break; } return -1; } diff --git a/Telegram/SourceFiles/media/media_clip_ffmpeg.cpp b/Telegram/SourceFiles/media/media_clip_ffmpeg.cpp index 9753634831..86fb2cd7b1 100644 --- a/Telegram/SourceFiles/media/media_clip_ffmpeg.cpp +++ b/Telegram/SourceFiles/media/media_clip_ffmpeg.cpp @@ -582,6 +582,10 @@ int64_t FFMpegReaderImplementation::_seek(void *opaque, int64_t offset, int when case SEEK_SET: return l->_device->seek(offset) ? l->_device->pos() : -1; case SEEK_CUR: return l->_device->seek(l->_device->pos() + offset) ? l->_device->pos() : -1; case SEEK_END: return l->_device->seek(l->_device->size() + offset) ? l->_device->pos() : -1; + case AVSEEK_SIZE: { + // Special whence for determining filesize without any seek. + return l->_dataSize; + } break; } return -1; }