Ticket #205: mtd_cleanup.patch
File mtd_cleanup.patch, 17.0 KB (added by , 20 years ago) |
---|
-
jobthread.cpp
24 24 #include <qdir.h> 25 25 #include <qapplication.h> 26 26 #include <qdeepcopy.h> 27 #include <qprocess.h> 27 28 28 29 #include <mythtv/mythcontext.h> 29 30 #include <mythtv/mythdbcon.h> … … 211 212 --------------------------------------------------------------------- 212 213 */ 213 214 215 namespace 216 { 217 class MutexUnlocker { 218 public: 219 MutexUnlocker(QMutex *mutex) : m_mutex(mutex) 220 { 221 if (!(m_mutex && m_mutex->locked())) 222 { 223 cerr << __FILE__ << ": Invalid mutext passed to MutexUnlocker" 224 << endl; 225 } 226 } 227 228 ~MutexUnlocker() 229 { 230 m_mutex->unlock(); 231 } 232 233 private: 234 QMutex *m_mutex; 235 }; 236 237 template <typename HTYPE, typename CLEANF_RET = void> 238 class HandleCloser 239 { 240 typedef CLEANF_RET (*clean_fun_t)(HTYPE); 241 242 public: 243 HandleCloser(HTYPE handle, clean_fun_t cleaner) : m_handle(handle), 244 m_cleaner(cleaner) 245 { 246 } 247 248 ~HandleCloser() { 249 if (m_handle) 250 { 251 m_cleaner(m_handle); 252 } 253 } 254 255 HTYPE getHandle() 256 { 257 return m_handle; 258 } 259 260 private: 261 HTYPE m_handle; 262 clean_fun_t m_cleaner; 263 }; 264 } 265 214 266 DVDThread::DVDThread(MTD *owner, 215 267 QMutex *drive_mutex, 216 268 const QString &dvd_device, … … 225 277 dvd_device_location = dvd_device; 226 278 dvd_title = track - 1; 227 279 destination_file_string = dest_file; 228 ripfile = NULL;229 280 rip_name = name; 230 281 } 231 282 … … 269 320 } 270 321 } 271 322 323 MutexUnlocker qmul(dvd_device_access); 324 272 325 if(!keepGoing()) 273 326 { 274 327 problem("abandoned job because master control said we need to shut down"); 275 dvd_device_access->unlock();276 328 return false; 277 329 } 278 330 … … 284 336 // Lets open our destination file 285 337 // 286 338 287 if(ripfile) 339 RipFile ripfile(to_location, extension, true); 340 if(!ripfile.open(IO_WriteOnly | IO_Raw | IO_Truncate, multiple_files)) 288 341 { 289 cerr << "jobthread.o: How is it that you already have a ripfile set?" << endl; 290 delete ripfile; 291 } 292 293 ripfile = new RipFile(to_location, extension); 294 if(!ripfile->open(IO_WriteOnly | IO_Raw | IO_Truncate, multiple_files)) 295 { 296 problem(QString("DVDPerfectThread could not open output file: %1").arg(ripfile->name())); 297 dvd_device_access->unlock(); 342 problem(QString("DVDPerfectThread could not open output file: %1") 343 .arg(ripfile.name())); 298 344 return false; 299 345 } 300 346 … … 305 351 306 352 int angle = 0; // Change that at some point 307 353 308 the_dvd = DVDOpen(dvd_device_location); 354 HandleCloser<dvd_reader_t *> the_dvd_closer(DVDOpen(dvd_device_location), 355 DVDClose); 356 dvd_reader_t *the_dvd = the_dvd_closer.getHandle(); 309 357 if(!the_dvd) 310 358 { 311 359 problem(QString("DVDPerfectThread could not access this dvd device: %1").arg(dvd_device_location)); 312 ripfile->remove();313 delete ripfile;314 ripfile = NULL;315 dvd_device_access->unlock();316 360 return false; 317 361 } 318 362 319 363 320 ifo_handle_t *vmg_file = ifoOpen( the_dvd, 0); 364 HandleCloser<ifo_handle_t *> vmg_file_closer(ifoOpen(the_dvd, 0), 365 ifoClose); 366 ifo_handle_t *vmg_file = vmg_file_closer.getHandle(); 321 367 if(!vmg_file) 322 368 { 323 369 problem("DVDPerfectThread could not open VMG info."); 324 ripfile->remove();325 delete ripfile;326 ripfile = NULL;327 DVDClose(the_dvd);328 dvd_device_access->unlock();329 370 return false; 330 371 } 331 372 tt_srpt_t *tt_srpt = vmg_file->tt_srpt; … … 337 378 if(title_number < 0 || title_number > tt_srpt->nr_of_srpts ) 338 379 { 339 380 problem(QString("DVDPerfectThread could not open title number %1").arg(title_number + 1)); 340 ripfile->remove();341 delete ripfile;342 ripfile = NULL;343 ifoClose(vmg_file);344 DVDClose(the_dvd);345 dvd_device_access->unlock();346 381 return false; 347 382 } 348 383 349 ifo_handle_t *vts_file = ifoOpen(the_dvd, tt_srpt->title[title_number].title_set_nr); 384 HandleCloser<ifo_handle_t *> vts_file_cleaner( 385 ifoOpen(the_dvd, tt_srpt->title[title_number].title_set_nr), 386 ifoClose); 387 ifo_handle_t *vts_file = vts_file_cleaner.getHandle(); 350 388 if(!vts_file) 351 389 { 352 390 problem("DVDPerfectThread could not open the title's info file"); 353 ripfile->remove();354 delete ripfile;355 ripfile = NULL;356 ifoClose(vmg_file);357 DVDClose(the_dvd);358 dvd_device_access->unlock();359 391 return false; 360 392 } 361 393 … … 388 420 // OK ... now actually open 389 421 // 390 422 391 title = DVDOpenFile(the_dvd, 392 tt_srpt->title[ title_number ].title_set_nr, 393 DVD_READ_TITLE_VOBS ); 423 HandleCloser<dvd_file_t *> title_closer(DVDOpenFile(the_dvd, 424 tt_srpt->title[ title_number ].title_set_nr, 425 DVD_READ_TITLE_VOBS), DVDCloseFile); 426 dvd_file_t *title = title_closer.getHandle(); 394 427 if(!title) 395 428 { 396 429 problem("DVDPerfectThread could not open the title's actual VOB(s)"); 397 ripfile->remove();398 delete ripfile;399 ripfile = NULL;400 ifoClose(vts_file);401 ifoClose(vmg_file);402 DVDClose(the_dvd);403 dvd_device_access->unlock();404 430 return false; 405 431 } 406 432 … … 408 434 409 435 QTime job_time; 410 436 job_time.start(); 437 unsigned char video_data[ 1024 * DVD_VIDEO_LB_LEN ]; 411 438 412 439 int next_cell = start_cell; 413 440 for(int cur_cell = start_cell; next_cell < cur_pgc->nr_of_cells; ) … … 449 476 if( len != 1) 450 477 { 451 478 problem(QString("DVDPerfectThread read failed for block %1").arg(cur_pack)); 452 ifoClose(vts_file);453 ifoClose(vmg_file);454 DVDCloseFile( title );455 DVDClose(the_dvd);456 dvd_device_access->unlock();457 ripfile->remove();458 delete ripfile;459 ripfile = NULL;460 479 return false; 461 480 } 462 481 … … 503 522 .arg(cur_output_size) 504 523 .arg(cur_pack) 505 524 ); 506 ripfile->remove();507 delete ripfile;508 ripfile = NULL;509 ifoClose(vts_file);510 ifoClose(vmg_file);511 DVDCloseFile( title );512 DVDClose(the_dvd);513 dvd_device_access->unlock();514 525 return false; 515 526 } 516 527 … … 518 529 overall_progress = subjob_progress * sub_to_overall_multiple; 519 530 updateSubjobString(job_time.elapsed() / 1000, 520 531 QObject::tr("Ripping to file ~")); 521 if(!ripfile ->writeBlocks(video_data, cur_output_size * DVD_VIDEO_LB_LEN))532 if(!ripfile.writeBlocks(video_data, cur_output_size * DVD_VIDEO_LB_LEN)) 522 533 { 523 534 problem("Couldn't write blocks during a rip. Filesystem size exceeded? Disc full?"); 524 ripfile->remove();525 delete ripfile;526 ripfile = NULL;527 DVDCloseFile( title );528 ifoClose(vts_file);529 ifoClose(vmg_file);530 DVDClose(the_dvd);531 dvd_device_access->unlock();532 535 return false; 533 536 } 534 537 … … 544 547 if(!keepGoing()) 545 548 { 546 549 problem("abandoned job because master control said we need to shut down"); 547 ripfile->remove();548 delete ripfile;549 ripfile = NULL;550 DVDCloseFile( title );551 ifoClose(vts_file);552 ifoClose(vmg_file);553 DVDClose(the_dvd);554 dvd_device_access->unlock();555 550 return false; 556 551 } 557 552 } … … 561 556 // Wow, we're done. 562 557 // 563 558 564 ifoClose(vts_file); 565 ifoClose(vmg_file); 566 DVDCloseFile( title ); 567 DVDClose(the_dvd); 568 ripfile->close(); 569 dvd_device_access->unlock(); 559 ripfile.close(); 570 560 sendLoggingEvent("job thread finished ripping dvd title"); 571 561 return true; 572 562 } 573 563 574 564 DVDThread::~DVDThread() 575 565 { 576 if(ripfile);577 {578 delete ripfile;579 }580 566 } 581 567 582 568 /* … … 645 631 } 646 632 } 647 633 634 MutexUnlocker qmul(dvd_device_access); 648 635 if(!keepGoing()) 649 636 { 650 637 problem("abandoned job because master control said we need to shut down"); 651 dvd_device_access->unlock();652 638 return false; 653 639 } 654 640 655 ripfile = new RipFile(destination_file_string, ".iso");656 if(!ripfile ->open(IO_WriteOnly | IO_Raw | IO_Truncate, false))641 RipFile ripfile(destination_file_string, ".iso", true); 642 if(!ripfile.open(IO_WriteOnly | IO_Raw | IO_Truncate, false)) 657 643 { 658 problem(QString("DVDISOCopyThread could not open output file: %1") .arg(ripfile->name()));659 dvd_device_access->unlock();644 problem(QString("DVDISOCopyThread could not open output file: %1") 645 .arg(ripfile.name())); 660 646 return false; 661 647 } 662 648 663 sendLoggingEvent(QString("ISO DVD image copy to: %1").arg(ripfile ->name()));649 sendLoggingEvent(QString("ISO DVD image copy to: %1").arg(ripfile.name())); 664 650 665 651 int file = open( dvd_device_location, O_RDONLY ); 666 652 if(file == -1) 667 653 { 668 654 problem(QString("DVDISOCopyThread could not open dvd device: %1").arg(dvd_device_location)); 669 ripfile->remove();670 delete ripfile;671 ripfile = NULL;672 dvd_device_access->unlock();673 655 return false; 674 656 } 675 657 … … 690 672 { 691 673 perror("read"); 692 674 problem(QString("DVDISOCopyThread dvd device read error")); 693 ripfile->remove();694 if (ripfile)695 {696 delete ripfile;697 ripfile = NULL;698 }699 dvd_device_access->unlock();700 675 return false; 701 676 } 702 677 if(bytes_read == 0) … … 704 679 break; 705 680 } 706 681 707 if(!ripfile ->writeBlocks(buffer, bytes_read))682 if(!ripfile.writeBlocks(buffer, bytes_read)) 708 683 { 709 684 problem(QString("DVDISOCopyThread rip file write error")); 710 ripfile->remove();711 if (ripfile)712 {713 delete ripfile;714 ripfile = NULL;715 }716 dvd_device_access->unlock();717 685 return false; 718 686 } 719 687 … … 732 700 if(!keepGoing()) 733 701 { 734 702 problem("abandoned job because master control said we need to shut down"); 735 ripfile->remove();736 if (ripfile)737 {738 delete ripfile;739 ripfile = NULL;740 }741 dvd_device_access->unlock();742 703 return false; 743 704 } 744 705 } 745 706 746 ripfile->close(); 747 if (ripfile) 748 { 749 delete ripfile; 750 ripfile = NULL; 751 } 752 dvd_device_access->unlock(); 707 ripfile.close(); 753 708 sendLoggingEvent("job thread finished copying ISO image"); 754 709 return true; 755 710 } … … 1451 1406 // 1452 1407 if(working_directory) 1453 1408 { 1454 if(ripfile)1455 {1456 ripfile->remove();1457 if (ripfile)1458 {1459 delete ripfile;1460 ripfile = NULL;1461 }1462 }1463 1464 1409 if(two_pass) 1465 1410 { 1466 1411 working_directory->remove("twopass.log"); … … 1495 1440 { 1496 1441 delete tc_process; 1497 1442 } 1498 1499 if(ripfile)1500 {1501 delete ripfile;1502 }1503 1443 } 1504 -
dvdprobe.cpp
21 21 #include <mythtv/mythcontext.h> 22 22 #include <mythtv/mythdbcon.h> 23 23 24 #include <dvdread/ifo_read.h> 24 25 25 26 DVDSubTitle::DVDSubTitle(int subtitle_id, const QString &a_language) 26 27 { -
jobthread.h
12 12 13 13 #include <qthread.h> 14 14 #include <qstringlist.h> 15 #include <qfile.h>16 #include <qprocess.h>17 #include <dvdread/dvd_reader.h>18 #include <dvdread/ifo_types.h>19 #include <dvdread/ifo_read.h>20 #include <dvdread/nav_read.h>21 15 22 16 #include "fileobs.h" 23 17 … … 113 107 const QString &extension, 114 108 bool multiple_files); 115 109 116 RipFile *ripfile;117 110 QMutex *dvd_device_access; 118 111 QString dvd_device_location; 119 112 QString destination_file_string; 120 113 int dvd_title; 121 dvd_reader_t *the_dvd;122 dvd_file_t *title;123 unsigned char video_data[ 1024 * DVD_VIDEO_LB_LEN ];124 114 QString rip_name; 125 115 }; 126 116 … … 216 206 int quality; 217 207 QDir *working_directory; 218 208 QStringList tc_arguments; 219 QProcess *tc_process;209 class QProcess *tc_process; 220 210 bool two_pass; 221 211 int audio_track; 222 212 int length_in_seconds; -
dvdprobe.h
13 13 #include <qstring.h> 14 14 #include <qptrlist.h> 15 15 16 #include <dvdread/dvd_reader.h> 17 #include <dvdread/ifo_read.h> 16 #include <dvdread/ifo_types.h> 18 17 19 18 class DVDSubTitle 20 19 { -
serversocket.cpp
8 8 9 9 */ 10 10 11 #include <qsocket.h> 12 11 13 #include <stdlib.h> 12 14 #include <iostream> 13 15 using namespace std; -
fileobs.cpp
17 17 #include "fileobs.h" 18 18 #include "qdir.h" 19 19 20 RipFile::RipFile(const QString &a_base, const QString &an_extension) 20 RipFile::RipFile(const QString &a_base, const QString &an_extension, 21 bool auto_remove_bad) : base_name(a_base), extension(an_extension), 22 auto_remove_bad_rips(auto_remove_bad) 21 23 { 22 24 filesize = gContext->GetNumSetting("MTDRipSize", 0) * 1024 * 1024; 23 base_name = a_base;24 extension = an_extension;25 25 active_file = NULL; 26 26 files.clear(); 27 27 files.setAutoDelete(true); … … 46 46 47 47 void RipFile::close() 48 48 { 49 auto_remove_bad_rips = false; 49 50 if(active_file) 50 51 { 51 52 active_file->close(); … … 155 156 156 157 RipFile::~RipFile() 157 158 { 159 if (active_file && auto_remove_bad_rips) 160 { 161 remove(); 162 } 158 163 files.clear(); 159 164 } 160 161 -
serversocket.h
10 10 11 11 */ 12 12 13 #include <qsocket.h>14 13 #include <qserversocket.h> 15 14 15 class QSocket; 16 16 17 18 17 class MTDServerSocket : public QServerSocket 19 18 { 20 19 -
mtd.cpp
11 11 #include <qstringlist.h> 12 12 #include <qregexp.h> 13 13 #include <qdir.h> 14 #include <qtimer.h> 14 15 15 16 #include <mythtv/util.h> 16 17 #include <mythtv/mythcontext.h> -
fileobs.h
21 21 22 22 public: 23 23 24 RipFile(const QString &a_base, const QString &an_extension); 24 RipFile(const QString &a_base, const QString &an_extension, 25 bool auto_remove_bad); 25 26 ~RipFile(); 26 27 27 28 bool open(int mode, bool multiple_files); … … 40 41 int access_mode; 41 42 QPtrList<QFile> files; 42 43 bool use_multiple_files; 44 bool auto_remove_bad_rips; 43 45 }; 44 46 45 47 #endif // fileobs_h_ -
mtd.h
11 11 */ 12 12 13 13 #include <qobject.h> 14 #include <qstringlist.h>15 14 #include <qptrlist.h> 16 #include <qtimer.h>17 15 18 16 #include "logging.h" 19 17 #include "serversocket.h" … … 21 19 #include "dvdprobe.h" 22 20 #include "threadevents.h" 23 21 22 class QStringList; 23 class QTimer; 24 24 25 class DiscCheckingThread : public QThread 25 26 { 26 27 -
logging.h
9 9 Headers for logging object of the myth transcoding daemon 10 10 11 11 */ 12 #include <unistd.h>13 #include <iostream>14 using namespace std;15 12 16 13 #include <qobject.h> 17 14 #include <qstring.h> 18 15 #include <qfile.h> 19 #include <qtextstream.h>20 16 21 17 22 18 class MTDLogger : public QObject