Ticket #125: dvdimage.diff

File dvdimage.diff, 8.4 KB (added by dl.sims@…, 20 years ago)

Patch to add ISO Image rip ability to mythdvd

  • mythplugins/mythdvd/mythdvd/titledialog.cpp

     
    113113        if(quality_select)
    114114        {
    115115            quality_select->cleanOut();
     116            quality_select->addItem(-1, tr("ISO Image"));
    116117            quality_select->addItem(0, tr("Perfect"));
    117118            QString q_string = QString("SELECT name,intid FROM dvdtranscode "
    118119                                       "WHERE input = %1 ;")
  • mythplugins/mythdvd/mtd/jobthread.cpp

     
    88
    99*/
    1010
     11#include <sys/types.h>
     12#include <sys/stat.h>
     13#include <fcntl.h>
     14
    1115#include <iostream>
    1216using namespace std;
    1317
     
    543547---------------------------------------------------------------------
    544548*/
    545549
     550DVDISOCopyThread::DVDISOCopyThread(MTD *owner,
     551                                   QMutex *drive_mutex,
     552                                   const QString &dvd_device,
     553                                   int track,
     554                                   const QString &dest_file,
     555                                   const QString &name,
     556                                   const QString &start_string,
     557                                   int nice_priority)
     558                 :DVDThread(owner,
     559                            drive_mutex,
     560                            dvd_device,
     561                            track,
     562                            dest_file,
     563                            name,
     564                            start_string,
     565                            nice_priority)
     566
     567{
     568}
     569
     570void DVDISOCopyThread::run()
     571{
     572    //
     573    //  Be nice
     574    //
     575   
     576    nice(nice_level);
     577    job_name = QString(QObject::tr("ISO Image Copy of %1")).arg(rip_name);
     578    if(keepGoing())
     579    {
     580        copyFullDisc();
     581    }
     582}
     583
     584bool DVDISOCopyThread::copyFullDisc(void)
     585{
     586    bool loop = true;
     587
     588    setSubName(QObject::tr("Waiting for Access to DVD"), 1);
     589
     590    while(loop)
     591    {
     592        if(dvd_device_access->tryLock())
     593        {
     594            loop = false;
     595        }
     596        else
     597        {
     598            if(keepGoing())
     599            {
     600                sleep(5);
     601            }
     602            else
     603            {
     604                problem("abandoned job because master control said we need to shut down");
     605                return false;
     606            }
     607        }
     608    }
     609
     610    if(!keepGoing())
     611    {
     612        problem("abandoned job because master control said we need to shut down");
     613        dvd_device_access->unlock();
     614        return false;
     615    }
     616
     617    ripfile = new RipFile(destination_file_string, ".iso");
     618    if(!ripfile->open(IO_WriteOnly | IO_Raw | IO_Truncate, false))
     619    {
     620        problem(QString("DVDISOCopyThread could not open output file: %1").arg(ripfile->name()));
     621        dvd_device_access->unlock();
     622        return false;
     623    }
     624
     625    sendLoggingEvent(QString("ISO DVD image copy to: %1").arg(ripfile->name()));
     626
     627    int file = open( dvd_device_location, O_RDONLY );
     628    if(file == -1)
     629    {
     630        problem(QString("DVDISOCopyThread could not open dvd device: %1").arg(dvd_device_location));
     631        ripfile->remove();
     632        delete ripfile;
     633        ripfile = NULL;
     634        dvd_device_access->unlock();
     635        return false;
     636    }
     637
     638    off_t dvd_size = lseek(file, 0, SEEK_END);
     639    lseek(file, 0, SEEK_SET);
     640
     641    int buf_size = 4098;
     642    unsigned char *buffer = new unsigned char[buf_size];
     643    long long total_bytes(0);
     644
     645    QTime job_time;
     646    job_time.start();
     647
     648    while( 1 )
     649    {
     650        int bytes_read = read(file, buffer, buf_size);
     651        if(bytes_read == -1)
     652        {
     653            perror("read");
     654            problem(QString("DVDISOCopyThread dvd device read error"));
     655            ripfile->remove();
     656            delete ripfile;
     657            ripfile = NULL;
     658            delete buffer;
     659            dvd_device_access->unlock();
     660            return false;
     661        }
     662        if(bytes_read == 0)
     663        {
     664            break;
     665        }
     666
     667        if(!ripfile->writeBlocks(buffer, bytes_read))
     668        {
     669            problem(QString("DVDISOCopyThread rip file write error"));
     670            ripfile->remove();
     671            delete ripfile;
     672            ripfile = NULL;
     673            delete buffer;
     674            dvd_device_access->unlock();
     675            return false;
     676        }
     677
     678        total_bytes += bytes_read;
     679
     680        setSubProgress((double) (total_bytes) / (double) (dvd_size), 1);
     681        overall_progress = subjob_progress * sub_to_overall_multiple;
     682        updateSubjobString(job_time.elapsed() / 1000,
     683                           QObject::tr("Ripping to file ~"));
     684
     685        //
     686        //  Escape out and clean up if mtd main thread
     687        //  tells us to
     688        //
     689           
     690        if(!keepGoing())
     691        {
     692            problem("abandoned job because master control said we need to shut down");
     693            ripfile->remove();
     694            delete ripfile;
     695            ripfile = NULL;
     696            delete buffer;
     697            dvd_device_access->unlock();
     698            return false;
     699        }
     700    }
     701
     702    delete buffer;
     703    ripfile->close();
     704    delete ripfile;
     705    dvd_device_access->unlock();
     706    sendLoggingEvent("job thread finished copying ISO image");
     707    return true;
     708}
     709
     710DVDISOCopyThread::~DVDISOCopyThread()
     711{
     712}
     713
     714/*
     715---------------------------------------------------------------------
     716*/
     717
    546718DVDPerfectThread::DVDPerfectThread(MTD *owner,
    547719                                   QMutex *drive_mutex,
    548720                                   const QString &dvd_device,
  • mythplugins/mythdvd/mtd/jobthread.h

     
    113113    QString      rip_name;
    114114};
    115115
     116class DVDISOCopyThread : public DVDThread
     117{
     118    //
     119    // Copy a byte-for-byte image of the disk
     120    // to an iso file.
     121    //
     122
     123  public:
     124
     125    DVDISOCopyThread(MTD *owner,
     126                     QMutex *drive_mutex,
     127                     const QString &dvd_device,
     128                     int track,
     129                     const QString &dest_file,
     130                     const QString &name,
     131                     const QString &start_string,
     132                     int nice_priority);
     133
     134    ~DVDISOCopyThread();
     135                     
     136    virtual void run();
     137
     138    bool copyFullDisc(void);
     139};
     140
    116141class DVDPerfectThread : public DVDThread
    117142{
    118143    //
  • mythplugins/mythdvd/mtd/mtd.cpp

     
    625625    }
    626626   
    627627    int quality = tokens[4].toInt(&ok);
    628     if(quality < 0 || !ok)
     628    if(quality < -1 || !ok)
    629629    {
    630630        emit writeToLog(QString("bad quality value in job request: %1").arg(flat));
    631631        return;
     
    685685
    686686    //
    687687    //  OK, we are ready to launch this job
    688     // 
     688    //
    689689
    690     if(quality == 0)
     690    if(quality == -1)
    691691    {
    692692        QFile final_file(dest_dir.filePath(file_name));
    693693
     694        if(!checkFinalFile(&final_file, ".iso"))
     695        {
     696            emit writeToLog("Final file name is not useable. File exists? Other Pending job?");
     697            return;
     698        }
     699   
     700        emit writeToLog(QString("launching job: %1").arg(flat));
     701
     702        //
     703        //  Full disc copy to an iso image.
     704        //
     705 
     706        JobThread *new_job = new DVDISOCopyThread(this,
     707                                                  dvd_drive_access,
     708                                                  dvd_device,
     709                                                  dvd_title,
     710                                                  final_file.name(),
     711                                                  file_name,
     712                                                  flat,
     713                                                  nice_level);
     714        job_threads.append(new_job);
     715        new_job->start();
     716    }
     717    else if(quality == 0)
     718    {
     719        QFile final_file(dest_dir.filePath(file_name));
     720
    694721        if(!checkFinalFile(&final_file, ".mpg"))
    695722        {
    696723            emit writeToLog("Final file name is not useable. File exists? Other Pending job?");