Move GstStartup
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* Copyright (C) 2003-2005 by Mark Kretschmann <markey@web.de> *
|
||||
* Copyright (C) 2005 by Jakub Stachowski <qbast@go2.pl> *
|
||||
* Copyright (C) 2006 Paul Cifarelli <paul@cifarelli.net> *
|
||||
* Copyright (C) 2017-2021 Jonas Kvinge <jonas@jkvinge.net> *
|
||||
* Copyright (C) 2017-2024 Jonas Kvinge <jonas@jkvinge.net> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
@@ -97,7 +97,6 @@ constexpr qint64 kSeekDelayNanosec = 100 * kNsecPerMsec; // 100msec
|
||||
GstEngine::GstEngine(SharedPtr<TaskManager> task_manager, QObject *parent)
|
||||
: EngineBase(parent),
|
||||
task_manager_(task_manager),
|
||||
gst_startup_(nullptr),
|
||||
discoverer_(nullptr),
|
||||
buffering_task_id_(-1),
|
||||
latest_buffer_(nullptr),
|
||||
@@ -129,7 +128,6 @@ GstEngine::GstEngine(SharedPtr<TaskManager> task_manager, QObject *parent)
|
||||
|
||||
GstEngine::~GstEngine() {
|
||||
|
||||
EnsureInitialized();
|
||||
current_pipeline_.reset();
|
||||
|
||||
if (latest_buffer_) {
|
||||
@@ -181,8 +179,6 @@ EngineBase::State GstEngine::state() const {
|
||||
|
||||
void GstEngine::StartPreloading(const QUrl &media_url, const QUrl &stream_url, const bool force_stop_at_end, const qint64 beginning_nanosec, const qint64 end_nanosec) {
|
||||
|
||||
EnsureInitialized();
|
||||
|
||||
const QByteArray gst_url = FixupUrl(stream_url);
|
||||
|
||||
// No crossfading, so we can just queue the new URL in the existing pipeline and get gapless playback (hopefully)
|
||||
@@ -200,8 +196,6 @@ void GstEngine::StartPreloading(const QUrl &media_url, const QUrl &stream_url, c
|
||||
|
||||
bool GstEngine::Load(const QUrl &media_url, const QUrl &stream_url, const EngineBase::TrackChangeFlags change, const bool force_stop_at_end, const quint64 beginning_nanosec, const qint64 end_nanosec, const std::optional<double> ebur128_integrated_loudness_lufs) {
|
||||
|
||||
EnsureInitialized();
|
||||
|
||||
EngineBase::Load(media_url, stream_url, change, force_stop_at_end, beginning_nanosec, end_nanosec, ebur128_integrated_loudness_lufs);
|
||||
|
||||
const QByteArray gst_url = FixupUrl(stream_url);
|
||||
@@ -270,8 +264,6 @@ bool GstEngine::Load(const QUrl &media_url, const QUrl &stream_url, const Engine
|
||||
|
||||
bool GstEngine::Play(const bool pause, const quint64 offset_nanosec) {
|
||||
|
||||
EnsureInitialized();
|
||||
|
||||
if (!current_pipeline_ || current_pipeline_->is_buffering() || current_pipeline_->state() == GstState::GST_STATE_PLAYING) return false;
|
||||
|
||||
if (OldExclusivePipelineActive()) {
|
||||
@@ -458,8 +450,6 @@ const EngineBase::Scope &GstEngine::scope(const int chunk_length) {
|
||||
|
||||
EngineBase::OutputDetailsList GstEngine::GetOutputsList() const {
|
||||
|
||||
const_cast<GstEngine*>(this)->EnsureInitialized();
|
||||
|
||||
OutputDetailsList outputs;
|
||||
|
||||
GstRegistry *registry = gst_registry_get();
|
||||
@@ -498,8 +488,6 @@ EngineBase::OutputDetailsList GstEngine::GetOutputsList() const {
|
||||
|
||||
bool GstEngine::ValidOutput(const QString &output) {
|
||||
|
||||
EnsureInitialized();
|
||||
|
||||
const OutputDetailsList output_details = GetOutputsList();
|
||||
return std::any_of(output_details.begin(), output_details.end(), [output](const OutputDetails &output_detail) { return output_detail.name == output; });
|
||||
|
||||
@@ -804,8 +792,6 @@ void GstEngine::BufferingFinished() {
|
||||
|
||||
QByteArray GstEngine::FixupUrl(const QUrl &url) {
|
||||
|
||||
EnsureInitialized();
|
||||
|
||||
QByteArray uri;
|
||||
|
||||
// It's a file:// url with a hostname set.
|
||||
@@ -901,8 +887,6 @@ void GstEngine::StopTimers() {
|
||||
|
||||
GstEnginePipelinePtr GstEngine::CreatePipeline() {
|
||||
|
||||
EnsureInitialized();
|
||||
|
||||
GstEnginePipelinePtr pipeline = make_shared<GstEnginePipeline>();
|
||||
pipeline->set_output_device(output_, device_);
|
||||
pipeline->set_exclusive_mode(exclusive_mode_);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Copyright (C) 2003-2005 by Mark Kretschmann <markey@web.de> *
|
||||
* Copyright (C) 2005 by Jakub Stachowski <qbast@go2.pl> *
|
||||
* Copyright (C) 2006 Paul Cifarelli <paul@cifarelli.net> *
|
||||
* Copyright (C) 2017-2021 Jonas Kvinge <jonas@jkvinge.net> *
|
||||
* Copyright (C) 2017-2024 Jonas Kvinge <jonas@jkvinge.net> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
@@ -41,7 +41,6 @@
|
||||
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "enginebase.h"
|
||||
#include "gststartup.h"
|
||||
#include "gstenginepipeline.h"
|
||||
#include "gstbufferconsumer.h"
|
||||
|
||||
@@ -85,9 +84,6 @@ class GstEngine : public EngineBase, public GstBufferConsumer {
|
||||
bool ALSADeviceSupport(const QString &output) const override;
|
||||
bool ExclusiveModeSupport(const QString &output) const override;
|
||||
|
||||
void SetStartup(GstStartup *gst_startup) { gst_startup_ = gst_startup; }
|
||||
void EnsureInitialized() { gst_startup_->EnsureInitialized(); }
|
||||
|
||||
void ConsumeBuffer(GstBuffer *buffer, const int pipeline_id, const QString &format) override;
|
||||
|
||||
public Q_SLOTS:
|
||||
@@ -153,7 +149,6 @@ class GstEngine : public EngineBase, public GstBufferConsumer {
|
||||
|
||||
private:
|
||||
SharedPtr<TaskManager> task_manager_;
|
||||
GstStartup *gst_startup_;
|
||||
GstDiscoverer *discoverer_;
|
||||
|
||||
int buffering_task_id_;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
|
||||
* Copyright 2018-2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
|
||||
* Copyright 2018-2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
|
||||
* Copyright 2018-2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -25,15 +25,11 @@
|
||||
#include <gst/gst.h>
|
||||
#include <gst/pbutils/pbutils.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QMetaObject>
|
||||
#include <QCoreApplication>
|
||||
#include <QStandardPaths>
|
||||
#include <QtConcurrentRun>
|
||||
#include <QString>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QAbstractEventDispatcher>
|
||||
|
||||
#include "core/logging.h"
|
||||
#include "utilities/envutils.h"
|
||||
@@ -46,38 +42,9 @@
|
||||
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
|
||||
GThread *GstStartup::kGThread = nullptr;
|
||||
namespace GstStartup {
|
||||
|
||||
gpointer GstStartup::GLibMainLoopThreadFunc(gpointer data) {
|
||||
|
||||
Q_UNUSED(data)
|
||||
|
||||
qLog(Info) << "Creating GLib main event loop.";
|
||||
|
||||
GMainLoop *gloop = g_main_loop_new(nullptr, false);
|
||||
g_main_loop_run(gloop);
|
||||
g_main_loop_unref(gloop);
|
||||
|
||||
return nullptr;
|
||||
|
||||
}
|
||||
|
||||
GstStartup::GstStartup(QObject *parent) : QObject(parent) {
|
||||
|
||||
initializing_ = QtConcurrent::run(&GstStartup::InitializeGStreamer);
|
||||
|
||||
const QMetaObject *mo = QAbstractEventDispatcher::instance(qApp->thread())->metaObject();
|
||||
if (mo && strcmp(mo->className(), "QEventDispatcherGlib") != 0 && strcmp(mo->superClass()->className(), "QEventDispatcherGlib") != 0) {
|
||||
kGThread = g_thread_new(nullptr, GstStartup::GLibMainLoopThreadFunc, nullptr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
GstStartup::~GstStartup() {
|
||||
if (kGThread) g_thread_unref(kGThread);
|
||||
}
|
||||
|
||||
void GstStartup::InitializeGStreamer() {
|
||||
void Initialize() {
|
||||
|
||||
SetEnvironment();
|
||||
|
||||
@@ -110,7 +77,7 @@ void GstStartup::InitializeGStreamer() {
|
||||
|
||||
}
|
||||
|
||||
void GstStartup::SetEnvironment() {
|
||||
void SetEnvironment() {
|
||||
|
||||
#ifdef USE_BUNDLE
|
||||
|
||||
@@ -177,7 +144,6 @@ void GstStartup::SetEnvironment() {
|
||||
|
||||
#endif // USE_BUNDLE
|
||||
|
||||
|
||||
#if defined(Q_OS_WIN32) || defined(Q_OS_MACOS)
|
||||
QString gst_registry_filename = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + QStringLiteral("/gst-registry-%1-bin").arg(QCoreApplication::applicationVersion());
|
||||
qLog(Debug) << "Setting GStreamer registry file to" << gst_registry_filename;
|
||||
@@ -185,3 +151,5 @@ void GstStartup::SetEnvironment() {
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
} // namespace GstStartup
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
|
||||
* Copyright 2018-2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -20,32 +20,9 @@
|
||||
#ifndef GSTSTARTUP_H
|
||||
#define GSTSTARTUP_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <gst/gst.h>
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QObject>
|
||||
#include <QFuture>
|
||||
|
||||
class GstStartup : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit GstStartup(QObject *parent = nullptr);
|
||||
~GstStartup() override;
|
||||
|
||||
void EnsureInitialized() { initializing_.waitForFinished(); }
|
||||
|
||||
private:
|
||||
static GThread *kGThread;
|
||||
static gpointer GLibMainLoopThreadFunc(gpointer data);
|
||||
|
||||
static void InitializeGStreamer();
|
||||
static void SetEnvironment();
|
||||
|
||||
QFuture<void> initializing_;
|
||||
};
|
||||
namespace GstStartup {
|
||||
void Initialize();
|
||||
void SetEnvironment();
|
||||
} // namespace
|
||||
|
||||
#endif // GSTSTARTUP_H
|
||||
|
||||
Reference in New Issue
Block a user