mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-28 13:56:59 +01:00
Fix AvPlayer startup state
This commit is contained in:
+24
-15
@@ -706,7 +706,7 @@ public:
|
|||||||
int Enable(uint32_t id) {
|
int Enable(uint32_t id) {
|
||||||
std::scoped_lock lifecycle_lock(lifecycle_mutex);
|
std::scoped_lock lifecycle_lock(lifecycle_mutex);
|
||||||
std::lock_guard state_lock(mutex);
|
std::lock_guard state_lock(mutex);
|
||||||
if (!stopped) {
|
if (state == State::Playing) {
|
||||||
return AVPLAYER_ERROR_OPERATION_FAILED;
|
return AVPLAYER_ERROR_OPERATION_FAILED;
|
||||||
}
|
}
|
||||||
if (fmt == nullptr || id >= fmt->nb_streams) {
|
if (fmt == nullptr || id >= fmt->nb_streams) {
|
||||||
@@ -724,7 +724,7 @@ public:
|
|||||||
int Disable(uint32_t id) {
|
int Disable(uint32_t id) {
|
||||||
std::scoped_lock lifecycle_lock(lifecycle_mutex);
|
std::scoped_lock lifecycle_lock(lifecycle_mutex);
|
||||||
std::lock_guard state_lock(mutex);
|
std::lock_guard state_lock(mutex);
|
||||||
if (!stopped) {
|
if (state == State::Playing) {
|
||||||
return AVPLAYER_ERROR_OPERATION_FAILED;
|
return AVPLAYER_ERROR_OPERATION_FAILED;
|
||||||
}
|
}
|
||||||
if (video_id == static_cast<int>(id)) {
|
if (video_id == static_cast<int>(id)) {
|
||||||
@@ -755,9 +755,11 @@ public:
|
|||||||
return AVPLAYER_ERROR_OPERATION_FAILED;
|
return AVPLAYER_ERROR_OPERATION_FAILED;
|
||||||
}
|
}
|
||||||
time = CurrentTimeNoLock();
|
time = CurrentTimeNoLock();
|
||||||
restart = !stopped;
|
restart = state == State::Playing;
|
||||||
was_paused = paused;
|
was_paused = paused;
|
||||||
stopped = true;
|
if (restart) {
|
||||||
|
state = State::Ready;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (restart) {
|
if (restart) {
|
||||||
StopWorkers();
|
StopWorkers();
|
||||||
@@ -778,7 +780,7 @@ public:
|
|||||||
int StartImpl(uint64_t ms, bool paused_after_start = false, bool show_seek_frame = false) {
|
int StartImpl(uint64_t ms, bool paused_after_start = false, bool show_seek_frame = false) {
|
||||||
{
|
{
|
||||||
std::lock_guard lock(mutex);
|
std::lock_guard lock(mutex);
|
||||||
stopped = true;
|
state = State::Ready;
|
||||||
}
|
}
|
||||||
StopWorkers();
|
StopWorkers();
|
||||||
interrupt_io = false;
|
interrupt_io = false;
|
||||||
@@ -791,14 +793,17 @@ public:
|
|||||||
AutoEnable();
|
AutoEnable();
|
||||||
}
|
}
|
||||||
if (!video_id && !audio_id) {
|
if (!video_id && !audio_id) {
|
||||||
|
state = State::Stopped;
|
||||||
return AVPLAYER_ERROR_OPERATION_FAILED;
|
return AVPLAYER_ERROR_OPERATION_FAILED;
|
||||||
}
|
}
|
||||||
if (!OpenCodecs()) {
|
if (!OpenCodecs()) {
|
||||||
ResetNoLock(true);
|
ResetNoLock(true);
|
||||||
|
state = State::Stopped;
|
||||||
return AVPLAYER_ERROR_OPERATION_FAILED;
|
return AVPLAYER_ERROR_OPERATION_FAILED;
|
||||||
}
|
}
|
||||||
if (!AllocateBuffers()) {
|
if (!AllocateBuffers()) {
|
||||||
ResetNoLock(true);
|
ResetNoLock(true);
|
||||||
|
state = State::Stopped;
|
||||||
return AVPLAYER_ERROR_NO_MEMORY;
|
return AVPLAYER_ERROR_NO_MEMORY;
|
||||||
}
|
}
|
||||||
SeekNoLock(ms);
|
SeekNoLock(ms);
|
||||||
@@ -809,12 +814,11 @@ public:
|
|||||||
pause_time = clock_start;
|
pause_time = clock_start;
|
||||||
seek_video_frame_pending =
|
seek_video_frame_pending =
|
||||||
paused_after_start && show_seek_frame && video_id.has_value();
|
paused_after_start && show_seek_frame && video_id.has_value();
|
||||||
stopped = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!StartWorkers()) {
|
if (!StartWorkers()) {
|
||||||
std::lock_guard lock(mutex);
|
std::lock_guard lock(mutex);
|
||||||
stopped = true;
|
state = State::Stopped;
|
||||||
ResetNoLock(true);
|
ResetNoLock(true);
|
||||||
result = AVPLAYER_ERROR_OPERATION_FAILED;
|
result = AVPLAYER_ERROR_OPERATION_FAILED;
|
||||||
}
|
}
|
||||||
@@ -830,8 +834,8 @@ public:
|
|||||||
std::scoped_lock lifecycle_lock(lifecycle_mutex);
|
std::scoped_lock lifecycle_lock(lifecycle_mutex);
|
||||||
{
|
{
|
||||||
std::lock_guard lock(mutex);
|
std::lock_guard lock(mutex);
|
||||||
was_playing_video = !stopped && video_id.has_value();
|
was_playing_video = state == State::Playing && video_id.has_value();
|
||||||
stopped = true;
|
state = State::Stopped;
|
||||||
}
|
}
|
||||||
StopWorkers();
|
StopWorkers();
|
||||||
{
|
{
|
||||||
@@ -872,7 +876,8 @@ public:
|
|||||||
}
|
}
|
||||||
bool Active() const {
|
bool Active() const {
|
||||||
std::lock_guard lock(mutex);
|
std::lock_guard lock(mutex);
|
||||||
return !stopped && !pipeline_failed && !DrainedNoLock();
|
return state == State::Ready ||
|
||||||
|
(state == State::Playing && !pipeline_failed && !DrainedNoLock());
|
||||||
}
|
}
|
||||||
uint64_t CurrentTime() const {
|
uint64_t CurrentTime() const {
|
||||||
std::lock_guard lock(mutex);
|
std::lock_guard lock(mutex);
|
||||||
@@ -888,7 +893,7 @@ public:
|
|||||||
return StartImpl(ms, was_paused, true);
|
return StartImpl(ms, was_paused, true);
|
||||||
}
|
}
|
||||||
uint64_t CurrentTimeNoLock() const {
|
uint64_t CurrentTimeNoLock() const {
|
||||||
if (stopped) {
|
if (state != State::Playing) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
@@ -925,7 +930,7 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
std::lock_guard lock(mutex);
|
std::lock_guard lock(mutex);
|
||||||
if (stopped || !video_id) {
|
if (state != State::Playing || !video_id) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const bool deliver_seek_frame = paused && seek_video_frame_pending;
|
const bool deliver_seek_frame = paused && seek_video_frame_pending;
|
||||||
@@ -966,7 +971,8 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
std::lock_guard lock(mutex);
|
std::lock_guard lock(mutex);
|
||||||
if (paused || stopped || !audio_id || trick_speed != AVPLAYER_TRICK_SPEED_NORMAL) {
|
if (paused || state != State::Playing || !audio_id ||
|
||||||
|
trick_speed != AVPLAYER_TRICK_SPEED_NORMAL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
auto frame = audio_frames.TryPop();
|
auto frame = audio_frames.TryPop();
|
||||||
@@ -1000,6 +1006,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
enum class State { Ready, Playing, Stopped };
|
||||||
|
|
||||||
bool DrainedNoLock() const {
|
bool DrainedNoLock() const {
|
||||||
return demux_eof && video_done && audio_done && video_frames.Empty() &&
|
return demux_eof && video_done && audio_done && video_frames.Empty() &&
|
||||||
audio_frames.Empty();
|
audio_frames.Empty();
|
||||||
@@ -1198,6 +1206,7 @@ private:
|
|||||||
StopWorkers();
|
StopWorkers();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
state = State::Playing;
|
||||||
stop_event_sent = false;
|
stop_event_sent = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1676,7 +1685,7 @@ private:
|
|||||||
std::condition_variable completion_changed;
|
std::condition_variable completion_changed;
|
||||||
std::mutex lifecycle_mutex;
|
std::mutex lifecycle_mutex;
|
||||||
mutable std::mutex mutex;
|
mutable std::mutex mutex;
|
||||||
bool stopped = true;
|
State state = State::Ready;
|
||||||
bool paused = false;
|
bool paused = false;
|
||||||
bool seek_video_frame_pending = false;
|
bool seek_video_frame_pending = false;
|
||||||
std::atomic_bool loop {false};
|
std::atomic_bool loop {false};
|
||||||
@@ -2029,7 +2038,7 @@ Bool KYTY_SYSV_ABI AvPlayerGetAudioData(AvPlayerInternal* h, AvPlayerFrameInfo*
|
|||||||
}
|
}
|
||||||
Bool KYTY_SYSV_ABI AvPlayerIsActive(AvPlayerInternal* h) {
|
Bool KYTY_SYSV_ABI AvPlayerIsActive(AvPlayerInternal* h) {
|
||||||
PRINT_NAME();
|
PRINT_NAME();
|
||||||
return h != nullptr && h->source != nullptr && h->source->Active() ? 1 : 0;
|
return h != nullptr && (h->source == nullptr || h->source->Active());
|
||||||
}
|
}
|
||||||
uint64_t KYTY_SYSV_ABI AvPlayerCurrentTime(AvPlayerInternal* h) {
|
uint64_t KYTY_SYSV_ABI AvPlayerCurrentTime(AvPlayerInternal* h) {
|
||||||
PRINT_NAME();
|
PRINT_NAME();
|
||||||
|
|||||||
Reference in New Issue
Block a user