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

K3bDevice::Toc K3bDevice::Device::readToc (  )  const

Returns:
The toc of the media or an empty (invalid) K3bDevice::Toc if no or an empty media is inserted.

Definition at line 761 of file k3bdevice.cpp.

References blockDeviceName(), close(), currentProfile(), dvdMediaType(), fixupToc(), isDVD(), isOpen(), K3b::Msf::lba(), open(), readCapacity(), and readRawToc().

Referenced by discSize(), and diskInfo().

{
  // if the device is already opened we do not close it
  // to allow fast multible method calls in a row
  bool needToClose = !isOpen();

  Toc toc;

  if( !open() )
    return toc;

  if( isDVD() ) {
    int mediaType = dvdMediaType();
    //
    // Use the profile if available because DVD-ROM units need to treat DVD+-R(W) media as DVD-ROM
    // if supported at all
    //
    if( currentProfile() == MEDIA_DVD_ROM )
      mediaType = MEDIA_DVD_ROM;

    // FIXME: add DVD-R Dual Layer

   switch( mediaType ) {

    case MEDIA_DVD_ROM:
    case MEDIA_DVD_RW_OVWR:
    case MEDIA_DVD_PLUS_RW:
      {
//    unsigned char* data = 0;
//    int dataLen = 0;
//    if( readTrackInformation( &data, dataLen, 0x1, 0x1 ) ) {
//      track_info_t* trackInfo = (track_info_t*)data;

//      Track track;
//      track.m_firstSector = 0;
//      track.m_lastSector = from4Byte( trackInfo->track_size ) - 1;
//      track.m_session = 1;
//      track.m_type = Track::DATA;
//      track.m_mode = Track::DVD;
//      track.m_copyPermitted = ( mediaType != MEDIA_DVD_ROM );
//      track.m_preEmphasis = ( mediaType != MEDIA_DVD_ROM );

//      delete [] data;

//      //
//      // There seem to be devices that report a bogus track length here...
//      // In that case we just fall through :(
//      // Maybe we should try readFormattedToc here and do this check there
//      //
//      if( track.length() > 1 ) {
//        toc.append( track );          
//        break;
//      }
//    }
//    else
//      kdDebug() << "(K3bDevice::Device) " << blockDeviceName()
//              << "READ TRACK INFORMATION for toc failed." << endl;

// FIXME: why not use this for all cases. In the end we always do a readFormattedToc anyway...
      if( !readFormattedToc( toc, true ) ) {
        K3b::Msf size;
        if( readCapacity( size ) ) {
          Track track;
          track.m_firstSector = 0;
          track.m_lastSector = size.lba();
          track.m_session = 1;
          track.m_type = Track::DATA;
          track.m_mode = Track::DVD;
          track.m_copyPermitted = ( mediaType != MEDIA_DVD_ROM );
          track.m_preEmphasis = ( mediaType != MEDIA_DVD_ROM );
          
          toc.append( track );
          
          break;
        }
        else
          kdDebug() << "(K3bDevice::Device) " << blockDeviceName()
                  << "READ CAPACITY for toc failed." << endl;
      }
      else
        break;
      }

      // fallthrough...

    case MEDIA_DVD_R:
    case MEDIA_DVD_R_DL:
    case MEDIA_DVD_R_DL_SEQ:
    case MEDIA_DVD_R_DL_JUMP:
    case MEDIA_DVD_R_SEQ:
      // multisession possible
      readFormattedToc( toc, true );
      break;

    case MEDIA_DVD_RW:
    case MEDIA_DVD_RW_SEQ:
      // is multisession possible?
      readFormattedToc( toc, true );
      break;

    case MEDIA_DVD_PLUS_R:
    case MEDIA_DVD_PLUS_R_DL:
      //
      // a DVD+R disk may have multible sessions
      // every session may contain up to 16 fragments
      // if the disk is open there is one open session
      // every closed session is viewed as a track whereas
      // every fragment of the open session is viewed as a track
      //
      // We may use
      // READ DISK INFORMATION
      // READ TRACK INFORMATION: track number FFh refers to the incomplete fragment (track)
      // READ TOC/PMA/ATIP: form 0 refers to all closed sessions
      //                    form 1 refers to the last closed session
      //
      readFormattedToc( toc, true );
      break;

    case MEDIA_DVD_RAM:
      kdDebug() << "(K3bDevice::readDvdToc) no dvdram support" << endl;
      break;
    default:
      kdDebug() << "(K3bDevice::readDvdToc) no dvd." << endl;
    }
  }
  else {
    bool success = readRawToc( toc );
    if( !success ) {
      success = readFormattedToc( toc );

#ifdef Q_OS_LINUX
      if( !success ) {
      kdDebug() << "(K3bDevice::Device) MMC READ TOC failed. falling back to cdrom.h." << endl;
      readTocLinux(toc);
      }
#endif

      if( success )
      fixupToc( toc );
    }
  }

  if( needToClose )
    close();

  return toc;
}


Generated by  Doxygen 1.6.0   Back to index