mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2026-06-08 02:35:01 -06:00
* avplayer: code improvements * avplayer: implemented pause/resume * avplayer: implemented sync modes * avplayer: issue warning on loopback * avplayer: sync on video ts in default mode when audio ts is not available * avplayer: removed waits for the frame in Get*Data, replaced cv with sleep * avplayer: removed all waits from GetVideoData * avplayer: fix warning propagation + small fixes * Using texture memory for video frames, dropped video frame cache, syncing audio to video * do not sync to audio when audio is not enabled * removed logs, fixed sync * reverted the removal of pre-allocated buffers
95 lines
1.7 KiB
C++
95 lines
1.7 KiB
C++
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#pragma once
|
|
|
|
#include <mutex>
|
|
#include <optional>
|
|
#include <string_view>
|
|
#include <utility>
|
|
#include <queue>
|
|
|
|
#include "core/libraries/avplayer/avplayer.h"
|
|
|
|
#define AVPLAYER_IS_ERROR(x) ((x) < 0)
|
|
|
|
namespace Libraries::AvPlayer {
|
|
|
|
enum class AvState {
|
|
Unknown,
|
|
Initial,
|
|
AddingSource,
|
|
Ready,
|
|
Play,
|
|
Stop,
|
|
EndOfFile,
|
|
Pause,
|
|
C0x08,
|
|
Jump,
|
|
TrickMode,
|
|
C0x0B,
|
|
Buffering,
|
|
Starting,
|
|
Error,
|
|
};
|
|
|
|
enum class AvEventType {
|
|
ChangeFlowState = 21,
|
|
WarningId = 22,
|
|
RevertState = 30,
|
|
AddSource = 40,
|
|
Error = 255,
|
|
};
|
|
|
|
union AvPlayerEventData {
|
|
u32 num_frames; // 20
|
|
AvState state; // AvEventType::ChangeFlowState
|
|
s32 error; // AvEventType::WarningId
|
|
u32 attempt; // AvEventType::AddSource
|
|
};
|
|
|
|
struct AvPlayerEvent {
|
|
AvEventType event;
|
|
AvPlayerEventData payload;
|
|
};
|
|
|
|
template <class T>
|
|
class AvPlayerQueue {
|
|
public:
|
|
size_t Size() {
|
|
return m_queue.size();
|
|
}
|
|
|
|
void Push(T&& value) {
|
|
std::lock_guard guard(m_mutex);
|
|
m_queue.emplace(std::forward<T>(value));
|
|
}
|
|
|
|
T& Front() {
|
|
return m_queue.front();
|
|
}
|
|
|
|
std::optional<T> Pop() {
|
|
if (Size() == 0) {
|
|
return std::nullopt;
|
|
}
|
|
std::lock_guard guard(m_mutex);
|
|
auto result = std::move(m_queue.front());
|
|
m_queue.pop();
|
|
return result;
|
|
}
|
|
|
|
void Clear() {
|
|
std::lock_guard guard(m_mutex);
|
|
m_queue = {};
|
|
}
|
|
|
|
private:
|
|
std::mutex m_mutex{};
|
|
std::queue<T> m_queue{};
|
|
};
|
|
|
|
AvPlayerSourceType GetSourceType(std::string_view path);
|
|
|
|
} // namespace Libraries::AvPlayer
|