Make videos larger, fix playback animation.

This commit is contained in:
John Preston 2019-03-08 16:35:04 +04:00
parent 84b09795f3
commit f481f1e142
5 changed files with 49 additions and 37 deletions

View file

@ -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;

View file

@ -75,6 +75,7 @@ protected:
private:
QSize countOptimalSize() override;
QSize countCurrentSize(int newWidth) override;
QSize countOptimalDimensions() const;
void validateGroupedCache(
const QRect &geometry,

View file

@ -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();
}
}

View file

@ -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() {

View file

@ -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();