[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdemultimedia/kioslave/audiocd
From:       David Faure <faure () kde ! org>
Date:       2005-12-28 19:42:47
Message-ID: 1135798967.850406.17153.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 492099 by dfaure:

Abort when lame aborts, no point in keeping extracting the stuff for nothing.
Report messages from lame's stderr in the kio error box.
Not that the user can do much about
"kio_audiocd: Lame stderr: Unknown genre: Vocal Jazz.  Specify genre name or number"
though :(
I guess we need to parse lame --genre-list...


 M  +5 -1      audiocd.cpp  
 M  +6 -1      plugins/audiocdencoder.h  
 M  +15 -0     plugins/lame/encoderlame.cpp  
 M  +1 -0      plugins/lame/encoderlame.h  


--- trunk/KDE/kdemultimedia/kioslave/audiocd/audiocd.cpp #492098:492099
@@ -790,7 +790,11 @@
 		if(encoderProcessed == -1){
 			kdDebug(7117) << "Encoder processing error, stopping." << endl;
 			ok = false;
-			error( ERR_SLAVE_DEFINED, i18n( "Couldn't read %1: encoding failed" ).arg( fileName ) );
+			QString errMsg = i18n( "Couldn't read %1: encoding failed" ).arg( fileName );
+			QString details = encoder->lastErrorMessage();
+			if ( !details.isEmpty() )
+			    errMsg += "\n" + details;
+			error( ERR_SLAVE_DEFINED, errMsg );
 			break;
 		}
 		processed += encoderProcessed;
--- trunk/KDE/kdemultimedia/kioslave/audiocd/plugins/audiocdencoder.h #492098:492099
@@ -102,7 +102,7 @@
    * This function is most likly called many many times.
    * @param buf pointer to the audio that has been read in so far
    * @param frames the number of frames of audio that are in buf
-   * @return size of the data that was created by this function.
+   * @return size of the data that was created by this function, -1 on error.
    */
   virtual long read(int16_t * buf, int frames) = 0;
 
@@ -119,6 +119,11 @@
                    { Q_UNUSED(manager); return NULL; }; 
  
   /**
+   * Returns the last error message; called when e.g. read() returns -1.
+   */
+  virtual QString lastErrorMessage() const { return QString::null; }
+
+  /**
    * Helper function to load all of the AudioCD Encoders from libraries.
    * Uses KStandardDirs to find where libraries could be, opens all of the ones
    * that we might own audiocd_encoder_* and then uses the symbol 
--- trunk/KDE/kdemultimedia/kioslave/audiocd/plugins/lame/encoderlame.cpp #492098:492099
@@ -47,6 +47,8 @@
 public:
 	int bitrate;
 	bool waitingForWrite;
+	bool processHasExited;
+	QString lastErrorMessage;
 	uint lastSize;
 	KProcess *currentEncodeProcess;
 	KTempFile *tempFile;
@@ -55,6 +57,7 @@
 EncoderLame::EncoderLame(KIO::SlaveBase *slave) : QObject(), AudioCDEncoder(slave) {
 	d = new Private();
 	d->waitingForWrite = false;
+	d->processHasExited = false;
 	d->lastSize = 0;
 	loadSettings();
 }
@@ -180,6 +183,7 @@
 	QString prefix = locateLocal("tmp", "");
 	d->tempFile = new KTempFile(prefix, ".mp3");
 	d->tempFile->setAutoDelete(true);
+	d->lastErrorMessage = QString::null;
 
 	// -x bitswap
 	// -r raw/pcm
@@ -213,10 +217,14 @@
 
 void EncoderLame::processExited ( KProcess *process ){
 	kdDebug(7117) << "Lame Encoding process exited with: " << process->exitStatus() << endl;
+	d->processHasExited = true;
 }
 
 void EncoderLame::receivedStderr( KProcess * /*process*/, char *buffer, int /*buflen*/ ){
 	kdDebug(7117) << "Lame stderr: " << buffer << endl;
+	if ( !d->lastErrorMessage.isEmpty() )
+		d->lastErrorMessage += '\t';
+	d->lastErrorMessage += QString::fromLocal8Bit( buffer );
 }
 
 void EncoderLame::receivedStdout( KProcess * /*process*/, char *buffer, int /*length*/ ){
@@ -230,6 +238,8 @@
 long EncoderLame::read(int16_t *buf, int frames){
 	if(!d->currentEncodeProcess)
 		return 0;
+        if (d->processHasExited)
+		return -1;
 
 	// Pipe the raw data to lame
 	char * cbuf = reinterpret_cast<char *>(buf);
@@ -311,4 +321,9 @@
 }
 
 
+QString EncoderLame::lastErrorMessage() const
+{
+	return d->lastErrorMessage;
+}
+
 #include "encoderlame.moc"
--- trunk/KDE/kdemultimedia/kioslave/audiocd/plugins/lame/encoderlame.h #492098:492099
@@ -45,6 +45,7 @@
 	virtual long readInit(long size);
 	virtual long read(int16_t * buf, int frames);
 	virtual long readCleanup();
+	virtual QString lastErrorMessage() const;
   
 	virtual QWidget* getConfigureWidget(KConfigSkeleton** manager) const;
 
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic