2018-02-27 18:06:05 +01:00
|
|
|
/*
|
|
|
|
* Strawberry Music Player
|
|
|
|
* This file was part of Clementine.
|
|
|
|
* Copyright 2010, David Sansome <me@davidsansome.com>
|
2021-03-20 21:14:47 +01:00
|
|
|
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
|
2018-02-27 18:06:05 +01:00
|
|
|
*
|
|
|
|
* Strawberry 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 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
2018-08-09 18:10:03 +02:00
|
|
|
*
|
2018-02-27 18:06:05 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SONGLOADER_H
|
|
|
|
#define SONGLOADER_H
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <memory>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <functional>
|
|
|
|
#include <glib.h>
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_GSTREAMER
|
2018-05-01 00:41:33 +02:00
|
|
|
# include <gst/gst.h>
|
2018-02-27 18:06:05 +01:00
|
|
|
#endif
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QtGlobal>
|
2018-02-27 18:06:05 +01:00
|
|
|
#include <QObject>
|
|
|
|
#include <QThreadPool>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QByteArray>
|
|
|
|
#include <QSet>
|
|
|
|
#include <QString>
|
2019-04-20 15:28:16 +02:00
|
|
|
#include <QStringList>
|
2018-02-27 18:06:05 +01:00
|
|
|
#include <QUrl>
|
|
|
|
|
|
|
|
#include "song.h"
|
|
|
|
|
2020-02-08 03:40:30 +01:00
|
|
|
class QTimer;
|
2018-02-27 18:06:05 +01:00
|
|
|
class Player;
|
2018-05-01 00:41:33 +02:00
|
|
|
class CollectionBackendInterface;
|
2018-02-27 18:06:05 +01:00
|
|
|
class PlaylistParser;
|
2018-05-01 00:41:33 +02:00
|
|
|
class ParserBase;
|
|
|
|
class CueParser;
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
#if defined(HAVE_AUDIOCD) && defined(HAVE_GSTREAMER)
|
|
|
|
class CddaSongLoader;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class SongLoader : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2020-04-07 16:48:12 +02:00
|
|
|
explicit SongLoader(CollectionBackendInterface *collection, const Player *player, QObject *parent = nullptr);
|
2020-06-15 21:55:05 +02:00
|
|
|
~SongLoader() override;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
enum Result {
|
|
|
|
Success,
|
|
|
|
Error,
|
|
|
|
BlockingLoadRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const int kDefaultTimeout;
|
|
|
|
|
|
|
|
const QUrl &url() const { return url_; }
|
|
|
|
const SongList &songs() const { return songs_; }
|
|
|
|
|
|
|
|
int timeout() const { return timeout_; }
|
|
|
|
void set_timeout(int msec) { timeout_ = msec; }
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
// If Success is returned the songs are fully loaded. If BlockingLoadRequired is returned LoadFilenamesBlocking() needs to be called next.
|
2018-02-27 18:06:05 +01:00
|
|
|
Result Load(const QUrl &url);
|
2018-05-01 00:41:33 +02:00
|
|
|
// Loads the files with only filenames. When finished, songs() contains a complete list of all Song objects, but without metadata.
|
|
|
|
// This method is blocking, do not call it from the UI thread.
|
2019-04-20 15:28:16 +02:00
|
|
|
SongLoader::Result LoadFilenamesBlocking();
|
2018-05-01 00:41:33 +02:00
|
|
|
// Completely load songs previously loaded with LoadFilenamesBlocking().
|
|
|
|
// When finished, the Song objects in songs() contain metadata now. This method is blocking, do not call it from the UI thread.
|
2018-02-27 18:06:05 +01:00
|
|
|
void LoadMetadataBlocking();
|
|
|
|
Result LoadAudioCD();
|
|
|
|
|
2019-04-20 15:28:16 +02:00
|
|
|
QStringList errors() { return errors_; }
|
|
|
|
|
|
|
|
signals:
|
2020-04-07 16:48:12 +02:00
|
|
|
void AudioCDTracksLoadFinished();
|
2021-01-26 16:48:04 +01:00
|
|
|
void LoadAudioCDFinished(bool success);
|
2018-02-27 18:06:05 +01:00
|
|
|
void LoadRemoteFinished();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void Timeout();
|
|
|
|
void StopTypefind();
|
|
|
|
#if defined(HAVE_AUDIOCD) && defined(HAVE_GSTREAMER)
|
2020-04-07 16:48:12 +02:00
|
|
|
void AudioCDTracksLoadFinishedSlot(const SongList &songs, const QString &error);
|
2018-02-27 18:06:05 +01:00
|
|
|
void AudioCDTracksTagsLoaded(const SongList &songs);
|
2018-05-01 00:41:33 +02:00
|
|
|
#endif // HAVE_AUDIOCD && HAVE_GSTREAMER
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
enum State { WaitingForType, WaitingForMagic, WaitingForData, Finished };
|
|
|
|
|
|
|
|
Result LoadLocal(const QString &filename);
|
2019-04-20 15:28:16 +02:00
|
|
|
SongLoader::Result LoadLocalAsync(const QString &filename);
|
2018-02-27 18:06:05 +01:00
|
|
|
void EffectiveSongLoad(Song *song);
|
|
|
|
Result LoadLocalPartial(const QString &filename);
|
|
|
|
void LoadLocalDirectory(const QString &filename);
|
|
|
|
void LoadPlaylist(ParserBase *parser, const QString &filename);
|
|
|
|
|
2018-08-09 18:10:03 +02:00
|
|
|
void AddAsRawStream();
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
#ifdef HAVE_GSTREAMER
|
2019-04-20 15:28:16 +02:00
|
|
|
Result LoadRemote();
|
2018-05-01 00:41:33 +02:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
// GStreamer callbacks
|
|
|
|
static void TypeFound(GstElement *typefind, uint probability, GstCaps *caps, void *self);
|
2020-06-14 18:58:24 +02:00
|
|
|
static GstPadProbeReturn DataReady(GstPad*, GstPadProbeInfo *info, gpointer self);
|
2018-02-27 18:06:05 +01:00
|
|
|
static GstBusSyncReply BusCallbackSync(GstBus*, GstMessage*, gpointer);
|
|
|
|
static gboolean BusCallback(GstBus*, GstMessage*, gpointer);
|
|
|
|
|
|
|
|
void StopTypefindAsync(bool success);
|
|
|
|
void ErrorMessageReceived(GstMessage *msg);
|
|
|
|
void EndOfStreamReached();
|
|
|
|
void MagicReady();
|
|
|
|
bool IsPipelinePlaying();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
private:
|
|
|
|
static QSet<QString> sRawUriSchemes;
|
|
|
|
|
|
|
|
QUrl url_;
|
|
|
|
SongList songs_;
|
|
|
|
|
|
|
|
QTimer *timeout_timer_;
|
|
|
|
PlaylistParser *playlist_parser_;
|
|
|
|
CueParser *cue_parser_;
|
|
|
|
|
|
|
|
// For async loads
|
2019-04-20 15:28:16 +02:00
|
|
|
std::function<Result()> preload_func_;
|
2018-02-27 18:06:05 +01:00
|
|
|
int timeout_;
|
|
|
|
State state_;
|
|
|
|
bool success_;
|
|
|
|
ParserBase *parser_;
|
|
|
|
QString mime_type_;
|
|
|
|
QByteArray buffer_;
|
|
|
|
CollectionBackendInterface *collection_;
|
|
|
|
const Player *player_;
|
|
|
|
|
|
|
|
#ifdef HAVE_GSTREAMER
|
|
|
|
std::shared_ptr<GstElement> pipeline_;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QThreadPool thread_pool_;
|
2019-04-20 15:28:16 +02:00
|
|
|
|
|
|
|
QStringList errors_;
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SONGLOADER_H
|