Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UsbCam/jpeg: Cleanups, notify framebuffer manager #12278

Merged
merged 3 commits into from
Aug 26, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Core/HLE/sceKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
#include "sceHeap.h"
#include "sceDmac.h"
#include "sceMp4.h"
#include "sceUsbCam.h"

#include "../Util/PPGeDraw.h"

Expand Down Expand Up @@ -143,6 +144,7 @@ void __KernelInit()
__AudioCodecInit();
__VideoPmpInit();
__UsbGpsInit();
__UsbCamInit();

SaveState::Init(); // Must be after IO, as it may create a directory
Reporting::Init();
Expand All @@ -166,6 +168,8 @@ void __KernelShutdown()
hleCurrentThreadName = NULL;
kernelObjects.Clear();

__UsbCamShutdown();

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Spacious.

-[Unknown]

__AudioCodecShutdown();
__VideoPmpShutdown();
__AACShutdown();
Expand Down
35 changes: 26 additions & 9 deletions Core/HLE/sceUsbCam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.

#include <algorithm>
#include <mutex>

#include "base/NativeApp.h"
Expand All @@ -29,9 +30,25 @@ PspUsbCamSetupVideoParam videoParam;

unsigned int videoBufferLength = 0;
unsigned int nextVideoFrame = 0;
unsigned char videoBuffer[40 * 1000];
uint8_t *videoBuffer;
std::mutex videoBufferMutex;

enum {
VIDEO_BUFFER_SIZE = 40 * 1000,
};

void __UsbCamInit() {
videoBuffer = new uint8_t[VIDEO_BUFFER_SIZE];
}

void __UsbCamShutdown() {
delete[] videoBuffer;
videoBuffer = nullptr;
}

// TODO: Technically, we should store the videoBuffer into the savestate, if this
// module has been initialized.

static int sceUsbCamSetupMic(u32 paramAddr, u32 workareaAddr, int wasize) {
INFO_LOG(HLE, "UNIMPL sceUsbCamSetupMic");
if (Memory::IsValidRange(paramAddr, sizeof(micParam))) {
Expand Down Expand Up @@ -74,6 +91,7 @@ static int sceUsbCamSetupVideo(u32 paramAddr, u32 workareaAddr, int wasize) {

INFO_LOG(HLE, "UNIMPL sceUsbCamSetupVideo - size: %d", videoParam.size);
INFO_LOG(HLE, "UNIMPL sceUsbCamSetupVideo - resolution: %d", videoParam.resolution);
INFO_LOG(HLE, "UNIMPL sceUsbCamSetupVideo - framesize: %d", videoParam.framesize);
return 0;
}

Expand All @@ -96,20 +114,19 @@ static int sceUsbCamAutoImageReverseSW(int rev) {

static int sceUsbCamReadVideoFrameBlocking(u32 bufAddr, u32 size) {
std::lock_guard<std::mutex> lock(videoBufferMutex);
for (unsigned int i = 0; i < videoBufferLength && i < size; i++) {
if (Memory::IsValidAddress(bufAddr + i)) {
Memory::Write_U8(videoBuffer[i], bufAddr + i);
}

u32 transferSize = std::min(videoBufferLength, size);
if (Memory::IsValidRange(bufAddr, size)) {
Memory::Memcpy(bufAddr, videoBuffer, transferSize);
}
return videoBufferLength;
}

static int sceUsbCamReadVideoFrame(u32 bufAddr, u32 size) {
std::lock_guard<std::mutex> lock(videoBufferMutex);
for (unsigned int i = 0; i < videoBufferLength && i < size; i++) {
if (Memory::IsValidAddress(bufAddr + i)) {
Memory::Write_U8(videoBuffer[i], bufAddr + i);
}
u32 transferSize = std::min(videoBufferLength, size);
if (Memory::IsValidRange(bufAddr, size)) {
Memory::Memcpy(bufAddr, videoBuffer, transferSize);
}
nextVideoFrame = videoBufferLength;
return 0;
Expand Down
3 changes: 3 additions & 0 deletions Core/HLE/sceUsbCam.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

void Register_sceUsbCam();

void __UsbCamInit();
void __UsbCamShutdown();

namespace Camera {
void pushCameraImage(long long length, unsigned char *image);
}
Expand Down