Load the audio cd in a separate thread
This commit is contained in:
parent
4458d45200
commit
84f1b7bae0
|
@ -15,6 +15,8 @@
|
||||||
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <QtConcurrentRun>
|
||||||
|
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
#include <gst/tag/tag.h>
|
#include <gst/tag/tag.h>
|
||||||
|
|
||||||
|
@ -27,7 +29,9 @@ CddaSongLoader::CddaSongLoader(const QUrl& url, QObject* parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
url_(url),
|
url_(url),
|
||||||
cdda_(nullptr),
|
cdda_(nullptr),
|
||||||
cdio_(nullptr) {}
|
cdio_(nullptr) {
|
||||||
|
connect(this, SIGNAL(MusicBrainzDiscIdLoaded(const QString&)), SLOT(LoadAudioCDTags(const QString&)));
|
||||||
|
}
|
||||||
|
|
||||||
CddaSongLoader::~CddaSongLoader() {
|
CddaSongLoader::~CddaSongLoader() {
|
||||||
if (cdio_) cdio_destroy(cdio_);
|
if (cdio_) cdio_destroy(cdio_);
|
||||||
|
@ -42,6 +46,9 @@ QUrl CddaSongLoader::GetUrlFromTrack(int track_number) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CddaSongLoader::LoadSongs() {
|
void CddaSongLoader::LoadSongs() {
|
||||||
|
QtConcurrent::run(this, &CddaSongLoader::LoadSongsFromCdda);
|
||||||
|
}
|
||||||
|
void CddaSongLoader::LoadSongsFromCdda() {
|
||||||
QMutexLocker locker(&mutex_load_);
|
QMutexLocker locker(&mutex_load_);
|
||||||
cdio_ = cdio_open(url_.path().toLocal8Bit().constData(), DRIVER_DEVICE);
|
cdio_ = cdio_open(url_.path().toLocal8Bit().constData(), DRIVER_DEVICE);
|
||||||
if (cdio_ == nullptr) {
|
if (cdio_ == nullptr) {
|
||||||
|
@ -101,7 +108,6 @@ void CddaSongLoader::LoadSongs() {
|
||||||
}
|
}
|
||||||
emit SongsLoaded(songs);
|
emit SongsLoaded(songs);
|
||||||
|
|
||||||
|
|
||||||
gst_tag_register_musicbrainz_tags();
|
gst_tag_register_musicbrainz_tags();
|
||||||
|
|
||||||
GstElement* pipeline = gst_pipeline_new("pipeline");
|
GstElement* pipeline = gst_pipeline_new("pipeline");
|
||||||
|
@ -157,13 +163,8 @@ void CddaSongLoader::LoadSongs() {
|
||||||
&string_mb)) {
|
&string_mb)) {
|
||||||
QString musicbrainz_discid(string_mb);
|
QString musicbrainz_discid(string_mb);
|
||||||
qLog(Info) << "MusicBrainz discid: " << musicbrainz_discid;
|
qLog(Info) << "MusicBrainz discid: " << musicbrainz_discid;
|
||||||
|
emit MusicBrainzDiscIdLoaded(musicbrainz_discid);
|
||||||
|
|
||||||
MusicBrainzClient* musicbrainz_client = new MusicBrainzClient;
|
|
||||||
connect(musicbrainz_client, SIGNAL(Finished(const QString&, const QString&,
|
|
||||||
MusicBrainzClient::ResultList)),
|
|
||||||
SLOT(AudioCDTagsLoaded(const QString&, const QString&,
|
|
||||||
MusicBrainzClient::ResultList)));
|
|
||||||
musicbrainz_client->StartDiscIdRequest(musicbrainz_discid);
|
|
||||||
g_free(string_mb);
|
g_free(string_mb);
|
||||||
gst_message_unref(msg_tag);
|
gst_message_unref(msg_tag);
|
||||||
gst_tag_list_free(tags);
|
gst_tag_list_free(tags);
|
||||||
|
@ -175,6 +176,16 @@ void CddaSongLoader::LoadSongs() {
|
||||||
gst_object_unref(pipeline);
|
gst_object_unref(pipeline);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CddaSongLoader::LoadAudioCDTags(const QString& musicbrainz_discid) const {
|
||||||
|
MusicBrainzClient* musicbrainz_client = new MusicBrainzClient;
|
||||||
|
connect(musicbrainz_client, SIGNAL(Finished(const QString&, const QString&,
|
||||||
|
MusicBrainzClient::ResultList)),
|
||||||
|
SLOT(AudioCDTagsLoaded(const QString&, const QString&,
|
||||||
|
MusicBrainzClient::ResultList)));
|
||||||
|
|
||||||
|
musicbrainz_client->StartDiscIdRequest(musicbrainz_discid);
|
||||||
|
}
|
||||||
|
|
||||||
void CddaSongLoader::AudioCDTagsLoaded(
|
void CddaSongLoader::AudioCDTagsLoaded(
|
||||||
const QString& artist, const QString& album,
|
const QString& artist, const QString& album,
|
||||||
const MusicBrainzClient::ResultList& results) {
|
const MusicBrainzClient::ResultList& results) {
|
||||||
|
|
|
@ -50,13 +50,16 @@ class CddaSongLoader : public QObject {
|
||||||
void SongsLoaded(const SongList& songs);
|
void SongsLoaded(const SongList& songs);
|
||||||
void SongsDurationLoaded(const SongList& songs);
|
void SongsDurationLoaded(const SongList& songs);
|
||||||
void SongsMetadataLoaded(const SongList& songs);
|
void SongsMetadataLoaded(const SongList& songs);
|
||||||
|
void MusicBrainzDiscIdLoaded(const QString& musicbrainz_discid);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void LoadAudioCDTags(const QString& musicbrainz_discid) const;
|
||||||
void AudioCDTagsLoaded(const QString& artist, const QString& album,
|
void AudioCDTagsLoaded(const QString& artist, const QString& album,
|
||||||
const MusicBrainzClient::ResultList& results);
|
const MusicBrainzClient::ResultList& results);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUrl GetUrlFromTrack(int track_number) const;
|
QUrl GetUrlFromTrack(int track_number) const;
|
||||||
|
void LoadSongsFromCdda();
|
||||||
|
|
||||||
QUrl url_;
|
QUrl url_;
|
||||||
GstElement* cdda_;
|
GstElement* cdda_;
|
||||||
|
|
Loading…
Reference in New Issue