app: migrate the viewer panel to the facade playback engine
This commit is contained in:
@@ -152,7 +152,7 @@ These tests depend on:
|
||||
|
||||
The viewer subsystem has the following thread safety characteristics:
|
||||
|
||||
1. **ViewerPlaybackTimer**: Thread-safe for concurrent reads, but Start() should not be called concurrently with GetTimestampNow()
|
||||
1. **ViewerPlaybackTimer**: removed when playback moved to the facade playback engine (the facade owns the master clock now)
|
||||
2. **ViewerQueue**: NOT thread-safe - requires external synchronization for concurrent modifications
|
||||
3. **ViewerSafeMarginInfo**: Thread-safe for read-only access after construction
|
||||
4. **AudioPlaybackCache**: Uses internal locking for thread safety
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
* Copyright (C) 2025 Olive CE Team
|
||||
*
|
||||
* Comprehensive smoke tests for the viewer and preview display subsystem including:
|
||||
* - ViewerPlaybackTimer timing calculations
|
||||
* - ViewerQueue frame management
|
||||
* - ViewerSafeMarginInfo safety margin calculations
|
||||
* - PreviewAutoCacher cache management
|
||||
@@ -13,11 +12,9 @@
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QThread>
|
||||
#include <QElapsedTimer>
|
||||
#include <QSignalSpy>
|
||||
|
||||
// Viewer headers
|
||||
#include "widget/viewer/viewerplaybacktimer.h"
|
||||
#include "widget/viewer/viewerqueue.h"
|
||||
#include "widget/viewer/viewersafemargininfo.h"
|
||||
#include "codec/conformmanager.h"
|
||||
@@ -39,167 +36,6 @@ namespace viewer
|
||||
namespace test
|
||||
{
|
||||
|
||||
// ============================================================================
|
||||
// Smoke Test: ViewerPlaybackTimer
|
||||
// ============================================================================
|
||||
|
||||
TEST(ViewerSmokeTimer, DefaultConstruction)
|
||||
{
|
||||
ViewerPlaybackTimer timer;
|
||||
|
||||
// After Start() is called, the timer must return valid timestamps
|
||||
timer.start(0, 1, 1.0 / 24.0);
|
||||
EXPECT_GE(timer.get_timestamp_now(), 0);
|
||||
}
|
||||
|
||||
TEST(ViewerSmokeTimer, BasicTiming)
|
||||
{
|
||||
ViewerPlaybackTimer timer;
|
||||
|
||||
// Start at timestamp 0, 1x speed, 24fps (timebase = 1/24)
|
||||
timer.start(0, 1, 1.0 / 24.0);
|
||||
|
||||
// Immediately get timestamp (should be close to 0)
|
||||
int64_t ts = timer.get_timestamp_now();
|
||||
EXPECT_GE(ts, 0);
|
||||
|
||||
// Wait a bit and check timestamp has increased
|
||||
QThread::msleep(50); // 50ms
|
||||
int64_t ts2 = timer.get_timestamp_now();
|
||||
|
||||
// At 24fps, 50ms is more than one frame period (~41.7ms), so the
|
||||
// timestamp must have advanced by at least one frame
|
||||
EXPECT_GT(ts2, ts);
|
||||
}
|
||||
|
||||
TEST(ViewerSmokeTimer, PlaybackSpeedForward)
|
||||
{
|
||||
ViewerPlaybackTimer timer;
|
||||
|
||||
// Start at timestamp 100, 2x speed, 30fps
|
||||
timer.start(100, 2, 1.0 / 30.0);
|
||||
|
||||
int64_t ts1 = timer.get_timestamp_now();
|
||||
QThread::msleep(50);
|
||||
int64_t ts2 = timer.get_timestamp_now();
|
||||
|
||||
// At 2x speed, time should advance twice as fast
|
||||
EXPECT_GT(ts2, ts1);
|
||||
}
|
||||
|
||||
TEST(ViewerSmokeTimer, PlaybackSpeedReverse)
|
||||
{
|
||||
ViewerPlaybackTimer timer;
|
||||
|
||||
// Start at timestamp 1000, -1x speed (reverse), 24fps
|
||||
timer.start(1000, -1, 1.0 / 24.0);
|
||||
|
||||
int64_t ts1 = timer.get_timestamp_now();
|
||||
QThread::msleep(50);
|
||||
int64_t ts2 = timer.get_timestamp_now();
|
||||
|
||||
// In reverse, timestamp should decrease
|
||||
EXPECT_LT(ts2, ts1);
|
||||
}
|
||||
|
||||
TEST(ViewerSmokeTimer, DifferentTimebases)
|
||||
{
|
||||
// Frame counts track wall time at each timebase's rate. Measure the
|
||||
// actual interval so scheduling jitter on loaded CI runners (observed on
|
||||
// macOS, where msleep(100) overslept ~2.5x) can't break the comparison.
|
||||
for (double fps : { 24.0, 60.0 }) {
|
||||
ViewerPlaybackTimer timer;
|
||||
QElapsedTimer wall;
|
||||
timer.start(0, 1, 1.0 / fps);
|
||||
wall.start();
|
||||
QThread::msleep(100);
|
||||
|
||||
const int64_t ts = timer.get_timestamp_now();
|
||||
const int64_t expected =
|
||||
qFloor(static_cast<double>(wall.elapsed()) / (1000.0 / fps));
|
||||
EXPECT_NEAR(ts, expected, 1) << "fps=" << fps;
|
||||
}
|
||||
|
||||
// With highly distinct timebases the faster one always produces more
|
||||
// frames in the same interval, even on heavily loaded machines
|
||||
ViewerPlaybackTimer slow, fast;
|
||||
slow.start(0, 1, 1.0);
|
||||
fast.start(0, 1, 1.0 / 240.0);
|
||||
QThread::msleep(100);
|
||||
|
||||
EXPECT_LT(slow.get_timestamp_now(), fast.get_timestamp_now());
|
||||
}
|
||||
|
||||
TEST(ViewerSmokeTimer, ZeroSpeed)
|
||||
{
|
||||
ViewerPlaybackTimer timer;
|
||||
|
||||
// Start with 0 speed (paused)
|
||||
timer.start(500, 0, 1.0 / 24.0);
|
||||
|
||||
int64_t ts1 = timer.get_timestamp_now();
|
||||
QThread::msleep(50);
|
||||
int64_t ts2 = timer.get_timestamp_now();
|
||||
|
||||
// With 0 speed, timestamp should not change
|
||||
EXPECT_EQ(ts1, ts2);
|
||||
}
|
||||
|
||||
class FakeAudioClock : public PlaybackAudioClock {
|
||||
public:
|
||||
virtual double seconds() const override
|
||||
{
|
||||
return seconds_;
|
||||
}
|
||||
|
||||
double seconds_ = -1.0;
|
||||
};
|
||||
|
||||
TEST(ViewerSmokeTimer, AudioClockDrivesTimestamp)
|
||||
{
|
||||
FakeAudioClock clock;
|
||||
ViewerPlaybackTimer timer;
|
||||
|
||||
// Start at timestamp 100, 1x speed, 32fps (exact in floating point)
|
||||
timer.start(100, 1, 1.0 / 32.0, &clock);
|
||||
|
||||
// One second of consumed audio = 32 frames, regardless of wall time
|
||||
clock.seconds_ = 1.0;
|
||||
EXPECT_EQ(timer.get_timestamp_now(), 132);
|
||||
|
||||
// The audio clock fully overrides the wall clock (no sleep involved)
|
||||
clock.seconds_ = 0.5;
|
||||
EXPECT_EQ(timer.get_timestamp_now(), 116);
|
||||
}
|
||||
|
||||
TEST(ViewerSmokeTimer, AudioClockScalesWithPlaybackSpeed)
|
||||
{
|
||||
FakeAudioClock clock;
|
||||
ViewerPlaybackTimer timer;
|
||||
|
||||
// At 2x speed one output second is two timeline seconds
|
||||
timer.start(0, 2, 1.0 / 32.0, &clock);
|
||||
clock.seconds_ = 0.5;
|
||||
EXPECT_EQ(timer.get_timestamp_now(), 32);
|
||||
|
||||
// In reverse the playhead moves backward at |speed|
|
||||
timer.start(100, -2, 1.0 / 32.0, &clock);
|
||||
clock.seconds_ = 1.0;
|
||||
EXPECT_EQ(timer.get_timestamp_now(), 36);
|
||||
}
|
||||
|
||||
TEST(ViewerSmokeTimer, InvalidAudioClockFallsBackToWallClock)
|
||||
{
|
||||
FakeAudioClock clock; // seconds() returns -1: no clocked output running
|
||||
ViewerPlaybackTimer timer;
|
||||
|
||||
timer.start(0, 1, 1.0 / 24.0, &clock);
|
||||
EXPECT_GE(timer.get_timestamp_now(), 0);
|
||||
|
||||
QThread::msleep(50); // 50ms > one 24fps frame period
|
||||
EXPECT_GT(timer.get_timestamp_now(), 0);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Smoke Test: ViewerQueue
|
||||
// ============================================================================
|
||||
@@ -615,41 +451,6 @@ TEST(ViewerSmokeRational, Flipped)
|
||||
// Smoke Test: Thread Safety
|
||||
// ============================================================================
|
||||
|
||||
TEST(ViewerSmokeThread, ConcurrentTimerAccess)
|
||||
{
|
||||
const int num_threads = 4;
|
||||
const int num_iterations = 100;
|
||||
|
||||
ViewerPlaybackTimer timer;
|
||||
timer.start(0, 1, 1.0 / 30.0);
|
||||
|
||||
std::vector<std::thread> threads;
|
||||
std::atomic<int> monotonic_violations{ 0 };
|
||||
|
||||
// Each thread reads the timer repeatedly; because playback is forward, a
|
||||
// thread must never observe a timestamp smaller than the one it read before
|
||||
for (int t = 0; t < num_threads; ++t) {
|
||||
threads.emplace_back([&timer, &monotonic_violations, num_iterations]() {
|
||||
int64_t previous = 0;
|
||||
for (int i = 0; i < num_iterations; ++i) {
|
||||
const int64_t ts = timer.get_timestamp_now();
|
||||
if (ts < previous) {
|
||||
monotonic_violations++;
|
||||
}
|
||||
previous = ts;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for (auto &t : threads) {
|
||||
t.join();
|
||||
}
|
||||
|
||||
EXPECT_EQ(monotonic_violations.load(), 0);
|
||||
// The threads ran long enough that the timer must have advanced at all
|
||||
EXPECT_GE(timer.get_timestamp_now(), 0);
|
||||
}
|
||||
|
||||
TEST(ViewerSmokeThread, ConcurrentQueueAccess)
|
||||
{
|
||||
const int num_threads = 4;
|
||||
@@ -684,39 +485,6 @@ TEST(ViewerSmokeThread, ConcurrentQueueAccess)
|
||||
// Smoke Test: Integration Scenarios
|
||||
// ============================================================================
|
||||
|
||||
TEST(ViewerSmokeIntegration, PlaybackSequenceSimulation)
|
||||
{
|
||||
// Simulate a basic playback sequence
|
||||
ViewerPlaybackTimer timer;
|
||||
ViewerQueue queue;
|
||||
|
||||
// Start playback at frame 0, 24fps; timestamps are expressed in frames
|
||||
timer.start(0, 1, 1.0 / 24.0);
|
||||
|
||||
// Queue some frames
|
||||
for (int i = 0; i < 10; i++) {
|
||||
ViewerPlaybackFrame frame{ Rational(i, 24), QVariant(i) };
|
||||
queue.append_timewise(frame, 1);
|
||||
}
|
||||
|
||||
// Get current timestamp (in frames) and convert it to a time in seconds
|
||||
const int64_t current_ts = timer.get_timestamp_now();
|
||||
const Rational current_time(current_ts, 24);
|
||||
|
||||
// Find the first queued frame at or after the current playback time
|
||||
bool found = false;
|
||||
for (const auto &frame : queue) {
|
||||
if (frame.timestamp >= current_time) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Playback just started at frame 0 and the queue holds frames 0-9, so a
|
||||
// current-or-future frame must be available
|
||||
EXPECT_TRUE(found);
|
||||
}
|
||||
|
||||
TEST(ViewerSmokeIntegration, SafeMarginWithDifferentAspectRatios)
|
||||
{
|
||||
// Test safe margins for different aspect ratios
|
||||
@@ -730,29 +498,6 @@ TEST(ViewerSmokeIntegration, SafeMarginWithDifferentAspectRatios)
|
||||
}
|
||||
}
|
||||
|
||||
TEST(ViewerSmokeIntegration, ReversePlaybackScenario)
|
||||
{
|
||||
ViewerPlaybackTimer timer;
|
||||
ViewerQueue queue;
|
||||
|
||||
// Start reverse playback from frame 100
|
||||
timer.start(100, -1, 1.0 / 24.0);
|
||||
|
||||
// Queue frames in reverse order
|
||||
for (int i = 100; i >= 90; i--) {
|
||||
ViewerPlaybackFrame frame{ Rational(i, 24), QVariant(i) };
|
||||
queue.append_timewise(frame, -1);
|
||||
}
|
||||
|
||||
// Get timestamps - should decrease
|
||||
int64_t ts1 = timer.get_timestamp_now();
|
||||
QThread::msleep(50);
|
||||
int64_t ts2 = timer.get_timestamp_now();
|
||||
|
||||
EXPECT_LT(ts2, ts1);
|
||||
EXPECT_EQ(queue.front().timestamp, Rational(100, 24));
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace viewer
|
||||
} // namespace olive
|
||||
|
||||
Reference in New Issue
Block a user