Logo Search packages:      
Sourcecode: k9copy version File versions  Download package

int k9DVD::scandvd ( const QString &  device  )  [virtual]

Opens and estimates the size of each stream

Parameters:
device input device
Returns:
return code (0=ok)

Definition at line 278 of file k9dvd.cpp.

References addTitle(), k9DVDProgress::setpbTitleStep(), and k9DVDProgress::setpbTotalStep().

                                          {
    char ctitle[255];
    k9DVDChapter::setcptChapter(0);
    dvd_reader_t *dvd;
    ifo_handle_t *ifo_zero, *ifo;
    pgcit_t *vts_pgcit;
    vtsi_mat_t *vtsi_mat;
    vmgi_mat_t *vmgi_mat;
    audio_attr_t *audio_attr;
    video_attr_t *video_attr;
    subp_attr_t *subp_attr;
    pgc_t *pgc;
    int i, j,  ltitles, titlesets,cell, vts_ttn, title_set_nr;
    char lang_code[2];
    int has_title = 0, ret = 0;
    int max_length = 0;
    struct stat dvd_stat;
    bool ok;
    tt_srpt_t   *tt_srpt;
    QString txt,c;

    int menuSizes[100];
    for ( j=0; j<100;j++)
        menuSizes[j]=0;

    titles.clear();
    Device=device;

    error=false;
    errMsg="";

    progressDlg= new k9DVDProgress(qApp->mainWidget(),"progress",true);
    progressDlg->setpbTitleStep(0);
    progressDlg->setpbTotalStep(0);
    progressDlg->show();
    qApp->processEvents();

    k9DVDTitle *l_track;
    k9DVDAudioStream *l_auds;
    k9DVDChapter *l_chap;
    k9DVDSubtitle *l_sub;
    QString sh,sm,ss;

    ret = stat(device.latin1(), &dvd_stat);
    if ( ret < 0 ) {
        c.sprintf(tr2i18n("Can't find device %s\n"), device.latin1());
        setError(c);
        return 1;
    }

    DVDHandle = DVDOpen(device.latin1());
    dvd=DVDHandle;
    if( !dvd ) {
        c.sprintf(tr2i18n("Can't open disc %s!\n"), device.latin1());
        setError(c);
        return 2;
    }
    ifo_zero = ifoOpen(dvd, 0);
    if ( !ifo_zero ) {
        c=tr2i18n("Can't open main ifo!\n");
        setError(c);
        return 3;
    }

    ltitles = ifo_zero->tt_srpt->nr_of_srpts;
    titleCount = 0;
    int indexedCount=0;
    has_title = get_title_name(device.latin1(), ctitle);

    vmgi_mat = ifo_zero->vmgi_mat;
    titlesets = vmgi_mat->vmg_nr_of_title_sets;
    menuSizes[0]=vmgi_mat->vmg_last_sector;

    title=( has_title ? tr2i18n("unknown") : ctitle);

    for (int ts=1;ts <=titlesets;ts++) {

        tt_srpt = ifo_zero->tt_srpt;
        ifo = ifoOpen(dvd,ts);
        if (ifo==NULL)
            continue;

        for (j=0; j < ifo->vts_pgcit->nr_of_pgci_srp; j++) {
            // tt_srpt->title[j].title_set_nr);
            // GENERAL
            vtsi_mat   = ifo->vtsi_mat;
            vts_pgcit  = ifo->vts_pgcit;
            pgc = vts_pgcit->pgci_srp[j].pgc;
            if (vtsi_mat && (pgc->nr_of_cells >0)) {
                titleCount++;
                vts_ttn =  j+1;//ifo->vts_ptt_srpt->title[j].ptt[0].pgcn; //ifo_zero->tt_srpt->title[j].vts_ttn;
                if (isTitleIndex(ifo_zero,ts,vts_ttn))
                    indexedCount++;

                txt.sprintf(tr2i18n("Title %d"),indexedCount);
                emit sigTotalText (txt);
                emit sigTitleProgress(indexedCount,ltitles);
                video_attr = &vtsi_mat->vts_video_attr;

                vmgi_mat = ifo_zero->vmgi_mat;
                title_set_nr = ts; //ifo_zero->tt_srpt->title[j].title_set_nr;
                menuSizes[title_set_nr]=vtsi_mat->vtstt_vobs + vtsi_mat->vtsi_last_sector +1;

                //vts_pgcit->pgci_srp[ifo->vts_ptt_srpt->title[vts_ttn - 1].ptt[0].pgcn - 1].pgc;

                int titleStartSector=pgc->cell_playback[0].first_sector;
                //l_track=addTitle(j+1,title_set_nr,ifo->vts_ptt_srpt->title[vts_ttn - 1].ptt[0].pgcn - 1,titleStartSector,isTitleIndex(ifo_zero,ts,vts_ttn));
                bool titleIndexed=isTitleIndex(ifo_zero,ts,vts_ttn);
                l_track=addTitle(titleCount, indexedCount,title_set_nr,j,titleStartSector,titleIndexed);

                sh.sprintf("%02x",pgc->playback_time.hour);
                sm.sprintf("%02x",pgc->playback_time.minute);
                ss.sprintf("%02x",pgc->playback_time.second);
                l_track->length.setHMS(sh.toInt(&ok,10),sm.toInt(&ok,10),ss.toInt(&ok,10));

                //printf(tr2i18n("Title: %02d, Length: %02x:%02x:%02x "), j+1, pgc->playback_time.hour, pgc->playback_time.minute, pgc->playback_time.second);

                if (dvdtime2msec(&pgc->playback_time) > max_length && isTitleIndex(ifo_zero,ts,vts_ttn)) {
                    max_length = dvdtime2msec(&pgc->playback_time);
                    longestTitle = l_track;
                }

                l_track->chapterCount =  pgc->nr_of_programs;//  ifo_zero->tt_srpt->title[j].nr_of_ptts;
                l_track->audioStreamCount = vtsi_mat->nr_of_vts_audio_streams;
                l_track->subPictureCount = vtsi_mat->nr_of_vts_subp_streams;
                l_track->VTS = ts;//  ifo_zero->tt_srpt->title[j].title_set_nr;
                l_track->TTN = j+1; // ifo_zero->tt_srpt->title[j].vts_ttn;
                l_track->FPS = frames_per_s[(pgc->playback_time.frame_u & 0xc0) >> 6];
                l_track->format= (*lvideoFormat.at(video_attr->video_format)).latin1();
                format = l_track->format;
                /*      QStringList::Iterator it;
                it= videoFormat.at(video_attr->video_format);
                c= (*it).latin1();
                */

                l_track->aspectRatio = (*laspectRatio.at(video_attr->display_aspect_ratio)).latin1();
                l_track->width = (*lvideoWidth.at(video_attr->picture_size)).latin1();
                ;
                l_track->height = (*lvideoHeight.at(video_attr->video_format)).latin1();
                l_track->DF = (*lpermittedDf.at(video_attr->permitted_df)).latin1();

                for (i=0; i<16; i++) {
                    QString pal;
                    pal.sprintf("%08x",pgc->palette[i]);
                    l_track->palette.append(pal);
                }

                // ANGLES
                l_track->angleCount =  ifo_zero->tt_srpt->title[j].nr_of_angles;

                // AUDIO
                //                  for (i=0; i<vtsi_mat->nr_of_vts_audio_streams; i++) {
                l_track->audioStreamCount=0;
            for (i=0; i<vtsi_mat->nr_of_vts_audio_streams; i++) {
                    if (pgc->audio_control[i]>>8 !=0) {
                  l_track->audioStreamCount++;
                    l_auds=l_track->addAudioStream();
                        l_auds->setselected(!titleIndexed);
                        audio_attr = &vtsi_mat->vts_audio_attr[i];
                        sprintf(lang_code, "%c%c", audio_attr->lang_code>>8, audio_attr->lang_code & 0xff);
                        if (!lang_code[0]) {
                            lang_code[0] = 'x';
                            lang_code[1] = 'x';
                        }
                        l_auds->langCod=lang_code;
                        l_auds->language=lang_name(lang_code);
                        l_auds->format= (*laudioFormat.at(audio_attr->audio_format)).latin1();
                        l_auds->frequency = (*lsampleFreq.at(audio_attr->sample_frequency)).latin1();
                        l_auds->quantization = (*lquantization.at(audio_attr->quantization)).latin1();
                        l_auds->channels = audio_attr->channels+1;
                        l_auds->appMode = audio_attr->application_mode;
                        l_auds->content = (*laudioType.at(audio_attr->lang_extension)).latin1();
                        //if (((pgc->audio_control[i]>>8) & 0x80) ==0x80) {
                        l_auds->id = 1+ ((pgc->audio_control[i]>>8) & 0x7) ;
                        //} else {
                        //    l_auds->id=1;
                        //}
                    }
                }
                // CHAPTERS
                cell = 0;
                unsigned long total_sectors = 0;

                l_track->chapterCount= pgc->nr_of_programs;
                for (i=0;i < l_track->chapterCount;i++)
                    l_track->addChapter(i+1);

                k9DVDChapter *l_pchap=NULL;
                for (i=0; i<pgc->nr_of_programs; i++) {
                    int second=0, minute=0, hour=0, tmp;
                    char hex[2];
                    int next = pgc->program_map[i+1];
                    unsigned long sectors = 0;
                    l_chap = l_track->getChapter(i);
                    //first sector
                    l_chap->startSector=pgc->cell_playback[cell].first_sector;
                    ;
                    l_chap->endSector=0;
                    if (i == pgc->nr_of_programs - 1)
                        next = pgc->nr_of_cells + 1;

                uint angleStart=0,angleEnd=0;
                    while (cell < next - 1) {
                        //using c2 otherwise the value of cell were lost
                        //int c2=cell;
                        //l_chap->cells.append(c2);
                        int startSect=pgc->cell_playback[cell].first_sector;
                        l_chap->startSectors.append(startSect);

                        sprintf(hex, "%02x", pgc->cell_playback[cell].playback_time.second);
                        tmp = second + atoi(hex);
                        minute = minute + (tmp / 60);
                        second = tmp % 60;
                        sprintf(hex, "%02x", pgc->cell_playback[cell].playback_time.minute);
                        tmp = minute + atoi(hex);
                        hour = hour + (tmp / 60);
                        minute = tmp % 60;

                        l_chap->endSector= pgc->cell_playback[cell].last_sector;
                        //last sector
                        sectors += pgc->cell_playback[cell].last_sector - pgc->cell_playback[cell].first_sector + 1;

                        /* Check if we're entering an angle block. (vamp_play-title) */
                  int cell2=cell;
                        if ( pgc->cell_playback[ cell ].block_type
                                == BLOCK_TYPE_ANGLE_BLOCK  && cell>angleEnd ) {
                      angleStart=cell;
                            for( int idc = 0;; ++idc ) {
                        k9ChapterCell * chapterCell=new k9ChapterCell(cell2+idc,idc+1);
                        l_chap->cells.append(chapterCell);  
                        if (idc==0) 
                              chapterCell->setangleBlock(angleStart);
                        else 
                              chapterCell->setangleBlock(angleInside);
                                if( pgc->cell_playback[ cell2 + idc ].block_mode
                                        == BLOCK_MODE_LAST_CELL ) {
                            angleEnd=cell2+idc+1;
                            chapterCell->setangleBlock(angleEnd);
                                    break;
                                }
                            }
                        } else {
                      if (!(cell>=angleStart  && cell <angleEnd)) {
                        l_chap->cells.append(new k9ChapterCell(cell,1));
                      }
                        }
                  cell++;
                    }

                    l_track->vobusize_mb += calcVobuSize(ifo,l_chap);
                    total_sectors += sectors;
                    l_chap->length.setHMS(hour,minute,second);
                    l_chap->sectors=sectors;
                    if (l_pchap!=NULL) {
                        QTime t;
                        int position;
                        t.setHMS(0,0,0);
                        position=t.secsTo(l_chap->length);
                        t=l_pchap->time.addSecs(position);
                        l_chap->time=t;
                    }
                    l_pchap=l_chap;
                }
                l_track->size_mb =((float)total_sectors *2048)/(1024*1024);

                // SUBTITLES
            l_track->subPictureCount=0;
                for (i=0; i<vtsi_mat->nr_of_vts_subp_streams; i++) {
                    if (pgc->subp_control[i]>>24 !=0) {
                  l_track->subPictureCount++;
                    subp_attr = &vtsi_mat->vts_subp_attr[i];
                        sprintf(lang_code, "%c%c", subp_attr->lang_code>>8, subp_attr->lang_code & 0xff);
                        if (!lang_code[0]) {
                            lang_code[0] = 'x';
                            lang_code[1] = 'x';
                        }
                        l_sub=l_track->addSubtitle(i+1);
                        l_sub->setselected(!titleIndexed);
                        l_sub->langCod=lang_code;
                        l_sub->language=lang_name(lang_code);
                        l_sub->content= (*lsubpType.at(subp_attr->lang_extension)).latin1();
                        unsigned char subpc;
                        subpc=pgc->subp_control[i]>>24;
                        if ((subpc & 0x80)==0x80) {
                            l_sub->id=1;
                            if ((subpc &0x1F) !=0)
                                l_sub->id = 1+ (subpc & 0x1F);
                            subpc=pgc->subp_control[i]>>16;
                            if ((subpc &0x1F) !=0)
                                l_sub->id = 1+ (subpc & 0x1F);
                            subpc=pgc->subp_control[i]>>8;
                            if ((subpc &0x1F) !=0)
                                l_sub->id = 1+ (subpc & 0x1F);
                            subpc=pgc->subp_control[i];
                            if ((subpc &0x1F) !=0)
                                l_sub->id = 1+ (subpc & 0x1F);

                        }
                    }
                }
                if (isTitleIndex(ifo_zero,ts,vts_ttn))
                    calcStreamSize(dvd,*l_track);
            }

        }
        ifoClose(ifo);
    }
    menuSize=0;
    for (j=0;j<100;j++)
        menuSize+=menuSizes[j];
    ifoClose(ifo_zero);

    delete progressDlg;
    progressDlg=0;
    opened=true;
    return 0;
}


Generated by  Doxygen 1.6.0   Back to index