diff --git a/Telegram/SourceFiles/history/media/history_media_video.cpp b/Telegram/SourceFiles/history/media/history_media_video.cpp index fb5ded111..323087da9 100644 --- a/Telegram/SourceFiles/history/media/history_media_video.cpp +++ b/Telegram/SourceFiles/history/media/history_media_video.cpp @@ -58,6 +58,33 @@ QSize HistoryVideo::sizeForAspectRatio() const { return { 1, 1 }; } +QSize HistoryVideo::countOptimalDimensions() const { + const auto desired = ConvertScale(_data->dimensions); + const auto size = desired.isEmpty() ? sizeForAspectRatio() : desired; + auto tw = size.width(); + auto th = size.height(); + if (!tw || !th) { + tw = th = 1; + } else if (tw >= th && tw > st::maxMediaSize) { + th = qRound((st::maxMediaSize / float64(tw)) * th); + tw = st::maxMediaSize; + } else if (tw < th && th > st::maxMediaSize) { + tw = qRound((st::maxMediaSize / float64(th)) * tw); + th = st::maxMediaSize; + } else if ((tw < st::msgVideoSize.width()) + && (tw * st::msgVideoSize.height() + >= th * st::msgVideoSize.width())) { + th = qRound((st::msgVideoSize.width() / float64(tw)) * th); + tw = st::msgVideoSize.width(); + } else if ((th < st::msgVideoSize.height()) + && (tw * st::msgVideoSize.height() + < th * st::msgVideoSize.width())) { + tw = qRound((st::msgVideoSize.height() / float64(th)) * tw); + th = st::msgVideoSize.height(); + } + return QSize(tw, th); +} + QSize HistoryVideo::countOptimalSize() { if (_parent->media() != this) { _caption = Text(); @@ -67,20 +94,9 @@ QSize HistoryVideo::countOptimalSize() { _parent->skipBlockHeight()); } - const auto size = sizeForAspectRatio(); - auto tw = ConvertScale(size.width()); - auto th = ConvertScale(size.height()); - if (!tw || !th) { - tw = th = 1; - } - if (tw * st::msgVideoSize.height() > th * st::msgVideoSize.width()) { - th = qRound((st::msgVideoSize.width() / float64(tw)) * th); - tw = st::msgVideoSize.width(); - } else { - tw = qRound((st::msgVideoSize.height() / float64(th)) * tw); - th = st::msgVideoSize.height(); - } - + const auto size = countOptimalDimensions(); + const auto tw = size.width(); + const auto th = size.height(); _thumbw = qMax(tw, 1); _thumbh = qMax(th, 1); @@ -101,20 +117,9 @@ QSize HistoryVideo::countOptimalSize() { } QSize HistoryVideo::countCurrentSize(int newWidth) { - const auto size = sizeForAspectRatio(); - auto tw = ConvertScale(size.width()); - auto th = ConvertScale(size.height()); - if (!tw || !th) { - tw = th = 1; - } - if (tw * st::msgVideoSize.height() > th * st::msgVideoSize.width()) { - th = qRound((st::msgVideoSize.width() / float64(tw)) * th); - tw = st::msgVideoSize.width(); - } else { - tw = qRound((st::msgVideoSize.height() / float64(th)) * tw); - th = st::msgVideoSize.height(); - } - + const auto size = countOptimalDimensions(); + auto tw = size.width(); + auto th = size.height(); if (newWidth < tw) { th = qRound((newWidth / float64(tw)) * th); tw = newWidth; diff --git a/Telegram/SourceFiles/history/media/history_media_video.h b/Telegram/SourceFiles/history/media/history_media_video.h index d536a7493..8d49a929d 100644 --- a/Telegram/SourceFiles/history/media/history_media_video.h +++ b/Telegram/SourceFiles/history/media/history_media_video.h @@ -75,6 +75,7 @@ protected: private: QSize countOptimalSize() override; QSize countCurrentSize(int newWidth) override; + QSize countOptimalDimensions() const; void validateGroupedCache( const QRect &geometry, diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index bf55844a2..a8359f7f0 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -2191,8 +2191,10 @@ void OverlayWidget::playbackPauseResume() { restartAtSeekPosition(0); } else if (_streamed->player.paused()) { _streamed->player.resume(); + updatePlaybackState(); } else { _streamed->player.pause(); + updatePlaybackState(); } } else { clearStreaming(); @@ -2275,8 +2277,9 @@ void OverlayWidget::playbackPauseOnCall() { if (_streamed->player.finished() || _streamed->player.paused()) { return; } - _streamed->player.pause(); _streamed->resumeOnCallEnd = true; + _streamed->player.pause(); + updatePlaybackState(); } void OverlayWidget::playbackResumeOnCall() { @@ -2285,6 +2288,7 @@ void OverlayWidget::playbackResumeOnCall() { if (_streamed->resumeOnCallEnd) { _streamed->resumeOnCallEnd = false; _streamed->player.resume(); + updatePlaybackState(); } } diff --git a/Telegram/SourceFiles/media/view/media_view_playback_progress.cpp b/Telegram/SourceFiles/media/view/media_view_playback_progress.cpp index ad8aeceff..48c180851 100644 --- a/Telegram/SourceFiles/media/view/media_view_playback_progress.cpp +++ b/Telegram/SourceFiles/media/view/media_view_playback_progress.cpp @@ -19,8 +19,8 @@ constexpr auto kPlaybackAnimationDurationMs = crl::time(200); } // namespace PlaybackProgress::PlaybackProgress() -: _a_value([=](float64 ms) { step_value(ms); }) -, _a_receivedTill([=](float64 ms) { step_receivedTill(ms); }) { +: _a_value([=](crl::time now) { return valueAnimationCallback(now); }) +, _a_receivedTill([=](crl::time now) { return receivedTillAnimationCallback(now); }) { } void PlaybackProgress::updateState(const Player::TrackState &state) { @@ -85,6 +85,7 @@ float64 PlaybackProgress::value() const { void PlaybackProgress::setValue(float64 value, bool animated) { if (animated) { + valueAnimationCallback(crl::now()); a_value.start(value); _a_value.start(); } else { @@ -97,6 +98,7 @@ void PlaybackProgress::setValue(float64 value, bool animated) { void PlaybackProgress::setReceivedTill(float64 value) { const auto current = a_receivedTill.current(); if (value > current && current > 0.) { + receivedTillAnimationCallback(crl::now()); a_receivedTill.start(value); _a_receivedTill.start(); } else if (value > a_value.current()) { @@ -109,32 +111,32 @@ void PlaybackProgress::setReceivedTill(float64 value) { emitUpdatedValue(); } -void PlaybackProgress::step_value(float64 now) { +bool PlaybackProgress::valueAnimationCallback(float64 now) { const auto time = (now - _a_value.started()); const auto dt = anim::Disabled() ? 1. : (time / kPlaybackAnimationDurationMs); if (dt >= 1.) { - _a_value.stop(); a_value.finish(); } else { a_value.update(dt, anim::linear); } emitUpdatedValue(); + return (dt < 1.); } -void PlaybackProgress::step_receivedTill(float64 now) { +bool PlaybackProgress::receivedTillAnimationCallback(float64 now) { const auto time = now - _a_receivedTill.started(); const auto dt = anim::Disabled() ? 1. : (time / kPlaybackAnimationDurationMs); if (dt >= 1.) { - _a_receivedTill.stop(); a_receivedTill.finish(); } else { a_receivedTill.update(dt, anim::linear); } emitUpdatedValue(); + return (dt < 1.); } void PlaybackProgress::emitUpdatedValue() { diff --git a/Telegram/SourceFiles/media/view/media_view_playback_progress.h b/Telegram/SourceFiles/media/view/media_view_playback_progress.h index b5c1963a9..6273633c1 100644 --- a/Telegram/SourceFiles/media/view/media_view_playback_progress.h +++ b/Telegram/SourceFiles/media/view/media_view_playback_progress.h @@ -33,8 +33,8 @@ public: void updateLoadingState(float64 progress); private: - void step_value(float64 now); - void step_receivedTill(float64 now); + bool valueAnimationCallback(float64 now); + bool receivedTillAnimationCallback(float64 now); void setReceivedTill(float64 value); void emitUpdatedValue();