name='generator' content='cgit v1.2.3-13-gbd6f'/>
aboutsummaryrefslogblamecommitdiff
path: root/src/plugins/Input/mpeg/decodermpegfactory.cpp
blob: 359539fe79299632b5fd2c9370e91b33524aa52f (plain) (tree)
1
2
                                                                            
                                                                            




















                                                                             

                     
                  







                               



                                           
                         
                              
                           
               
                        

                  
                           
      

                               

                                                                            






                                                                         
                                                                 




                                                                        
                                                    





                                                          
                                  







                                                             
                                         


                              
                                                     




                                                 
                                            

                             

                                                           



                                          

                                                      


         







                                                                   
                        

                           


               
                               


                                 
                               

                    

                                 
                               
                                                                     




                                                                    

                        




                                                                      
 

                                   
                            
     


                  
                                

                      
                                                             













                                                                                           
                                                                                               




                                                              


                 
                                                        



                                        
                                                                            
                                              
                                                                        




                                  
                                                                      
 
                         

                                                                 







                                                                    

                                                                     
     
                       


                                                                 


                                 


             
                                                                                                                 
 
                                          
 
                                   
                                           
 

                                                                                 
 
                                    



                                                                     
                                                        



                                                                              
                                                                  
 

                                   



                                        


                                        
                                                                                        


                                         
                                                                                   


                                         
                                    




                                          
 



                                                            
 

                                                          
 
                                                
             






                                                                                                  
                                                         
 










                                                                         
                 














                                                                                                                    
                 
                                                
                 




                                                                                           
                 




                                 
             




                                                                           
                                                                
             


                                                                        


             
 
                                                                    



                                                                                  
                                                          










                                                                                                                    
                                                                             






                                                                
                                                                        

































                                                                                                                         

 
                                                                                          
 
                                                                 










                                                                    




                                                                              
                                               


                                                        
                  



                                                         

                                                                             





                                               
 
/***************************************************************************
 *   Copyright (C) 2008-2021 by Ilya Kotov                                 *
 *   forkotov02@ya.ru                                                      *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 ***************************************************************************/

#include <QDialog>
#include <QMessageBox>
#include <QSettings>
#include <QFile>
#include <QTextCodec>
#include <QtDebug>
#include <taglib/tag.h>
#include <taglib/fileref.h>
#include <taglib/id3v1tag.h>
#include <taglib/id3v2tag.h>
#include <taglib/apetag.h>
#include <taglib/tfile.h>
#include <taglib/mpegfile.h>
#include <taglib/tfilestream.h>
#include <taglib/id3v2tag.h>
#include <taglib/id3v2header.h>
#include <taglib/textidentificationframe.h>
#include <taglib/id3v2framefactory.h>
#include "tagextractor.h"
#include "mpegmetadatamodel.h"
#include "settingsdialog.h"
#ifdef WITH_MAD
#include "decoder_mad.h"
#endif
#ifdef WITH_MPG123
#include "decoder_mpg123.h"
#endif
#include "decodermpegfactory.h"

#define CSTR_TO_QSTR(str,utf) codec->toUnicode(str.toCString(utf)).trimmed()

// DecoderMPEGFactory

DecoderMPEGFactory::DecoderMPEGFactory()
{
    //detecting rusxmms patch
    m_using_rusxmms = false;
    char str[] = { char(0xF2), char(0xE5), char(0xF1), char(0xF2), '\0'};
    QTextCodec *codec = QTextCodec::codecForName("windows-1251");
    TagLib::String tstr(str);
    if(codec->toUnicode(str) == QString::fromUtf8(tstr.toCString(true)))
    {
        qDebug("DecoderMADFactory: found taglib with rusxmms patch");
        m_using_rusxmms = true;
        TagExtractor::setForceUtf8(m_using_rusxmms);
    }
}

bool DecoderMPEGFactory::canDecode(QIODevice *input) const
{
    char buf[8192];
    qint64 dataSize = sizeof(buf);

    if(input->peek(buf, sizeof(buf)) != sizeof(buf))
        return false;

    if (!memcmp(buf, "FLV", 3)) //skip Macromedia Flash Video
        return false;

    if (!memcmp(buf + 8, "WAVE", 4))
        return !memcmp(buf + 20, "U" ,1);

    if(!memcmp(buf, "ID3", 3))
    {
        TagLib::ByteVector byteVector(buf, dataSize);