File indexing completed on 2024-05-19 04:49:32
0001 /**************************************************************************************** 0002 * Copyright (c) 2009 Téo Mrnjavac <teo@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #include "TranscodingController.h" 0018 0019 #include "formats/TranscodingNullFormat.h" 0020 #include "formats/TranscodingAacFormat.h" 0021 #include "formats/TranscodingAlacFormat.h" 0022 #include "formats/TranscodingFlacFormat.h" 0023 #include "formats/TranscodingMp3Format.h" 0024 #include "formats/TranscodingOpusFormat.h" 0025 #include "formats/TranscodingVorbisFormat.h" 0026 #include "formats/TranscodingWmaFormat.h" 0027 0028 using namespace Transcoding; 0029 0030 Controller::Controller( QObject *parent ) 0031 : QObject( parent ) 0032 { 0033 m_formats.insert( JUST_COPY, new NullFormat( JUST_COPY ) ); 0034 m_formats.insert( INVALID, new NullFormat( INVALID ) ); 0035 m_formats.insert( AAC, new AacFormat() ); 0036 m_formats.insert( ALAC, new AlacFormat() ); 0037 m_formats.insert( FLAC, new FlacFormat() ); 0038 m_formats.insert( MP3, new Mp3Format() ); 0039 m_formats.insert( OPUS, new OpusFormat() ); 0040 m_formats.insert( VORBIS, new VorbisFormat() ); 0041 m_formats.insert( WMA2, new WmaFormat() ); 0042 0043 KProcess *verifyAvailability = new KProcess( this ); 0044 verifyAvailability->setOutputChannelMode( KProcess::MergedChannels ); 0045 verifyAvailability->setProgram( QStringLiteral("ffmpeg") ); 0046 *verifyAvailability << QStringLiteral( "-codecs" ); 0047 connect( verifyAvailability, QOverload<int, KProcess::ExitStatus>::of(&KProcess::finished), 0048 this, &Controller::onAvailabilityVerified ); 0049 verifyAvailability->start(); 0050 } 0051 0052 Controller::~Controller() 0053 { 0054 qDeleteAll( m_formats ); 0055 } 0056 0057 void 0058 Controller::onAvailabilityVerified( int exitCode, QProcess::ExitStatus exitStatus ) //SLOT 0059 { 0060 Q_UNUSED( exitCode ) 0061 Q_UNUSED( exitStatus ) 0062 sender()->deleteLater(); 0063 QString output = qobject_cast< KProcess * >( sender() )->readAllStandardOutput().data(); 0064 if( output.simplified().isEmpty() ) 0065 return; 0066 const QStringList lines = output.split( QRegExp( QStringLiteral("\r|\n") ), Qt::SkipEmptyParts ); 0067 foreach( Format *format, m_formats ) 0068 { 0069 bool formatAvailable = false; 0070 for( const QString &line : lines ) 0071 { 0072 formatAvailable |= format->verifyAvailability( line ); 0073 if( formatAvailable ) 0074 break; 0075 } 0076 if( formatAvailable ) 0077 m_availableEncoders.insert( format->encoder() ); 0078 } 0079 } 0080 0081 Format * 0082 Controller::format( Encoder encoder ) const 0083 { 0084 Q_ASSERT(m_formats.contains( encoder )); 0085 return m_formats.value( encoder ); 0086 } 0087