Browse Source

fix: play button not responding + debug logging to log file

- chatview: QListView::mousePressEvent(event) instead of event->accept()
  (Qt needs base class press to set pressedIndex for editorEvent to fire)
- messagedelegate: GUI_DEBUG replaces qDebug (writes to log file)
- voiceplayback: DEBUG_DEBUG/DEBUG_WARN + debug_config.h include
- voicemessageencoder: same debug migration
- inputbar: GUI_INFO replaces qDebug
- messagelist: DEBUG_DEBUG/DEBUG_WARN replaces qDebug/qWarning
topo_upd
Evgeny 2 months ago
parent
commit
2687c3ed82
  1. 2
      tools/chatgui/src/chatview.cpp
  2. 8
      tools/chatgui/src/inputbar.cpp
  3. 4
      tools/chatgui/src/messagedelegate.cpp
  4. 6
      tools/chatgui/src/messagelist.cpp
  5. 17
      tools/chatgui/src/voicemessageencoder.cpp
  6. 22
      tools/chatgui/src/voiceplayback.cpp

2
tools/chatgui/src/chatview.cpp

@ -92,7 +92,7 @@ void ChatView::mousePressEvent(QMouseEvent *event) {
QModelIndex idx = indexAt(viewport()->mapFrom(this, event->pos())); QModelIndex idx = indexAt(viewport()->mapFrom(this, event->pos()));
m_pressIndex = QPersistentModelIndex(idx); m_pressIndex = QPersistentModelIndex(idx);
m_pressPos = event->pos(); m_pressPos = event->pos();
event->accept(); QListView::mousePressEvent(event);
} }
void ChatView::mouseMoveEvent(QMouseEvent *event) { void ChatView::mouseMoveEvent(QMouseEvent *event) {

8
tools/chatgui/src/inputbar.cpp

@ -206,7 +206,7 @@ void InputBar::onPttReleased() {
int durationMs = m_recorder->durationMs(); int durationMs = m_recorder->durationMs();
if (durationMs < 500) { if (durationMs < 500) {
qDebug("InputBar: voice message too short (%dms), discarded", durationMs); GUI_INFO("InputBar: voice message too short (%dms), discarded", durationMs);
return; return;
} }
@ -215,8 +215,8 @@ void InputBar::onPttReleased() {
QString mediaPath = m_mediaDirBase + "/" + m_channelIdForRecord; QString mediaPath = m_mediaDirBase + "/" + m_channelIdForRecord;
VoiceEncoder::ensureMediaDir(mediaPath); VoiceEncoder::ensureMediaDir(mediaPath);
qDebug("InputBar::onPttReleased: mediaDir=%s exists=%d channel=%s", GUI_INFO("InputBar::onPttReleased: mediaDir=%s exists=%d channel=%s",
qPrintable(mediaPath), QDir(mediaPath).exists(), qPrintable(m_channelIdForRecord)); qPrintable(mediaPath), QDir(mediaPath).exists(), qPrintable(m_channelIdForRecord));
QString fileName = VoiceEncoder::generateFileName(); QString fileName = VoiceEncoder::generateFileName();
QString filePath = mediaPath + "/" + fileName; QString filePath = mediaPath + "/" + fileName;
@ -224,7 +224,7 @@ void InputBar::onPttReleased() {
int frames = VoiceEncoder::encodeToFile(pcm, 48000, 1, filePath, durationSec); int frames = VoiceEncoder::encodeToFile(pcm, 48000, 1, filePath, durationSec);
if (frames > 0) { if (frames > 0) {
m_voiceFilePath = filePath; m_voiceFilePath = filePath;
qDebug("InputBar: voice message ready: %s (%.1fs)", qPrintable(filePath), durationSec); GUI_INFO("InputBar: voice message ready: %s (%.1fs)", qPrintable(filePath), durationSec);
emit sendVoiceMessage(filePath, durationMs); emit sendVoiceMessage(filePath, durationMs);
} }
} }

4
tools/chatgui/src/messagedelegate.cpp

@ -67,8 +67,8 @@ bool MessageDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
if (!L.voicePlayBtnRect.contains(localPos)) return false; if (!L.voicePlayBtnRect.contains(localPos)) return false;
QString filePath = index.data(MsgVoiceFileRole).toString(); QString filePath = index.data(MsgVoiceFileRole).toString();
qDebug("MessageDelegate::editorEvent voice click: filePath=%s exists=%d", GUI_DEBUG("editorEvent voice click: filePath=%s exists=%d",
qPrintable(filePath), QFile::exists(filePath)); qPrintable(filePath), QFile::exists(filePath));
if (filePath.isEmpty()) return false; if (filePath.isEmpty()) return false;
ensureVoiceTimer(); ensureVoiceTimer();

6
tools/chatgui/src/messagelist.cpp

@ -103,10 +103,10 @@ static void setVoiceMessageRoles(QStandardItem* item, const QByteArray& data,
if (!fname.isEmpty()) { if (!fname.isEmpty()) {
QString fullPath = mediaDirBase + "/" + channelId + "/" + fname; QString fullPath = mediaDirBase + "/" + channelId + "/" + fname;
item->setData(fullPath, MsgVoiceFileRole); item->setData(fullPath, MsgVoiceFileRole);
qDebug("setVoiceMessageRoles: voice file=%s dur=%s exists=%d", DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "setVoiceMessageRoles: voice file=%s dur=%s exists=%d",
qPrintable(fullPath), qPrintable(dur), QFile::exists(fullPath)); qPrintable(fullPath), qPrintable(dur), QFile::exists(fullPath));
} else { } else {
qWarning("setVoiceMessageRoles: empty filename, raw='%s'", qPrintable(raw)); DEBUG_WARN(DEBUG_CATEGORY_DEBUG, "setVoiceMessageRoles: empty filename, raw='%s'", qPrintable(raw));
} }
} }
} }

