diff --git a/Makefile b/Makefile index 12e72cb..67896d9 100644 --- a/Makefile +++ b/Makefile @@ -40,8 +40,8 @@ else endif release: BUILD_TYPE := release -release: CXXFLAGS := -O2 -ffast-math -march=native -fno-plt -fno-rtti -flto -fdata-sections -ffunction-sections -ffunction-sections -fomit-frame-pointer -fvisibility=hidden -pipe -DNDEBUG -release: LDFLAGS += -O2 -ffast-math -march=native -flto -Wl,-O1 $(PLATFORM_LDFLAGS) +release: CXXFLAGS := -O2 -ffast-math -march=native -fno-plt -fno-rtti -flto=jobserver -fdata-sections -ffunction-sections -ffunction-sections -fomit-frame-pointer -fvisibility=hidden -pipe -DNDEBUG +release: LDFLAGS += -O2 -ffast-math -march=native -flto=jobserver -Wl,-O1 $(PLATFORM_LDFLAGS) release: TARGET := $(TARGET_NAME) release: prepare diff --git a/settings.txt b/settings.txt index a5df215..b1be9f4 100644 --- a/settings.txt +++ b/settings.txt @@ -110,10 +110,8 @@ # Request extra frames onevery key press. Usefull if you do not see last updates after key press # Enable for RPI hardware decoding and other systems where hardware decoder tends to buffer frames -# 0 - disabled, enter number of frames to request (find minimal value that get all screen updates) -# Combine with force-redraw-timeout to request not imideately but with delay (also find minimal one) +# 0 - disabled, enter number of frames after which the request is made (find minimal value that get all screen updates) #force-redraw = 0 -#force-redraw-timeout = 0 # Corrects aspect of UI #aspect-correction = 1 diff --git a/src/application.cpp b/src/application.cpp index a6b3ae2..65334a8 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -195,11 +195,18 @@ bool Application::processSystemEvent(const SDL_Event &e) _active = false; return true; } +#ifndef NDEBUG case SDLK_d: { _debug = !_debug; return true; } +#endif + case SDLK_r: + { + _state.dirty = true; + _state.requestFrame = 1; + } } } @@ -323,9 +330,11 @@ void Application::loop() uint32_t frameId = 0; uint32_t dropframes = 0; int skipEvents = 0; +#ifndef NDEBUG Uint32 debugLast = SDL_GetTicks(); int debugSpeed = 0; int debugLastCount = 0; +#endif while (_active) { bool newFrame = false; @@ -370,11 +379,11 @@ void Application::loop() } } - if (_state.requestFrame > 0 && Settings::forceRedraw > 0 && ++_state.requestFrame - Settings::forceRedrawTimeout > 0) + if (_state.requestFrame > 0 && Settings::forceRedraw > 0 && _state.requestFrame++ % Settings::forceRedraw == 0) { log_d("Request screen update"); protocol.send(Message::Control(BTN_SCREEN_REFRESH)); - if (_state.requestFrame > Settings::forceRedrawTimeout + Settings::forceRedraw) + if (_state.requestFrame > Settings::forceRedraw*2) _state.requestFrame = 0; } } @@ -399,6 +408,7 @@ void Application::loop() } } +#ifndef NDEBUG if (_debug) { if (SDL_GetTicks() - debugLast >= 1000) @@ -410,7 +420,7 @@ void Application::loop() char debugBuffer[2048]; std::snprintf(debugBuffer, sizeof(debugBuffer), "%s\n" - "FRAME: %u / %u [%d] dropped: %d render: %uus / %uus\n" + "FRAME: %u / %u [%d] dropped: %d render: %dus / %dus\n" "USB: %s ~%dKB/s\n" "BUFF: video [%u] audio[main %u aux %u] out [%u]", status().c_str(), @@ -428,13 +438,14 @@ void Application::loop() protocol.writeQueue.count()); interface.debug(debugBuffer); } +#endif + std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now(); + frameTime = (int32_t)std::chrono::duration_cast(now - frameStart).count(); + frameStart = now; if (_active && !Settings::vsync && !_state.dirty) { - std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now(); - frameTime = (int32_t)std::chrono::duration_cast(now - frameStart).count(); frameDelay = (frameTarget - frameTime) * ((decoder.buffer.latestId() == frameId) ? 1.0 : 0.9); - frameStart = now; if (frameDelay > 0) { std::this_thread::sleep_for(std::chrono::microseconds(frameDelay)); @@ -463,6 +474,7 @@ const std::string Application::status() const << SDL_GetCurrentVideoDriver(); SDL_Window *window = SDL_GetKeyboardFocus(); + SDL_RendererInfo cr{}; if (window) { int width = 0; @@ -472,16 +484,26 @@ const std::string Application::status() const SDL_Renderer *renderer = SDL_GetRenderer(window); if (renderer) { - SDL_RendererInfo info{}; - if (SDL_GetRendererInfo(renderer, &info) == 0) + if (SDL_GetRendererInfo(renderer, &cr) == 0) { - out << " " << info.name - << ((info.flags & SDL_RENDERER_ACCELERATED) != 0 ? " accelerated" : "") - << ((info.flags & SDL_RENDERER_PRESENTVSYNC) != 0 ? " vsync" : ""); + out << ((cr.flags & SDL_RENDERER_ACCELERATED) != 0 ? " accelerated" : "") + << ((cr.flags & SDL_RENDERER_PRESENTVSYNC) != 0 ? " vsync" : ""); } } } - out << " " << SDL_GetCurrentAudioDriver(); + out << " audio: " << SDL_GetCurrentAudioDriver(); + + out << "\nBACKENDS:"; + for (int i = 0; i < SDL_GetNumRenderDrivers(); ++i) + { + SDL_RendererInfo info; + SDL_GetRenderDriverInfo(i, &info); + out << " "; + if(cr.name == info.name) + out << "[" << info.name << "]"; + else + out << info.name; + } int displayIndex = SDL_GetWindowDisplayIndex(window); if (displayIndex >= 0) diff --git a/src/interface.cpp b/src/interface.cpp index bce80cc..a0fca0b 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -10,7 +10,7 @@ Interface::Interface(SDL_Renderer *renderer) _state(0), _debug(false), _textStatus(font, font_len, Settings::fontSize), - _textDebug(font, font_len, 15), + _textDebug(font, font_len, 16), _mainImage(background, background_len) { } @@ -34,11 +34,13 @@ bool Interface::render(AVFrame *frame) (this->*_render)(frame); SDL_RenderCopy(_renderer, _texture, &_sourceRect, nullptr); +#ifndef NDEBUG if (_debug) { drawDebug(); _debug = false; } +#endif SDL_RenderPresent(_renderer); return true; @@ -85,7 +87,13 @@ bool Interface::drawHome(bool force, int state, std::string name) } if (drawText) - _textStatus.draw(_renderer, (width - _textStatus.width) / 2, height * 0.85 - _textStatus.height); + _textStatus.draw(_renderer, (width - _textStatus.width * Settings::aspectCorrection) / 2, height * 0.85 - _textStatus.height); + + if (_debug) + { + drawDebug(); + _debug = false; + } SDL_RenderPresent(_renderer); return true; @@ -104,7 +112,7 @@ void Interface::drawDebug() constexpr int padding = 8; constexpr int lineSpacing = 2; - const SDL_Color debugColor = {0, 255, 255, 255}; + const SDL_Color debugColor = {255, 255, 255, 255}; SDL_BlendMode previousBlendMode; Uint8 previousR, previousG, previousB, previousA; SDL_GetRenderDrawBlendMode(_renderer, &previousBlendMode); diff --git a/src/renderer.cpp b/src/renderer.cpp index c454bb5..e36a9ea 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -132,10 +132,9 @@ SDL_Rect RendererImage::draw(SDL_Renderer *renderer, int w, int h) SDL_GetRendererOutputSize(renderer, &width, &height); } - float scale = 1.0 * h / height; - int imgw = width * scale * Settings::aspectCorrection; + float scale = 1.0 * w / width; - SDL_Rect dst = {w - imgw, 0, imgw, h}; + SDL_Rect dst = {0, 0, w, (int)(height*scale)}; SDL_RenderCopy(renderer, _texture, nullptr, &dst); return dst; } diff --git a/src/settings.h b/src/settings.h index b287437..fe28953 100644 --- a/src/settings.h +++ b/src/settings.h @@ -41,7 +41,6 @@ public: static inline Setting renderingBuffer{"rendering-buffer", 5}; static inline Setting eventsSkip{"draw-skip-events", 3}; static inline Setting forceRedraw{"force-redraw", 0}; - static inline Setting forceRedrawTimeout{"force-redraw-timeout", 0}; static inline Setting aspectCorrection{"aspect-correction", 1}; static inline Setting renderDriver{"renderer-driver", ""}; static inline Setting alternativeRendering{"alternative-rendering", false};