Skip to content

Commit

Permalink
Clean up various files
Browse files Browse the repository at this point in the history
  • Loading branch information
RisingFog committed Sep 3, 2016
1 parent 9fb152c commit 3b40182
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 141 deletions.
121 changes: 10 additions & 111 deletions Core/AVIDump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ extern "C" {
#include "Core/Screenshot.h"

#include "GPU/Common/GPUDebugInterface.h"
#ifdef _WIN32
#include "GPU/Directx9/GPU_DX9.h"
#endif
#include "GPU/GLES/GPU_GLES.h"

#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55, 28, 1)
#define av_frame_alloc avcodec_alloc_frame
Expand All @@ -48,6 +44,7 @@ static bool s_start_dumping = false;
static int s_current_width;
static int s_current_height;
static int s_file_index = 0;
static GPUDebugBuffer buf;

static void InitAVCodec()
{
Expand Down Expand Up @@ -80,10 +77,10 @@ bool AVIDump::CreateAVI()
s_format_context = avformat_alloc_context();
std::stringstream s_file_index_str;
s_file_index_str << s_file_index;
snprintf(s_format_context->filename, sizeof(s_format_context->filename), "%s", (GetSysDirectory(DIRECTORY_VIDEO_DUMP) + "framedump" + s_file_index_str.str() + ".avi").c_str());
snprintf(s_format_context->filename, sizeof(s_format_context->filename), "%s", (GetSysDirectory(DIRECTORY_VIDEO) + "framedump" + s_file_index_str.str() + ".avi").c_str());
// Make sure that the path exists
if (!File::Exists(GetSysDirectory(DIRECTORY_VIDEO_DUMP)))
File::CreateDir(GetSysDirectory(DIRECTORY_VIDEO_DUMP));
if (!File::Exists(GetSysDirectory(DIRECTORY_VIDEO)))
File::CreateDir(GetSysDirectory(DIRECTORY_VIDEO));

if (File::Exists(s_format_context->filename))
File::Delete(s_format_context->filename);
Expand Down Expand Up @@ -150,101 +147,8 @@ static void PreparePacket(AVPacket* pkt)
pkt->stream_index = s_stream->index;
}

static const u8 *ConvertBufferTo888RGB(const GPUDebugBuffer &buf, u8 *&temp, u32 &w, u32 &h) {
// The temp buffer will be freed by the caller if set, and can be the return value.
temp = nullptr;

w = std::min(w, buf.GetStride());
h = std::min(h, buf.GetHeight());

const u8 *buffer = buf.GetData();
if (buf.GetFlipped() && buf.GetFormat() == GPU_DBG_FORMAT_888_RGB) {
// Silly OpenGL reads upside down, we flip to another buffer for simplicity.
temp = new u8[3 * w * h];
for (u32 y = 0; y < h; y++) {
memcpy(temp + y * w * 3, buffer + (buf.GetHeight() - y - 1) * buf.GetStride() * 3, w * 3);
}
buffer = temp;
}
else if (buf.GetFormat() != GPU_DBG_FORMAT_888_RGB) {
// Let's boil it down to how we need to interpret the bits.
int baseFmt = buf.GetFormat() & ~(GPU_DBG_FORMAT_REVERSE_FLAG | GPU_DBG_FORMAT_BRSWAP_FLAG);
bool rev = (buf.GetFormat() & GPU_DBG_FORMAT_REVERSE_FLAG) != 0;
bool brswap = (buf.GetFormat() & GPU_DBG_FORMAT_BRSWAP_FLAG) != 0;
bool flip = buf.GetFlipped();

temp = new u8[3 * w * h];

// This is pretty inefficient.
const u16 *buf16 = (const u16 *)buffer;
const u32 *buf32 = (const u32 *)buffer;
for (u32 y = 0; y < h; y++) {
for (u32 x = 0; x < w; x++) {
u8 *dst;
if (flip) {
dst = &temp[(h - y - 1) * w * 3 + x * 3];
}
else {
dst = &temp[y * w * 3 + x * 3];
}

u8 &r = brswap ? dst[2] : dst[0];
u8 &g = dst[1];
u8 &b = brswap ? dst[0] : dst[2];

u32 src;
switch (baseFmt) {
case GPU_DBG_FORMAT_565:
src = buf16[y * buf.GetStride() + x];
if (rev) {
src = bswap16(src);
}
r = Convert5To8((src >> 0) & 0x1F);
g = Convert6To8((src >> 5) & 0x3F);
b = Convert5To8((src >> 11) & 0x1F);
break;
case GPU_DBG_FORMAT_5551:
src = buf16[y * buf.GetStride() + x];
if (rev) {
src = bswap16(src);
}
r = Convert5To8((src >> 0) & 0x1F);
g = Convert5To8((src >> 5) & 0x1F);
b = Convert5To8((src >> 10) & 0x1F);
break;
case GPU_DBG_FORMAT_4444:
src = buf16[y * buf.GetStride() + x];
if (rev) {
src = bswap16(src);
}
r = Convert4To8((src >> 0) & 0xF);
g = Convert4To8((src >> 4) & 0xF);
b = Convert4To8((src >> 8) & 0xF);
break;
case GPU_DBG_FORMAT_8888:
src = buf32[y * buf.GetStride() + x];
if (rev) {
src = bswap32(src);
}
r = (src >> 0) & 0xFF;
g = (src >> 8) & 0xFF;
b = (src >> 16) & 0xFF;
break;
default:
ERROR_LOG(COMMON, "Unsupported framebuffer format for screenshot: %d", buf.GetFormat());
return nullptr;
}
}
}
buffer = temp;
}

return buffer;
}

void AVIDump::AddFrame()
{
GPUDebugBuffer buf;
gpuDebug->GetCurrentFramebuffer(buf);
u32 w = buf.GetStride();
u32 h = buf.GetHeight();
Expand All @@ -257,14 +161,10 @@ void AVIDump::AddFrame()
s_src_frame->width = s_width;
s_src_frame->height = s_height;

// Convert image from BGR24 to desired pixel format, and scale to initial
// width and height
if ((s_sws_context =
sws_getCachedContext(s_sws_context, w, h, AV_PIX_FMT_RGB24, s_width, s_height,
s_stream->codec->pix_fmt, SWS_BICUBIC, nullptr, nullptr, nullptr)))
// Convert image from BGR24 to desired pixel format, and scale to initial width and height
if ((s_sws_context = sws_getCachedContext(s_sws_context, w, h, AV_PIX_FMT_RGB24, s_width, s_height, s_stream->codec->pix_fmt, SWS_BICUBIC, nullptr, nullptr, nullptr)))
{
sws_scale(s_sws_context, s_src_frame->data, s_src_frame->linesize, 0, h,
s_scaled_frame->data, s_scaled_frame->linesize);
sws_scale(s_sws_context, s_src_frame->data, s_src_frame->linesize, 0, h, s_scaled_frame->data, s_scaled_frame->linesize);
}

s_scaled_frame->format = s_stream->codec->pix_fmt;
Expand Down Expand Up @@ -344,10 +244,9 @@ void AVIDump::CloseFile()
void AVIDump::CheckResolution(int width, int height)
{
// We check here to see if the requested width and height have changed since the last frame which
// was dumped, then create a new file accordingly. However, is it possible for the height
// (possibly width as well, but no examples known) to have a value of zero. This can occur as the
// VI is able to be set to a zero value for height/width to disable output. If this is the case,
// simply keep the last known resolution of the video for the added frame.
// was dumped, then create a new file accordingly. However, is it possible for the width and height
// to have a value of zero. If this is the case, simply keep the last known resolution of the video
// for the added frame.
if ((width != s_current_width || height != s_current_height) && (width > 0 && height > 0))
{
int temp_file_index = s_file_index;
Expand Down
5 changes: 0 additions & 5 deletions Core/CoreTiming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,6 @@ u64 GetTicks()
return (u64)globalTimer + slicelength - currentMIPS->downcount;
}

u64 GetTicksPerSecond()
{
return CPU_HZ;
}

u64 GetIdleTicks()
{
return (u64)idledCycles;
Expand Down
1 change: 0 additions & 1 deletion Core/CoreTiming.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ namespace CoreTiming
u64 GetIdleTicks();
u64 GetGlobalTimeUs();
u64 GetGlobalTimeUsScaled();
u64 GetTicksPerSecond();

// Returns the event_type identifier.
int RegisterEvent(const char *name, TimedCallback callback);
Expand Down
29 changes: 20 additions & 9 deletions Core/HLE/__sceAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "Core/MemMapHelpers.h"
#include "Core/Reporting.h"
#include "Core/System.h"
#include "Core/WaveFile.h"
#include "Core/HLE/__sceAudio.h"
#include "Core/HLE/sceAudio.h"
#include "Core/HLE/sceKernel.h"
Expand Down Expand Up @@ -67,9 +68,11 @@ static int audioIntervalCycles;
static int audioHostIntervalCycles;

static s32 *mixBuffer;

static s16 *clampedMixBuffer;
#ifndef MOBILE_DEVICE
WaveFileWriter g_wave_writer;
bool m_logAudio;
static bool m_logAudio;
#endif

// High and low watermarks, basically. For perfect emulation, the correct values are 0 and 1, respectively.
// TODO: Tweak. Hm, there aren't actually even used currently...
Expand Down Expand Up @@ -134,17 +137,21 @@ void __AudioInit() {
chans[i].clear();

mixBuffer = new s32[hwBlockSize * 2];
clampedMixBuffer = new s16[hwBlockSize * 2];
memset(mixBuffer, 0, hwBlockSize * 2 * sizeof(s32));

resampler.Clear();
CoreTiming::RegisterMHzChangeCallback(&__AudioCPUMHzChange);

#ifndef MOBILE_DEVICE
if (g_Config.bDumpAudio)
{
std::string audio_file_name = GetSysDirectory(DIRECTORY_VIDEO_DUMP) + "audiodump.wav";
std::string audio_file_name = GetSysDirectory(DIRECTORY_AUDIO) + "audiodump.wav";
// Create the path just in case it doesn't exist
File::CreateDir(GetSysDirectory(DIRECTORY_AUDIO));
File::CreateEmptyFile(audio_file_name);
__StartLogAudio(audio_file_name);
}
#endif
}

void __AudioDoState(PointerWrap &p) {
Expand Down Expand Up @@ -184,15 +191,18 @@ void __AudioDoState(PointerWrap &p) {

void __AudioShutdown() {
delete [] mixBuffer;
delete [] clampedMixBuffer;

mixBuffer = 0;
for (u32 i = 0; i < PSP_AUDIO_CHANNEL_MAX + 1; i++)
chans[i].clear();

#ifndef MOBILE_DEVICE
if (g_Config.bDumpAudio)
{
__StopLogAudio();
}
#endif
}

u32 __AudioEnqueue(AudioChannel &chan, int chanNum, bool blocking) {
Expand Down Expand Up @@ -380,15 +390,15 @@ void __AudioUpdate() {

if (g_Config.bEnableSound) {
resampler.PushSamples(mixBuffer, hwBlockSize);
#ifndef MOBILE_DEVICE
if (m_logAudio)
{
s16 *clamped_data = new s16[hwBlockSize * 2];

for (int i = 0; i < hwBlockSize * 2; i++) {
clamped_data[i] = clamp_s16(mixBuffer[i]);
clampedMixBuffer[i] = clamp_s16(mixBuffer[i]);
}
g_wave_writer.AddStereoSamples(clamped_data, hwBlockSize);
g_wave_writer.AddStereoSamples(clampedMixBuffer, hwBlockSize);
}
#endif
}
}

Expand All @@ -410,7 +420,7 @@ void __PushExternalAudio(const s32 *audio, int numSamples) {
resampler.Clear();
}
}

#ifndef MOBILE_DEVICE
void __StartLogAudio(const std::string& filename)
{
if (!m_logAudio)
Expand Down Expand Up @@ -439,3 +449,4 @@ void __StopLogAudio()
WARN_LOG(SCEAUDIO, "Audio logging has already been stopped");
}
}
#endif
1 change: 0 additions & 1 deletion Core/HLE/__sceAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#pragma once

#include "sceAudio.h"
#include "Core/WaveFile.h"

struct AudioDebugStats {
int buffered;
Expand Down
5 changes: 3 additions & 2 deletions Core/HLE/sceAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "Core/HLE/sceAudio.h"
#include "Core/HLE/__sceAudio.h"
#include "Core/Reporting.h"
#include "Core/WaveFile.h"

const u32 PSP_AUDIO_SAMPLE_MAX = 65536 - 64;
const int PSP_AUDIO_ERROR_SRC_FORMAT_4 = 0x80000003;
Expand Down Expand Up @@ -211,7 +212,7 @@ static u32 sceAudioChReserve(int chan, u32 sampleCount, u32 format) {
ERROR_LOG(SCEAUDIO, "sceAudioChReserve - no channels remaining");
return SCE_ERROR_AUDIO_NO_CHANNELS_AVAILABLE;
}
}
}
if ((u32)chan >= PSP_AUDIO_CHANNEL_MAX) {
ERROR_LOG(SCEAUDIO, "sceAudioChReserve(%08x, %08x, %08x) - bad channel", chan, sampleCount, format);
return SCE_ERROR_AUDIO_INVALID_CHANNEL;
Expand Down Expand Up @@ -457,7 +458,7 @@ static u32 sceAudioRoutingGetVolumeMode() {
return defaultRoutingVolMode;
}

const HLEFunction sceAudio[] =
const HLEFunction sceAudio[] =
{
// Newer simplified single channel audio output. Presumably for games that use Atrac3
// directly from Sas instead of playing it on a separate audio channel.
Expand Down
1 change: 0 additions & 1 deletion Core/HW/StereoResampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

#include "Common/ChunkFile.h"
#include "Common/CommonTypes.h"
#include "Core/WaveFile.h"

struct AudioDebugStats;

Expand Down
1 change: 0 additions & 1 deletion Core/SaveState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "Common/FileUtil.h"
#include "Common/ChunkFile.h"

#include "Core/AVIDump.h"
#include "Core/SaveState.h"
#include "Core/Config.h"
#include "Core/Core.h"
Expand Down
2 changes: 1 addition & 1 deletion Core/Screenshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static bool WriteScreenshotToPNG(png_imagep image, const char *filename, int con
}
#endif

static const u8 *ConvertBufferTo888RGB(const GPUDebugBuffer &buf, u8 *&temp, u32 &w, u32 &h) {
const u8 *ConvertBufferTo888RGB(const GPUDebugBuffer &buf, u8 *&temp, u32 &w, u32 &h) {
// The temp buffer will be freed by the caller if set, and can be the return value.
temp = nullptr;

Expand Down
4 changes: 4 additions & 0 deletions Core/Screenshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#pragma once

class GPUDebugBuffer;

enum ScreenshotFormat {
SCREENSHOT_PNG,
SCREENSHOT_JPG,
Expand All @@ -30,4 +32,6 @@ enum ScreenshotType {
SCREENSHOT_RENDER,
};

const u8 * ConvertBufferTo888RGB(const GPUDebugBuffer & buf, u8 *& temp, u32 & w, u32 & h);

bool TakeGameScreenshot(const char *filename, ScreenshotFormat fmt, ScreenshotType type, int *width = nullptr, int *height = nullptr, int maxRes = -1);
6 changes: 4 additions & 2 deletions Core/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,10 @@ std::string GetSysDirectory(PSPDirectories directoryType) {
return g_Config.appCacheDirectory;
}
return g_Config.memStickDirectory + "PSP/SYSTEM/CACHE/";
case DIRECTORY_VIDEO_DUMP:
return g_Config.memStickDirectory + "PSP/FRAMEDUMP/";
case DIRECTORY_VIDEO:
return g_Config.memStickDirectory + "PSP/VIDEO/";
case DIRECTORY_AUDIO:
return g_Config.memStickDirectory + "PSP/AUDIO/";
// Just return the memory stick root if we run into some sort of problem.
default:
ERROR_LOG(FILESYS, "Unknown directory type.");
Expand Down
3 changes: 2 additions & 1 deletion Core/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ enum PSPDirectories {
DIRECTORY_CACHE,
DIRECTORY_TEXTURES,
DIRECTORY_APP_CACHE, // Use the OS app cache if available
DIRECTORY_VIDEO_DUMP
DIRECTORY_VIDEO,
DIRECTORY_AUDIO
};

class GraphicsContext;
Expand Down
6 changes: 3 additions & 3 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,9 +676,9 @@ void GameSettingsScreen::CreateViews() {
#if defined(_WIN32) || (defined(USING_QT_UI) && !defined(MOBILE_DEVICE))
// Screenshot functionality is not yet available on non-Windows/non-Qt
systemSettings->Add(new CheckBox(&g_Config.bScreenshotsAsPNG, sy->T("Screenshots as PNG")));
systemSettings->Add(new CheckBox(&g_Config.bDumpFrames, sy->T("Dump Frames")));
systemSettings->Add(new CheckBox(&g_Config.bUseFFV1, sy->T("Use FFV1 for Frame Dumps")));
systemSettings->Add(new CheckBox(&g_Config.bDumpAudio, sy->T("Dump Audio")));
systemSettings->Add(new CheckBox(&g_Config.bDumpFrames, sy->T("Record Display")));
systemSettings->Add(new CheckBox(&g_Config.bUseFFV1, sy->T("Use Lossless Video Codec (FFV1)")));
systemSettings->Add(new CheckBox(&g_Config.bDumpAudio, sy->T("Export Audio")));
#endif
systemSettings->Add(new CheckBox(&g_Config.bDayLightSavings, sy->T("Day Light Saving")));
static const char *dateFormat[] = { "YYYYMMDD", "MMDDYYYY", "DDMMYYYY"};
Expand Down
Loading

0 comments on commit 3b40182

Please sign in to comment.