mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Always use crl::time for media durations.
This commit is contained in:
parent
39e8ed22a9
commit
bda3bae712
10 changed files with 23 additions and 17 deletions
|
@ -3417,7 +3417,7 @@ void ApiWrap::sendSharedContact(
|
||||||
void ApiWrap::sendVoiceMessage(
|
void ApiWrap::sendVoiceMessage(
|
||||||
QByteArray result,
|
QByteArray result,
|
||||||
VoiceWaveform waveform,
|
VoiceWaveform waveform,
|
||||||
int duration,
|
crl::time duration,
|
||||||
const SendAction &action) {
|
const SendAction &action) {
|
||||||
const auto caption = TextWithTags();
|
const auto caption = TextWithTags();
|
||||||
const auto to = fileLoadTaskOptions(action);
|
const auto to = fileLoadTaskOptions(action);
|
||||||
|
|
|
@ -302,7 +302,7 @@ public:
|
||||||
void sendVoiceMessage(
|
void sendVoiceMessage(
|
||||||
QByteArray result,
|
QByteArray result,
|
||||||
VoiceWaveform waveform,
|
VoiceWaveform waveform,
|
||||||
int duration,
|
crl::time duration,
|
||||||
const SendAction &action);
|
const SendAction &action);
|
||||||
void sendFiles(
|
void sendFiles(
|
||||||
Ui::PreparedList &&list,
|
Ui::PreparedList &&list,
|
||||||
|
|
|
@ -25,7 +25,7 @@ struct MessageToEdit {
|
||||||
struct VoiceToSend {
|
struct VoiceToSend {
|
||||||
QByteArray bytes;
|
QByteArray bytes;
|
||||||
VoiceWaveform waveform;
|
VoiceWaveform waveform;
|
||||||
int duration = 0;
|
crl::time duration = 0;
|
||||||
Api::SendOptions options;
|
Api::SendOptions options;
|
||||||
};
|
};
|
||||||
struct SendActionUpdate {
|
struct SendActionUpdate {
|
||||||
|
|
|
@ -72,8 +72,8 @@ enum class FilterType {
|
||||||
return std::clamp(float64(low) / high, 0., 1.);
|
return std::clamp(float64(low) / high, 0., 1.);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto Duration(int samples) {
|
[[nodiscard]] crl::time Duration(int samples) {
|
||||||
return samples / ::Media::Player::kDefaultFrequency;
|
return samples * crl::time(1000) / ::Media::Player::kDefaultFrequency;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto FormatVoiceDuration(int samples) {
|
[[nodiscard]] auto FormatVoiceDuration(int samples) {
|
||||||
|
|
|
@ -607,7 +607,7 @@ void ScheduledWidget::send(Api::SendOptions options) {
|
||||||
void ScheduledWidget::sendVoice(
|
void ScheduledWidget::sendVoice(
|
||||||
QByteArray bytes,
|
QByteArray bytes,
|
||||||
VoiceWaveform waveform,
|
VoiceWaveform waveform,
|
||||||
int duration) {
|
crl::time duration) {
|
||||||
const auto callback = [=](Api::SendOptions options) {
|
const auto callback = [=](Api::SendOptions options) {
|
||||||
sendVoice(bytes, waveform, duration, options);
|
sendVoice(bytes, waveform, duration, options);
|
||||||
};
|
};
|
||||||
|
@ -617,7 +617,7 @@ void ScheduledWidget::sendVoice(
|
||||||
void ScheduledWidget::sendVoice(
|
void ScheduledWidget::sendVoice(
|
||||||
QByteArray bytes,
|
QByteArray bytes,
|
||||||
VoiceWaveform waveform,
|
VoiceWaveform waveform,
|
||||||
int duration,
|
crl::time duration,
|
||||||
Api::SendOptions options) {
|
Api::SendOptions options) {
|
||||||
session().api().sendVoiceMessage(
|
session().api().sendVoiceMessage(
|
||||||
bytes,
|
bytes,
|
||||||
|
|
|
@ -197,11 +197,14 @@ private:
|
||||||
Api::SendOptions options) const;
|
Api::SendOptions options) const;
|
||||||
void send();
|
void send();
|
||||||
void send(Api::SendOptions options);
|
void send(Api::SendOptions options);
|
||||||
void sendVoice(QByteArray bytes, VoiceWaveform waveform, int duration);
|
|
||||||
void sendVoice(
|
void sendVoice(
|
||||||
QByteArray bytes,
|
QByteArray bytes,
|
||||||
VoiceWaveform waveform,
|
VoiceWaveform waveform,
|
||||||
int duration,
|
crl::time duration);
|
||||||
|
void sendVoice(
|
||||||
|
QByteArray bytes,
|
||||||
|
VoiceWaveform waveform,
|
||||||
|
crl::time duration,
|
||||||
Api::SendOptions options);
|
Api::SendOptions options);
|
||||||
void edit(
|
void edit(
|
||||||
not_null<HistoryItem*> item,
|
not_null<HistoryItem*> item,
|
||||||
|
|
|
@ -1560,7 +1560,7 @@ Ui::PreparedFileInformation PrepareForSending(
|
||||||
FFMpegAttributesReader reader(Core::FileLocation(fname), data);
|
FFMpegAttributesReader reader(Core::FileLocation(fname), data);
|
||||||
const auto positionMs = crl::time(0);
|
const auto positionMs = crl::time(0);
|
||||||
if (reader.open(positionMs) && reader.duration() > 0) {
|
if (reader.open(positionMs) && reader.duration() > 0) {
|
||||||
result.duration = reader.duration() / 1000;
|
result.duration = reader.duration();
|
||||||
result.title = reader.title();
|
result.title = reader.title();
|
||||||
result.performer = reader.performer();
|
result.performer = reader.performer();
|
||||||
result.cover = reader.cover();
|
result.cover = reader.cover();
|
||||||
|
|
|
@ -525,7 +525,7 @@ FileLoadTask::FileLoadTask(
|
||||||
FileLoadTask::FileLoadTask(
|
FileLoadTask::FileLoadTask(
|
||||||
not_null<Main::Session*> session,
|
not_null<Main::Session*> session,
|
||||||
const QByteArray &voice,
|
const QByteArray &voice,
|
||||||
int32 duration,
|
crl::time duration,
|
||||||
const VoiceWaveform &waveform,
|
const VoiceWaveform &waveform,
|
||||||
const FileLoadTo &to,
|
const FileLoadTo &to,
|
||||||
const TextWithTags &caption)
|
const TextWithTags &caption)
|
||||||
|
@ -851,8 +851,9 @@ void FileLoadTask::process(Args &&args) {
|
||||||
if (auto song = std::get_if<Ui::PreparedFileInformation::Song>(
|
if (auto song = std::get_if<Ui::PreparedFileInformation::Song>(
|
||||||
&_information->media)) {
|
&_information->media)) {
|
||||||
isSong = true;
|
isSong = true;
|
||||||
|
const auto seconds = song->duration / 1000;
|
||||||
auto flags = MTPDdocumentAttributeAudio::Flag::f_title | MTPDdocumentAttributeAudio::Flag::f_performer;
|
auto flags = MTPDdocumentAttributeAudio::Flag::f_title | MTPDdocumentAttributeAudio::Flag::f_performer;
|
||||||
attributes.push_back(MTP_documentAttributeAudio(MTP_flags(flags), MTP_int(song->duration), MTP_string(song->title), MTP_string(song->performer), MTPstring()));
|
attributes.push_back(MTP_documentAttributeAudio(MTP_flags(flags), MTP_int(seconds), MTP_string(song->title), MTP_string(song->performer), MTPstring()));
|
||||||
thumbnail = PrepareFileThumbnail(std::move(song->cover));
|
thumbnail = PrepareFileThumbnail(std::move(song->cover));
|
||||||
} else if (auto video = std::get_if<Ui::PreparedFileInformation::Video>(
|
} else if (auto video = std::get_if<Ui::PreparedFileInformation::Video>(
|
||||||
&_information->media)) {
|
&_information->media)) {
|
||||||
|
@ -866,9 +867,10 @@ void FileLoadTask::process(Args &&args) {
|
||||||
if (video->supportsStreaming) {
|
if (video->supportsStreaming) {
|
||||||
flags |= MTPDdocumentAttributeVideo::Flag::f_supports_streaming;
|
flags |= MTPDdocumentAttributeVideo::Flag::f_supports_streaming;
|
||||||
}
|
}
|
||||||
|
const auto realSeconds = video->duration / 1000.;
|
||||||
attributes.push_back(MTP_documentAttributeVideo(
|
attributes.push_back(MTP_documentAttributeVideo(
|
||||||
MTP_flags(flags),
|
MTP_flags(flags),
|
||||||
MTP_double(video->duration / 1000.),
|
MTP_double(realSeconds),
|
||||||
MTP_int(coverWidth),
|
MTP_int(coverWidth),
|
||||||
MTP_int(coverHeight),
|
MTP_int(coverHeight),
|
||||||
MTPint())); // preload_prefix_size
|
MTPint())); // preload_prefix_size
|
||||||
|
@ -970,8 +972,9 @@ void FileLoadTask::process(Args &&args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isVoice) {
|
if (isVoice) {
|
||||||
|
const auto seconds = _duration / 1000;
|
||||||
auto flags = MTPDdocumentAttributeAudio::Flag::f_voice | MTPDdocumentAttributeAudio::Flag::f_waveform;
|
auto flags = MTPDdocumentAttributeAudio::Flag::f_voice | MTPDdocumentAttributeAudio::Flag::f_waveform;
|
||||||
attributes[0] = MTP_documentAttributeAudio(MTP_flags(flags), MTP_int(_duration), MTPstring(), MTPstring(), MTP_bytes(documentWaveformEncode5bit(_waveform)));
|
attributes[0] = MTP_documentAttributeAudio(MTP_flags(flags), MTP_int(seconds), MTPstring(), MTPstring(), MTP_bytes(documentWaveformEncode5bit(_waveform)));
|
||||||
attributes.resize(1);
|
attributes.resize(1);
|
||||||
document = MTP_document(
|
document = MTP_document(
|
||||||
MTP_flags(0),
|
MTP_flags(0),
|
||||||
|
|
|
@ -256,7 +256,7 @@ public:
|
||||||
FileLoadTask(
|
FileLoadTask(
|
||||||
not_null<Main::Session*> session,
|
not_null<Main::Session*> session,
|
||||||
const QByteArray &voice,
|
const QByteArray &voice,
|
||||||
int32 duration,
|
crl::time duration,
|
||||||
const VoiceWaveform &waveform,
|
const VoiceWaveform &waveform,
|
||||||
const FileLoadTo &to,
|
const FileLoadTo &to,
|
||||||
const TextWithTags &caption);
|
const TextWithTags &caption);
|
||||||
|
@ -306,7 +306,7 @@ private:
|
||||||
QString _filepath;
|
QString _filepath;
|
||||||
QByteArray _content;
|
QByteArray _content;
|
||||||
std::unique_ptr<Ui::PreparedFileInformation> _information;
|
std::unique_ptr<Ui::PreparedFileInformation> _information;
|
||||||
int32 _duration = 0;
|
crl::time _duration = 0;
|
||||||
VoiceWaveform _waveform;
|
VoiceWaveform _waveform;
|
||||||
SendMediaType _type;
|
SendMediaType _type;
|
||||||
TextWithTags _caption;
|
TextWithTags _caption;
|
||||||
|
|
|
@ -27,7 +27,7 @@ struct PreparedFileInformation {
|
||||||
Editor::PhotoModifications modifications;
|
Editor::PhotoModifications modifications;
|
||||||
};
|
};
|
||||||
struct Song {
|
struct Song {
|
||||||
int duration = -1;
|
crl::time duration = -1;
|
||||||
QString title;
|
QString title;
|
||||||
QString performer;
|
QString performer;
|
||||||
QImage cover;
|
QImage cover;
|
||||||
|
|
Loading…
Add table
Reference in a new issue