MoodbarPipeline: Fix saving moodbar if the URL contains host

Fixes #1101
This commit is contained in:
Jonas Kvinge 2023-01-10 18:18:49 +01:00
parent 194e81205b
commit be6b974334
2 changed files with 25 additions and 8 deletions

View File

@ -19,7 +19,10 @@
#include <memory> #include <memory>
#include <cstdlib> #include <cstdlib>
#include <glib.h>
#include <glib-object.h> #include <glib-object.h>
#include <gst/gst.h>
#include <gst/app/gstappsink.h>
#include <QObject> #include <QObject>
#include <QCoreApplication> #include <QCoreApplication>
@ -36,9 +39,9 @@
const int MoodbarPipeline::kBands = 128; const int MoodbarPipeline::kBands = 128;
MoodbarPipeline::MoodbarPipeline(const QUrl &local_filename, QObject *parent) MoodbarPipeline::MoodbarPipeline(const QUrl &url, QObject *parent)
: QObject(parent), : QObject(parent),
local_filename_(local_filename), url_(url),
pipeline_(nullptr), pipeline_(nullptr),
convert_element_(nullptr), convert_element_(nullptr),
success_(false), success_(false),
@ -61,6 +64,16 @@ GstElement *MoodbarPipeline::CreateElement(const QString &factory_name) {
} }
QByteArray MoodbarPipeline::ToGstUrl(const QUrl &url) {
if (url.isLocalFile() && !url.host().isEmpty()) {
QString str = "file:////" + url.host() + url.path();
return str.toUtf8();
}
return url.toEncoded();
}
void MoodbarPipeline::Start() { void MoodbarPipeline::Start() {
Q_ASSERT(QThread::currentThread() != qApp->thread()); Q_ASSERT(QThread::currentThread() != qApp->thread());
@ -97,7 +110,9 @@ void MoodbarPipeline::Start() {
builder_ = std::make_unique<MoodbarBuilder>(); builder_ = std::make_unique<MoodbarBuilder>();
// Set properties // Set properties
g_object_set(decodebin, "uri", local_filename_.toEncoded().constData(), nullptr);
QByteArray gst_url = ToGstUrl(url_);
g_object_set(decodebin, "uri", gst_url.constData(), nullptr);
g_object_set(spectrum, "bands", kBands, nullptr); g_object_set(spectrum, "bands", kBands, nullptr);
GstFastSpectrum *fast_spectrum = reinterpret_cast<GstFastSpectrum*>(spectrum); GstFastSpectrum *fast_spectrum = reinterpret_cast<GstFastSpectrum*>(spectrum);
@ -128,7 +143,7 @@ void MoodbarPipeline::ReportError(GstMessage *msg) {
g_error_free(error); g_error_free(error);
g_free(debugs); g_free(debugs);
qLog(Error) << "Error processing" << local_filename_ << ":" << message; qLog(Error) << "Error processing" << url_ << ":" << message;
} }

View File

@ -23,12 +23,13 @@
#include <QString> #include <QString>
#include <QUrl> #include <QUrl>
#include <memory>
#include <glib.h> #include <glib.h>
#include <glib-object.h>
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/app/gstappsink.h> #include <gst/app/gstappsink.h>
#include <memory>
class MoodbarBuilder; class MoodbarBuilder;
// Creates moodbar data for a single local music file. // Creates moodbar data for a single local music file.
@ -36,7 +37,7 @@ class MoodbarPipeline : public QObject {
Q_OBJECT Q_OBJECT
public: public:
explicit MoodbarPipeline(const QUrl &local_filename, QObject *parent = nullptr); explicit MoodbarPipeline(const QUrl &url, QObject *parent = nullptr);
~MoodbarPipeline() override; ~MoodbarPipeline() override;
bool success() const { return success_; } bool success() const { return success_; }
@ -51,6 +52,7 @@ class MoodbarPipeline : public QObject {
private: private:
GstElement *CreateElement(const QString &factory_name); GstElement *CreateElement(const QString &factory_name);
QByteArray ToGstUrl(const QUrl &url);
void ReportError(GstMessage *msg); void ReportError(GstMessage *msg);
void Stop(const bool success); void Stop(const bool success);
void Cleanup(); void Cleanup();
@ -63,7 +65,7 @@ class MoodbarPipeline : public QObject {
private: private:
static const int kBands; static const int kBands;
QUrl local_filename_; QUrl url_;
GstElement *pipeline_; GstElement *pipeline_;
GstElement *convert_element_; GstElement *convert_element_;