diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index 7ef207d6cf..ed44df027c 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -326,6 +326,7 @@ void StartStreaming( auto options = Media::Streaming::PlaybackOptions(); options.speed = 1.; + options.position = (document->duration() / 2) * crl::time(1000); player->init(options); player->updates( ) | rpl::start_with_next_error_done([=](Update &&update) { diff --git a/Telegram/SourceFiles/media/streaming/media_streaming_audio_track.cpp b/Telegram/SourceFiles/media/streaming/media_streaming_audio_track.cpp index e183a2bdb9..6d2d9cc129 100644 --- a/Telegram/SourceFiles/media/streaming/media_streaming_audio_track.cpp +++ b/Telegram/SourceFiles/media/streaming/media_streaming_audio_track.cpp @@ -25,7 +25,8 @@ AudioTrack::AudioTrack( , _stream(std::move(stream)) , _audioId(audioId) , _ready(std::move(ready)) -, _error(std::move(error)) { +, _error(std::move(error)) +, _playPosition(options.position) { Expects(_ready != nullptr); Expects(_error != nullptr); Expects(_audioId.playId() != 0); diff --git a/Telegram/SourceFiles/media/streaming/media_streaming_audio_track.h b/Telegram/SourceFiles/media/streaming/media_streaming_audio_track.h index e3f8aa7432..8bcbb0eee4 100644 --- a/Telegram/SourceFiles/media/streaming/media_streaming_audio_track.h +++ b/Telegram/SourceFiles/media/streaming/media_streaming_audio_track.h @@ -69,6 +69,8 @@ private: // Accessed from the main thread. base::Subscription _subscription; + // First set from the same unspecified thread before _ready is called. + // After that accessed from the main thread. rpl::variable _playPosition; }; diff --git a/Telegram/SourceFiles/media/streaming/media_streaming_loader_mtproto.cpp b/Telegram/SourceFiles/media/streaming/media_streaming_loader_mtproto.cpp index bb3d23c3b6..cb941510a0 100644 --- a/Telegram/SourceFiles/media/streaming/media_streaming_loader_mtproto.cpp +++ b/Telegram/SourceFiles/media/streaming/media_streaming_loader_mtproto.cpp @@ -138,6 +138,13 @@ void LoaderMtproto::cancelRequestsBefore(int offset) { _sender.requestCanceller(), &base::flat_map::value_type::second); _requests.erase(from, till); + + if (!_requests.empty() && _requests.front().first > offset) { + ranges::for_each( + base::take(_requests), + _sender.requestCanceller(), + &base::flat_map::value_type::second); + } } } // namespace Streaming diff --git a/Telegram/SourceFiles/media/streaming/media_streaming_video_track.cpp b/Telegram/SourceFiles/media/streaming/media_streaming_video_track.cpp index 99110fffba..7736edd5a6 100644 --- a/Telegram/SourceFiles/media/streaming/media_streaming_video_track.cpp +++ b/Telegram/SourceFiles/media/streaming/media_streaming_video_track.cpp @@ -280,7 +280,9 @@ VideoTrackObject::TrackTime VideoTrackObject::trackTime() const { const auto correction = _audioId.playId() ? Media::Player::mixer()->getVideoTimeCorrection(_audioId) : Media::Player::Mixer::TimeCorrection(); - const auto knownValue = correction ? correction.audioPositionValue : 0; + const auto knownValue = correction + ? correction.audioPositionValue + : _startedPosition; const auto knownTime = correction ? correction.audioPositionTime : _startedTime; @@ -288,8 +290,7 @@ VideoTrackObject::TrackTime VideoTrackObject::trackTime() const { const auto sinceKnown = (worldNow - knownTime); result.worldNow = worldNow; - result.trackNow = _startedPosition - + knownValue + result.trackNow = knownValue + crl::time(std::round(sinceKnown * _options.speed)); return result; }