示例#1
0
void K3bAudioMaxSpeedJob::WorkThread::run()
{
  kdDebug() << k_funcinfo << endl;
  m_canceled = false;

  emitStarted();

  K3bAudioDataSourceIterator it( m_doc );

  // count sources for minimal progress info
  int numSources = 0;
  int sourcesDone = 0;
  while( it.current() ) {
    ++numSources;
    it.next();
  }

  bool success = true;
  maxSpeed = 175*1000;
  it.first();

  while( it.current() && !m_canceled ) {
    if( !it.current()->seek(0) ) {
      kdDebug() << "(K3bAudioMaxSpeedJob) seek failed." << endl;
      success = false;
      break;
    }
      
    // read some data
    int speed = speedTest( it.current() );

    ++sourcesDone;
    emitPercent( 100*numSources/sourcesDone );

    if( speed < 0 ) {
      success = false;
      break;
    }
    else if( speed > 0 ) {
      // update the max speed
      maxSpeed = QMIN( maxSpeed, speed );
    }
      
    it.next();
  }

  if( m_canceled ) {
    emitCanceled();
    success = false;
  }

  if( success )
    kdDebug() << "(K3bAudioMaxSpeedJob) max speed: " << maxSpeed << endl;

  emitFinished( success );
}
示例#2
0
void K3bAudioImager::WorkThread::run()
{
  m_canceled = false;

  emitStarted();

  lastError = K3bAudioImager::ERROR_UNKNOWN;

  //
  // 
  //
  QStringList::iterator imageFileIt = m_imageNames.begin();
  K3bWaveFileWriter waveFileWriter;

  K3bAudioTrack* track = m_doc->firstTrack();
  int trackNumber = 1;
  unsigned long long totalSize = m_doc->length().audioBytes();
  unsigned long long totalRead = 0;
  char buffer[2352 * 10];

  while( track ) {

    emitNextTrack( trackNumber, m_doc->numOfTracks() );

    //
    // Seek to the beginning of the track
    //
    if( !track->seek(0) ) {
      emitInfoMessage( i18n("Unable to seek in track %1.").arg(trackNumber), K3bJob::ERROR );
      emitFinished(false);
      return;
    }

    //
    // Initialize the reading
    //
    int read = 0;
    unsigned long long trackRead = 0;

    //
    // Create the image file
    //
    if( m_fd == -1 ) {
      if( !waveFileWriter.open( *imageFileIt ) ) {
	emitInfoMessage( i18n("Could not open %1 for writing").arg(*imageFileIt), K3bJob::ERROR );
	emitFinished(false);
	return;
      }
    }

    //
    // Read data from the track
    //
    while( (read = track->read( buffer, sizeof(buffer) )) > 0 ) {
      if( m_fd == -1 ) {
	waveFileWriter.write( buffer, read, K3bWaveFileWriter::BigEndian );
      }
      else {
	if( ::write( m_fd, reinterpret_cast<void*>(buffer), read ) != read ) {
	  kdDebug() << "(K3bAudioImager::WorkThread) writing to fd " << m_fd << " failed." << endl;
	  lastError = K3bAudioImager::ERROR_FD_WRITE;
	  emitFinished(false);
	  return;
	}
      }

      if( m_canceled ) {
	emitCanceled();
	emitFinished(false);
	return;
      }

      //
      // Emit progress
      //
      totalRead += read;
      trackRead += read;
	
      emitSubPercent( 100*trackRead/track->length().audioBytes() );
      emitPercent( 100*totalRead/totalSize );
      emitProcessedSubSize( trackRead/1024/1024, track->length().audioBytes()/1024/1024 );
      emitProcessedSize( totalRead/1024/1024, totalSize/1024/1024 );
    }

    if( read < 0 ) {
      emitInfoMessage( i18n("Error while decoding track %1.").arg(trackNumber), K3bJob::ERROR );
      kdDebug() << "(K3bAudioImager::WorkThread) read error on track " << trackNumber
		<< " at pos " << K3b::Msf(trackRead/2352) << endl;
      lastError = K3bAudioImager::ERROR_DECODING_TRACK;
      emitFinished(false);
      return;
    }

    track = track->next();
    trackNumber++;
    imageFileIt++;
  }

  emitFinished(true);
}
示例#3
0
 void cancel() {
   m_canceled = true;
   emitCanceled();
   wait();
 }