void SongLoaderInserter::AudioCDTagsLoaded(bool success) { SongLoader* loader = qobject_cast<SongLoader*>(sender()); if (!loader || !destination_) return; if (success) destination_->UpdateItems(loader->songs()); else qLog(Error) << "Error while getting audio CD metadata from MusicBrainz"; deleteLater(); }
gboolean SongLoader::BusCallback(GstBus*, GstMessage* msg, gpointer self) { SongLoader* instance = reinterpret_cast<SongLoader*>(self); switch (GST_MESSAGE_TYPE(msg)) { case GST_MESSAGE_ERROR: instance->ErrorMessageReceived(msg); break; default: break; } return TRUE; }
GstBusSyncReply SongLoader::BusCallbackSync(GstBus*, GstMessage* msg, gpointer self) { SongLoader* instance = reinterpret_cast<SongLoader*>(self); switch (GST_MESSAGE_TYPE(msg)) { case GST_MESSAGE_EOS: instance->EndOfStreamReached(); break; case GST_MESSAGE_ERROR: instance->ErrorMessageReceived(msg); break; default: break; } return GST_BUS_PASS; }
gboolean SongLoader::DataReady(GstPad*, GstBuffer* buf, void* self) { SongLoader* instance = static_cast<SongLoader*>(self); if (instance->state_ == Finished) return true; // Append the data to the buffer instance->buffer_.append(reinterpret_cast<const char*>(GST_BUFFER_DATA(buf)), GST_BUFFER_SIZE(buf)); qLog(Debug) << "Received total" << instance->buffer_.size() << "bytes"; if (instance->state_ == WaitingForMagic && (instance->buffer_.size() >= PlaylistParser::kMagicSize || !instance->IsPipelinePlaying())) { // Got enough that we can test the magic instance->MagicReady(); } return true; }
// Load audio CD tracks: // First, we add tracks (without metadata) into the playlist // In the meantime, MusicBrainz will be queried to get songs' metadata. // AudioCDTagsLoaded will be called next, and playlist's items will be updated. void SongLoaderInserter::LoadAudioCD(Playlist* destination, int row, bool play_now, bool enqueue) { destination_ = destination; row_ = row; play_now_ = play_now; enqueue_ = enqueue; SongLoader* loader = new SongLoader(library_, player_, this); connect(loader, SIGNAL(LoadAudioCDFinished(bool)), SLOT(AudioCDTagsLoaded(bool))); qLog(Info) << "Loading audio CD..."; SongLoader::Result ret = loader->LoadAudioCD(); if (ret == SongLoader::Error) { emit Error(tr("Error while loading audio CD")); delete loader; } else { songs_ = loader->songs(); InsertSongs(); } }
void SongLoader::TypeFound(GstElement*, uint, GstCaps* caps, void* self) { SongLoader* instance = static_cast<SongLoader*>(self); if (instance->state_ != WaitingForType) return; // Check the mimetype instance->mime_type_ = gst_structure_get_name(gst_caps_get_structure(caps, 0)); qLog(Debug) << "Mime type is" << instance->mime_type_; if (instance->mime_type_ == "text/plain" || instance->mime_type_ == "text/uri-list" || instance->podcast_parser_->supported_mime_types().contains( instance->mime_type_)) { // Yeah it might be a playlist, let's get some data and have a better look instance->state_ = WaitingForMagic; return; } // Nope, not a playlist - we're done instance->StopTypefindAsync(true); }
GstPadProbeReturn SongLoader::DataReady(GstPad*, GstPadProbeInfo* info, gpointer self) { SongLoader* instance = reinterpret_cast<SongLoader*>(self); if (instance->state_ == Finished) return GST_PAD_PROBE_OK; GstBuffer* buffer = gst_pad_probe_info_get_buffer(info); GstMapInfo map; gst_buffer_map(buffer, &map, GST_MAP_READ); // Append the data to the buffer instance->buffer_.append(reinterpret_cast<const char*>(map.data), map.size); qLog(Debug) << "Received total" << instance->buffer_.size() << "bytes"; gst_buffer_unmap(buffer, &map); if (instance->state_ == WaitingForMagic && (instance->buffer_.size() >= PlaylistParser::kMagicSize || !instance->IsPipelinePlaying())) { // Got enough that we can test the magic instance->MagicReady(); } return GST_PAD_PROBE_OK; }
void SongLoaderInserter::Load(Playlist* destination, int row, bool play_now, bool enqueue, const QList<QUrl>& urls) { destination_ = destination; row_ = row; play_now_ = play_now; enqueue_ = enqueue; connect(destination, SIGNAL(destroyed()), SLOT(DestinationDestroyed())); connect(this, SIGNAL(PreloadFinished()), SLOT(InsertSongs())); connect(this, SIGNAL(EffectiveLoadFinished(const SongList&)), destination, SLOT(UpdateItems(const SongList&))); for (const QUrl& url : urls) { SongLoader* loader = new SongLoader(library_, player_, this); SongLoader::Result ret = loader->Load(url); if (ret == SongLoader::BlockingLoadRequired) { pending_.append(loader); continue; } if (ret == SongLoader::Success) songs_ << loader->songs(); else emit Error(tr("Error loading %1").arg(url.toString())); delete loader; } if (pending_.isEmpty()) { InsertSongs(); deleteLater(); } else { QtConcurrent::run(this, &SongLoaderInserter::AsyncLoad); } }