Use DocumentData::getDuration for all types.

This commit is contained in:
John Preston 2019-03-06 12:21:42 +04:00
parent 41c60419f1
commit 01d763eed1
11 changed files with 27 additions and 41 deletions

View File

@ -108,7 +108,7 @@ MTPVector<MTPDocumentAttribute> ComposeSendingDocumentAttributes(
const auto dimensions = document->dimensions;
auto attributes = QVector<MTPDocumentAttribute>(1, filenameAttribute);
if (dimensions.width() > 0 && dimensions.height() > 0) {
const auto duration = document->duration();
const auto duration = document->getDuration();
if (duration >= 0) {
auto flags = MTPDdocumentAttributeVideo::Flags(0);
if (document->isVideoMessage()) {

View File

@ -1397,8 +1397,15 @@ bool DocumentData::isVideoFile() const {
return (type == VideoDocument);
}
int32 DocumentData::duration() const {
return (isAnimation() || isVideoFile()) ? _duration : -1;
TimeId DocumentData::getDuration() const {
if (const auto song = this->song()) {
return std::max(song->duration, 0);
} else if (const auto voice = this->voice()) {
return std::max(voice->duration, 0);
} else if (isAnimation() || isVideoFile()) {
return std::max(_duration, 0);
}
return -1;
}
bool DocumentData::isImage() const {

View File

@ -163,7 +163,7 @@ public:
[[nodiscard]] bool isGifv() const;
[[nodiscard]] bool isTheme() const;
[[nodiscard]] bool isSharedMediaMusic() const;
[[nodiscard]] int32 duration() const;
[[nodiscard]] TimeId getDuration() const;
[[nodiscard]] bool isImage() const;
void recountIsImage();
[[nodiscard]] bool supportsStreaming() const;

View File

@ -21,14 +21,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
int documentMaxStatusWidth(DocumentData *document) {
auto result = st::normalFont->width(formatDownloadText(document->size, document->size));
const auto duration = document->getDuration();
if (const auto song = document->song()) {
accumulate_max(result, st::normalFont->width(formatPlayedText(song->duration, song->duration)));
accumulate_max(result, st::normalFont->width(formatDurationAndSizeText(song->duration, document->size)));
accumulate_max(result, st::normalFont->width(formatPlayedText(duration, duration)));
accumulate_max(result, st::normalFont->width(formatDurationAndSizeText(duration, document->size)));
} else if (const auto voice = document->voice()) {
accumulate_max(result, st::normalFont->width(formatPlayedText(voice->duration, voice->duration)));
accumulate_max(result, st::normalFont->width(formatDurationAndSizeText(voice->duration, document->size)));
accumulate_max(result, st::normalFont->width(formatPlayedText(duration, duration)));
accumulate_max(result, st::normalFont->width(formatDurationAndSizeText(duration, document->size)));
} else if (document->isVideoFile()) {
accumulate_max(result, st::normalFont->width(formatDurationAndSizeText(document->duration(), document->size)));
accumulate_max(result, st::normalFont->width(formatDurationAndSizeText(duration, document->size)));
} else {
accumulate_max(result, st::normalFont->width(formatSizeText(document->size)));
}

View File

@ -729,7 +729,7 @@ void HistoryGif::setStatusSize(int newSize) const {
if (newSize < 0) {
_statusText = formatDurationText(-newSize - 1);
} else {
_statusText = formatDurationText(_data->duration());
_statusText = formatDurationText(_data->getDuration());
}
} else {
HistoryFileMedia::setStatusSize(newSize, _data->size, -2, 0);
@ -749,7 +749,7 @@ void HistoryGif::updateStatusText() const {
} else if (_data->loaded()) {
statusSize = FileStatusSizeLoaded;
if (const auto video = activeRoundPlayer()) {
statusSize = -1 - _data->duration();
statusSize = -1 - _data->getDuration();
const auto type = AudioMsgId::Type::Voice;
const auto state = Media::Player::instance()->getState(type);

View File

@ -518,7 +518,7 @@ void HistoryVideo::validateGroupedCache(
}
void HistoryVideo::setStatusSize(int newSize) const {
HistoryFileMedia::setStatusSize(newSize, _data->size, _data->duration(), 0);
HistoryFileMedia::setStatusSize(newSize, _data->size, _data->getDuration(), 0);
}
TextWithEntities HistoryVideo::selectedText(TextSelection selection) const {

View File

@ -73,12 +73,8 @@ int FileBase::content_height() const {
int FileBase::content_duration() const {
if (const auto document = getShownDocument()) {
if (document->duration() > 0) {
return document->duration();
} else if (const auto song = document->song()) {
if (song->duration) {
return song->duration;
}
if (document->getDuration() > 0) {
return document->getDuration();
}
}
return getResultDuration();

View File

@ -670,13 +670,7 @@ Media::Player::TrackState Player::prepareLegacyState() const {
result.length = _totalDuration;
if (result.length == kTimeUnknown) {
const auto document = _options.audioId.audio();
const auto duration = !document
? crl::time(0)
: document->song()
? document->song()->duration
: document->voice()
? document->voice()->duration
: document->duration();
const auto duration = document ? document->getDuration() : 0;
if (duration > 0) {
result.length = duration * crl::time(1000);
} else {

View File

@ -2292,17 +2292,7 @@ void OverlayWidget::updatePlaybackState() {
if (videoIsGifv()) {
return;
}
auto state = _streamed->player.prepareLegacyState();
if (state.length == kTimeUnknown) {
const auto duration = _doc->song()
? _doc->song()->duration
: _doc->duration();
if (duration > 0) {
state.length = std::max(
duration * crl::time(1000),
crl::time(state.position));
}
}
const auto state = _streamed->player.prepareLegacyState();
if (state.position != kTimeUnknown && state.length != kTimeUnknown) {
_streamed->controls.updatePlayback(state);
}

View File

@ -400,7 +400,7 @@ Video::Video(
not_null<DocumentData*> video)
: RadialProgressItem(parent)
, _data(video)
, _duration(formatDurationText(_data->duration())) {
, _duration(formatDurationText(_data->getDuration())) {
setDocumentLinks(_data);
_data->loadThumbnail(parent->fullId());
}
@ -837,9 +837,7 @@ void Voice::updateName() {
}
int Voice::duration() const {
return _data->voice()
? _data->voice()->duration
: std::max(_data->duration(), 0);
return std::max(_data->getDuration(), 0);
}
bool Voice::updateStatusText() {

View File

@ -48,7 +48,7 @@ void Document::writeToStream(QDataStream &stream, DocumentData *document) {
}
writeStorageImageLocation(stream, document->sticker()->loc);
} else {
stream << qint32(document->duration());
stream << qint32(document->getDuration());
if (const auto thumb = document->thumbnail()) {
writeStorageImageLocation(stream, thumb->location());
} else {