~ubuntu-branches/ubuntu/natty/kdemultimedia/natty-proposed

« back to all changes in this revision

Viewing changes to kioslave/audiocd/plugins/lame/encoderlame.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Debian Qt/KDE Maintainers
  • Date: 2011-05-26 02:41:36 UTC
  • mfrom: (0.2.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 108.
  • Revision ID: james.westby@ubuntu.com-20110526024136-jjwsigfy402jhupm
Tags: upstream-4.6.3
ImportĀ upstreamĀ versionĀ 4.6.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
#include <kdebug.h>
25
25
#include <qgroupbox.h>
26
 
#include <k3process.h>
27
 
 
 
26
#include <qstringlist.h>
28
27
#include <kglobal.h>
29
28
#include <klocale.h>
30
29
#include <qapplication.h>
31
30
#include <qfileinfo.h>
32
31
#include <ktemporaryfile.h>
33
32
#include <kstandarddirs.h>
34
 
#include "collectingprocess.h"
 
33
// #include "collectingprocess.h"
35
34
 
36
35
extern "C"
37
36
{
51
50
        QString lastErrorMessage;
52
51
        QStringList genreList;
53
52
        uint lastSize;
54
 
        K3Process *currentEncodeProcess;
 
53
        KProcess *currentEncodeProcess;
55
54
        KTemporaryFile *tempFile;
56
55
};
57
56
 
69
68
 
70
69
QWidget* EncoderLame::getConfigureWidget(KConfigSkeleton** manager) const {
71
70
  (*manager) = Settings::self();
72
 
  KGlobal::locale()->insertCatalog("audiocd_encoder_lame");
 
71
  KGlobal::locale()->insertCatalog( QLatin1String( "audiocd_encoder_lame" ));
73
72
  EncoderLameConfig *config = new EncoderLameConfig();
74
73
  config->cbr_settings->hide();
75
74
  return config;
82
81
 
83
82
        // Ask lame for the list of genres it knows; otherwise it barfs when doing
84
83
        // e.g. lame --tg 'Vocal Jazz'
85
 
    CollectingProcess proc;
 
84
        KProcess proc;
 
85
        proc.setOutputChannelMode(KProcess::MergedChannels);
86
86
        proc << "lame" << "--genre-list";
87
 
        proc.start(K3Process::Block, K3Process::Stdout);
88
 
 
89
 
        if(proc.exitStatus() != 0)
90
 
                return false;
91
 
 
92
 
        QString str = QString::fromLocal8Bit( proc.collectedStdout() );
93
 
    d->genreList = str.split( '\n', QString::SkipEmptyParts );
 
87
        proc.execute();
 
88
 
 
89
        if(proc.exitStatus() != QProcess::NormalExit)
 
90
                return FALSE;
 
91
 
 
92
        QByteArray array = proc.readAll();
 
93
        QString str = QString::fromLocal8Bit( array );
 
94
        d->genreList = str.split( '\n', QString::SkipEmptyParts );
94
95
        // Remove the numbers in front of every genre
95
96
        for( QStringList::Iterator it = d->genreList.begin(); it != d->genreList.end(); ++it ) {
96
97
                QString& genre = *it;
228
229
}
229
230
 
230
231
long EncoderLame::readInit(long /*size*/){
231
 
        // Create K3Process
232
 
        d->currentEncodeProcess = new K3Process(0);
 
232
        // Create KProcess
 
233
        d->currentEncodeProcess = new KProcess();
233
234
        d->tempFile = new KTemporaryFile();
234
235
        d->tempFile->setSuffix(".mp3");
235
236
        d->tempFile->open();
249
250
        //kDebug(7117) << d->currentEncodeProcess->args();
250
251
 
251
252
 
252
 
        connect(d->currentEncodeProcess, SIGNAL(receivedStdout(K3Process *, char *, int)),
253
 
                         this, SLOT(receivedStdout(K3Process *, char *, int)));
254
 
        connect(d->currentEncodeProcess, SIGNAL(receivedStderr(K3Process *, char *, int)),
255
 
                         this, SLOT(receivedStderr(K3Process *, char *, int)));
256
 
        connect(d->currentEncodeProcess, SIGNAL(wroteStdin(K3Process *)),
257
 
                         this, SLOT(wroteStdin(K3Process *)));
 
253
        connect(d->currentEncodeProcess, SIGNAL(readyReadStandardOutput()),
 
254
                         this, SLOT(receivedStdout()));
 
255
        connect(d->currentEncodeProcess, SIGNAL(readyReadStandardError()),
 
256
                         this, SLOT(receivedStderr()));
 
257
//      connect(d->currentEncodeProcess, SIGNAL(bytesWritten()),
 
258
//                          this, SLOT(wroteStdin()));
258
259
 
259
 
        connect(d->currentEncodeProcess, SIGNAL(processExited(K3Process *)),
260
 
                         this, SLOT(processExited(K3Process *)));
 
260
        connect(d->currentEncodeProcess, SIGNAL(finished(int, QProcess::ExitStatus)),
 
261
                         this, SLOT(processExited(int, QProcess::ExitStatus)));
261
262
 
262
263
        // Launch!
263
 
        d->currentEncodeProcess->start(K3Process::NotifyOnExit, K3ShellProcess::All);
 
264
        d->currentEncodeProcess->setOutputChannelMode(KProcess::SeparateChannels);
 
265
        d->currentEncodeProcess->start();
264
266
        return 0;
265
267
}
266
268
 
267
 
void EncoderLame::processExited ( K3Process *process ){
268
 
        kDebug(7117) << "Lame Encoding process exited with: " << process->exitStatus();
 
269
void EncoderLame::processExited ( int exitCode, QProcess::ExitStatus /*status*/ ){
 
270
        kDebug(7117) << "Lame Encoding process exited with: " << exitCode;
269
271
        d->processHasExited = true;
270
272
}
271
273
 
272
 
void EncoderLame::receivedStderr( K3Process * /*process*/, char *buffer, int /*buflen*/ ){
273
 
        kDebug(7117) << "Lame stderr: " << buffer;
 
274
void EncoderLame::receivedStderr(){
 
275
        QByteArray error = d->currentEncodeProcess->readAllStandardError();
 
276
        kDebug(7117) << "Lame stderr: " << error;
274
277
        if ( !d->lastErrorMessage.isEmpty() )
275
278
                d->lastErrorMessage += '\t';
276
 
        d->lastErrorMessage += QString::fromLocal8Bit( buffer );
277
 
}
278
 
 
279
 
void EncoderLame::receivedStdout( K3Process * /*process*/, char *buffer, int /*length*/ ){
280
 
        kDebug(7117) << "Lame stdout: " << buffer;
281
 
}
282
 
 
283
 
void EncoderLame::wroteStdin( K3Process * /*procces*/ ){
284
 
        d->waitingForWrite = false;
285
 
}
 
279
        d->lastErrorMessage += QString::fromLocal8Bit( error );
 
280
}
 
281
 
 
282
void EncoderLame::receivedStdout(){
 
283
        QString output = QString::fromLocal8Bit(d->currentEncodeProcess->readAllStandardOutput());
 
284
        kDebug(7117) << "Lame stdout: " << output;
 
285
}
 
286
 
 
287
// void EncoderLame::wroteStdin(){
 
288
//      d->waitingForWrite = false;
 
289
// }
286
290
 
287
291
long EncoderLame::read(int16_t *buf, int frames){
288
292
        if(!d->currentEncodeProcess)
292
296
 
293
297
        // Pipe the raw data to lame
294
298
        char * cbuf = reinterpret_cast<char *>(buf);
295
 
        d->currentEncodeProcess->writeStdin( cbuf, frames*4);
296
 
 
 
299
        d->currentEncodeProcess->write(cbuf, frames * 4);
297
300
        // We can't return until the buffer has been written
298
 
        d->waitingForWrite = true;
299
 
        while(d->waitingForWrite && d->currentEncodeProcess->isRunning()){
300
 
                qApp->processEvents();
301
 
                usleep(1);
302
 
        }
 
301
        d->currentEncodeProcess->waitForBytesWritten(-1);
303
302
 
304
303
        // Determine the file size increase
305
304
        QFileInfo file(d->tempFile->fileName());
313
312
                return 0;
314
313
 
315
314
        // Let lame tag the first frame of the mp3
316
 
        d->currentEncodeProcess->closeStdin();
317
 
        while( d->currentEncodeProcess->isRunning()){
318
 
                qApp->processEvents();
319
 
                usleep(1);
320
 
        }
 
315
        d->currentEncodeProcess->closeWriteChannel();
 
316
        d->currentEncodeProcess->waitForFinished(-1);
321
317
 
322
318
        // Now copy the file out of the temp into kio
323
319
        QFile file( d->tempFile->fileName() );