mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-04-21 03:54:45 +00:00
avplayer: removed waits for the frame in Get*Data, replaced cv with sleep
This commit is contained in:
parent
f52c92e1a6
commit
cba5111288
3 changed files with 13 additions and 29 deletions
|
@ -19,7 +19,7 @@ s32 PS4_SYSV_ABI sceAvPlayerAddSource(AvPlayerHandle handle, const char* filenam
|
|||
|
||||
s32 PS4_SYSV_ABI sceAvPlayerAddSourceEx(AvPlayerHandle handle, AvPlayerUriType uri_type,
|
||||
AvPlayerSourceDetails* source_details) {
|
||||
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
|
||||
LOG_TRACE(Lib_AvPlayer, "(STUBBED) called");
|
||||
if (handle == nullptr || uri_type != AvPlayerUriType::Source) {
|
||||
return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS;
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ s32 PS4_SYSV_ABI sceAvPlayerEnableStream(AvPlayerHandle handle, u32 stream_id) {
|
|||
bool PS4_SYSV_ABI sceAvPlayerGetAudioData(AvPlayerHandle handle, AvPlayerFrameInfo* p_info) {
|
||||
LOG_TRACE(Lib_AvPlayer, "called");
|
||||
if (handle == nullptr || p_info == nullptr) {
|
||||
return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS;
|
||||
return false;
|
||||
}
|
||||
return handle->GetAudioData(*p_info);
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ s32 PS4_SYSV_ABI sceAvPlayerGetStreamInfo(AvPlayerHandle handle, u32 stream_id,
|
|||
bool PS4_SYSV_ABI sceAvPlayerGetVideoData(AvPlayerHandle handle, AvPlayerFrameInfo* video_info) {
|
||||
LOG_TRACE(Lib_AvPlayer, "called");
|
||||
if (handle == nullptr || video_info == nullptr) {
|
||||
return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS;
|
||||
return false;
|
||||
}
|
||||
return handle->GetVideoData(*video_info);
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ bool PS4_SYSV_ABI sceAvPlayerGetVideoDataEx(AvPlayerHandle handle,
|
|||
AvPlayerFrameInfoEx* video_info) {
|
||||
LOG_TRACE(Lib_AvPlayer, "called");
|
||||
if (handle == nullptr || video_info == nullptr) {
|
||||
return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS;
|
||||
return false;
|
||||
}
|
||||
return handle->GetVideoData(*video_info);
|
||||
}
|
||||
|
|
|
@ -272,7 +272,6 @@ bool AvPlayerSource::Stop() {
|
|||
m_video_buffers.Push(std::move(m_current_video_frame.value()));
|
||||
m_current_video_frame.reset();
|
||||
}
|
||||
m_stop_cv.Notify();
|
||||
|
||||
m_audio_packets.Clear();
|
||||
m_video_packets.Clear();
|
||||
|
@ -314,27 +313,17 @@ bool AvPlayerSource::GetVideoData(AvPlayerFrameInfoEx& video_info) {
|
|||
return false;
|
||||
}
|
||||
|
||||
m_video_frames_cv.Wait([this] { return m_video_frames.Size() != 0 || m_is_eof; });
|
||||
|
||||
auto frame = m_video_frames.Pop();
|
||||
if (!frame.has_value()) {
|
||||
LOG_TRACE(Lib_AvPlayer, "Could get video frame. EOF reached.");
|
||||
if (m_video_frames.Size() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto frame = m_video_frames.Pop();
|
||||
if (m_state.GetSyncMode() == AvPlayerAvSyncMode::Default) {
|
||||
const auto desired_time =
|
||||
const auto current_time =
|
||||
m_audio_stream_index.has_value() ? m_last_audio_packet_time : CurrentTime();
|
||||
if (desired_time < frame->info.timestamp) {
|
||||
using namespace std::chrono;
|
||||
const auto start = high_resolution_clock::now();
|
||||
if (!m_stop_cv.WaitFor(milliseconds(frame->info.timestamp - desired_time), [&] {
|
||||
const auto passed =
|
||||
duration_cast<milliseconds>(high_resolution_clock::now() - start).count();
|
||||
return (desired_time + passed) >= frame->info.timestamp;
|
||||
})) {
|
||||
return false;
|
||||
}
|
||||
if (0 < current_time && current_time < frame->info.timestamp) {
|
||||
std::this_thread::sleep_for(
|
||||
std::chrono::milliseconds(frame->info.timestamp - current_time));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -353,16 +342,13 @@ bool AvPlayerSource::GetAudioData(AvPlayerFrameInfo& audio_info) {
|
|||
return false;
|
||||
}
|
||||
|
||||
m_audio_frames_cv.Wait([this] { return m_audio_frames.Size() != 0 || m_is_eof; });
|
||||
|
||||
auto frame = m_audio_frames.Pop();
|
||||
if (!frame.has_value()) {
|
||||
LOG_TRACE(Lib_AvPlayer, "Could get audio frame. EOF reached.");
|
||||
if (m_audio_frames.Size() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// return the buffer to the queue
|
||||
auto frame = m_audio_frames.Pop();
|
||||
if (m_current_audio_frame.has_value()) {
|
||||
// return the buffer to the queue
|
||||
m_audio_buffers.Push(std::move(m_current_audio_frame.value()));
|
||||
m_audio_buffers_cv.Notify();
|
||||
}
|
||||
|
|
|
@ -202,8 +202,6 @@ private:
|
|||
EventCV m_video_frames_cv{};
|
||||
EventCV m_video_buffers_cv{};
|
||||
|
||||
EventCV m_stop_cv{};
|
||||
|
||||
std::mutex m_state_mutex{};
|
||||
Kernel::Thread m_demuxer_thread{};
|
||||
Kernel::Thread m_video_decoder_thread{};
|
||||
|
|
Loading…
Add table
Reference in a new issue