diff --git a/DumpDVD/Dvd/DvdRipper.cpp b/DumpDVD/Dvd/DvdRipper.cpp index a651577..73aaef8 100644 --- a/DumpDVD/Dvd/DvdRipper.cpp +++ b/DumpDVD/Dvd/DvdRipper.cpp @@ -268,7 +268,7 @@ namespace Li::Dvd { this->sectorsReadSoFar = 0; this->fileReadSoFar = 0; this->keepRunning = false; - this->ripinThread->join(); + this->ripinThread->detach(); delete this->driveIoCtl; delete this->ripinThread; diff --git a/DumpDVD/Gui/DumpDVD.cpp b/DumpDVD/Gui/DumpDVD.cpp index e42199a..bcc7a4a 100644 --- a/DumpDVD/Gui/DumpDVD.cpp +++ b/DumpDVD/Gui/DumpDVD.cpp @@ -36,18 +36,24 @@ namespace Li::Gui { } DumpDVD::~DumpDVD() { - this->keepPolling = false; - this->pollDrives->join(); + if (this->imRippinIt) { + this->endRipNow(); + std::filesystem::remove(std::string(this->outputFile)); + } + else { + this->keepPolling = false; + this->pollDrives->detach(); + delete this->pollDrives; + } + delete this->lock; - delete this->pollDrives; freeOldDriveList(); } void DumpDVD::pollDrivesThread() { while (this->keepPolling) { - if ( (this->counter % (60 * 10)) == 0) { - this->refreshDriveList(); - } + this->refreshDriveList(); + std::this_thread::sleep_for(std::chrono::seconds(10)); } } @@ -103,7 +109,7 @@ namespace Li::Gui { void DumpDVD::startRip() { if (this->GetCurrentSelectedDrive()->DiscInDrive()) { this->keepPolling = false; - this->pollDrives->join(); + this->pollDrives->detach(); delete this->pollDrives; std::vector* speeds = this->GetCurrentSelectedDrive()->SupportedSpeeds(); @@ -119,11 +125,15 @@ namespace Li::Gui { } } - void DumpDVD::endRipAndGoBackToMenu() { + void DumpDVD::endRipNow() { this->dvdRipper->EndRip(); delete this->dvdRipper; - this->imRippinIt = false; + } + + void DumpDVD::endRipAndGoBackToMenu() { + this->endRipNow(); + this->reset(); this->keepPolling = true; @@ -177,7 +187,7 @@ namespace Li::Gui { if (this->dvdRipper->Done()) { if (!this->dvdRipper->Error()) { - ImGui::Begin("Complete", &this->imRippinIt, ImGuiWindowFlags_NoCollapse); + ImGui::Begin("Complete", &this->imRippinIt, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize); ImGui::Text("ISO file was created successfully."); if (ImGui::Button("OK")) { this->endRipAndGoBackToMenu(); @@ -185,7 +195,7 @@ namespace Li::Gui { ImGui::End(); } else { - ImGui::Begin("Error", &this->imRippinIt, ImGuiWindowFlags_NoCollapse); + ImGui::Begin("Error", &this->imRippinIt, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize); ImGui::Text("Error occured when creating an ISO\n\"%s\"", this->dvdRipper->ErrorMessage().c_str()); if (ImGui::Button("OK")) { this->endRipAndGoBackToMenu(); @@ -284,7 +294,7 @@ namespace Li::Gui { ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always); ImGui::SetNextWindowSize(ImGui::GetIO().DisplaySize, ImGuiCond_Always); - ImGui::Begin("DVD Dumper", NULL, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | + ImGui::Begin("DVD Dumper", NULL, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoFocusOnAppearing); if (this->imRippinIt) diff --git a/DumpDVD/Gui/DumpDVD.hpp b/DumpDVD/Gui/DumpDVD.hpp index a92e6ba..6189c9e 100644 --- a/DumpDVD/Gui/DumpDVD.hpp +++ b/DumpDVD/Gui/DumpDVD.hpp @@ -41,6 +41,7 @@ namespace Li::Gui { void reset(); void startRip(); + void endRipNow(); void endRipAndGoBackToMenu(); void showRipMenu(); diff --git a/DumpDVD/Gui/MainWindow.cpp b/DumpDVD/Gui/MainWindow.cpp index b3452f5..fadb646 100644 --- a/DumpDVD/Gui/MainWindow.cpp +++ b/DumpDVD/Gui/MainWindow.cpp @@ -1,38 +1,25 @@ #include "MainWindow.hpp" -#ifdef _WIN32 -#include "D3D.hpp" -#include -#endif +#include "SDL.hpp" +#include "DumpDVD.hpp" -#include -#include #include #include #include -#include "SDL.hpp" -#include "DumpDVD.hpp" namespace Li::Gui { MainWindow::MainWindow() { this->sdl = new SDL("DumpDVD", 800, 400); + this->sdl->SetMaxFPS(24.0); DumpDVD* dumpDvdMenu = new DumpDVD(); - uint32_t lastRenderTime = SDL_GetTicks(); while (!this->sdl->IsExiting()) { - uint32_t curRenderTime = SDL_GetTicks(); - uint32_t delta = curRenderTime - lastRenderTime; - if (delta > 1000 / 60.0) - { - this->sdl->PollEvent(); - this->sdl->NewFrame(); + this->sdl->PollEvent(); + this->sdl->NewFrame(); - dumpDvdMenu->RenderUI(); + dumpDvdMenu->RenderUI(); - this->sdl->Render(); - - lastRenderTime = curRenderTime; - } + this->sdl->Render(); } delete dumpDvdMenu; diff --git a/DumpDVD/Gui/SDL.cpp b/DumpDVD/Gui/SDL.cpp index 9fda9b0..d5710aa 100644 --- a/DumpDVD/Gui/SDL.cpp +++ b/DumpDVD/Gui/SDL.cpp @@ -6,6 +6,9 @@ #include #endif +#include +#include + #include #include #include @@ -50,7 +53,9 @@ namespace Li::Gui { #else #error No imgui renderer backend provided for this platform #endif - isExiting = false; + this->isExiting = false; + this->SetMaxFPS(24.0); + this->lastRenderTime = SDL_GetTicks(); } bool SDL::IsExiting() { return this->isExiting; @@ -77,16 +82,31 @@ namespace Li::Gui { } } void SDL::NewFrame() { + this->curRenderTime = SDL_GetTicks(); + this->renderer->ImGuiNewFrame(); ImGui_ImplSDL2_NewFrame(); ImGui::NewFrame(); } + void SDL::SetMaxFPS(float fpsLimit) { + this->maxFps = fpsLimit; + this->limit = (1000 / this->maxFps); + } void SDL::Render() { ImGui::Render(); ImVec4 clearColor = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); this->renderer->Render(clearColor); + + this->lastRenderTime = this->curRenderTime; + this->delta = (this->curRenderTime - this->lastRenderTime); + + if (this->delta < this->limit) + { + uint32_t remain = (this->limit - this->delta); + std::this_thread::sleep_for(std::chrono::milliseconds(remain)); + } } SDL::~SDL() { diff --git a/DumpDVD/Gui/SDL.hpp b/DumpDVD/Gui/SDL.hpp index bec75d6..b6e1b9c 100644 --- a/DumpDVD/Gui/SDL.hpp +++ b/DumpDVD/Gui/SDL.hpp @@ -11,12 +11,22 @@ namespace Li::Gui { SDL_WindowFlags windowFlags; SDL_SysWMinfo wmInfo; SDL_Window* window; + + + float maxFps; + uint32_t limit; + + uint32_t lastRenderTime; + uint32_t curRenderTime; + uint32_t delta; + Renderer* renderer; bool isExiting; public: bool IsExiting(); void NewFrame(); + void SetMaxFPS(float fpsLimit); void PollEvent(); void Render(); SDL(std::string windowTitle, int windowWidth, int windowHeight); diff --git a/lib/libdvdcss.lib b/lib/libdvdcss.lib index 53a5d1e..e1e478c 100644 Binary files a/lib/libdvdcss.lib and b/lib/libdvdcss.lib differ diff --git a/libdvdcss/src/css.c b/libdvdcss/src/css.c index 55cb8df..b3ca4e2 100644 --- a/libdvdcss/src/css.c +++ b/libdvdcss/src/css.c @@ -200,7 +200,7 @@ int dvdcss_title ( dvdcss_t dvdcss, int i_block ) { return 0; } - +#ifdef ENABLE_CACHE /* Check if we've already cracked this key */ p_title = dvdcss->p_titles; while( p_title != NULL @@ -253,7 +253,7 @@ int dvdcss_title ( dvdcss_t dvdcss, int i_block ) close( i_fd ); } } - +#endif /* Crack or decrypt Content Scrambling System (CSS) title key * for current Video Title Set (VTS). */ if( i_ret < 0 ) @@ -273,7 +273,7 @@ int dvdcss_title ( dvdcss_t dvdcss, int i_block ) /* We cache this anyway, so we don't need to check again. */ } } - +#ifdef ENABLE_CACHE /* Key is valid, we store it on disk. */ if( dvdcss->psz_cachefile[0] && b_cache ) { @@ -294,7 +294,6 @@ int dvdcss_title ( dvdcss_t dvdcss, int i_block ) close( i_fd ); } } - /* Find our spot in the list */ p_newtitle = NULL; p_title = dvdcss->p_titles; @@ -329,6 +328,7 @@ int dvdcss_title ( dvdcss_t dvdcss, int i_block ) p_title->p_next = p_newtitle; } +#endif memcpy( dvdcss->css.p_title_key, p_title_key, DVD_KEY_SIZE ); return 0; } diff --git a/libdvdcss/src/libdvdcss.c b/libdvdcss/src/libdvdcss.c index 627fcc6..202010c 100644 --- a/libdvdcss/src/libdvdcss.c +++ b/libdvdcss/src/libdvdcss.c @@ -91,7 +91,7 @@ * "C:\Documents and Settings\$USER\Application Data\dvdcss\" under Win32. * The special value "off" disables caching. */ - +//#define ENABLE_CACHE 1 /* * Preamble */ @@ -204,6 +204,7 @@ static int set_access_method( dvdcss_t dvdcss ) static int set_cache_directory( dvdcss_t dvdcss ) { +#ifdef ENABLE_CACHE char *psz_cache = getenv( "DVDCSS_CACHE" ); if( psz_cache && !strcmp( psz_cache, "off" ) ) @@ -299,11 +300,13 @@ static int set_cache_directory( dvdcss_t dvdcss ) print_error( dvdcss, "cache directory name is too long" ); return -1; } +#endif return 0; } static int init_cache_dir( dvdcss_t dvdcss ) { +#ifdef ENABLE_CACHE static const char psz_tag[] = "Signature: 8a477f597d28d172789f06886806bc55\r\n" "# This file is a cache directory tag created by libdvdcss.\r\n" @@ -344,11 +347,13 @@ static int init_cache_dir( dvdcss_t dvdcss ) } close( i_fd ); } +#endif return 0; } static void create_cache_subdir( dvdcss_t dvdcss ) { +#ifdef ENABLE_CACHE uint8_t p_sector[DVDCSS_BLOCK_SIZE]; char psz_key[STRING_KEY_SIZE + 1]; char *psz_title; @@ -465,10 +470,12 @@ static void create_cache_subdir( dvdcss_t dvdcss ) error: dvdcss->psz_cachefile[0] = '\0'; +#endif } static void init_cache( dvdcss_t dvdcss ) { +#ifdef ENABLE_CACHE /* Set CSS key cache directory. */ int i_ret = set_cache_directory( dvdcss ); if ( i_ret < 0 ) @@ -485,6 +492,7 @@ static void init_cache( dvdcss_t dvdcss ) /* If the cache is enabled, create a DVD-specific subdirectory. */ create_cache_subdir( dvdcss ); +#endif } LIBDVDCSS_EXPORT char* dvdcss_get_cur_disckey(dvdcss_t dvdcss) { @@ -628,9 +636,9 @@ static dvdcss_t dvdcss_open_common ( const char *psz_target, void *p_stream, print_debug( dvdcss, "could not get disc key" ); } } - +#ifdef ENABLE_CACHE init_cache( dvdcss ); - +#endif /* Seek to the beginning, just for safety. */ dvdcss->pf_seek( dvdcss, 0 );