Skip to content

Commit

Permalink
WIP Videodec2
Browse files Browse the repository at this point in the history
  • Loading branch information
polybiusproxy committed Oct 4, 2024
1 parent a5968b6 commit bc9849b
Show file tree
Hide file tree
Showing 10 changed files with 536 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,13 @@ set(USBD_LIB src/core/libraries/usbd/usbd.cpp
src/core/libraries/usbd/usbd.h
)

set(VDEC_LIB src/core/libraries/videodec/videodec2_impl.cpp
src/core/libraries/videodec/videodec2_impl.h
src/core/libraries/videodec/videodec2.cpp
src/core/libraries/videodec/videodec2.h
src/core/libraries/videodec/videodec2_avc.h
)

set(NP_LIBS src/core/libraries/np_manager/np_manager.cpp
src/core/libraries/np_manager/np_manager.h
src/core/libraries/np_score/np_score.cpp
Expand Down Expand Up @@ -460,6 +467,7 @@ set(CORE src/core/aerolib/stubs.cpp
${PLAYGO_LIB}
${RANDOM_LIB}
${USBD_LIB}
${VDEC_LIB}
${MISC_LIBS}
${DIALOGS_LIB}
${DEV_TOOLS}
Expand Down
1 change: 1 addition & 0 deletions src/common/logging/filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ bool ParseFilterRule(Filter& instance, Iterator begin, Iterator end) {
SUB(Lib, ErrorDialog) \
SUB(Lib, ImeDialog) \
SUB(Lib, AvPlayer) \
SUB(Lib, Vdec2) \
SUB(Lib, Ngs2) \
SUB(Lib, Audio3d) \
CLS(Frontend) \
Expand Down
1 change: 1 addition & 0 deletions src/common/logging/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ enum class Class : u8 {
Lib_ErrorDialog, ///< The LibSceErrorDialog implementation.
Lib_ImeDialog, ///< The LibSceImeDialog implementation.
Lib_AvPlayer, ///< The LibSceAvPlayer implementation.
Lib_Vdec2, ///< The LibSceVideodec2 implementation.
Lib_Ngs2, ///< The LibSceNgs2 implementation.
Lib_Audio3d, ///< The LibSceAudio3d implementation.
Frontend, ///< Emulator UI
Expand Down
2 changes: 2 additions & 0 deletions src/core/libraries/libs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "core/libraries/system/systemservice.h"
#include "core/libraries/system/userservice.h"
#include "core/libraries/usbd/usbd.h"
#include "core/libraries/videodec/videodec2.h"
#include "core/libraries/videoout/video_out.h"

namespace Libraries {
Expand Down Expand Up @@ -76,6 +77,7 @@ void InitHLELibs(Core::Loader::SymbolsResolver* sym) {
Libraries::ErrorDialog::RegisterlibSceErrorDialog(sym);
Libraries::ImeDialog::RegisterlibSceImeDialog(sym);
Libraries::AvPlayer::RegisterlibSceAvPlayer(sym);
Libraries::Vdec2::RegisterlibSceVdec2(sym);
Libraries::Audio3d::RegisterlibSceAudio3d(sym);
}

Expand Down
156 changes: 156 additions & 0 deletions src/core/libraries/videodec/videodec2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include "videodec2.h"
#include "videodec2_impl.h"

#include "common/logging/log.h"
#include "core/libraries/error_codes.h"
#include "core/libraries/libs.h"

namespace Libraries::Vdec2 {

int PS4_SYSV_ABI sceVideodec2QueryComputeMemoryInfo(SceVideodec2ComputeMemoryInfo* pMemInfoOut) {
LOG_ERROR(Lib_Vdec2, "called");

if (pMemInfoOut->thisSize != sizeof(SceVideodec2ComputeMemoryInfo)) {
return 0x811d0101;
}

pMemInfoOut->pCpuGpuMemory = nullptr;
pMemInfoOut->cpuGpuMemorySize = 16384; // Bogus value

return ORBIS_OK;
}

s32 PS4_SYSV_ABI
sceVideodec2AllocateComputeQueue(const SceVideodec2ComputeConfigInfo* pComputeCfgInfoIn,
const SceVideodec2ComputeMemoryInfo* pComputeMemInfoIn,
SceVideodec2ComputeQueue* pComputeQueueOut) {
LOG_ERROR(Lib_Vdec2, "called");
return ORBIS_OK;
}

s32 PS4_SYSV_ABI sceVideodec2ReleaseComputeQueue(SceVideodec2ComputeQueue computeQueueIn) {
LOG_ERROR(Lib_Vdec2, "called");
return ORBIS_OK;
}

int PS4_SYSV_ABI sceVideodec2QueryDecoderMemoryInfo(const SceVideodec2DecoderConfigInfo* pCfgInfoIn,
SceVideodec2DecoderMemoryInfo* pMemInfoOut) {
LOG_ERROR(Lib_Vdec2, "called");

if ((pCfgInfoIn->thisSize == 0x48) && (pMemInfoOut->thisSize == 0x48)) {
pMemInfoOut->pCpuMemory = nullptr;
pMemInfoOut->pGpuMemory = nullptr;
pMemInfoOut->pCpuGpuMemory = nullptr;

pMemInfoOut->cpuGpuMemorySize = 16384; // Bogus value
pMemInfoOut->cpuMemorySize = 16384; // Bogus value
pMemInfoOut->gpuMemorySize = 16384; // Bogus value

pMemInfoOut->maxFrameBufferSize = 16384; // Bogus value
pMemInfoOut->frameBufferAlignment = 16384; // Bogus value
} else {
return 0x811d0101;
}

return ORBIS_OK;
}

s32 PS4_SYSV_ABI
sceVideodec2CreateDecoder(const SceVideodec2DecoderConfigInfo* pDecoderConfigInfoIn,
const SceVideodec2DecoderMemoryInfo* pDecoderMemoryInfoIn,
SceVideodec2Decoder* pDecoderInstanceOut) {
LOG_ERROR(Lib_Vdec2, "called");

*pDecoderInstanceOut = new Videodec2(*pDecoderConfigInfoIn, *pDecoderMemoryInfoIn);
return ORBIS_OK;
}

s32 PS4_SYSV_ABI sceVideodec2DeleteDecoder(SceVideodec2Decoder decoder) {
LOG_ERROR(Lib_Vdec2, "called");
delete decoder;
return ORBIS_OK;
}

s32 PS4_SYSV_ABI sceVideodec2Decode(SceVideodec2Decoder decoder,
const SceVideodec2InputData* pInputDataInOut,
SceVideodec2FrameBuffer* pFrameBufferInOut,
SceVideodec2OutputInfo* pOutputInfoOut) {
LOG_ERROR(Lib_Vdec2, "called");

if (decoder == nullptr) {
return 0x811D0103; // SCE_VIDEODEC2_ERROR_DECODER_INSTANCE;
}

LOG_TRACE(Lib_Vdec2, "bogus trace: {} - {} - {}", pInputDataInOut->thisSize,
pFrameBufferInOut->thisSize, pOutputInfoOut->thisSize);
return decoder->Decode(*pInputDataInOut, *pFrameBufferInOut, *pOutputInfoOut);
}

s32 PS4_SYSV_ABI sceVideodec2Flush(SceVideodec2Decoder decoder,
SceVideodec2FrameBuffer* pFrameBufferInOut,
SceVideodec2OutputInfo* pOutputInfoOut) {
LOG_ERROR(Lib_Vdec2, "called");
return ORBIS_OK;
}

s32 PS4_SYSV_ABI sceVideodec2Reset(SceVideodec2Decoder decoder) {
LOG_ERROR(Lib_Vdec2, "called");
return ORBIS_OK;
}

s32 PS4_SYSV_ABI sceVideodec2GetPictureInfo(const SceVideodec2OutputInfo* pOutputInfoIn,
void* p1stPictureInfoOut, void* p2ndPictureInfoOut) {
LOG_ERROR(Lib_Vdec2, "called");

// AVFrame* frame = (AVFrame*)pOutputInfoIn->pFrameBuffer;

if (p1stPictureInfoOut) {
SceVideodec2AvcPictureInfo* picInfo = (SceVideodec2AvcPictureInfo*)p1stPictureInfoOut;

memset(p1stPictureInfoOut, 0, sizeof(SceVideodec2AvcPictureInfo));
picInfo->isValid = 1;
picInfo->frameCropLeftOffset = 0; // frame->crop_left;
picInfo->frameCropRightOffset = 0; // frame->crop_right;
picInfo->frameCropTopOffset = 0; // frame->crop_top;
picInfo->frameCropBottomOffset = 0; // frame->crop_bottom;
}

if (pOutputInfoIn->pictureCount == 2 && p2ndPictureInfoOut) {
SceVideodec2AvcPictureInfo* picInfo = (SceVideodec2AvcPictureInfo*)p2ndPictureInfoOut;

memset(p2ndPictureInfoOut, 0, sizeof(SceVideodec2AvcPictureInfo));
picInfo->isValid = 1;
picInfo->frameCropLeftOffset = 0;
picInfo->frameCropRightOffset = 0;
picInfo->frameCropTopOffset = 0;
picInfo->frameCropBottomOffset = 0;
}

return ORBIS_OK;
}

void RegisterlibSceVdec2(Core::Loader::SymbolsResolver* sym) {
LIB_FUNCTION("RnDibcGCPKw", "libSceVideodec2", 1, "libSceVideodec2", 1, 1,
sceVideodec2QueryComputeMemoryInfo);
LIB_FUNCTION("eD+X2SmxUt4", "libSceVideodec2", 1, "libSceVideodec2", 1, 1,
sceVideodec2AllocateComputeQueue);
LIB_FUNCTION("UvtA3FAiF4Y", "libSceVideodec2", 1, "libSceVideodec2", 1, 1,
sceVideodec2ReleaseComputeQueue);

LIB_FUNCTION("qqMCwlULR+E", "libSceVideodec2", 1, "libSceVideodec2", 1, 1,
sceVideodec2QueryDecoderMemoryInfo);
LIB_FUNCTION("CNNRoRYd8XI", "libSceVideodec2", 1, "libSceVideodec2", 1, 1,
sceVideodec2CreateDecoder);
LIB_FUNCTION("jwImxXRGSKA", "libSceVideodec2", 1, "libSceVideodec2", 1, 1,
sceVideodec2DeleteDecoder);
LIB_FUNCTION("852F5+q6+iM", "libSceVideodec2", 1, "libSceVideodec2", 1, 1, sceVideodec2Decode);
LIB_FUNCTION("l1hXwscLuCY", "libSceVideodec2", 1, "libSceVideodec2", 1, 1, sceVideodec2Flush);
LIB_FUNCTION("wJXikG6QFN8", "libSceVideodec2", 1, "libSceVideodec2", 1, 1, sceVideodec2Reset);
LIB_FUNCTION("NtXRa3dRzU0", "libSceVideodec2", 1, "libSceVideodec2", 1, 1,
sceVideodec2GetPictureInfo);
}

} // namespace Libraries::Vdec2
133 changes: 133 additions & 0 deletions src/core/libraries/videodec/videodec2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include "common/types.h"

#include "videodec2_avc.h"

namespace Core::Loader {
class SymbolsResolver;
}
namespace Libraries::Vdec2 {

class Videodec2;

using SceVideodec2Decoder = Videodec2*;
typedef void* SceVideodec2ComputeQueue;

struct SceVideodec2DecoderConfigInfo {
u64 thisSize;
u32 resourceType;
u32 codecType;
u32 profile;
u32 maxLevel;
s32 maxFrameWidth;
s32 maxFrameHeight;
s32 maxDpbFrameCount;
u32 decodePipelineDepth;
SceVideodec2ComputeQueue computeQueue;
u64 cpuAffinityMask;
s32 cpuThreadPriority;
bool optimizeProgressiveVideo;
bool checkMemoryType;
uint8_t reserved0;
uint8_t reserved1;
void* extraConfigInfo;
};

struct SceVideodec2DecoderMemoryInfo {
u64 thisSize;
u64 cpuMemorySize;
void* pCpuMemory;
u64 gpuMemorySize;
void* pGpuMemory;
u64 cpuGpuMemorySize;
void* pCpuGpuMemory;
u64 maxFrameBufferSize;
u32 frameBufferAlignment;
u32 reserved0;
};

struct SceVideodec2InputData {
u64 thisSize;
void* pAuData;
u64 auSize;
u64 ptsData;
u64 dtsData;
u64 attachedData;
};

struct SceVideodec2OutputInfo {
u64 thisSize;
bool isValid;
bool isErrorFrame;
uint8_t pictureCount;
u32 codecType;
u32 frameWidth;
u32 framePitch;
u32 frameHeight;
void* pFrameBuffer;
u64 frameBufferSize;
};

struct SceVideodec2FrameBuffer {
u64 thisSize;
void* pFrameBuffer;
u64 frameBufferSize;
bool isAccepted;
};

struct SceVideodec2ComputeMemoryInfo {
u64 thisSize;
u64 cpuGpuMemorySize;
void* pCpuGpuMemory;
};

struct SceVideodec2ComputeConfigInfo {
u64 thisSize;
u16 computePipeId;
u16 computeQueueId;
bool checkMemoryType;
uint8_t reserved0;
u16 reserved1;
};

s32 PS4_SYSV_ABI
sceVideodec2QueryComputeMemoryInfo(SceVideodec2ComputeMemoryInfo* pComputeMemInfoOut);

s32 PS4_SYSV_ABI
sceVideodec2AllocateComputeQueue(const SceVideodec2ComputeConfigInfo* pComputeCfgInfoIn,
const SceVideodec2ComputeMemoryInfo* pComputeMemInfoIn,
SceVideodec2ComputeQueue* pComputeQueueOut);

s32 PS4_SYSV_ABI sceVideodec2ReleaseComputeQueue(SceVideodec2ComputeQueue computeQueueIn);

s32 PS4_SYSV_ABI
sceVideodec2QueryDecoderMemoryInfo(const SceVideodec2DecoderConfigInfo* pDecoderConfigInfoIn,
SceVideodec2DecoderMemoryInfo* pDecoderMemoryInfoOut);

s32 PS4_SYSV_ABI
sceVideodec2CreateDecoder(const SceVideodec2DecoderConfigInfo* pDecoderConfigInfoIn,
const SceVideodec2DecoderMemoryInfo* pDecoderMemoryInfoIn,
SceVideodec2Decoder* pDecoderInstanceOut);

s32 PS4_SYSV_ABI sceVideodec2DeleteDecoder(SceVideodec2Decoder decoder);

s32 PS4_SYSV_ABI sceVideodec2Decode(SceVideodec2Decoder decoder,
const SceVideodec2InputData* pInputDataInOut,
SceVideodec2FrameBuffer* pFrameBufferInOut,
SceVideodec2OutputInfo* pOutputInfoOut);

s32 PS4_SYSV_ABI sceVideodec2Flush(SceVideodec2Decoder decoder,
SceVideodec2FrameBuffer* pFrameBufferInOut,
SceVideodec2OutputInfo* pOutputInfoOut);

s32 PS4_SYSV_ABI sceVideodec2Reset(SceVideodec2Decoder decoder);

s32 PS4_SYSV_ABI sceVideodec2GetPictureInfo(const SceVideodec2OutputInfo* pOutputInfoIn,
void* p1stPictureInfoOut, void* p2ndPictureInfoOut);

void RegisterlibSceVdec2(Core::Loader::SymbolsResolver* sym);
} // namespace Libraries::Vdec2
Loading

0 comments on commit bc9849b

Please sign in to comment.