mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-31 03:27:40 +01:00
Start to reactivate audio CD support
This commit is contained in:
parent
67e233408c
commit
a8266173c5
@ -216,8 +216,7 @@ optional_component(SEAFILE ON "Seafile support"
|
||||
DEPENDS "Taglib 1.8" "TAGLIB_VERSION VERSION_GREATER 1.7.999"
|
||||
)
|
||||
|
||||
# Note: broken with gstreamer-1.0 - API changes in the audiocdsrc element.
|
||||
optional_component(AUDIOCD OFF "Devices: Audio CD support"
|
||||
optional_component(AUDIOCD ON "Devices: Audio CD support"
|
||||
DEPENDS "libcdio" CDIO_FOUND
|
||||
)
|
||||
|
||||
|
@ -136,89 +136,89 @@ SongLoader::Result SongLoader::LoadLocalPartial(const QString& filename) {
|
||||
}
|
||||
|
||||
SongLoader::Result SongLoader::LoadAudioCD() {
|
||||
#ifdef HAVE_AUDIOCD
|
||||
// Create gstreamer cdda element
|
||||
GstElement* cdda = gst_element_make_from_uri(
|
||||
GST_URI_SRC, "cdda://", nullptr, nullptr);
|
||||
if (cdda == nullptr) {
|
||||
qLog(Error) << "Error while creating CDDA GstElement";
|
||||
return Error;
|
||||
}
|
||||
|
||||
// Change the element's state to ready and paused, to be able to query it
|
||||
if (gst_element_set_state(cdda, GST_STATE_READY) ==
|
||||
GST_STATE_CHANGE_FAILURE ||
|
||||
gst_element_set_state(cdda, GST_STATE_PAUSED) ==
|
||||
GST_STATE_CHANGE_FAILURE) {
|
||||
qLog(Error) << "Error while changing CDDA GstElement's state";
|
||||
gst_element_set_state(cdda, GST_STATE_NULL);
|
||||
gst_object_unref(GST_OBJECT(cdda));
|
||||
return Error;
|
||||
}
|
||||
|
||||
// Get number of tracks
|
||||
GstFormat fmt = gst_format_get_by_nick("track");
|
||||
gint64 num_tracks = 0;
|
||||
if (!gst_element_query_duration(cdda, fmt, &num_tracks)) {
|
||||
qLog(Error) << "Error while querying cdda GstElement";
|
||||
gst_object_unref(GST_OBJECT(cdda));
|
||||
return Error;
|
||||
}
|
||||
|
||||
for (int track_number = 1; track_number <= num_tracks; track_number++) {
|
||||
// Init song
|
||||
Song song;
|
||||
guint64 duration = 0;
|
||||
// quint64 == ulonglong and guint64 == ulong, therefore we must cast
|
||||
if (gst_tag_list_get_uint64(
|
||||
GST_CDDA_BASE_SRC(cdda)->tracks[track_number - 1].tags,
|
||||
GST_TAG_DURATION, &duration)) {
|
||||
song.set_length_nanosec((quint64)duration);
|
||||
}
|
||||
song.set_valid(true);
|
||||
song.set_filetype(Song::Type_Cdda);
|
||||
song.set_url(QUrl(QString("cdda://%1").arg(track_number)));
|
||||
song.set_title(QString("Track %1").arg(track_number));
|
||||
song.set_track(track_number);
|
||||
songs_ << song;
|
||||
}
|
||||
|
||||
// Generate MusicBrainz DiscId
|
||||
gst_tag_register_musicbrainz_tags();
|
||||
GstElement* pipe = gst_pipeline_new("pipeline");
|
||||
gst_bin_add(GST_BIN(pipe), cdda);
|
||||
gst_element_set_state(pipe, GST_STATE_READY);
|
||||
gst_element_set_state(pipe, GST_STATE_PAUSED);
|
||||
GstMessage* msg = gst_bus_timed_pop_filtered(
|
||||
GST_ELEMENT_BUS(pipe), GST_CLOCK_TIME_NONE, GST_MESSAGE_TAG);
|
||||
GstTagList* tags = nullptr;
|
||||
gst_message_parse_tag(msg, &tags);
|
||||
char* string_mb = nullptr;
|
||||
if (gst_tag_list_get_string(tags, GST_TAG_CDDA_MUSICBRAINZ_DISCID,
|
||||
&string_mb)) {
|
||||
QString musicbrainz_discid(string_mb);
|
||||
qLog(Info) << "MusicBrainz discid: " << musicbrainz_discid;
|
||||
|
||||
MusicBrainzClient* musicbrainz_client = new MusicBrainzClient(this);
|
||||
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);
|
||||
}
|
||||
|
||||
// Clean all the Gstreamer objects we have used: we don't need them anymore
|
||||
gst_object_unref(GST_OBJECT(cdda));
|
||||
gst_element_set_state(pipe, GST_STATE_NULL);
|
||||
gst_object_unref(GST_OBJECT(pipe));
|
||||
gst_object_unref(GST_OBJECT(msg));
|
||||
gst_object_unref(GST_OBJECT(tags));
|
||||
|
||||
return Success;
|
||||
#else // HAVE_AUDIOCD
|
||||
//#ifdef HAVE_AUDIOCD
|
||||
// // Create gstreamer cdda element
|
||||
// GstElement* cdda = gst_element_make_from_uri(
|
||||
// GST_URI_SRC, "cdda://", nullptr, nullptr);
|
||||
// if (cdda == nullptr) {
|
||||
// qLog(Error) << "Error while creating CDDA GstElement";
|
||||
// return Error;
|
||||
// }
|
||||
//
|
||||
// // Change the element's state to ready and paused, to be able to query it
|
||||
// if (gst_element_set_state(cdda, GST_STATE_READY) ==
|
||||
// GST_STATE_CHANGE_FAILURE ||
|
||||
// gst_element_set_state(cdda, GST_STATE_PAUSED) ==
|
||||
// GST_STATE_CHANGE_FAILURE) {
|
||||
// qLog(Error) << "Error while changing CDDA GstElement's state";
|
||||
// gst_element_set_state(cdda, GST_STATE_NULL);
|
||||
// gst_object_unref(GST_OBJECT(cdda));
|
||||
// return Error;
|
||||
// }
|
||||
//
|
||||
// // Get number of tracks
|
||||
// GstFormat fmt = gst_format_get_by_nick("track");
|
||||
// gint64 num_tracks = 0;
|
||||
// if (!gst_element_query_duration(cdda, fmt, &num_tracks)) {
|
||||
// qLog(Error) << "Error while querying cdda GstElement";
|
||||
// gst_object_unref(GST_OBJECT(cdda));
|
||||
// return Error;
|
||||
// }
|
||||
//
|
||||
// for (int track_number = 1; track_number <= num_tracks; track_number++) {
|
||||
// // Init song
|
||||
// Song song;
|
||||
// guint64 duration = 0;
|
||||
// // quint64 == ulonglong and guint64 == ulong, therefore we must cast
|
||||
// if (gst_tag_list_get_uint64(
|
||||
// GST_CDDA_BASE_SRC(cdda)->tracks[track_number - 1].tags,
|
||||
// GST_TAG_DURATION, &duration)) {
|
||||
// song.set_length_nanosec((quint64)duration);
|
||||
// }
|
||||
// song.set_valid(true);
|
||||
// song.set_filetype(Song::Type_Cdda);
|
||||
// song.set_url(QUrl(QString("cdda://%1").arg(track_number)));
|
||||
// song.set_title(QString("Track %1").arg(track_number));
|
||||
// song.set_track(track_number);
|
||||
// songs_ << song;
|
||||
// }
|
||||
//
|
||||
// // Generate MusicBrainz DiscId
|
||||
// gst_tag_register_musicbrainz_tags();
|
||||
// GstElement* pipe = gst_pipeline_new("pipeline");
|
||||
// gst_bin_add(GST_BIN(pipe), cdda);
|
||||
// gst_element_set_state(pipe, GST_STATE_READY);
|
||||
// gst_element_set_state(pipe, GST_STATE_PAUSED);
|
||||
// GstMessage* msg = gst_bus_timed_pop_filtered(
|
||||
// GST_ELEMENT_BUS(pipe), GST_CLOCK_TIME_NONE, GST_MESSAGE_TAG);
|
||||
// GstTagList* tags = nullptr;
|
||||
// gst_message_parse_tag(msg, &tags);
|
||||
// char* string_mb = nullptr;
|
||||
// if (gst_tag_list_get_string(tags, GST_TAG_CDDA_MUSICBRAINZ_DISCID,
|
||||
// &string_mb)) {
|
||||
// QString musicbrainz_discid(string_mb);
|
||||
// qLog(Info) << "MusicBrainz discid: " << musicbrainz_discid;
|
||||
//
|
||||
// MusicBrainzClient* musicbrainz_client = new MusicBrainzClient(this);
|
||||
// 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);
|
||||
// }
|
||||
//
|
||||
// // Clean all the Gstreamer objects we have used: we don't need them anymore
|
||||
// gst_object_unref(GST_OBJECT(cdda));
|
||||
// gst_element_set_state(pipe, GST_STATE_NULL);
|
||||
// gst_object_unref(GST_OBJECT(pipe));
|
||||
// gst_object_unref(GST_OBJECT(msg));
|
||||
// gst_object_unref(GST_OBJECT(tags));
|
||||
//
|
||||
// return Success;
|
||||
//#else // HAVE_AUDIOCD
|
||||
return Error;
|
||||
#endif
|
||||
//#endif
|
||||
}
|
||||
|
||||
void SongLoader::AudioCDTagsLoaded(
|
||||
|
@ -16,6 +16,9 @@
|
||||
*/
|
||||
|
||||
#include <QMutexLocker>
|
||||
#include <gst/gst.h>
|
||||
#include <gst/tag/tag.h>
|
||||
#include <gst/audio/gstaudiocdsrc.h>
|
||||
|
||||
#include "core/logging.h"
|
||||
#include "core/timeconstants.h"
|
||||
@ -44,14 +47,21 @@ void CddaDevice::Init() {
|
||||
return;
|
||||
}
|
||||
// Create gstreamer cdda element
|
||||
cdda_ = gst_element_make_from_uri(GST_URI_SRC, "cdda://", nullptr);
|
||||
GError* error = nullptr;
|
||||
cdda_ = gst_element_make_from_uri(GST_URI_SRC, "cdda://", nullptr, &error);
|
||||
if (error) {
|
||||
qLog(Error) << error->code << error->message;
|
||||
}
|
||||
if (cdda_ == nullptr) {
|
||||
model_->Reset();
|
||||
return;
|
||||
}
|
||||
|
||||
GST_CDDA_BASE_SRC(cdda_)->device =
|
||||
g_strdup(url_.path().toLocal8Bit().constData());
|
||||
g_object_set(cdda_, "device", g_strdup(url_.path().toLocal8Bit().constData()),
|
||||
nullptr);
|
||||
if (g_object_class_find_property (G_OBJECT_GET_CLASS (cdda_), "paranoia-mode")) {
|
||||
g_object_set (cdda_, "paranoia-mode", 0, NULL);
|
||||
}
|
||||
|
||||
// Change the element's state to ready and paused, to be able to query it
|
||||
if (gst_element_set_state(cdda_, GST_STATE_READY) ==
|
||||
@ -68,7 +78,7 @@ void CddaDevice::Init() {
|
||||
GstFormat fmt = gst_format_get_by_nick("track");
|
||||
GstFormat out_fmt = fmt;
|
||||
gint64 num_tracks = 0;
|
||||
if (!gst_element_query_duration(cdda_, &out_fmt, &num_tracks) ||
|
||||
if (!gst_element_query_duration(cdda_, out_fmt, &num_tracks) ||
|
||||
out_fmt != fmt) {
|
||||
qLog(Error) << "Error while querying cdda GstElement";
|
||||
model_->Reset();
|
||||
@ -80,13 +90,6 @@ void CddaDevice::Init() {
|
||||
for (int track_number = 1; track_number <= num_tracks; track_number++) {
|
||||
// Init song
|
||||
Song song;
|
||||
guint64 duration = 0;
|
||||
// quint64 == ulonglong and guint64 == ulong, therefore we must cast
|
||||
if (gst_tag_list_get_uint64(
|
||||
GST_CDDA_BASE_SRC(cdda_)->tracks[track_number - 1].tags,
|
||||
GST_TAG_DURATION, &duration)) {
|
||||
song.set_length_nanosec((quint64)duration);
|
||||
}
|
||||
song.set_id(track_number);
|
||||
song.set_valid(true);
|
||||
song.set_filetype(Song::Type_Cdda);
|
||||
@ -105,37 +108,81 @@ void CddaDevice::Init() {
|
||||
model_->Reset();
|
||||
emit SongsDiscovered(songs);
|
||||
|
||||
// Generate MusicBrainz DiscId
|
||||
gst_tag_register_musicbrainz_tags();
|
||||
GstElement* pipe = gst_pipeline_new("pipeline");
|
||||
gst_bin_add(GST_BIN(pipe), cdda_);
|
||||
gst_element_set_state(pipe, GST_STATE_READY);
|
||||
gst_element_set_state(pipe, GST_STATE_PAUSED);
|
||||
GstMessage* msg = gst_bus_timed_pop_filtered(
|
||||
GST_ELEMENT_BUS(pipe), GST_CLOCK_TIME_NONE, GST_MESSAGE_TAG);
|
||||
GstTagList* tags = nullptr;
|
||||
gst_message_parse_tag(msg, &tags);
|
||||
char* string_mb = nullptr;
|
||||
if (gst_tag_list_get_string(tags, GST_TAG_CDDA_MUSICBRAINZ_DISCID,
|
||||
&string_mb)) {
|
||||
QString musicbrainz_discid(string_mb);
|
||||
qLog(Info) << "MusicBrainz discid: " << musicbrainz_discid;
|
||||
|
||||
MusicBrainzClient* musicbrainz_client = new MusicBrainzClient(this);
|
||||
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);
|
||||
gst_tag_register_musicbrainz_tags();
|
||||
|
||||
GstElement* pipeline = gst_pipeline_new("pipeline");
|
||||
GstElement* sink = gst_element_factory_make ("fakesink", NULL);
|
||||
gst_bin_add_many (GST_BIN (pipeline), cdda_, sink, NULL);
|
||||
gst_element_link (cdda_, sink);
|
||||
gst_element_set_state(pipeline, GST_STATE_READY);
|
||||
gst_element_set_state(pipeline, GST_STATE_PAUSED);
|
||||
|
||||
// Get TOC and TAG messages
|
||||
GstMessage* msg = nullptr;
|
||||
GstMessage* msg_toc = nullptr;
|
||||
GstMessage* msg_tag = nullptr;
|
||||
while ((msg = gst_bus_timed_pop_filtered(GST_ELEMENT_BUS(pipeline),
|
||||
GST_SECOND, (GstMessageType)(GST_MESSAGE_TOC | GST_MESSAGE_TAG)))) {
|
||||
if (GST_MESSAGE_TYPE(msg) == GST_MESSAGE_TOC) {
|
||||
if (msg_toc) gst_message_unref(msg_toc); // Shouldn't happen, but just in case
|
||||
msg_toc = msg;
|
||||
} else if (GST_MESSAGE_TYPE(msg) == GST_MESSAGE_TAG) {
|
||||
if (msg_tag) gst_message_unref(msg_tag);
|
||||
msg_tag = msg;
|
||||
}
|
||||
}
|
||||
|
||||
// Clean all the Gstreamer objects we have used: we don't need them anymore
|
||||
gst_element_set_state(pipe, GST_STATE_NULL);
|
||||
// Handle TOC message: get tracks duration
|
||||
if (msg_toc) {
|
||||
GstToc* toc;
|
||||
gst_message_parse_toc (msg_toc, &toc, nullptr);
|
||||
if (toc) {
|
||||
GList* entries = gst_toc_get_entries(toc);
|
||||
if (entries && songs.size() <= g_list_length (entries)) {
|
||||
int i = 0;
|
||||
for (GList* node = entries; node != nullptr; node = node->next) {
|
||||
GstTocEntry *entry = static_cast<GstTocEntry*>(node->data);
|
||||
quint64 duration = 0;
|
||||
gint64 start, stop;
|
||||
if (gst_toc_entry_get_start_stop_times (entry, &start, &stop))
|
||||
duration = stop - start;
|
||||
songs[i++].set_length_nanosec(duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
gst_message_unref(msg_toc);
|
||||
}
|
||||
// Update songs with duration
|
||||
model_->Reset();
|
||||
emit SongsDiscovered(songs);
|
||||
song_count_ = songs.size();
|
||||
|
||||
// Handle TAG message: generate MusicBrainz DiscId
|
||||
if (msg_tag) {
|
||||
GstTagList* tags = nullptr;
|
||||
gst_message_parse_tag(msg_tag, &tags);
|
||||
char* string_mb = nullptr;
|
||||
if (gst_tag_list_get_string(tags, GST_TAG_CDDA_MUSICBRAINZ_DISCID,
|
||||
&string_mb)) {
|
||||
QString musicbrainz_discid(string_mb);
|
||||
qLog(Info) << "MusicBrainz discid: " << musicbrainz_discid;
|
||||
|
||||
MusicBrainzClient* musicbrainz_client = new MusicBrainzClient(this);
|
||||
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);
|
||||
gst_message_unref(msg_tag);
|
||||
gst_tag_list_free(tags);
|
||||
}
|
||||
}
|
||||
|
||||
gst_element_set_state(pipeline, GST_STATE_NULL);
|
||||
// This will also cause cdda_ to be unref'd.
|
||||
gst_object_unref(GST_OBJECT(pipe));
|
||||
gst_object_unref(GST_OBJECT(msg));
|
||||
gst_tag_list_free(tags);
|
||||
gst_object_unref(pipeline);
|
||||
}
|
||||
|
||||
void CddaDevice::AudioCDTagsLoaded(
|
||||
|
@ -41,10 +41,6 @@
|
||||
#include <qtsparkle/Updater>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_AUDIOCD
|
||||
#include <gst/cdda/gstcddabasesrc.h>
|
||||
#endif
|
||||
|
||||
#include "core/appearance.h"
|
||||
#include "core/application.h"
|
||||
#include "core/backgroundstreams.h"
|
||||
|
Loading…
x
Reference in New Issue
Block a user