media: Ed25519-подписи блоков, local_attrs, MediaBlockReader, файловые вложения
This commit is contained in:
1 parent
6b765de5cc
commit
d4a396f888
20 files changed
+851
-70
No files matched your search
@@ -2,6 +2,7 @@
|
||||
#include "emojipanel.h"
|
||||
#include "audiorecorder.h"
|
||||
#include "voicemessageencoder.h"
|
||||
#include "media_blocks.h"
|
||||
#include "debug_ui.h"
|
||||
#include <QDebug>
|
||||
#include <QTextEdit>
|
||||
@@ -53,15 +54,10 @@ InputBar::InputBar(EmojiPanel *emojiPanel, AudioRecorder *recorder, QWidget *par
|
||||
layout->setContentsMargins(8, 4, 8, 4);
|
||||
layout->setSpacing(4);
|
||||
|
||||
auto *attachBtn = makeIconBtn(QString::fromUtf8("\xF0\x9F\x93\x8E"),
|
||||
QString::fromUtf8("Прикрепить"), this);
|
||||
connect(attachBtn, &QPushButton::clicked, this, [this]() {
|
||||
QString path = QFileDialog::getOpenFileName(this, QString::fromUtf8("Прикрепить файл"));
|
||||
if (!path.isEmpty()) {
|
||||
qDebug() << "Attached:" << path;
|
||||
}
|
||||
});
|
||||
layout->addWidget(wrapBottomBtn(attachBtn, 3), 0, Qt::AlignBottom);
|
||||
m_attachBtn = makeIconBtn(QString::fromUtf8("\xF0\x9F\x93\x8E"),
|
||||
QString::fromUtf8("Прикрепить"), this);
|
||||
connect(m_attachBtn, &QPushButton::clicked, this, &InputBar::onAttachClicked);
|
||||
layout->addWidget(wrapBottomBtn(m_attachBtn, 3), 0, Qt::AlignBottom);
|
||||
|
||||
m_input->setAcceptRichText(false);
|
||||
m_input->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
@@ -233,30 +229,61 @@ void InputBar::onPttReleased() {
|
||||
qPrintable(mediaPath), QDir(mediaPath).exists(), qPrintable(m_channelIdForRecord));
|
||||
|
||||
QString fileName = VoiceEncoder::generateFileName();
|
||||
QString filePath = mediaPath + "/" + fileName;
|
||||
QString tempPath = mediaPath + "/" + fileName;
|
||||
float durationSec = 0;
|
||||
int frames = VoiceEncoder::encodeToFile(pcm, 48000, 1, filePath, durationSec);
|
||||
if (frames > 0) {
|
||||
m_voiceFilePath = filePath;
|
||||
|
||||
const auto& wf = m_recorder->waveformLevels();
|
||||
QString wfStr;
|
||||
int N = (int)wf.size();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
int s = i * N / 100, e = (i + 1) * N / 100;
|
||||
if (s >= N) s = N - 1;
|
||||
if (e <= s) e = s + 1;
|
||||
if (e > N) e = N;
|
||||
float sum = 0; int cnt = 0;
|
||||
for (int j = s; j < e; j++) { sum += wf[j]; cnt++; }
|
||||
float v = cnt > 0 ? sum / cnt : 0;
|
||||
if (i > 0) wfStr += ',';
|
||||
wfStr += QString::number(v, 'f', 3);
|
||||
}
|
||||
GUI_INFO("InputBar: voice message ready: %s (%.1fs) wf=%d levels",
|
||||
qPrintable(filePath), durationSec, N);
|
||||
emit sendVoiceMessage(filePath, durationMs, wfStr);
|
||||
int frames = VoiceEncoder::encodeToFile(pcm, 48000, 1, tempPath, durationSec);
|
||||
if (frames <= 0) {
|
||||
QFile::remove(tempPath);
|
||||
return;
|
||||
}
|
||||
|
||||
MediaBlockInfo blk = media_split_to_blocks(tempPath, mediaPath, true);
|
||||
if (blk.numBlocks <= 0) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_DEBUG, "InputBar: block split failed");
|
||||
return;
|
||||
}
|
||||
|
||||
m_voiceFilePath = QString("%1/%2_%3_%4.%5").arg(mediaPath, blk.dt, blk.basename, blk.suffix, blk.ext);
|
||||
|
||||
const auto& wf = m_recorder->waveformLevels();
|
||||
QString wfStr;
|
||||
int N = (int)wf.size();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
int s = i * N / 100, e = (i + 1) * N / 100;
|
||||
if (s >= N) s = N - 1;
|
||||
if (e <= s) e = s + 1;
|
||||
if (e > N) e = N;
|
||||
float sum = 0; int cnt = 0;
|
||||
for (int j = s; j < e; j++) { sum += wf[j]; cnt++; }
|
||||
float v = cnt > 0 ? sum / cnt : 0;
|
||||
if (i > 0) wfStr += ',';
|
||||
wfStr += QString::number(v, 'f', 3);
|
||||
}
|
||||
GUI_INFO("InputBar: voice message ready: dt=%s stem=%s blocks=%d dur=%.1fs",
|
||||
qPrintable(blk.dt), qPrintable(blk.basename), blk.numBlocks, durationSec);
|
||||
emit sendVoiceMessage(blk.dt, blk.basename, blk.suffix, blk.ext,
|
||||
blk.numBlocks, blk.blockSize, durationMs, wfStr);
|
||||
}
|
||||
|
||||
void InputBar::onAttachClicked() {
|
||||
if (m_channelIdForRecord.isEmpty()) return;
|
||||
QString srcPath = QFileDialog::getOpenFileName(this, QString::fromUtf8("Прикрепить файл"));
|
||||
if (srcPath.isEmpty()) return;
|
||||
|
||||
QFileInfo fi(srcPath);
|
||||
if (fi.size() == 0) { DEBUG_WARN(DEBUG_CATEGORY_DEBUG, "InputBar::onAttachClicked: empty file"); return; }
|
||||
|
||||
QString mediaPath = m_mediaDirBase + "/" + m_channelIdForRecord;
|
||||
VoiceEncoder::ensureMediaDir(mediaPath);
|
||||
QDir().mkpath(mediaPath);
|
||||
|
||||
MediaBlockInfo blk = media_split_to_blocks(srcPath, mediaPath, false);
|
||||
if (blk.numBlocks <= 0) { DEBUG_WARN(DEBUG_CATEGORY_DEBUG, "InputBar::onAttachClicked: split failed"); return; }
|
||||
|
||||
GUI_INFO("InputBar::onAttachClicked: file=%s dt=%s blocks=%d",
|
||||
qPrintable(fi.fileName()), qPrintable(blk.dt), blk.numBlocks);
|
||||
emit sendFileAttachment(blk.dt, blk.basename, blk.suffix, blk.ext,
|
||||
blk.numBlocks, blk.blockSize, fi.fileName());
|
||||
}
|
||||
|
||||
void InputBar::resizeEvent(QResizeEvent* event) {
|
||||
|
||||
Reference in new issue
Block a user