+ while (!producer_thread_should_quit.should_quit()) {
+ // Process any queued commands from other threads.
+ vector<QueuedCommand> commands;
+ {
+ lock_guard<mutex> lock(queue_mu);
+ swap(commands, command_queue);
+ }
+ for (const QueuedCommand &cmd : commands) {
+ switch (cmd.command) {
+ case QueuedCommand::REWIND:
+ if (av_seek_frame(format_ctx.get(), /*stream_index=*/-1, /*timestamp=*/0, /*flags=*/0) < 0) {
+ fprintf(stderr, "%s: Rewind failed, stopping play.\n", pathname.c_str());
+ }
+ pts_origin = last_pts = 0;
+ start = next_frame_start = steady_clock::now();
+ break;
+
+ case QueuedCommand::CHANGE_RATE:
+ start = next_frame_start;
+ pts_origin = last_pts;
+ rate = cmd.new_rate;
+ break;
+ }
+ }
+