aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Transports/http/httpinputsource.h
blob: cea3bc7b4a95a6804e5430cc7ecb08f0c6f26901 (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
48
/***************************************************************************
 *   Copyright (C) 2009-2012 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.         *
 ***************************************************************************/

#ifndef HTTPINPUTSOURCE_H
#define HTTPINPUTSOURCE_H

#include <qmmp/inputsource.h>

class HttpStreamReader;

/**
    @author Ilya Kotov <forkotov02@hotmail.ru>
*/
class HTTPInputSource : public InputSource
{
Q_OBJECT
public:
    HTTPInputSource(const QString &url, QObject *parent = 0);

    QIODevice *ioDevice();
    bool initialize();
    bool isReady();
    bool isWaiting();
    QString contentType() const;

private:
    HttpStreamReader *m_reader;

};

#endif // HTTPINPUTSOURCE_H
7 06:39:56 +0000 prepare for sid plugin implementation' href='/qmmp/commit/src/plugins/Input/sid/decoder_sid.cpp?h=main&id=c9da71f2828b7940f62e77615915c906c04f8af9'>c9da71f28
b470ca97b

986b28417

b55c45843
986b28417

fef0263b8

9eded5482
fef0263b8
9eded5482

fef0263b8
c9da71f28
986b28417
c9da71f28
986b28417
c9da71f28


fef0263b8
c9da71f28
fef0263b8
c9da71f28
fef0263b8
c9da71f28


986b28417
fef0263b8
986b28417




986b28417

7681777e3


86d896deb

64c175369
fef0263b8
86d896deb






7681777e3
b917024aa
7681777e3









c9da71f28


7681777e3


c9da71f28

7681777e3

c9da71f28






fef0263b8
c9da71f28





b470ca97b
49284bb0d
c9da71f28



868b4f765
c9da71f28








868b4f765
c9da71f28



74fe5b8ff
c9da71f28
b470ca97b




fef0263b8
c9da71f28
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
                                                                            
                                                                            
                                                                            
















                                                                             

                    
                             




                                       
                                     

                                  
                                  


                        





                                                                        







                             

                          

                          
                                              

                                               

                                  
     
                                                                                      

                     
                                          
 
                                  
     
                                                             


                     
                             
 
                           
     
                                                                 


                     
                                       
                                                    




                                                                

                          


                                                                 

                                                  
                                        
                              






                                                              
 
                             









                                                                   


                                           


                                                                                 

                                         

                                                                         






                                                                                    
                                





                                                                                  
                                                        
                                                     



                                            
                                    








                                 
                               



             
                                                         
 




                                                                         
                                                     
 
/***************************************************************************
 *   Copyright (C) 2013-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 <QFileInfo>
#include <QSettings>
#include <QRegularExpression>
#include <sidplayfp/sidplayfp.h>
#include <sidplayfp/SidTune.h>
#include <sidplayfp/sidbuilder.h>
#include <sidplayfp/SidConfig.h>
#include <sidplayfp/builders/residfp.h>
#include <sidplayfp/builders/resid.h>
#include <sidplayfp/SidInfo.h>
#include <sidplayfp/SidTuneInfo.h>
#include <sidplayfp/SidDatabase.h>
#include "decoder_sid.h"

// Decoder class
DecoderSID::DecoderSID(SidDatabase *db, const QString &url) : Decoder(),
    m_url(url),
    m_player(new sidplayfp()),
    m_db(db),
    m_tune(nullptr)
{}

DecoderSID::~DecoderSID()
{
    delete m_player;
}

bool DecoderSID::initialize()
{
    m_length_in_bytes = 0;
    m_read_bytes = 0;
    QString path = m_url;
    path.remove("sid://");
    path.remove(QRegularExpression("#\\d+$"));
    int track = m_url.section("#", -1).toInt();

    m_tune.load(qPrintable(path));
    if(!m_tune.getInfo())
    {
        qWarning("DecoderSID: unable to load tune, error: %s", m_tune.statusString());
        return false;
    }
    int count = m_tune.getInfo()->songs();

    if(track > count || track < 1)
    {
        qWarning("DecoderSID: track number is out of range");
        return false;
    }

    m_tune.selectSong(track);

    if(!m_tune.getStatus())
    {
        qWarning("DecoderSID: error: %s", m_tune.statusString());
        return false;
    }

    //send metadata for pseudo-protocol
    const SidTuneInfo *tune_info = m_tune.getInfo();
    QMap<Qmmp::MetaData, QString> metadata;
    metadata.insert(Qmmp::TITLE,  tune_info->infoString(0));
    metadata.insert(Qmmp::ARTIST, tune_info->infoString(1));
    metadata.insert(Qmmp::COMMENT, tune_info->commentString(0));
    metadata.insert(Qmmp::TRACK, QString("%1").arg(track));
    addMetaData(metadata);

    //read settings
    QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
    settings.beginGroup("SID");
    if(settings.value("use_hvsc", false).toBool())
    {
        char md5[SidTune::MD5_LENGTH+1];
        m_tune.createMD5(md5);
        m_length = m_db->length(md5, track);
    }

    if(m_length <= 0)
        m_length = settings.value("song_length", 180).toInt();

    qDebug("DecoderSID: song length: %d", m_length);

    sidbuilder *rs = nullptr;
    if(settings.value("engine", "residfp").toString() == "residfp")
    {
        rs = new ReSIDfpBuilder("ReSIDfp builder");
        qDebug("DecoderSID: using ReSIDfp emulation");
    }
    else
    {
        rs = new ReSIDBuilder("ReSID builder");
        qDebug("DecoderSID: using ReSID emulation");
    }
    rs->create(m_player->info().maxsids());

    SidConfig cfg = m_player->config();
    cfg.frequency    = settings.value("sample_rate", 44100).toInt();
    int sm = settings.value("resampling_method", SidConfig::INTERPOLATE).toInt();
    cfg.samplingMethod = (SidConfig::sampling_method_t) sm;
    cfg.playback     = SidConfig::STEREO;
    cfg.sidEmulation = rs;
    cfg.fastSampling = settings.value("fast_resampling", false).toBool();
    settings.endGroup();

    if(!m_player->config(cfg))
    {
        qWarning("DecoderSID: unable to load config, error: %s", m_player->error());
        return false;
    }

    if(!m_player->load(&m_tune))
    {
        qWarning("DecoderSID: unable to load tune, error: %s", m_player->error());
        return false;
    }

    configure(44100, 2);
    m_length_in_bytes = audioParameters().sampleRate() *
            audioParameters().frameSize() * m_length;
    qDebug("DecoderSID: initialize succes");
    return true;
}

qint64 DecoderSID::totalTime() const
{
    return 0;
}

void DecoderSID::seek(qint64 pos)
{
    Q_UNUSED(pos);
}

int DecoderSID::bitrate() const
{
    return 8;
}

qint64 DecoderSID::read(unsigned char *data, qint64 size)
{
    size = qMin(size, qMax(m_length_in_bytes - m_read_bytes, qint64(0)));
    size -= size % 4;
    if(size <= 0)
        return 0;
    m_read_bytes += size;
    return m_player->play((short *)data, size/2) * 2;
}