aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Visual/projectm/projectmwrapper.cpp
blob: 2241d141d6f6594f848872cca7004440f623aa4e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/***************************************************************************
 *   Copyright (C) 2013 by Ilya Kotov                                      *
 *   forkotov02@hotmail.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 "projectmwrapper.h"

ProjectMWrapper::ProjectMWrapper(std::string config_file, int flags, QObject *parent) :
    QObject(parent), projectM(config_file, flags)
{
}

ProjectMWrapper::ProjectMWrapper(projectM::Settings settings, int flags, QObject *parent) :
    QObject(parent), projectM(settings, flags)
{
}

ProjectMWrapper::~ProjectMWrapper()
{
}

void ProjectMWrapper::selectPreset(int index)
{
    if(index >= 0)
        projectM::selectPreset(index);
}

void ProjectMWrapper::presetSwitchedEvent(bool isHardCut, unsigned int index) const
{
    Q_UNUSED(isHardCut);
    emit currentPresetChanged(index);
}
;trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> 2009-09-23 12:40:02 +0000 committer trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> 2009-09-23 12:40:02 +0000 ported ffmpeg plugin (Closes issue 170)' href='/qmmp/commit/src/plugins/Input/ffmpeg/decoderffmpegfactory.cpp?id=e231bb9701639b20dd917865040b727af9b0b77e'>e231bb970
e8d99698c
2d622fd9b
998a80dff
2d622fd9b




1dd7b2517

c82014160
1dd7b2517


c82014160
1dd7b2517

d489c39c0
2d622fd9b
aa3f57c02
d489c39c0
cae079da6

6a5a5359f
d489c39c0

6a5a5359f
11b7655bb
d489c39c0

11b7655bb
0fc031da9





038c5112b
0fc031da9
013ee07b5
0fc031da9
013ee07b5
0fc031da9
6a5a5359f
0fc031da9
6a5a5359f
0fc031da9
961485569
0fc031da9
3f6b469fa
0fc031da9
fe09b0a7a
0fc031da9
fe09b0a7a
ebbe48277

11b7655bb
2d622fd9b

2111b8272
c6d40b3e6
ae75e5707
6d082ac87


2b4c4d7eb
639c76276
c3972ebea























ebbe48277

6d082ac87




2a9593b20
75719b8c8
2b4c4d7eb
aa3f57c02
2b4c4d7eb
855778271
aa3f57c02
855778271
aa3f57c02
d75bbe5a8
aa3f57c02
0a29533bd
3f6b469fa

aa3f57c02


7b1cb9167
aa3f57c02
3f6b469fa
6a5a5359f




ecc490d2a
013ee07b5

11b7655bb
998a80dff
c031570b3
afd64439f
c6d40b3e6
2d622fd9b
e231bb970
2d622fd9b
aab3498cd
998a80dff


2d622fd9b

0027a3d62
2d622fd9b
998a80dff











ce79cbc21
bad6ade61
ce79cbc21

b917024aa
2e50594a7
3f525068c
998a80dff
3f525068c
998a80dff
3f525068c
5c583bfdd

ce79cbc21

5c583bfdd
ce79cbc21
b917024aa
5c583bfdd
998a80dff














7e1ff6bc1


998a80dff




0027a3d62
26724c66d
998a80dff












b917024aa
ae4597427
b917024aa
ae4597427
b917024aa


ae4597427








2ee8fd4c1
ae4597427
f73b33648
ae4597427

6e7107f38
b917024aa
6e7107f38
b917024aa
2ee8fd4c1

ae4597427


2ee8fd4c1
ae4597427


2ee8fd4c1
ae4597427
2ee8fd4c1
ae4597427
2ee8fd4c1
ae4597427
2ee8fd4c1
0027a3d62
2ee8fd4c1
0027a3d62
26724c66d
0027a3d62
2783c49ba
ce79cbc21
2d622fd9b

1cc4b9337
2d622fd9b
4444443a1
1cc4b9337
2d622fd9b

e8d99698c




2d622fd9b




a1f385f90



e8d99698c




a1f385f90



41c8a60a2
2d622fd9b
2111b8272




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
                                                                            
                                                                            
                                                                            













                                                                            
                                                                            

                                                                             
                    
                      

                           
           
                                 
                               
                           
                             

 
                                
                           
                           
                              




                                 

                                            
                                                                     


                            
      

 
                                                        
 
                                               
 

                               
                                                          

                                                                          
                                       
                     

                                                       
                     





                                                                    
                    
                                                                 
                    
                                                                  
                    
                                                                 
                    
                                                                 
                    
                                                                 
                    
                                                                 
                    
                                                                 
                    
                                                                                              
                    

                                      
                 

 
                                                          
 
                                                                 


                                                                                                                    
                                                                       
 























                                                                                         

                                              




                                                   
 
                                 
                                          
                                 
                                                  
                                 
                                                    
                                 
                                                
                                 
                                                               
                                 

                                                            


                                                                                
                                               
     
                                 




                                                                         
                                    

                                  
                               
                                     
                             
                      
 
 
                                                                            
 
                                    


                                              

 
                                                                                                                   
 











                                                                                
 
                                   

                                           
                                  
 
               
                                                                                     
     
                                                                                          
      

                                                            

                                    
     
 
                                           
 














                                                                                    


                                                                                    




                                                                                                        
                                   
     












                                                                                        
                                                                               
                                                                                             
                                                                                 
                                                                                     


                                                                                   








                                                                               
                 
                                                                 
                 

                                                              
                  
                                                                   
                  
                                                                         

                 


                                                                                                
                  


                                                                                         
                   
                                                                                       
                 
                                                                                   
                 
                                                                                   
                
                                                    
                 
                                                      
     
 
                              
                                       

 
                                                                                            
 
                       
                                         

 




                                                        




                                                                



                                                        




                                                       



                                                            
                                                                         
 




                                                 
/***************************************************************************
 *   Copyright (C) 2008-2020 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 <QSettings>
#include <QMessageBox>
#include <QFileInfo>
#include <qmmp/cueparser.h>
extern "C"{
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libavutil/dict.h>
#include <libavutil/avutil.h>
}

#include "ffmpegmetadatamodel.h"
#include "settingsdialog.h"
#include "decoder_ffmpeg.h"
#include "decoder_ffmpegcue.h"
#include "decoderffmpegfactory.h"


// DecoderFFmpegFactory

DecoderFFmpegFactory::DecoderFFmpegFactory()
{
#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58,10,100)) //ffmpeg-3.5
    avcodec_register_all();
    avformat_network_init();
    av_register_all();
#endif
}

bool DecoderFFmpegFactory::canDecode(QIODevice *i) const
{
    QStringList filters = properties().filters;

    AVProbeData pd;
    memset(&pd, 0, sizeof(pd));
    uint8_t buf[PROBE_BUFFER_SIZE + AVPROBE_PADDING_SIZE];
    pd.buf_size = i->peek((char*)buf, sizeof(buf) - AVPROBE_PADDING_SIZE);
    pd.buf = buf;
    if(pd.buf_size < PROBE_BUFFER_SIZE)
        return false;
    AVInputFormat *fmt = av_probe_input_format(&pd, 1);
    if(!fmt)
        return false;

    QStringList formats = QString::fromLatin1(fmt->name).split(",");

    if(filters.contains("*.wma") && formats.contains("asf"))
        return true;
    else if(filters.contains("*.mp3") && formats.contains("mp3"))
        return true;
    else if(filters.contains("*.aac") && formats.contains("aac"))
        return true;
    else if(filters.contains("*.ac3") && formats.contains("eac3"))
        return true;
    else if(filters.contains("*.dts") && formats.contains("dts"))
        return true;
    else if(filters.contains("*.mka") && formats.contains("mka"))
        return true;
    else if(filters.contains("*.vqf") && formats.contains("vqf"))
        return true;
    else if(filters.contains("*.ape") && formats.contains("ape"))
        return true;
    else if(filters.contains("*.tta") && formats.contains("tta"))
        return true;
    else if(filters.contains("*.m4a") && (formats.contains("m4a") || formats.contains("mp4")))
        return true;
    else if(filters.contains("*.tak"))
        return true;
    return false;
}

DecoderProperties DecoderFFmpegFactory::properties() const
{
    QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
    QStringList filters = {
        "*.wma", "*.ape", "*.tta", "*.m4a", "*.aac", "*.ra", "*.shn", "*.vqf", "*.ac3", "*.tak", "*.dsf", "*.dsdiff"
    };
    filters = settings.value("FFMPEG/filters", filters).toStringList();

    if(!avcodec_find_decoder(AV_CODEC_ID_WMAV1))
        filters.removeAll("*.wma");
    if(!avcodec_find_decoder(AV_CODEC_ID_APE))
        filters.removeAll("*.ape");
    if(!avcodec_find_decoder(AV_CODEC_ID_TTA))
        filters.removeAll("*.tta");
    if(!avcodec_find_decoder(AV_CODEC_ID_AAC))
        filters.removeAll("*.aac");
    if(!avcodec_find_decoder(AV_CODEC_ID_MP3))
        filters.removeAll("*.mp3");
    if(!avcodec_find_decoder(AV_CODEC_ID_AAC) && !avcodec_find_decoder(AV_CODEC_ID_ALAC))
        filters.removeAll("*.m4a");
    if(!avcodec_find_decoder(AV_CODEC_ID_RA_288))
        filters.removeAll("*.ra");
    if(!avcodec_find_decoder(AV_CODEC_ID_SHORTEN))
        filters.removeAll("*.shn");
    if(!avcodec_find_decoder(AV_CODEC_ID_EAC3))
        filters.removeAll("*.ac3");
    if(!avcodec_find_decoder(AV_CODEC_ID_DTS))
        filters.removeAll("*.dts");
    if(!avcodec_find_decoder(AV_CODEC_ID_TRUEHD))
        filters.removeAll("*.mka");
    if(!avcodec_find_decoder(AV_CODEC_ID_TWINVQ))
        filters.removeAll("*.vqf");
    if(!avcodec_find_decoder(AV_CODEC_ID_TAK))
        filters.removeAll("*.tak");
    if(!avcodec_find_decoder(AV_CODEC_ID_DSD_LSBF))
    {
        filters.removeAll("*.dsf");
        filters.removeAll("*.dsdiff");
    }

    DecoderProperties properties;
    properties.name = tr("FFmpeg Plugin");
    properties.filters = filters;
    properties.description = tr("FFmpeg Formats");
    if(filters.contains("*.wma"))
        properties.contentTypes << "audio/x-ms-wma";
    if(filters.contains("*.mp3"))
        properties.contentTypes << "audio/mpeg";
    if(filters.contains("*.aac"))
        properties.contentTypes << "audio/aac" << "audio/aacp";
    if(filters.contains("*.shn"))
        properties.contentTypes << "audio/x-ffmpeg-shorten";
    if(filters.contains("*.m4a"))
    {
        properties.contentTypes << "audio/3gpp" << "audio/3gpp2" << "audio/mp4";
        properties.contentTypes << "audio/MP4A-LATM" << "audio/mpeg4-generic";
        properties.contentTypes << "audio/m4a";
    }
    if(filters.contains("*.ac3"))
        properties.contentTypes << "audio/ac3" << "audio/eac3";
    if(filters.contains("*.dts"))
        properties.contentTypes << "audio/dts";
    if(filters.contains("*.mka"))
        properties.contentTypes << "audio/true-hd" << "audio/x-matroska";
    properties.shortName = "ffmpeg";
    properties.hasAbout = true;
    properties.hasSettings = true;
    properties.noInput = false;
    properties.protocols << "ffmpeg";
    properties.priority = 10;
    return properties;
}

Decoder *DecoderFFmpegFactory::create(const QString &path, QIODevice *input)
{
    if(path.startsWith("ffmpeg://"))
        return new DecoderFFmpegCue(path);
    else
        return new DecoderFFmpeg(path, input);
}

QList<TrackInfo *> DecoderFFmpegFactory::createPlayList(const QString &path, TrackInfo::Parts parts, QStringList *)
{
    int track = -1; //cue track
    QString filePath = path;

    if(path.contains("://")) //is it cue track?
    {
        filePath.remove("ffmpeg://");
        filePath.remove(QRegExp("#\\d+$"));
        track = path.section("#", -1).toInt();
        parts = TrackInfo::AllParts; //extract all metadata for single cue track
    }

     TrackInfo *info = new TrackInfo(filePath);

    if(parts == TrackInfo::Parts())
        return QList<TrackInfo*>() << info;

    AVFormatContext *in = nullptr;

#ifdef Q_OS_WIN
    if(avformat_open_input(&in, filePath.toUtf8().constData(), nullptr, nullptr) < 0)
#else
    if(avformat_open_input(&in, filePath.toLocal8Bit().constData(), nullptr, nullptr) < 0)
#endif
    {
        qDebug("DecoderFFmpegFactory: unable to open file");
        delete info;
        return  QList<TrackInfo*>();
    }

    avformat_find_stream_info(in, nullptr);

    if(parts & TrackInfo::Properties)
    {
        int idx = av_find_best_stream(in, AVMEDIA_TYPE_AUDIO, -1, -1, nullptr, 0);
        if(idx >= 0)
        {
    #if (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57,48,0)) //ffmpeg-3.1:  57.48.101
            AVCodecParameters *c = in->streams[idx]->codecpar;
    #else
            AVCodecContext *c = in->streams[idx]->codec;
    #endif
            info->setValue(Qmmp::BITRATE, int(c->bit_rate) / 1000);
            info->setValue(Qmmp::SAMPLERATE, c->sample_rate);
            info->setValue(Qmmp::CHANNELS, c->channels);
            info->setValue(Qmmp::BITS_PER_SAMPLE, c->bits_per_raw_sample);

            AVCodec *codec = avcodec_find_decoder(c->codec_id);
            if(codec)
                info->setValue(Qmmp::FORMAT_NAME, QString::fromLatin1(codec->name));
            info->setValue(Qmmp::FILE_SIZE, QFileInfo(filePath).size()); //adds file size for cue tracks
            info->setDuration(in->duration * 1000 / AV_TIME_BASE);
        }
    }

    if(parts & TrackInfo::MetaData)
    {
        AVDictionaryEntry *cuesheet = av_dict_get(in->metadata,"cuesheet",nullptr,0);
        if(cuesheet)
        {
            CueParser parser(cuesheet->value);
            parser.setDuration(info->duration());
            parser.setProperties(info->properties());
            parser.setUrl("ffmpeg", filePath);

            avformat_close_input(&in);
            delete info;
            return (track > 0) ? parser.createPlayList(track) : parser.createPlayList();
        }

        AVDictionaryEntry *album = av_dict_get(in->metadata,"album",nullptr,0);
        AVDictionaryEntry *album_artist = av_dict_get(in->metadata,"album_artist",nullptr,0);
        AVDictionaryEntry *artist = av_dict_get(in->metadata,"artist",nullptr,0);
        AVDictionaryEntry *composer = av_dict_get(in->metadata,"composer",nullptr,0);
        AVDictionaryEntry *comment = av_dict_get(in->metadata,"comment",nullptr,0);
        AVDictionaryEntry *genre = av_dict_get(in->metadata,"genre",nullptr,0);
        AVDictionaryEntry *title = av_dict_get(in->metadata,"title",nullptr,0);
        AVDictionaryEntry *year = av_dict_get(in->metadata,"date",nullptr,0);
        AVDictionaryEntry *track = av_dict_get(in->metadata,"track",nullptr,0);

        if(!album)
            album = av_dict_get(in->metadata,"WM/AlbumTitle",nullptr,0);

        if(!artist)
            artist = av_dict_get(in->metadata,"author",nullptr,0);

        if(!year)
            year = av_dict_get(in->metadata,"WM/Year",nullptr,0);
        if(!year)
            year = av_dict_get(in->metadata,"year",nullptr,0);

        if(!track)
            track = av_dict_get(in->metadata,"WM/Track",nullptr,0);
        if(!track)
            track = av_dict_get(in->metadata,"WM/TrackNumber",nullptr,0);

        if(album)
            info->setValue(Qmmp::ALBUM, QString::fromUtf8(album->value).trimmed());
        if(album_artist)
            info->setValue(Qmmp::ALBUMARTIST, QString::fromUtf8(album_artist->value).trimmed());
        if(artist)
            info->setValue(Qmmp::ARTIST, QString::fromUtf8(artist->value).trimmed());
        if(composer)
            info->setValue(Qmmp::COMPOSER, QString::fromUtf8(composer->value).trimmed());
        if(comment)
            info->setValue(Qmmp::COMMENT, QString::fromUtf8(comment->value).trimmed());
        if(genre)
            info->setValue(Qmmp::GENRE, QString::fromUtf8(genre->value).trimmed());
        if(title)
            info->setValue(Qmmp::TITLE, QString::fromUtf8(title->value).trimmed());
        if(year)
            info->setValue(Qmmp::YEAR, year->value);