mirror of
https://github.com/moonlight-stream/moonlight-qt
synced 2025-01-09 09:48:43 +00:00
Replace uses of strcpy() and sprintf()
This commit is contained in:
parent
e1e3d8e710
commit
f7bb4611e9
5 changed files with 87 additions and 46 deletions
|
@ -190,13 +190,9 @@ void Session::clConnectionStatusUpdate(int connectionStatus)
|
||||||
switch (connectionStatus)
|
switch (connectionStatus)
|
||||||
{
|
{
|
||||||
case CONN_STATUS_POOR:
|
case CONN_STATUS_POOR:
|
||||||
if (s_ActiveSession->m_StreamConfig.bitrate > 5000) {
|
s_ActiveSession->m_OverlayManager.updateOverlayText(Overlay::OverlayStatusUpdate,
|
||||||
strcpy(s_ActiveSession->m_OverlayManager.getOverlayText(Overlay::OverlayStatusUpdate), "Slow connection to PC\nReduce your bitrate");
|
s_ActiveSession->m_StreamConfig.bitrate > 5000 ?
|
||||||
}
|
"Slow connection to PC\nReduce your bitrate" : "Poor connection to PC");
|
||||||
else {
|
|
||||||
strcpy(s_ActiveSession->m_OverlayManager.getOverlayText(Overlay::OverlayStatusUpdate), "Poor connection to PC");
|
|
||||||
}
|
|
||||||
s_ActiveSession->m_OverlayManager.setOverlayTextUpdated(Overlay::OverlayStatusUpdate);
|
|
||||||
s_ActiveSession->m_OverlayManager.setOverlayState(Overlay::OverlayStatusUpdate, true);
|
s_ActiveSession->m_OverlayManager.setOverlayState(Overlay::OverlayStatusUpdate, true);
|
||||||
break;
|
break;
|
||||||
case CONN_STATUS_OKAY:
|
case CONN_STATUS_OKAY:
|
||||||
|
@ -1288,8 +1284,7 @@ void Session::notifyMouseEmulationMode(bool enabled)
|
||||||
|
|
||||||
// We re-use the status update overlay for mouse mode notification
|
// We re-use the status update overlay for mouse mode notification
|
||||||
if (m_MouseEmulationRefCount > 0) {
|
if (m_MouseEmulationRefCount > 0) {
|
||||||
strcpy(m_OverlayManager.getOverlayText(Overlay::OverlayStatusUpdate), "Gamepad mouse mode active\nLong press Start to deactivate");
|
m_OverlayManager.updateOverlayText(Overlay::OverlayStatusUpdate, "Gamepad mouse mode active\nLong press Start to deactivate");
|
||||||
m_OverlayManager.setOverlayTextUpdated(Overlay::OverlayStatusUpdate);
|
|
||||||
m_OverlayManager.setOverlayState(Overlay::OverlayStatusUpdate, true);
|
m_OverlayManager.setOverlayState(Overlay::OverlayStatusUpdate, true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -604,10 +604,11 @@ void FFmpegVideoDecoder::addVideoStats(VIDEO_STATS& src, VIDEO_STATS& dst)
|
||||||
dst.renderedFps = (float)dst.renderedFrames / ((float)(now - dst.measurementStartTimestamp) / 1000);
|
dst.renderedFps = (float)dst.renderedFrames / ((float)(now - dst.measurementStartTimestamp) / 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FFmpegVideoDecoder::stringifyVideoStats(VIDEO_STATS& stats, char* output)
|
void FFmpegVideoDecoder::stringifyVideoStats(VIDEO_STATS& stats, char* output, ssize_t length)
|
||||||
{
|
{
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
const char* codecString;
|
const char* codecString;
|
||||||
|
int ret;
|
||||||
|
|
||||||
// Start with an empty string
|
// Start with an empty string
|
||||||
output[offset] = 0;
|
output[offset] = 0;
|
||||||
|
@ -652,54 +653,82 @@ void FFmpegVideoDecoder::stringifyVideoStats(VIDEO_STATS& stats, char* output)
|
||||||
|
|
||||||
if (stats.receivedFps > 0) {
|
if (stats.receivedFps > 0) {
|
||||||
if (m_VideoDecoderCtx != nullptr) {
|
if (m_VideoDecoderCtx != nullptr) {
|
||||||
offset += sprintf(&output[offset],
|
ret = snprintf(&output[offset],
|
||||||
"Video stream: %dx%d %.2f FPS (Codec: %s)\n",
|
length - offset,
|
||||||
m_VideoDecoderCtx->width,
|
"Video stream: %dx%d %.2f FPS (Codec: %s)\n",
|
||||||
m_VideoDecoderCtx->height,
|
m_VideoDecoderCtx->width,
|
||||||
stats.totalFps,
|
m_VideoDecoderCtx->height,
|
||||||
codecString);
|
stats.totalFps,
|
||||||
|
codecString);
|
||||||
|
if (ret < 0 || ret >= length - offset) {
|
||||||
|
SDL_assert(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
offset += ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
offset += sprintf(&output[offset],
|
ret = snprintf(&output[offset],
|
||||||
"Incoming frame rate from network: %.2f FPS\n"
|
length - offset,
|
||||||
"Decoding frame rate: %.2f FPS\n"
|
"Incoming frame rate from network: %.2f FPS\n"
|
||||||
"Rendering frame rate: %.2f FPS\n",
|
"Decoding frame rate: %.2f FPS\n"
|
||||||
stats.receivedFps,
|
"Rendering frame rate: %.2f FPS\n",
|
||||||
stats.decodedFps,
|
stats.receivedFps,
|
||||||
stats.renderedFps);
|
stats.decodedFps,
|
||||||
|
stats.renderedFps);
|
||||||
|
if (ret < 0 || ret >= length - offset) {
|
||||||
|
SDL_assert(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
offset += ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stats.framesWithHostProcessingLatency > 0) {
|
if (stats.framesWithHostProcessingLatency > 0) {
|
||||||
offset += sprintf(&output[offset],
|
ret = snprintf(&output[offset],
|
||||||
"Host processing latency min/max/average: %.1f/%.1f/%.1f ms\n",
|
length - offset,
|
||||||
(float)stats.minHostProcessingLatency / 10,
|
"Host processing latency min/max/average: %.1f/%.1f/%.1f ms\n",
|
||||||
(float)stats.maxHostProcessingLatency / 10,
|
(float)stats.minHostProcessingLatency / 10,
|
||||||
(float)stats.totalHostProcessingLatency / 10 / stats.framesWithHostProcessingLatency);
|
(float)stats.maxHostProcessingLatency / 10,
|
||||||
|
(float)stats.totalHostProcessingLatency / 10 / stats.framesWithHostProcessingLatency);
|
||||||
|
if (ret < 0 || ret >= length - offset) {
|
||||||
|
SDL_assert(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
offset += ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stats.renderedFrames != 0) {
|
if (stats.renderedFrames != 0) {
|
||||||
char rttString[32];
|
char rttString[32];
|
||||||
|
|
||||||
if (stats.lastRtt != 0) {
|
if (stats.lastRtt != 0) {
|
||||||
sprintf(rttString, "%u ms (variance: %u ms)", stats.lastRtt, stats.lastRttVariance);
|
snprintf(rttString, sizeof(rttString), "%u ms (variance: %u ms)", stats.lastRtt, stats.lastRttVariance);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sprintf(rttString, "N/A");
|
snprintf(rttString, sizeof(rttString), "N/A");
|
||||||
}
|
}
|
||||||
|
|
||||||
offset += sprintf(&output[offset],
|
ret = snprintf(&output[offset],
|
||||||
"Frames dropped by your network connection: %.2f%%\n"
|
length - offset,
|
||||||
"Frames dropped due to network jitter: %.2f%%\n"
|
"Frames dropped by your network connection: %.2f%%\n"
|
||||||
"Average network latency: %s\n"
|
"Frames dropped due to network jitter: %.2f%%\n"
|
||||||
"Average decoding time: %.2f ms\n"
|
"Average network latency: %s\n"
|
||||||
"Average frame queue delay: %.2f ms\n"
|
"Average decoding time: %.2f ms\n"
|
||||||
"Average rendering time (including monitor V-sync latency): %.2f ms\n",
|
"Average frame queue delay: %.2f ms\n"
|
||||||
(float)stats.networkDroppedFrames / stats.totalFrames * 100,
|
"Average rendering time (including monitor V-sync latency): %.2f ms\n",
|
||||||
(float)stats.pacerDroppedFrames / stats.decodedFrames * 100,
|
(float)stats.networkDroppedFrames / stats.totalFrames * 100,
|
||||||
rttString,
|
(float)stats.pacerDroppedFrames / stats.decodedFrames * 100,
|
||||||
(float)stats.totalDecodeTime / stats.decodedFrames,
|
rttString,
|
||||||
(float)stats.totalPacerTime / stats.renderedFrames,
|
(float)stats.totalDecodeTime / stats.decodedFrames,
|
||||||
(float)stats.totalRenderTime / stats.renderedFrames);
|
(float)stats.totalPacerTime / stats.renderedFrames,
|
||||||
|
(float)stats.totalRenderTime / stats.renderedFrames);
|
||||||
|
if (ret < 0 || ret >= length - offset) {
|
||||||
|
SDL_assert(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
offset += ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -707,7 +736,7 @@ void FFmpegVideoDecoder::logVideoStats(VIDEO_STATS& stats, const char* title)
|
||||||
{
|
{
|
||||||
if (stats.renderedFps > 0 || stats.renderedFrames != 0) {
|
if (stats.renderedFps > 0 || stats.renderedFrames != 0) {
|
||||||
char videoStatsStr[512];
|
char videoStatsStr[512];
|
||||||
stringifyVideoStats(stats, videoStatsStr);
|
stringifyVideoStats(stats, videoStatsStr, sizeof(videoStatsStr));
|
||||||
|
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
"%s", title);
|
"%s", title);
|
||||||
|
@ -1393,7 +1422,9 @@ int FFmpegVideoDecoder::submitDecodeUnit(PDECODE_UNIT du)
|
||||||
addVideoStats(m_LastWndVideoStats, lastTwoWndStats);
|
addVideoStats(m_LastWndVideoStats, lastTwoWndStats);
|
||||||
addVideoStats(m_ActiveWndVideoStats, lastTwoWndStats);
|
addVideoStats(m_ActiveWndVideoStats, lastTwoWndStats);
|
||||||
|
|
||||||
stringifyVideoStats(lastTwoWndStats, Session::get()->getOverlayManager().getOverlayText(Overlay::OverlayDebug));
|
stringifyVideoStats(lastTwoWndStats,
|
||||||
|
Session::get()->getOverlayManager().getOverlayText(Overlay::OverlayDebug),
|
||||||
|
Session::get()->getOverlayManager().getOverlayMaxTextLength());
|
||||||
Session::get()->getOverlayManager().setOverlayTextUpdated(Overlay::OverlayDebug);
|
Session::get()->getOverlayManager().setOverlayTextUpdated(Overlay::OverlayDebug);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ public:
|
||||||
private:
|
private:
|
||||||
bool completeInitialization(const AVCodec* decoder, PDECODER_PARAMETERS params, bool testFrame, bool useAlternateFrontend);
|
bool completeInitialization(const AVCodec* decoder, PDECODER_PARAMETERS params, bool testFrame, bool useAlternateFrontend);
|
||||||
|
|
||||||
void stringifyVideoStats(VIDEO_STATS& stats, char* output);
|
void stringifyVideoStats(VIDEO_STATS& stats, char* output, ssize_t length);
|
||||||
|
|
||||||
void logVideoStats(VIDEO_STATS& stats, const char* title);
|
void logVideoStats(VIDEO_STATS& stats, const char* title);
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,19 @@ char* OverlayManager::getOverlayText(OverlayType type)
|
||||||
return m_Overlays[type].text;
|
return m_Overlays[type].text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OverlayManager::updateOverlayText(OverlayType type, const char* text)
|
||||||
|
{
|
||||||
|
strncpy(m_Overlays[type].text, text, sizeof(m_Overlays[0].text));
|
||||||
|
m_Overlays[type].text[getOverlayMaxTextLength() - 1] = '\0';
|
||||||
|
|
||||||
|
setOverlayTextUpdated(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
int OverlayManager::getOverlayMaxTextLength()
|
||||||
|
{
|
||||||
|
return sizeof(m_Overlays[0].text);
|
||||||
|
}
|
||||||
|
|
||||||
int OverlayManager::getOverlayFontSize(OverlayType type)
|
int OverlayManager::getOverlayFontSize(OverlayType type)
|
||||||
{
|
{
|
||||||
return m_Overlays[type].fontSize;
|
return m_Overlays[type].fontSize;
|
||||||
|
|
|
@ -29,6 +29,8 @@ public:
|
||||||
|
|
||||||
bool isOverlayEnabled(OverlayType type);
|
bool isOverlayEnabled(OverlayType type);
|
||||||
char* getOverlayText(OverlayType type);
|
char* getOverlayText(OverlayType type);
|
||||||
|
void updateOverlayText(OverlayType type, const char* text);
|
||||||
|
int getOverlayMaxTextLength();
|
||||||
void setOverlayTextUpdated(OverlayType type);
|
void setOverlayTextUpdated(OverlayType type);
|
||||||
void setOverlayState(OverlayType type, bool enabled);
|
void setOverlayState(OverlayType type, bool enabled);
|
||||||
SDL_Color getOverlayColor(OverlayType type);
|
SDL_Color getOverlayColor(OverlayType type);
|
||||||
|
|
Loading…
Reference in a new issue