17
tools/chatgui/src/voicemessageencoder.cpp

@ -4,6 +4,8 @@ extern "C" {
#include "../../../lib/opus_codec.h" #include "../../../lib/opus_codec.h"
} }
#include "../../lib/debug_config.h"
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
#include <QDateTime> #include <QDateTime>
@ -29,7 +31,7 @@ int VoiceEncoder::preset() { return s_preset; }
int VoiceEncoder::encodeToFile(const std::vector<int16_t>& pcm, int sampleRate, int channels, int VoiceEncoder::encodeToFile(const std::vector<int16_t>& pcm, int sampleRate, int channels,
const QString& filePath, float& outDurationSec) { const QString& filePath, float& outDurationSec) {
if (pcm.empty() || sampleRate <= 0 || channels <= 0) { if (pcm.empty() || sampleRate <= 0 || channels <= 0) {
qWarning("VoiceEncoder: invalid input (pcm=%zu rate=%d ch=%d)", pcm.size(), sampleRate, channels); DEBUG_WARN(DEBUG_CATEGORY_DEBUG, "VoiceEncoder: invalid input (pcm=%zu rate=%d ch=%d)", pcm.size(), sampleRate, channels);
return -1; return -1;
} }
@ -39,7 +41,7 @@ int VoiceEncoder::encodeToFile(const std::vector<int16_t>& pcm, int sampleRate,
opus_codec_encoder_t* enc = opus_codec_encoder_create(sampleRate, channels); opus_codec_encoder_t* enc = opus_codec_encoder_create(sampleRate, channels);
if (!enc) { if (!enc) {
qWarning("VoiceEncoder: encoder create failed"); DEBUG_WARN(DEBUG_CATEGORY_DEBUG, "VoiceEncoder: encoder create failed");
return -1; return -1;
} }
opus_codec_encoder_bitrate_set(enc, s_bitrates[s_preset]); opus_codec_encoder_bitrate_set(enc, s_bitrates[s_preset]);
@ -47,11 +49,12 @@ int VoiceEncoder::encodeToFile(const std::vector<int16_t>& pcm, int sampleRate,
QFile file(filePath); QFile file(filePath);
if (!file.open(QIODevice::WriteOnly)) { if (!file.open(QIODevice::WriteOnly)) {
qWarning("VoiceEncoder: cannot open file %s (%s)", qPrintable(filePath), qPrintable(file.errorString())); DEBUG_WARN(DEBUG_CATEGORY_DEBUG, "VoiceEncoder: cannot open file %s (%s)", qPrintable(filePath), qPrintable(file.errorString()));
opus_codec_encoder_destroy(enc); opus_codec_encoder_destroy(enc);
return -1; return -1;
} }
qDebug("VoiceEncoder::encodeToFile: writing to %s pcm=%zu samples", qPrintable(filePath), pcm.size()); DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "VoiceEncoder::encodeToFile: writing to %s pcm=%zu samples preset=%d",
qPrintable(filePath), pcm.size(), s_preset);
/* write header */ /* write header */
uint32_t magic = OPUS_MAGIC; uint32_t magic = OPUS_MAGIC;
@ -78,7 +81,7 @@ int VoiceEncoder::encodeToFile(const std::vector<int16_t>& pcm, int sampleRate,
file.write((const char*)packet, len); file.write((const char*)packet, len);
frameCount++; frameCount++;
} else if (len < 0) { } else if (len < 0) {
qWarning("VoiceEncoder: encode error at frame %d: %d", frameCount, len); DEBUG_WARN(DEBUG_CATEGORY_DEBUG, "VoiceEncoder: encode error at frame %d: %d", frameCount, len);
} }
} }
@ -89,7 +92,7 @@ int VoiceEncoder::encodeToFile(const std::vector<int16_t>& pcm, int sampleRate,
outDurationSec = (float)frameCount * FRAME_MS / 1000.0f; outDurationSec = (float)frameCount * FRAME_MS / 1000.0f;
qDebug("VoiceEncoder: wrote %d frames (%.1fs) to %s", frameCount, outDurationSec, qPrintable(filePath)); DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "VoiceEncoder: wrote %d frames (%.1fs) to %s", frameCount, outDurationSec, qPrintable(filePath));
opus_codec_encoder_destroy(enc); opus_codec_encoder_destroy(enc);
return frameCount; return frameCount;
} }
@ -110,6 +113,6 @@ QString VoiceEncoder::mediaDir(const QString& dbPath, const QString& channelId)
void VoiceEncoder::ensureMediaDir(const QString& dir) { void VoiceEncoder::ensureMediaDir(const QString& dir) {
QDir d; QDir d;
if (!d.mkpath(dir)) { if (!d.mkpath(dir)) {
qWarning("VoiceEncoder: cannot create media dir %s", qPrintable(dir)); DEBUG_WARN(DEBUG_CATEGORY_DEBUG, "VoiceEncoder: cannot create media dir %s", qPrintable(dir));
} }
} }

22
tools/chatgui/src/voiceplayback.cpp

@ -5,6 +5,8 @@ extern "C" {
#include "../../../lib/opus_codec.h" #include "../../../lib/opus_codec.h"
} }
#include "../../lib/debug_config.h"
#include <QFile> #include <QFile>
#include <QDebug> #include <QDebug>
@ -14,14 +16,14 @@ int VoicePlayer::decodeOpusFile(const QString& filePath, std::vector<int16_t>& o
int& outSampleRate, int& outChannels, float& outDurationSec) { int& outSampleRate, int& outChannels, float& outDurationSec) {
QFile file(filePath); QFile file(filePath);
if (!file.exists()) { if (!file.exists()) {
qWarning("VoicePlayer: file not found: %s", qPrintable(filePath)); DEBUG_WARN(DEBUG_CATEGORY_DEBUG, "VoicePlayer: file not found: %s", qPrintable(filePath));
return -1; return -1;
} }
if (!file.open(QIODevice::ReadOnly)) { if (!file.open(QIODevice::ReadOnly)) {
qWarning("VoicePlayer: cannot open %s (%s)", qPrintable(filePath), qPrintable(file.errorString())); DEBUG_WARN(DEBUG_CATEGORY_DEBUG, "VoicePlayer: cannot open %s (%s)", qPrintable(filePath), qPrintable(file.errorString()));
return -1; return -1;
} }
qDebug("VoicePlayer: opened file %s size=%lld", qPrintable(filePath), (long long)file.size()); DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "VoicePlayer: opened file %s size=%lld", qPrintable(filePath), (long long)file.size());
uint32_t magic, sr32; uint32_t magic, sr32;
uint16_t ch16, frameSamples; uint16_t ch16, frameSamples;
@ -29,7 +31,7 @@ int VoicePlayer::decodeOpusFile(const QString& filePath, std::vector<int16_t>& o
file.read((char*)&sr32, 4) != 4 || file.read((char*)&sr32, 4) != 4 ||
file.read((char*)&ch16, 2) != 2 || file.read((char*)&ch16, 2) != 2 ||
file.read((char*)&frameSamples, 2) != 2) { file.read((char*)&frameSamples, 2) != 2) {
qWarning("VoicePlayer: invalid header in %s", qPrintable(filePath)); DEBUG_WARN(DEBUG_CATEGORY_DEBUG, "VoicePlayer: invalid header in %s", qPrintable(filePath));
return -1; return -1;
} }
@ -40,7 +42,7 @@ int VoicePlayer::decodeOpusFile(const QString& filePath, std::vector<int16_t>& o
opus_codec_decoder_t* dec = opus_codec_decoder_create(sampleRate, channels); opus_codec_decoder_t* dec = opus_codec_decoder_create(sampleRate, channels);
if (!dec) { if (!dec) {
qWarning("VoicePlayer: decoder create failed"); DEBUG_WARN(DEBUG_CATEGORY_DEBUG, "VoicePlayer: decoder create failed");
return -1; return -1;
} }
@ -67,23 +69,23 @@ int VoicePlayer::decodeOpusFile(const QString& filePath, std::vector<int16_t>& o
} }
outDurationSec = (float)frameCount * 20.0f / 1000.0f; outDurationSec = (float)frameCount * 20.0f / 1000.0f;
qDebug("VoicePlayer: decoded %d frames (%.1fs) from %s", frameCount, outDurationSec, qPrintable(filePath)); DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "VoicePlayer: decoded %d frames (%.1fs) from %s", frameCount, outDurationSec, qPrintable(filePath));
opus_codec_decoder_destroy(dec); opus_codec_decoder_destroy(dec);
return frameCount; return frameCount;
} }
void VoicePlayer::playOpusFile(const QString& filePath) { void VoicePlayer::playOpusFile(const QString& filePath) {
qDebug("VoicePlayer::playOpusFile: %s", qPrintable(filePath)); DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "VoicePlayer::playOpusFile: %s", qPrintable(filePath));
std::vector<int16_t> pcm; std::vector<int16_t> pcm;
int sampleRate, channels; int sampleRate, channels;
float duration; float duration;
if (decodeOpusFile(filePath, pcm, sampleRate, channels, duration) <= 0) { if (decodeOpusFile(filePath, pcm, sampleRate, channels, duration) <= 0) {
qWarning("VoicePlayer::playOpusFile: decode failed for %s", qPrintable(filePath)); DEBUG_WARN(DEBUG_CATEGORY_DEBUG, "VoicePlayer::playOpusFile: decode failed for %s", qPrintable(filePath));
return; return;
} }
qDebug("VoicePlayer::playOpusFile: decoded %zu samples %dHz %dch %.1fs → playing", DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "VoicePlayer::playOpusFile: decoded %zu samples %dHz %dch %.1fs",
pcm.size(), sampleRate, channels, duration); pcm.size(), sampleRate, channels, duration);
SoundManager::instance()->playRawPcm(pcm.data(), pcm.size() / channels, sampleRate, channels); SoundManager::instance()->playRawPcm(pcm.data(), pcm.size() / channels, sampleRate, channels);
} }

Loading…
Cancel
Save