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

int K3bDevice::Device::rawTocDataWithBcdValues ( unsigned char *  data,
int  dataLen 
) const [private]

Internal method which checks if the raw toc data has bcd values or hex.

Returns:
0 if hex, 1 if bcd, -1 if none

Definition at line 1149 of file k3bdevice.cpp.

Referenced by readRawToc().

{
  toc_raw_track_descriptor* tr = (toc_raw_track_descriptor*)&data[4];

  bool notBcd = false;
  bool notHex = false;

  //
  // in most cases this will already tell us if a drive does not provide bcd numbers
  // (which should be all newer MMC drives)
  //
  for( int i = 0; i < (dataLen-4)/(int)sizeof(toc_raw_track_descriptor); ++i ) {
    if( tr[i].adr == 1 && tr[i].point <= 0xa2) {
      if( !K3bDevice::isValidBcd(tr[i].p_min) ||
        !K3bDevice::isValidBcd(tr[i].p_sec) ||
        !K3bDevice::isValidBcd(tr[i].p_frame) ) {
      notBcd = true;
      break;
      }

      // we only need to check sec and frame since min needs to be <= 99
      // and bcd values are never bigger than 99.
      else if( (int)K3bDevice::fromBcd(tr[i].p_sec) >= 60 ||
             (int)K3bDevice::fromBcd(tr[i].p_frame) >= 75 ) {
      notBcd = true;
      break;
      }
    }
  }


  //
  // all values are valid bcd values but we still don't know for sure if they are really
  // used as bcd. So we also check the HEX values.
  //
  for( int i = 0; i < (dataLen-4)/(int)sizeof(toc_raw_track_descriptor); ++i ) {
    if( tr[i].adr == 1 && tr[i].point <= 0xa2 ) {
      if( (int)tr[i].p_min > 99 ||
        (int)tr[i].p_sec >= 60 ||
        (int)tr[i].p_frame >= 75 ) {
      notHex = true;
      break;
      }
    }
  }
  

  //
  // If all values are valid bcd and valid hex we check the start sectors of the tracks.
  //
  if( !notHex || !notBcd ) {
    K3b::Msf sessionLeadOutHex, sessionLeadOutBcd;
    K3b::Msf lastTrackHex, lastTrackBcd;

    for( int i = 0; i < (dataLen-4)/(int)sizeof(toc_raw_track_descriptor); ++i ) {

      if( tr[i].adr == 1 ) {
      if( tr[i].point < 0x64 ) {
        
        // check hex values
        if( K3b::Msf( tr[i].p_min, tr[i].p_sec, tr[i].p_frame ) <
            lastTrackHex )
          notHex = true;
        
        // check bcd values
        if( K3b::Msf( K3bDevice::fromBcd(tr[i].p_min), K3bDevice::fromBcd(tr[i].p_sec), K3bDevice::fromBcd(tr[i].p_frame) ) <
            lastTrackBcd )
          notBcd = true;

        lastTrackBcd = K3b::Msf( K3bDevice::fromBcd(tr[i].p_min), K3bDevice::fromBcd(tr[i].p_sec), K3bDevice::fromBcd(tr[i].p_frame) );
        lastTrackHex = K3b::Msf( tr[i].p_min, tr[i].p_sec, tr[i].p_frame );
      }
      else if( tr[i].point == 0xa2 ) {
        if( sessionLeadOutHex < lastTrackHex )
          notHex = true;
        if( sessionLeadOutBcd < lastTrackBcd )
          notBcd = true;

        sessionLeadOutHex = K3b::Msf( tr[i].p_min, tr[i].p_sec, tr[i].p_frame );
        sessionLeadOutBcd = K3b::Msf( K3bDevice::fromBcd(tr[i].p_min), K3bDevice::fromBcd(tr[i].p_sec), K3bDevice::fromBcd(tr[i].p_frame) );
      }
      }
    }

    // check the last track
    if( sessionLeadOutHex < lastTrackHex )
      notHex = true;
    if( sessionLeadOutBcd < lastTrackBcd )
      notBcd = true;
  }


  if( !notBcd && !notHex ) {
    kdDebug() << "(K3bDevice::Device) need to compare raw toc to formatted toc. :(" << endl;
    //
    // All values are valid bcd and valid HEX values so we compare with the formatted toc.
    // This slows us down a lot but in most cases this should not be reached anyway.
    //
    // TODO: also check the bcd values
    //
    K3bDevice::Toc formattedToc;
    if( readFormattedToc( formattedToc, false ) ) {
      for( int i = 0; i < (dataLen-4)/(int)sizeof(toc_raw_track_descriptor); ++i ) {
      if( tr[i].adr == 1 && tr[i].point < 0x64 ) {
        unsigned int track = (int)tr[i].point;

        // FIXME: do bcd drive also encode the track number in bcd? If so test it, too.

        if( track > formattedToc.count() ) {
          notHex = true;
          break;
        }

        K3b::Msf posHex( tr[i].p_min,
                     tr[i].p_sec,
                     tr[i].p_frame );
        K3b::Msf posBcd( K3bDevice::fromBcd(tr[i].p_min), 
                     K3bDevice::fromBcd(tr[i].p_sec), 
                     K3bDevice::fromBcd(tr[i].p_frame) );
        posHex -= 150;
        posBcd -= 150;
        if( posHex != formattedToc[track-1].firstSector() )
          notHex = true;
        if( posBcd != formattedToc[track-1].firstSector() )
          notBcd = true;
      }
      }
    }
  }

  if( notBcd )
    kdDebug() << "(K3bDevice::Device) found invalid bcd values. No bcd toc." << endl;
  if( notHex )
    kdDebug() << "(K3bDevice::Device) found invalid hex values. No hex toc." << endl;

  if( notBcd == notHex ) {
    kdDebug() << "(K3bDevice::Device) unable to determine if hex or bcd." << endl;
    return -1;
  }
  else if( notBcd )
    return 0;
  else
    return 1;
}


Generated by  Doxygen 1.6.0   Back to index