2010-06-15 15:24:17 +02:00
|
|
|
/* This file is part of Clementine.
|
2014-11-02 19:36:21 +01:00
|
|
|
Copyright 2010, 2012-2014, David Sansome <me@davidsansome.com>
|
|
|
|
Copyright 2010-2011, 2014, John Maguire <john.maguire@gmail.com>
|
|
|
|
Copyright 2011-2012, 2014, Arnaud Bienner <arnaud.bienner@gmail.com>
|
|
|
|
Copyright 2011, Paweł Bara <keirangtp@gmail.com>
|
|
|
|
Copyright 2014, Alexander Bikadorov <abiku@cs.tu-berlin.de>
|
|
|
|
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
|
2010-06-15 15:24:17 +02:00
|
|
|
|
|
|
|
Clementine 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.
|
|
|
|
|
|
|
|
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-11-01 19:26:05 +01:00
|
|
|
#ifndef CORE_SONGLOADER_H_
|
|
|
|
#define CORE_SONGLOADER_H_
|
2010-06-15 15:24:17 +02:00
|
|
|
|
2014-04-02 15:57:01 +02:00
|
|
|
#include <functional>
|
2014-02-06 14:48:00 +01:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
|
2010-06-15 15:24:17 +02:00
|
|
|
#include <QObject>
|
2012-07-16 00:06:55 +02:00
|
|
|
#include <QThreadPool>
|
2010-06-15 15:24:17 +02:00
|
|
|
#include <QUrl>
|
|
|
|
|
|
|
|
#include "song.h"
|
2013-02-17 08:19:05 +01:00
|
|
|
#include "core/tagreaderclient.h"
|
2011-06-10 01:08:43 +02:00
|
|
|
#include "musicbrainz/musicbrainzclient.h"
|
2010-06-15 15:24:17 +02:00
|
|
|
|
2011-01-04 00:36:10 +01:00
|
|
|
class CueParser;
|
2010-08-31 23:24:57 +02:00
|
|
|
class LibraryBackendInterface;
|
2010-06-15 15:24:17 +02:00
|
|
|
class ParserBase;
|
2014-01-24 13:54:38 +01:00
|
|
|
class Player;
|
2010-06-15 15:24:17 +02:00
|
|
|
class PlaylistParser;
|
2012-03-11 18:57:15 +01:00
|
|
|
class PodcastParser;
|
2014-10-26 03:32:37 +01:00
|
|
|
class CddaSongLoader;
|
2010-06-15 15:24:17 +02:00
|
|
|
|
|
|
|
class SongLoader : public QObject {
|
|
|
|
Q_OBJECT
|
2014-11-01 19:26:05 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2014-01-24 13:54:38 +01:00
|
|
|
SongLoader(LibraryBackendInterface* library, const Player* player,
|
2014-02-10 16:03:54 +01:00
|
|
|
QObject* parent = nullptr);
|
2010-06-15 20:24:08 +02:00
|
|
|
~SongLoader();
|
2010-06-15 15:24:17 +02:00
|
|
|
|
|
|
|
enum Result {
|
|
|
|
Success,
|
|
|
|
Error,
|
2014-04-07 15:38:26 +02:00
|
|
|
BlockingLoadRequired,
|
2010-06-15 15:24:17 +02:00
|
|
|
};
|
|
|
|
|
2010-06-23 13:51:13 +02:00
|
|
|
static const int kDefaultTimeout;
|
|
|
|
|
2010-06-15 15:24:17 +02:00
|
|
|
const QUrl& url() const { return url_; }
|
|
|
|
const SongList& songs() const { return songs_; }
|
|
|
|
|
2010-06-23 13:51:13 +02:00
|
|
|
int timeout() const { return timeout_; }
|
|
|
|
void set_timeout(int msec) { timeout_ = msec; }
|
|
|
|
|
2014-04-07 15:38:26 +02:00
|
|
|
// If Success is returned the songs are fully loaded. If BlockingLoadRequired
|
|
|
|
// is returned LoadFilenamesBlocking() needs to be called next.
|
2010-06-23 13:51:13 +02:00
|
|
|
Result Load(const QUrl& url);
|
2014-04-07 15:27:47 +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.
|
|
|
|
void LoadFilenamesBlocking();
|
|
|
|
// 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.
|
|
|
|
void LoadMetadataBlocking();
|
2011-06-10 01:08:43 +02:00
|
|
|
Result LoadAudioCD();
|
2011-04-16 16:04:15 +02:00
|
|
|
|
2014-11-01 19:26:05 +01:00
|
|
|
signals:
|
2014-10-26 03:32:37 +01:00
|
|
|
void AudioCDTracksLoaded();
|
2014-04-07 15:27:47 +02:00
|
|
|
void LoadAudioCDFinished(bool success);
|
|
|
|
void LoadRemoteFinished();
|
2010-06-15 15:24:17 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private slots:
|
2010-06-15 15:24:17 +02:00
|
|
|
void Timeout();
|
|
|
|
void StopTypefind();
|
2014-10-26 17:12:00 +01:00
|
|
|
#ifdef HAVE_AUDIOCD
|
2014-10-26 03:32:37 +01:00
|
|
|
void AudioCDTracksLoadedSlot(const SongList& songs);
|
|
|
|
void AudioCDTracksTagsLoaded(const SongList& songs);
|
2014-11-01 19:26:05 +01:00
|
|
|
#endif // HAVE_AUDIOCD
|
2010-06-15 15:24:17 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
|
|
|
enum State { WaitingForType, WaitingForMagic, WaitingForData, Finished, };
|
2010-06-15 15:24:17 +02:00
|
|
|
|
2013-02-17 08:10:08 +01:00
|
|
|
Result LoadLocal(const QString& filename);
|
2014-04-02 15:57:01 +02:00
|
|
|
void LoadLocalAsync(const QString& filename);
|
2014-04-07 15:27:47 +02:00
|
|
|
void EffectiveSongLoad(Song* song);
|
2011-04-16 16:04:15 +02:00
|
|
|
Result LoadLocalPartial(const QString& filename);
|
2010-06-15 16:24:17 +02:00
|
|
|
void LoadLocalDirectory(const QString& filename);
|
2010-08-03 16:59:18 +02:00
|
|
|
void LoadPlaylist(ParserBase* parser, const QString& filename);
|
2010-06-15 15:24:17 +02:00
|
|
|
|
2010-06-26 15:20:08 +02:00
|
|
|
void AddAsRawStream();
|
|
|
|
|
2014-04-02 15:57:01 +02:00
|
|
|
void LoadRemote();
|
2010-06-26 15:20:08 +02:00
|
|
|
|
2010-06-15 15:24:17 +02:00
|
|
|
// GStreamer callbacks
|
2014-02-07 16:34:20 +01:00
|
|
|
static void TypeFound(GstElement* typefind, uint probability, GstCaps* caps,
|
|
|
|
void* self);
|
2014-06-09 08:20:24 +02:00
|
|
|
static GstPadProbeReturn DataReady(GstPad*, GstPadProbeInfo* buf,
|
|
|
|
gpointer self);
|
2010-06-15 15:24:17 +02: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();
|
2011-11-10 21:42:06 +01:00
|
|
|
bool IsPipelinePlaying();
|
2010-06-23 13:47:54 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2010-06-23 13:47:54 +02:00
|
|
|
static QSet<QString> sRawUriSchemes;
|
|
|
|
|
2010-06-15 15:24:17 +02:00
|
|
|
QUrl url_;
|
|
|
|
SongList songs_;
|
|
|
|
|
|
|
|
QTimer* timeout_timer_;
|
|
|
|
PlaylistParser* playlist_parser_;
|
2012-03-11 18:57:15 +01:00
|
|
|
PodcastParser* podcast_parser_;
|
2011-01-04 00:36:10 +01:00
|
|
|
CueParser* cue_parser_;
|
2010-06-15 15:24:17 +02:00
|
|
|
|
|
|
|
// For async loads
|
2014-04-02 15:57:01 +02:00
|
|
|
std::function<void()> preload_func_;
|
2010-06-23 13:51:13 +02:00
|
|
|
int timeout_;
|
2010-06-15 15:24:17 +02:00
|
|
|
State state_;
|
|
|
|
bool success_;
|
|
|
|
ParserBase* parser_;
|
2010-06-15 16:52:42 +02:00
|
|
|
QString mime_type_;
|
2012-03-11 18:57:15 +01:00
|
|
|
bool is_podcast_;
|
2010-06-15 15:24:17 +02:00
|
|
|
QByteArray buffer_;
|
2010-08-31 23:24:57 +02:00
|
|
|
LibraryBackendInterface* library_;
|
2014-01-24 13:54:38 +01:00
|
|
|
const Player* player_;
|
2010-06-26 15:20:08 +02:00
|
|
|
|
2014-02-06 14:48:00 +01:00
|
|
|
std::shared_ptr<GstElement> pipeline_;
|
2012-07-16 00:06:55 +02:00
|
|
|
|
|
|
|
QThreadPool thread_pool_;
|
2010-06-15 15:24:17 +02:00
|
|
|
};
|
|
|
|
|
2014-11-01 19:26:05 +01:00
|
|
|
#endif // CORE_SONGLOADER_H_
|