Ticket #205: mtd_cleanup2.patch
File mtd_cleanup2.patch, 17.6 KB (added by , 19 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 { 219 public: 220 MutexUnlocker(QMutex *mutex) : m_mutex(mutex) 221 { 222 if (!(m_mutex && m_mutex->locked())) 223 { 224 cerr << __FILE__ << ": Invalid mutext passed to MutexUnlocker" 225 << endl; 226 } 227 } 228 229 ~MutexUnlocker() 230 { 231 m_mutex->unlock(); 232 } 233 234 private: 235 QMutex *m_mutex; 236 }; 237 238 template <typename HTYPE, typename CLEANF_RET = void> 239 class SmartHandle 240 { 241 private: 242 typedef CLEANF_RET (*clean_fun_t)(HTYPE); 243 244 public: 245 SmartHandle(HTYPE handle, clean_fun_t cleaner) : m_handle(handle), 246 m_cleaner(cleaner) 247 { 248 } 249 250 ~SmartHandle() { 251 if (m_handle) 252 { 253 m_cleaner(m_handle); 254 } 255 } 256 257 HTYPE get() 258 { 259 return m_handle; 260 } 261 262 HTYPE operator->() { 263 return m_handle; 264 } 265 266 private: 267 HTYPE m_handle; 268 clean_fun_t m_cleaner; 269 }; 270 } 271 214 272 DVDThread::DVDThread(MTD *owner, 215 273 QMutex *drive_mutex, 216 274 const QString &dvd_device, … … 225 283 dvd_device_location = dvd_device; 226 284 dvd_title = track - 1; 227 285 destination_file_string = dest_file; 228 ripfile = NULL;229 286 rip_name = name; 230 287 } 231 288 … … 269 326 } 270 327 } 271 328 329 MutexUnlocker qmul(dvd_device_access); 330 272 331 if(!keepGoing()) 273 332 { 274 333 problem("abandoned job because master control said we need to shut down"); 275 dvd_device_access->unlock();276 334 return false; 277 335 } 278 336 … … 284 342 // Lets open our destination file 285 343 // 286 344 287 if(ripfile) 345 RipFile ripfile(to_location, extension, true); 346 if(!ripfile.open(IO_WriteOnly | IO_Raw | IO_Truncate, multiple_files)) 288 347 { 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(); 348 problem(QString("DVDPerfectThread could not open output file: %1") 349 .arg(ripfile.name())); 298 350 return false; 299 351 } 300 352 … … 305 357 306 358 int angle = 0; // Change that at some point 307 359 308 the_dvd = DVDOpen(dvd_device_location); 309 if(!the_dvd) 360 SmartHandle<dvd_reader_t *> the_dvd(DVDOpen(dvd_device_location), 361 DVDClose); 362 if(!the_dvd.get()) 310 363 { 311 364 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 365 return false; 317 366 } 318 367 319 368 320 ifo_handle_t *vmg_file = ifoOpen( the_dvd, 0);321 if(!vmg_file )369 SmartHandle<ifo_handle_t *> vmg_file(ifoOpen(the_dvd.get(), 0), ifoClose); 370 if(!vmg_file.get()) 322 371 { 323 372 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 373 return false; 330 374 } 331 375 tt_srpt_t *tt_srpt = vmg_file->tt_srpt; … … 337 381 if(title_number < 0 || title_number > tt_srpt->nr_of_srpts ) 338 382 { 339 383 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 384 return false; 347 385 } 348 386 349 ifo_handle_t *vts_file = ifoOpen(the_dvd, tt_srpt->title[title_number].title_set_nr); 350 if(!vts_file) 387 SmartHandle<ifo_handle_t *> vts_file( 388 ifoOpen(the_dvd.get(), tt_srpt->title[title_number].title_set_nr), 389 ifoClose); 390 if(!vts_file.get()) 351 391 { 352 392 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 393 return false; 360 394 } 361 395 … … 388 422 // OK ... now actually open 389 423 // 390 424 391 title = DVDOpenFile(the_dvd, 392 tt_srpt->title[ title_number ].title_set_nr, 393 DVD_READ_TITLE_VOBS ); 394 if(!title) 425 SmartHandle<dvd_file_t *> title( 426 DVDOpenFile(the_dvd.get(), 427 tt_srpt->title[title_number].title_set_nr, 428 DVD_READ_TITLE_VOBS), 429 DVDCloseFile); 430 if(!title.get()) 395 431 { 396 432 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 433 return false; 405 434 } 406 435 … … 408 437 409 438 QTime job_time; 410 439 job_time.start(); 440 441 unsigned char video_data[ 1024 * DVD_VIDEO_LB_LEN ]; 411 442 412 443 int next_cell = start_cell; 413 444 for(int cur_cell = start_cell; next_cell < cur_pgc->nr_of_cells; ) … … 445 476 // Read the NAV packet. 446 477 // 447 478 448 int len = DVDReadBlocks( title, (int) cur_pack, 1, video_data);479 int len = DVDReadBlocks(title.get(), (int) cur_pack, 1, video_data); 449 480 if( len != 1) 450 481 { 451 482 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 483 return false; 461 484 } 462 485 … … 496 519 // Read in and output cursize packs 497 520 // 498 521 499 len = DVDReadBlocks( title, (int)cur_pack, cur_output_size, video_data ); 522 len = DVDReadBlocks(title.get(), (int)cur_pack, cur_output_size, 523 video_data); 500 524 if( len != (int) cur_output_size ) 501 525 { 502 526 problem(QString("DVDPerfectThread read failed for %1 blocks at %2") 503 527 .arg(cur_output_size) 504 528 .arg(cur_pack) 505 529 ); 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 530 return false; 515 531 } 516 532 … … 518 534 overall_progress = subjob_progress * sub_to_overall_multiple; 519 535 updateSubjobString(job_time.elapsed() / 1000, 520 536 QObject::tr("Ripping to file ~")); 521 if(!ripfile->writeBlocks(video_data, cur_output_size * DVD_VIDEO_LB_LEN)) 537 if(!ripfile.writeBlocks(video_data, 538 cur_output_size * DVD_VIDEO_LB_LEN)) 522 539 { 523 540 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 541 return false; 533 542 } 534 543 … … 544 553 if(!keepGoing()) 545 554 { 546 555 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 556 return false; 556 557 } 557 558 } … … 561 562 // Wow, we're done. 562 563 // 563 564 564 ifoClose(vts_file); 565 ifoClose(vmg_file); 566 DVDCloseFile( title ); 567 DVDClose(the_dvd); 568 ripfile->close(); 569 dvd_device_access->unlock(); 565 ripfile.close(); 570 566 sendLoggingEvent("job thread finished ripping dvd title"); 571 567 return true; 572 568 } 573 569 574 570 DVDThread::~DVDThread() 575 571 { 576 if(ripfile);577 {578 delete ripfile;579 }580 572 } 581 573 582 574 /* … … 645 637 } 646 638 } 647 639 640 MutexUnlocker qmul(dvd_device_access); 648 641 if(!keepGoing()) 649 642 { 650 643 problem("abandoned job because master control said we need to shut down"); 651 dvd_device_access->unlock();652 644 return false; 653 645 } 654 646 655 ripfile = new RipFile(destination_file_string, ".iso");656 if(!ripfile ->open(IO_WriteOnly | IO_Raw | IO_Truncate, false))647 RipFile ripfile(destination_file_string, ".iso", true); 648 if(!ripfile.open(IO_WriteOnly | IO_Raw | IO_Truncate, false)) 657 649 { 658 problem(QString("DVDISOCopyThread could not open output file: %1") .arg(ripfile->name()));659 dvd_device_access->unlock();650 problem(QString("DVDISOCopyThread could not open output file: %1") 651 .arg(ripfile.name())); 660 652 return false; 661 653 } 662 654 663 sendLoggingEvent(QString("ISO DVD image copy to: %1").arg(ripfile ->name()));655 sendLoggingEvent(QString("ISO DVD image copy to: %1").arg(ripfile.name())); 664 656 665 657 int file = open( dvd_device_location, O_RDONLY ); 666 658 if(file == -1) 667 659 { 668 660 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 661 return false; 674 662 } 675 663 … … 690 678 { 691 679 perror("read"); 692 680 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 681 return false; 701 682 } 702 683 if(bytes_read == 0) … … 704 685 break; 705 686 } 706 687 707 if(!ripfile ->writeBlocks(buffer, bytes_read))688 if(!ripfile.writeBlocks(buffer, bytes_read)) 708 689 { 709 690 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 691 return false; 718 692 } 719 693 … … 732 706 if(!keepGoing()) 733 707 { 734 708 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 709 return false; 743 710 } 744 711 } 745 712 746 ripfile->close(); 747 if (ripfile) 748 { 749 delete ripfile; 750 ripfile = NULL; 751 } 752 dvd_device_access->unlock(); 713 ripfile.close(); 753 714 sendLoggingEvent("job thread finished copying ISO image"); 754 715 return true; 755 716 } … … 1451 1412 // 1452 1413 if(working_directory) 1453 1414 { 1454 if(ripfile)1455 {1456 ripfile->remove();1457 if (ripfile)1458 {1459 delete ripfile;1460 ripfile = NULL;1461 }1462 }1463 1464 1415 if(two_pass) 1465 1416 { 1466 1417 working_directory->remove("twopass.log"); … … 1495 1446 { 1496 1447 delete tc_process; 1497 1448 } 1498 1499 if(ripfile)1500 {1501 delete ripfile;1502 }1503 1449 } 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 -
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> -
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 -
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