mirror of https://github.com/procxx/kepka.git
Make videos larger, fix playback animation.
This commit is contained in:
parent
84b09795f3
commit
f481f1e142
|
@ -58,6 +58,33 @@ QSize HistoryVideo::sizeForAspectRatio() const {
|
||||||
return { 1, 1 };
|
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() {
|
QSize HistoryVideo::countOptimalSize() {
|
||||||
if (_parent->media() != this) {
|
if (_parent->media() != this) {
|
||||||
_caption = Text();
|
_caption = Text();
|
||||||
|
@ -67,20 +94,9 @@ QSize HistoryVideo::countOptimalSize() {
|
||||||
_parent->skipBlockHeight());
|
_parent->skipBlockHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto size = sizeForAspectRatio();
|
const auto size = countOptimalDimensions();
|
||||||
auto tw = ConvertScale(size.width());
|
const auto tw = size.width();
|
||||||
auto th = ConvertScale(size.height());
|
const auto th = 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
_thumbw = qMax(tw, 1);
|
_thumbw = qMax(tw, 1);
|
||||||
_thumbh = qMax(th, 1);
|
_thumbh = qMax(th, 1);
|
||||||
|
|
||||||
|
@ -101,20 +117,9 @@ QSize HistoryVideo::countOptimalSize() {
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize HistoryVideo::countCurrentSize(int newWidth) {
|
QSize HistoryVideo::countCurrentSize(int newWidth) {
|
||||||
const auto size = sizeForAspectRatio();
|
const auto size = countOptimalDimensions();
|
||||||
auto tw = ConvertScale(size.width());
|
auto tw = size.width();
|
||||||
auto th = ConvertScale(size.height());
|
auto th = 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newWidth < tw) {
|
if (newWidth < tw) {
|
||||||
th = qRound((newWidth / float64(tw)) * th);
|
th = qRound((newWidth / float64(tw)) * th);
|
||||||
tw = newWidth;
|
tw = newWidth;
|
||||||
|
|
|
@ -75,6 +75,7 @@ protected:
|
||||||
private:
|
private:
|
||||||
QSize countOptimalSize() override;
|
QSize countOptimalSize() override;
|
||||||
QSize countCurrentSize(int newWidth) override;
|
QSize countCurrentSize(int newWidth) override;
|
||||||
|
QSize countOptimalDimensions() const;
|
||||||
|
|
||||||
void validateGroupedCache(
|
void validateGroupedCache(
|
||||||
const QRect &geometry,
|
const QRect &geometry,
|
||||||
|
|
|
@ -2191,8 +2191,10 @@ void OverlayWidget::playbackPauseResume() {
|
||||||
restartAtSeekPosition(0);
|
restartAtSeekPosition(0);
|
||||||
} else if (_streamed->player.paused()) {
|
} else if (_streamed->player.paused()) {
|
||||||
_streamed->player.resume();
|
_streamed->player.resume();
|
||||||
|
updatePlaybackState();
|
||||||
} else {
|
} else {
|
||||||
_streamed->player.pause();
|
_streamed->player.pause();
|
||||||
|
updatePlaybackState();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
clearStreaming();
|
clearStreaming();
|
||||||
|
@ -2275,8 +2277,9 @@ void OverlayWidget::playbackPauseOnCall() {
|
||||||
if (_streamed->player.finished() || _streamed->player.paused()) {
|
if (_streamed->player.finished() || _streamed->player.paused()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_streamed->player.pause();
|
|
||||||
_streamed->resumeOnCallEnd = true;
|
_streamed->resumeOnCallEnd = true;
|
||||||
|
_streamed->player.pause();
|
||||||
|
updatePlaybackState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverlayWidget::playbackResumeOnCall() {
|
void OverlayWidget::playbackResumeOnCall() {
|
||||||
|
@ -2285,6 +2288,7 @@ void OverlayWidget::playbackResumeOnCall() {
|
||||||
if (_streamed->resumeOnCallEnd) {
|
if (_streamed->resumeOnCallEnd) {
|
||||||
_streamed->resumeOnCallEnd = false;
|
_streamed->resumeOnCallEnd = false;
|
||||||
_streamed->player.resume();
|
_streamed->player.resume();
|
||||||
|
updatePlaybackState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,8 @@ constexpr auto kPlaybackAnimationDurationMs = crl::time(200);
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
PlaybackProgress::PlaybackProgress()
|
PlaybackProgress::PlaybackProgress()
|
||||||
: _a_value([=](float64 ms) { step_value(ms); })
|
: _a_value([=](crl::time now) { return valueAnimationCallback(now); })
|
||||||
, _a_receivedTill([=](float64 ms) { step_receivedTill(ms); }) {
|
, _a_receivedTill([=](crl::time now) { return receivedTillAnimationCallback(now); }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlaybackProgress::updateState(const Player::TrackState &state) {
|
void PlaybackProgress::updateState(const Player::TrackState &state) {
|
||||||
|
@ -85,6 +85,7 @@ float64 PlaybackProgress::value() const {
|
||||||
|
|
||||||
void PlaybackProgress::setValue(float64 value, bool animated) {
|
void PlaybackProgress::setValue(float64 value, bool animated) {
|
||||||
if (animated) {
|
if (animated) {
|
||||||
|
valueAnimationCallback(crl::now());
|
||||||
a_value.start(value);
|
a_value.start(value);
|
||||||
_a_value.start();
|
_a_value.start();
|
||||||
} else {
|
} else {
|
||||||
|
@ -97,6 +98,7 @@ void PlaybackProgress::setValue(float64 value, bool animated) {
|
||||||
void PlaybackProgress::setReceivedTill(float64 value) {
|
void PlaybackProgress::setReceivedTill(float64 value) {
|
||||||
const auto current = a_receivedTill.current();
|
const auto current = a_receivedTill.current();
|
||||||
if (value > current && current > 0.) {
|
if (value > current && current > 0.) {
|
||||||
|
receivedTillAnimationCallback(crl::now());
|
||||||
a_receivedTill.start(value);
|
a_receivedTill.start(value);
|
||||||
_a_receivedTill.start();
|
_a_receivedTill.start();
|
||||||
} else if (value > a_value.current()) {
|
} else if (value > a_value.current()) {
|
||||||
|
@ -109,32 +111,32 @@ void PlaybackProgress::setReceivedTill(float64 value) {
|
||||||
emitUpdatedValue();
|
emitUpdatedValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlaybackProgress::step_value(float64 now) {
|
bool PlaybackProgress::valueAnimationCallback(float64 now) {
|
||||||
const auto time = (now - _a_value.started());
|
const auto time = (now - _a_value.started());
|
||||||
const auto dt = anim::Disabled()
|
const auto dt = anim::Disabled()
|
||||||
? 1.
|
? 1.
|
||||||
: (time / kPlaybackAnimationDurationMs);
|
: (time / kPlaybackAnimationDurationMs);
|
||||||
if (dt >= 1.) {
|
if (dt >= 1.) {
|
||||||
_a_value.stop();
|
|
||||||
a_value.finish();
|
a_value.finish();
|
||||||
} else {
|
} else {
|
||||||
a_value.update(dt, anim::linear);
|
a_value.update(dt, anim::linear);
|
||||||
}
|
}
|
||||||
emitUpdatedValue();
|
emitUpdatedValue();
|
||||||
|
return (dt < 1.);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlaybackProgress::step_receivedTill(float64 now) {
|
bool PlaybackProgress::receivedTillAnimationCallback(float64 now) {
|
||||||
const auto time = now - _a_receivedTill.started();
|
const auto time = now - _a_receivedTill.started();
|
||||||
const auto dt = anim::Disabled()
|
const auto dt = anim::Disabled()
|
||||||
? 1.
|
? 1.
|
||||||
: (time / kPlaybackAnimationDurationMs);
|
: (time / kPlaybackAnimationDurationMs);
|
||||||
if (dt >= 1.) {
|
if (dt >= 1.) {
|
||||||
_a_receivedTill.stop();
|
|
||||||
a_receivedTill.finish();
|
a_receivedTill.finish();
|
||||||
} else {
|
} else {
|
||||||
a_receivedTill.update(dt, anim::linear);
|
a_receivedTill.update(dt, anim::linear);
|
||||||
}
|
}
|
||||||
emitUpdatedValue();
|
emitUpdatedValue();
|
||||||
|
return (dt < 1.);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlaybackProgress::emitUpdatedValue() {
|
void PlaybackProgress::emitUpdatedValue() {
|
||||||
|
|
|
@ -33,8 +33,8 @@ public:
|
||||||
void updateLoadingState(float64 progress);
|
void updateLoadingState(float64 progress);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void step_value(float64 now);
|
bool valueAnimationCallback(float64 now);
|
||||||
void step_receivedTill(float64 now);
|
bool receivedTillAnimationCallback(float64 now);
|
||||||
void setReceivedTill(float64 value);
|
void setReceivedTill(float64 value);
|
||||||
void emitUpdatedValue();
|
void emitUpdatedValue();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue