Show received audio frames and remove unused sample state

Compared with cdd2f8a:

- Show the number of audio frames successfully returned to the Qt sample directly on the normal Audio status line, making the count available in Release as well as Debug builds.

- Keep the detailed audio event and byte-flow diagnostics Debug-only while reusing the received-frame count for the SDK-to-APP diagnostic boundary.

- Remove write-only audio playback counters, queue-drop metadata, read/write gap maxima, and the unused audio packet ID field without changing the byte-accounting safeguards.

- Remove the unused preview-call timing accumulators and stored values while preserving Read timing, Driver GetFrame timing, startup latency, delivery accounting, and failure recovery.

Validation: git diff --check and focused source/reference inspection passed. No configure, build, runtime capture, audio playback, or hardware validation was run.
This commit is contained in:
Mark.lin
2026-09-10 14:23:26 +08:00
parent cdd2f8a75b
commit f612cfd11b
3 changed files with 21 additions and 82 deletions
+13 -69
View File
@@ -580,18 +580,11 @@ void MainWindow::startCapture(int channelIndex)
} }
channel.previewFailureCount = 0; channel.previewFailureCount = 0;
channel.previewCallAverageMs.store(0.0, std::memory_order_relaxed);
channel.previewCallMaximumMs.store(0.0, std::memory_order_relaxed);
channel.previewCallWindowMaximumMs.store(0.0, std::memory_order_relaxed);
channel.previewCallSamples.store(0, std::memory_order_relaxed);
channel.getFrameAverageMs.store(0.0, std::memory_order_relaxed); channel.getFrameAverageMs.store(0.0, std::memory_order_relaxed);
channel.getFrameMaximumMs.store(0.0, std::memory_order_relaxed); channel.getFrameMaximumMs.store(0.0, std::memory_order_relaxed);
channel.getFrameWindowMaximumMs.store(0.0, std::memory_order_relaxed); channel.getFrameWindowMaximumMs.store(0.0, std::memory_order_relaxed);
channel.getFrameSamples.store(0, std::memory_order_relaxed); channel.getFrameSamples.store(0, std::memory_order_relaxed);
channel.audioEnabled = audioEnabled; channel.audioEnabled = audioEnabled;
channel.audioFrames.store(0, std::memory_order_relaxed);
channel.audioBytes.store(0, std::memory_order_relaxed);
channel.audioQueueDrops.store(0, std::memory_order_relaxed);
channel.videoReceived = 0; channel.videoSubmitted = 0; channel.videoReceived = 0; channel.videoSubmitted = 0;
channel.videoSkipped = 0; channel.videoFailed = 0; channel.videoSkipped = 0; channel.videoFailed = 0;
channel.videoIdGaps = 0; channel.videoIdResets = 0; channel.videoIdGaps = 0; channel.videoIdResets = 0;
@@ -603,16 +596,13 @@ void MainWindow::startCapture(int channelIndex)
{ {
std::lock_guard<std::mutex> lock(channel.audioQueueMutex); std::lock_guard<std::mutex> lock(channel.audioQueueMutex);
channel.audioQueue.clear(); channel.audioQueue.clear();
channel.audioReceivedFrames = 0;
channel.audioReceivedBytes = channel.audioAcceptedBytes = channel.audioQueuedBytes = 0; channel.audioReceivedBytes = channel.audioAcceptedBytes = channel.audioQueuedBytes = 0;
channel.audioDroppedBytes = channel.audioCancelledBytes = 0; channel.audioDroppedBytes = channel.audioCancelledBytes = 0;
channel.audioFailedBytes = channel.audioIdGaps = channel.audioIdResets = 0; channel.audioFailedBytes = channel.audioIdGaps = channel.audioIdResets = 0;
channel.audioLastId = channel.audioLastDropId = 0; channel.audioLastId = 0;
channel.audioLastDropTimeMs = 0;
channel.audioMaxWriteStallMs = 0;
channel.audioMaxReadGapMs = 0;
} }
#if GVFG_INTERNAL_DIAGNOSTICS #if GVFG_INTERNAL_DIAGNOSTICS
channel.audioReceivedFrames = 0;
channel.haveDebugBaseline = false; channel.haveDebugBaseline = false;
channel.lastDebugDmaErrors = 0; channel.lastDebugDmaErrors = 0;
#endif #endif
@@ -824,18 +814,22 @@ void MainWindow::updateSignalStatus(bool queryHardware)
.arg(zeroCopy ? QStringLiteral("Zero-copy") : QStringLiteral("Copy")); .arg(zeroCopy ? QStringLiteral("Zero-copy") : QStringLiteral("Copy"));
if (channel.audioEnabled) if (channel.audioEnabled)
{ {
statusLines << QStringLiteral("CH%1 Audio | %2 Hz %3 ch %4-bit") uint64_t receivedFrames = 0;
{
std::lock_guard<std::mutex> lock(channel.audioQueueMutex);
receivedFrames = channel.audioReceivedFrames;
}
statusLines << QStringLiteral("CH%1 Audio | %2 Hz %3 ch %4-bit | received=%5 frames")
.arg(channelIndex) .arg(channelIndex)
.arg(channel.audioFormat.sample_rate) .arg(channel.audioFormat.sample_rate)
.arg(channel.audioFormat.channels) .arg(channel.audioFormat.channels)
.arg(channel.audioFormat.bits_per_sample); .arg(channel.audioFormat.bits_per_sample)
.arg(static_cast<qulonglong>(receivedFrames));
#if GVFG_INTERNAL_DIAGNOSTICS #if GVFG_INTERNAL_DIAGNOSTICS
uint64_t sdkFrames = 0;
uint64_t sdkBytes = 0; uint64_t sdkBytes = 0;
uint64_t appOutputBytes = 0; uint64_t appOutputBytes = 0;
{ {
std::lock_guard<std::mutex> lock(channel.audioQueueMutex); std::lock_guard<std::mutex> lock(channel.audioQueueMutex);
sdkFrames = channel.audioReceivedFrames;
sdkBytes = channel.audioReceivedBytes; sdkBytes = channel.audioReceivedBytes;
appOutputBytes = channel.audioAcceptedBytes; appOutputBytes = channel.audioAcceptedBytes;
} }
@@ -848,7 +842,7 @@ void MainWindow::updateSignalStatus(bool queryHardware)
.arg(static_cast<qulonglong>(audioStats.extra_audio_event_wakes)) .arg(static_cast<qulonglong>(audioStats.extra_audio_event_wakes))
.arg(static_cast<qulonglong>(audioStats.audio_frames_from_driver)) .arg(static_cast<qulonglong>(audioStats.audio_frames_from_driver))
.arg(static_cast<qulonglong>(audioStats.audio_bytes_from_driver)) .arg(static_cast<qulonglong>(audioStats.audio_bytes_from_driver))
.arg(static_cast<qulonglong>(sdkFrames)) .arg(static_cast<qulonglong>(receivedFrames))
.arg(static_cast<qulonglong>(sdkBytes)) .arg(static_cast<qulonglong>(sdkBytes))
.arg(static_cast<qulonglong>(appOutputBytes)); .arg(static_cast<qulonglong>(appOutputBytes));
} }
@@ -1145,16 +1139,12 @@ void MainWindow::captureReadLoop(int channelIndex)
{ {
constexpr uint64_t kTimingWarmupFrames = 30; constexpr uint64_t kTimingWarmupFrames = 30;
constexpr uint64_t kGetFrameTimingSampleFrames = 300; constexpr uint64_t kGetFrameTimingSampleFrames = 300;
constexpr uint64_t kPreviewTimingSampleFrames = 300;
std::chrono::steady_clock::time_point noFrameSince{}; std::chrono::steady_clock::time_point noFrameSince{};
std::chrono::steady_clock::time_point nextNoFrameReport{}; std::chrono::steady_clock::time_point nextNoFrameReport{};
bool captureStalledLogged = false; bool captureStalledLogged = false;
bool startupLatencyLogged = false; bool startupLatencyLogged = false;
uint64_t successfulFrameCount = 0; uint64_t successfulFrameCount = 0;
uint64_t previewTimingSampleCount = 0;
double previewTimingTotalMs = 0.0;
double previewTimingMaximumMs = 0.0;
uint64_t getFrameTimingSampleCount = 0; uint64_t getFrameTimingSampleCount = 0;
double getFrameTimingMaximumMs = 0.0; double getFrameTimingMaximumMs = 0.0;
ChannelRuntime &channel = channels_[channelIndex]; ChannelRuntime &channel = channels_[channelIndex];
@@ -1313,31 +1303,6 @@ void MainWindow::captureReadLoop(int channelIndex)
.arg(static_cast<qulonglong>(failures))); }, Qt::QueuedConnection); .arg(static_cast<qulonglong>(failures))); }, Qt::QueuedConnection);
} }
if (timingWarmupComplete)
{
double observedMaximum = channel.previewCallMaximumMs.load(std::memory_order_relaxed);
while (previewElapsedMs > observedMaximum &&
!channel.previewCallMaximumMs.compare_exchange_weak(
observedMaximum, previewElapsedMs, std::memory_order_relaxed))
{
}
previewTimingTotalMs += previewElapsedMs;
previewTimingMaximumMs = (std::max)(previewTimingMaximumMs, previewElapsedMs);
++previewTimingSampleCount;
if (previewTimingSampleCount >= kPreviewTimingSampleFrames)
{
const double averageMs =
previewTimingTotalMs / static_cast<double>(previewTimingSampleCount);
channel.previewCallAverageMs.store(averageMs, std::memory_order_relaxed);
channel.previewCallWindowMaximumMs.store(previewTimingMaximumMs, std::memory_order_relaxed);
channel.previewCallSamples.store(kPreviewTimingSampleFrames, std::memory_order_relaxed);
previewTimingSampleCount = 0;
previewTimingTotalMs = 0.0;
previewTimingMaximumMs = 0.0;
}
}
} }
} }
if (!channel.previewHandle) if (!channel.previewHandle)
@@ -1411,7 +1376,6 @@ void MainWindow::joinCaptureThread(int channel)
void MainWindow::audioReadLoop(int channelIndex) void MainWindow::audioReadLoop(int channelIndex)
{ {
ChannelRuntime &channel = channels_[channelIndex]; ChannelRuntime &channel = channels_[channelIndex];
auto lastArrival = std::chrono::steady_clock::time_point{};
while (!channel.stopRequested.load(std::memory_order_acquire)) while (!channel.stopRequested.load(std::memory_order_acquire))
{ {
{ {
@@ -1440,12 +1404,8 @@ void MainWindow::audioReadLoop(int channelIndex)
} }
const uint64_t audioId = frame.frame_id; const uint64_t audioId = frame.frame_id;
const auto arrival = std::chrono::steady_clock::now();
{ {
std::lock_guard<std::mutex> lock(channel.audioQueueMutex); std::lock_guard<std::mutex> lock(channel.audioQueueMutex);
if (lastArrival != std::chrono::steady_clock::time_point{})
channel.audioMaxReadGapMs = (std::max)(channel.audioMaxReadGapMs,
std::chrono::duration<double, std::milli>(arrival - lastArrival).count());
if (channel.audioReceivedBytes != 0) if (channel.audioReceivedBytes != 0)
{ {
if (audioId > channel.audioLastId && audioId - channel.audioLastId > 1) if (audioId > channel.audioLastId && audioId - channel.audioLastId > 1)
@@ -1455,11 +1415,8 @@ void MainWindow::audioReadLoop(int channelIndex)
} }
channel.audioLastId = audioId; channel.audioLastId = audioId;
channel.audioReceivedBytes += frame.data_size; channel.audioReceivedBytes += frame.data_size;
#if GVFG_INTERNAL_DIAGNOSTICS
++channel.audioReceivedFrames; ++channel.audioReceivedFrames;
#endif
} }
lastArrival = arrival;
std::vector<uint8_t> pcm(frame.data_size); std::vector<uint8_t> pcm(frame.data_size);
std::memcpy(pcm.data(), frame.data, frame.data_size); std::memcpy(pcm.data(), frame.data, frame.data_size);
const gvfg_status_t releaseStatus = const gvfg_status_t releaseStatus =
@@ -1490,13 +1447,10 @@ void MainWindow::audioReadLoop(int channelIndex)
const auto &oldest = channel.audioQueue.front(); const auto &oldest = channel.audioQueue.front();
channel.audioDroppedBytes += oldest.pcm.size(); channel.audioDroppedBytes += oldest.pcm.size();
channel.audioQueuedBytes -= oldest.pcm.size(); channel.audioQueuedBytes -= oldest.pcm.size();
channel.audioLastDropId = oldest.id;
channel.audioLastDropTimeMs = QDateTime::currentMSecsSinceEpoch();
channel.audioQueue.pop_front(); channel.audioQueue.pop_front();
channel.audioQueueDrops.fetch_add(1, std::memory_order_relaxed);
} }
channel.audioQueuedBytes += pcm.size(); channel.audioQueuedBytes += pcm.size();
channel.audioQueue.push_back({std::move(pcm), audioId}); channel.audioQueue.push_back({std::move(pcm)});
} }
channel.audioQueueReady.notify_one(); channel.audioQueueReady.notify_one();
} }
@@ -1544,7 +1498,6 @@ void MainWindow::audioPlaybackLoop(int channelIndex)
channel.audioDroppedBytes += channel.audioQueue.front().pcm.size(); channel.audioDroppedBytes += channel.audioQueue.front().pcm.size();
channel.audioQueuedBytes -= channel.audioQueue.front().pcm.size(); channel.audioQueuedBytes -= channel.audioQueue.front().pcm.size();
channel.audioQueue.pop_front(); channel.audioQueue.pop_front();
channel.audioQueueDrops.fetch_add(1, std::memory_order_relaxed);
} }
channel.audioQueueReady.wait_for(lock, std::chrono::milliseconds(500), [&channel]() { channel.audioQueueReady.wait_for(lock, std::chrono::milliseconds(500), [&channel]() {
return channel.stopRequested.load(std::memory_order_acquire); return channel.stopRequested.load(std::memory_order_acquire);
@@ -1567,7 +1520,6 @@ void MainWindow::audioPlaybackLoop(int channelIndex)
channel.audioDroppedBytes += channel.audioQueue.front().pcm.size(); channel.audioDroppedBytes += channel.audioQueue.front().pcm.size();
channel.audioQueuedBytes -= channel.audioQueue.front().pcm.size(); channel.audioQueuedBytes -= channel.audioQueue.front().pcm.size();
channel.audioQueue.pop_front(); channel.audioQueue.pop_front();
channel.audioQueueDrops.fetch_add(1, std::memory_order_relaxed);
} }
channel.audioQueueReady.wait_for(lock, std::chrono::milliseconds(500), [&channel]() { channel.audioQueueReady.wait_for(lock, std::chrono::milliseconds(500), [&channel]() {
return channel.stopRequested.load(std::memory_order_acquire); return channel.stopRequested.load(std::memory_order_acquire);
@@ -1609,8 +1561,6 @@ void MainWindow::audioPlaybackLoop(int channelIndex)
const bool stalled = result == 0 && now - lastProgress >= std::chrono::seconds(2); const bool stalled = result == 0 && now - lastProgress >= std::chrono::seconds(2);
{ {
std::lock_guard<std::mutex> lock(channel.audioQueueMutex); std::lock_guard<std::mutex> lock(channel.audioQueueMutex);
channel.audioMaxWriteStallMs = (std::max)(channel.audioMaxWriteStallMs,
std::chrono::duration<double, std::milli>(now - lastProgress).count());
if (result > 0) if (result > 0)
channel.audioAcceptedBytes += static_cast<uint64_t>(result); channel.audioAcceptedBytes += static_cast<uint64_t>(result);
else if (result < 0 || stalled) else if (result < 0 || stalled)
@@ -1634,12 +1584,7 @@ void MainWindow::audioPlaybackLoop(int channelIndex)
} }
std::this_thread::sleep_for(std::chrono::milliseconds(1)); std::this_thread::sleep_for(std::chrono::milliseconds(1));
} }
if (written == static_cast<qint64>(pcm.size())) if (written != static_cast<qint64>(pcm.size()) && !restartPlayback)
{
channel.audioFrames.fetch_add(1, std::memory_order_relaxed);
channel.audioBytes.fetch_add(pcm.size(), std::memory_order_relaxed);
}
else if (!restartPlayback)
{ {
std::lock_guard<std::mutex> lock(channel.audioQueueMutex); std::lock_guard<std::mutex> lock(channel.audioQueueMutex);
channel.audioCancelledBytes += pcm.size() - static_cast<uint64_t>(written); channel.audioCancelledBytes += pcm.size() - static_cast<uint64_t>(written);
@@ -1655,7 +1600,6 @@ void MainWindow::audioPlaybackLoop(int channelIndex)
channel.audioDroppedBytes += channel.audioQueue.front().pcm.size(); channel.audioDroppedBytes += channel.audioQueue.front().pcm.size();
channel.audioQueuedBytes -= channel.audioQueue.front().pcm.size(); channel.audioQueuedBytes -= channel.audioQueue.front().pcm.size();
channel.audioQueue.pop_front(); channel.audioQueue.pop_front();
channel.audioQueueDrops.fetch_add(1, std::memory_order_relaxed);
} }
channel.audioQueueReady.wait_for(lock, std::chrono::milliseconds(500), [&channel]() { channel.audioQueueReady.wait_for(lock, std::chrono::milliseconds(500), [&channel]() {
return channel.stopRequested.load(std::memory_order_acquire); return channel.stopRequested.load(std::memory_order_acquire);
+2 -13
View File
@@ -56,15 +56,13 @@ private:
std::thread audioPlaybackThread; std::thread audioPlaybackThread;
std::mutex audioQueueMutex; std::mutex audioQueueMutex;
std::condition_variable audioQueueReady; std::condition_variable audioQueueReady;
struct AudioPacket { std::vector<uint8_t> pcm; uint64_t id; }; struct AudioPacket { std::vector<uint8_t> pcm; };
std::deque<AudioPacket> audioQueue; std::deque<AudioPacket> audioQueue;
bool audioEnabled = false; bool audioEnabled = false;
gvfg_audio_format_t audioFormat{}; gvfg_audio_format_t audioFormat{};
std::atomic<uint64_t> audioFrames{0};
std::atomic<uint64_t> audioBytes{0};
std::atomic<uint64_t> audioQueueDrops{0};
// Audio accounting is protected by audioQueueMutex. Accepted means // Audio accounting is protected by audioQueueMutex. Accepted means
// written to QAudioSink, not physically played by the device. // written to QAudioSink, not physically played by the device.
uint64_t audioReceivedFrames = 0;
uint64_t audioReceivedBytes = 0; uint64_t audioReceivedBytes = 0;
uint64_t audioAcceptedBytes = 0; uint64_t audioAcceptedBytes = 0;
uint64_t audioQueuedBytes = 0; uint64_t audioQueuedBytes = 0;
@@ -74,10 +72,6 @@ private:
uint64_t audioIdGaps = 0; uint64_t audioIdGaps = 0;
uint64_t audioIdResets = 0; uint64_t audioIdResets = 0;
uint64_t audioLastId = 0; uint64_t audioLastId = 0;
uint64_t audioLastDropId = 0;
qint64 audioLastDropTimeMs = 0;
double audioMaxWriteStallMs = 0;
double audioMaxReadGapMs = 0;
std::atomic<uint64_t> videoReceived{0}, videoSubmitted{0}, videoSkipped{0}, videoFailed{0}; std::atomic<uint64_t> videoReceived{0}, videoSubmitted{0}, videoSkipped{0}, videoFailed{0};
std::atomic<uint64_t> videoIdGaps{0}, videoIdResets{0}; std::atomic<uint64_t> videoIdGaps{0}, videoIdResets{0};
std::atomic<uint64_t> videoLastId{0}; std::atomic<uint64_t> videoLastId{0};
@@ -91,15 +85,10 @@ private:
std::atomic<double> getFrameWindowMaximumMs{0.0}; std::atomic<double> getFrameWindowMaximumMs{0.0};
std::atomic<uint64_t> getFrameSamples{0}; std::atomic<uint64_t> getFrameSamples{0};
uint64_t previewFailureCount = 0; uint64_t previewFailureCount = 0;
std::atomic<double> previewCallAverageMs{0.0};
std::atomic<double> previewCallMaximumMs{0.0};
std::atomic<double> previewCallWindowMaximumMs{0.0};
std::atomic<uint64_t> previewCallSamples{0};
gvfg_signal_status_t cachedSignalStatus{}; gvfg_signal_status_t cachedSignalStatus{};
bool haveCachedSignalStatus = false; bool haveCachedSignalStatus = false;
QString lastLoggedInputStatus; QString lastLoggedInputStatus;
#if GVFG_INTERNAL_DIAGNOSTICS #if GVFG_INTERNAL_DIAGNOSTICS
uint64_t audioReceivedFrames = 0;
uint64_t lastDebugDmaErrors = 0; uint64_t lastDebugDmaErrors = 0;
bool haveDebugBaseline = false; bool haveDebugBaseline = false;
#endif #endif
+6
View File
@@ -94,6 +94,9 @@
<property name="text"> <property name="text">
<string>Zero-copy</string> <string>Zero-copy</string>
</property> </property>
<property name="checked">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item row="0" column="3"> <item row="0" column="3">
@@ -107,6 +110,9 @@
<property name="text"> <property name="text">
<string>Audio</string> <string>Audio</string>
</property> </property>
<property name="checked">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item row="1" column="0" colspan="4"> <item row="1" column="0" colspan="4">