mirror of
https://github.com/vale981/tdesktop
synced 2025-03-06 02:01:40 -05:00
Detect and send supports_streaming bit for videos.
This commit is contained in:
parent
a2b04c9d71
commit
ef38572d5a
9 changed files with 137 additions and 5 deletions
|
@ -97,6 +97,9 @@ MTPVector<MTPDocumentAttribute> ComposeSendingDocumentAttributes(
|
|||
if (document->isVideoMessage()) {
|
||||
flags |= MTPDdocumentAttributeVideo::Flag::f_round_message;
|
||||
}
|
||||
if (document->supportsStreaming()) {
|
||||
flags |= MTPDdocumentAttributeVideo::Flag::f_supports_streaming;
|
||||
}
|
||||
attributes.push_back(MTP_documentAttributeVideo(
|
||||
MTP_flags(flags),
|
||||
MTP_int(duration),
|
||||
|
|
|
@ -438,6 +438,8 @@ not_null<AuthSession*> DocumentData::session() const {
|
|||
}
|
||||
|
||||
void DocumentData::setattributes(const QVector<MTPDocumentAttribute> &attributes) {
|
||||
_isImage = false;
|
||||
_supportsStreaming = false;
|
||||
for (int32 i = 0, l = attributes.size(); i < l; ++i) {
|
||||
switch (attributes[i].type()) {
|
||||
case mtpc_documentAttributeImageSize: {
|
||||
|
@ -467,6 +469,7 @@ void DocumentData::setattributes(const QVector<MTPDocumentAttribute> &attributes
|
|||
type = d.is_round_message() ? RoundVideoDocument : VideoDocument;
|
||||
}
|
||||
_duration = d.vduration.v;
|
||||
_supportsStreaming = d.is_supports_streaming();
|
||||
dimensions = QSize(d.vw.v, d.vh.v);
|
||||
} break;
|
||||
case mtpc_documentAttributeAudio: {
|
||||
|
@ -1295,14 +1298,17 @@ int32 DocumentData::duration() const {
|
|||
}
|
||||
|
||||
bool DocumentData::isImage() const {
|
||||
return !isAnimation() && !isVideoFile() && (_duration > 0);
|
||||
return _isImage;
|
||||
}
|
||||
|
||||
bool DocumentData::supportsStreaming() const {
|
||||
return _supportsStreaming;
|
||||
}
|
||||
|
||||
void DocumentData::recountIsImage() {
|
||||
if (isAnimation() || isVideoFile()) {
|
||||
return;
|
||||
}
|
||||
_duration = fileIsImage(filename(), mimeString()) ? 1 : -1; // hack
|
||||
_isImage = !isAnimation()
|
||||
&& !isVideoFile()
|
||||
&& fileIsImage(filename(), mimeString());
|
||||
}
|
||||
|
||||
bool DocumentData::hasGoodStickerThumb() const {
|
||||
|
|
|
@ -152,6 +152,7 @@ public:
|
|||
int32 duration() const;
|
||||
bool isImage() const;
|
||||
void recountIsImage();
|
||||
bool supportsStreaming() const;
|
||||
void setData(const QByteArray &data) {
|
||||
_data = data;
|
||||
}
|
||||
|
@ -237,6 +238,8 @@ private:
|
|||
QByteArray _data;
|
||||
std::unique_ptr<DocumentAdditionalData> _additional;
|
||||
int32 _duration = -1;
|
||||
bool _isImage = false;
|
||||
bool _supportsStreaming = false;
|
||||
|
||||
ActionOnLoad _actionOnLoad = ActionOnLoadNone;
|
||||
FullMsgId _actionOnLoadMsgId;
|
||||
|
|
91
Telegram/SourceFiles/media/media_clip_check_streaming.cpp
Normal file
91
Telegram/SourceFiles/media/media_clip_check_streaming.cpp
Normal file
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "media/media_clip_check_streaming.h"
|
||||
|
||||
|
||||
namespace Media {
|
||||
namespace Clip {
|
||||
namespace {
|
||||
|
||||
constexpr auto kHeaderSize = 8;
|
||||
constexpr auto kFindMoovBefore = 128 * 1024;
|
||||
|
||||
template <typename Type>
|
||||
Type ReadBigEndian(bytes::const_span data) {
|
||||
const auto bytes = data.subspan(0, sizeof(Type)).data();
|
||||
return qFromBigEndian(*reinterpret_cast<const Type*>(bytes));
|
||||
}
|
||||
|
||||
bool IsAtom(bytes::const_span header, const char (&atom)[5]) {
|
||||
const auto check = header.subspan(4, 4);
|
||||
return bytes::compare(
|
||||
header.subspan(4, 4),
|
||||
bytes::make_span(atom).subspan(0, 4)) == 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool CheckStreamingSupport(
|
||||
const FileLocation &location,
|
||||
QByteArray data) {
|
||||
QBuffer buffer;
|
||||
QFile file;
|
||||
if (data.isEmpty()) {
|
||||
file.setFileName(location.name());
|
||||
} else {
|
||||
buffer.setBuffer(&data);
|
||||
}
|
||||
const auto size = data.isEmpty()
|
||||
? file.size()
|
||||
: data.size();
|
||||
const auto device = data.isEmpty()
|
||||
? static_cast<QIODevice*>(&file)
|
||||
: static_cast<QIODevice*>(&buffer);
|
||||
|
||||
if (size < kHeaderSize || !device->open(QIODevice::ReadOnly)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto lastReadPosition = 0;
|
||||
char atomHeader[kHeaderSize] = { 0 };
|
||||
auto atomHeaderBytes = bytes::make_span(atomHeader);
|
||||
while (true) {
|
||||
const auto position = device->pos();
|
||||
if (device->read(atomHeader, kHeaderSize) != kHeaderSize) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (lastReadPosition >= kFindMoovBefore) {
|
||||
return false;
|
||||
} else if (IsAtom(atomHeaderBytes, "moov")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const auto length = [&] {
|
||||
const auto result = ReadBigEndian<uint32>(atomHeaderBytes);
|
||||
if (result != 1) {
|
||||
return uint64(result);
|
||||
}
|
||||
char atomSize64[kHeaderSize] = { 0 };
|
||||
if (device->read(atomSize64, kHeaderSize) != kHeaderSize) {
|
||||
return uint64(-1);
|
||||
}
|
||||
auto atomSize64Bytes = bytes::make_span(atomSize64);
|
||||
return ReadBigEndian<uint64>(atomSize64Bytes);
|
||||
}();
|
||||
if (position + length > size) {
|
||||
break;
|
||||
}
|
||||
device->seek(position + length);
|
||||
lastReadPosition = position;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace Clip
|
||||
} // namespace Media
|
18
Telegram/SourceFiles/media/media_clip_check_streaming.h
Normal file
18
Telegram/SourceFiles/media/media_clip_check_streaming.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
namespace Media {
|
||||
namespace Clip {
|
||||
|
||||
bool CheckStreamingSupport(
|
||||
const FileLocation &location,
|
||||
QByteArray data);
|
||||
|
||||
} // namespace Clip
|
||||
} // namespace Media
|
|
@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "storage/file_download.h"
|
||||
#include "media/media_clip_ffmpeg.h"
|
||||
#include "media/media_clip_qtgif.h"
|
||||
#include "media/media_clip_check_streaming.h"
|
||||
#include "mainwidget.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
|
@ -892,6 +893,10 @@ FileMediaInformation::Video PrepareForSending(const QString &fname, const QByteA
|
|||
}
|
||||
result.duration = static_cast<int>(durationMs / 1000);
|
||||
}
|
||||
|
||||
result.supportsStreaming = CheckStreamingSupport(
|
||||
localLocation,
|
||||
localData);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -582,6 +582,9 @@ void FileLoadTask::process() {
|
|||
attributes.push_back(MTP_documentAttributeAnimated());
|
||||
}
|
||||
auto flags = MTPDdocumentAttributeVideo::Flags(0);
|
||||
if (video->supportsStreaming) {
|
||||
flags |= MTPDdocumentAttributeVideo::Flag::f_supports_streaming;
|
||||
}
|
||||
attributes.push_back(MTP_documentAttributeVideo(MTP_flags(flags), MTP_int(video->duration), MTP_int(coverWidth), MTP_int(coverHeight)));
|
||||
|
||||
goodThumbnail = video->thumbnail;
|
||||
|
|
|
@ -262,6 +262,7 @@ struct FileMediaInformation {
|
|||
};
|
||||
struct Video {
|
||||
bool isGifv = false;
|
||||
bool supportsStreaming = false;
|
||||
int duration = -1;
|
||||
QImage thumbnail;
|
||||
};
|
||||
|
|
|
@ -389,6 +389,8 @@
|
|||
<(src_loc)/media/media_audio_track.h
|
||||
<(src_loc)/media/media_child_ffmpeg_loader.cpp
|
||||
<(src_loc)/media/media_child_ffmpeg_loader.h
|
||||
<(src_loc)/media/media_clip_check_streaming.cpp
|
||||
<(src_loc)/media/media_clip_check_streaming.h
|
||||
<(src_loc)/media/media_clip_ffmpeg.cpp
|
||||
<(src_loc)/media/media_clip_ffmpeg.h
|
||||
<(src_loc)/media/media_clip_implementation.cpp
|
||||
|
|
Loading…
Add table
Reference in a new issue