Application: Use shared pointers

Fixes #1239
This commit is contained in:
Jonas Kvinge
2023-07-21 05:55:24 +02:00
parent d6b53f78ab
commit 2e61235403
316 changed files with 2170 additions and 1643 deletions

View File

@@ -45,6 +45,8 @@
#include "ebur128analysis.h"
using std::unique_ptr;
static const int kTimeoutSecs = 60;
namespace {
@@ -185,7 +187,7 @@ class EBUR128State {
static std::optional<EBUR128Measures> Finalize(EBUR128State &&state);
private:
std::unique_ptr<ebur128_state, ebur128_state_deleter> st;
unique_ptr<ebur128_state, ebur128_state_deleter> st;
};
class EBUR128AnalysisImpl {
@@ -342,7 +344,7 @@ GstFlowReturn EBUR128AnalysisImpl::NewBufferCallback(GstAppSink *app_sink, gpoin
EBUR128AnalysisImpl *me = reinterpret_cast<EBUR128AnalysisImpl*>(self);
std::unique_ptr<GstSample, GstSampleDeleter> sample(gst_app_sink_pull_sample(app_sink));
unique_ptr<GstSample, GstSampleDeleter> sample(gst_app_sink_pull_sample(app_sink));
if (!sample) return GST_FLOW_ERROR;
const FrameFormat dsc(gst_sample_get_caps(&*sample));

View File

@@ -48,6 +48,7 @@
#include <QMetaObject>
#include <QTimerEvent>
#include "core/shared_ptr.h"
#include "core/logging.h"
#include "core/taskmanager.h"
#include "core/signalchecker.h"
@@ -58,6 +59,8 @@
#include "gstbufferconsumer.h"
#include "enginemetadata.h"
using std::make_shared;
const char *GstEngine::kAutoSink = "autoaudiosink";
const char *GstEngine::kALSASink = "alsasink";
const char *GstEngine::kOpenALSASink = "openalsink";
@@ -75,7 +78,7 @@ const qint64 GstEngine::kTimerIntervalNanosec = 1000 * kNsecPerMsec; // 1s
const qint64 GstEngine::kPreloadGapNanosec = 8000 * kNsecPerMsec; // 8s
const qint64 GstEngine::kSeekDelayNanosec = 100 * kNsecPerMsec; // 100msec
GstEngine::GstEngine(TaskManager *task_manager, QObject *parent)
GstEngine::GstEngine(SharedPtr<TaskManager> task_manager, QObject *parent)
: EngineBase(parent),
task_manager_(task_manager),
gst_startup_(nullptr),
@@ -197,7 +200,7 @@ bool GstEngine::Load(const QUrl &media_url, const QUrl &stream_url, const Engine
return true;
}
std::shared_ptr<GstEnginePipeline> pipeline = CreatePipeline(media_url, stream_url, gst_url, force_stop_at_end ? end_nanosec : 0, ebur128_loudness_normalizing_gain_db_);
SharedPtr<GstEnginePipeline> pipeline = CreatePipeline(media_url, stream_url, gst_url, force_stop_at_end ? end_nanosec : 0, ebur128_loudness_normalizing_gain_db_);
if (!pipeline) return false;
if (crossfade) StartFadeout();
@@ -269,7 +272,7 @@ void GstEngine::Stop(const bool stop_after) {
// Check if we started a fade out. If it isn't finished yet and the user pressed stop, we cancel the fader and just stop the playback.
if (is_fading_out_to_pause_) {
QObject::disconnect(current_pipeline_.get(), &GstEnginePipeline::FaderFinished, nullptr, nullptr);
QObject::disconnect(&*current_pipeline_, &GstEnginePipeline::FaderFinished, nullptr, nullptr);
is_fading_out_to_pause_ = false;
has_faded_out_ = true;
@@ -291,7 +294,7 @@ void GstEngine::Pause() {
// Check if we started a fade out. If it isn't finished yet and the user pressed play, we inverse the fader and resume the playback.
if (is_fading_out_to_pause_) {
QObject::disconnect(current_pipeline_.get(), &GstEnginePipeline::FaderFinished, nullptr, nullptr);
QObject::disconnect(&*current_pipeline_, &GstEnginePipeline::FaderFinished, nullptr, nullptr);
current_pipeline_->StartFader(fadeout_pause_duration_nanosec_, QTimeLine::Forward, QEasingCurve::InOutQuad, false);
is_fading_out_to_pause_ = false;
has_faded_out_ = false;
@@ -322,7 +325,7 @@ void GstEngine::Unpause() {
// Check if we faded out last time. If yes, fade in no matter what the settings say.
// If we pause with fadeout, deactivate fadeout and resume playback, the player would be muted if not faded in.
if (has_faded_out_) {
QObject::disconnect(current_pipeline_.get(), &GstEnginePipeline::FaderFinished, nullptr, nullptr);
QObject::disconnect(&*current_pipeline_, &GstEnginePipeline::FaderFinished, nullptr, nullptr);
current_pipeline_->StartFader(fadeout_pause_duration_nanosec_, QTimeLine::Forward, QEasingCurve::InOutQuad, false);
has_faded_out_ = false;
}
@@ -742,24 +745,24 @@ void GstEngine::StartFadeout() {
if (is_fading_out_to_pause_) return;
fadeout_pipeline_ = current_pipeline_;
QObject::disconnect(fadeout_pipeline_.get(), nullptr, nullptr, nullptr);
QObject::disconnect(&*fadeout_pipeline_, nullptr, nullptr, nullptr);
fadeout_pipeline_->RemoveAllBufferConsumers();
fadeout_pipeline_->StartFader(fadeout_duration_nanosec_, QTimeLine::Backward);
QObject::connect(fadeout_pipeline_.get(), &GstEnginePipeline::FaderFinished, this, &GstEngine::FadeoutFinished);
QObject::connect(&*fadeout_pipeline_, &GstEnginePipeline::FaderFinished, this, &GstEngine::FadeoutFinished);
}
void GstEngine::StartFadeoutPause() {
fadeout_pause_pipeline_ = current_pipeline_;
QObject::disconnect(fadeout_pause_pipeline_.get(), &GstEnginePipeline::FaderFinished, nullptr, nullptr);
QObject::disconnect(&*fadeout_pause_pipeline_, &GstEnginePipeline::FaderFinished, nullptr, nullptr);
fadeout_pause_pipeline_->StartFader(fadeout_pause_duration_nanosec_, QTimeLine::Backward, QEasingCurve::InOutQuad, false);
if (fadeout_pipeline_ && fadeout_pipeline_->state() == GST_STATE_PLAYING) {
fadeout_pipeline_->StartFader(fadeout_pause_duration_nanosec_, QTimeLine::Backward, QEasingCurve::Linear, false);
}
QObject::connect(fadeout_pause_pipeline_.get(), &GstEnginePipeline::FaderFinished, this, &GstEngine::FadeoutPauseFinished);
QObject::connect(&*fadeout_pause_pipeline_, &GstEnginePipeline::FaderFinished, this, &GstEngine::FadeoutPauseFinished);
is_fading_out_to_pause_ = true;
}
@@ -780,11 +783,11 @@ void GstEngine::StopTimers() {
}
std::shared_ptr<GstEnginePipeline> GstEngine::CreatePipeline() {
SharedPtr<GstEnginePipeline> GstEngine::CreatePipeline() {
EnsureInitialized();
std::shared_ptr<GstEnginePipeline> ret = std::make_shared<GstEnginePipeline>();
SharedPtr<GstEnginePipeline> ret = make_shared<GstEnginePipeline>();
ret->set_output_device(output_, device_);
ret->set_volume_enabled(volume_control_);
ret->set_stereo_balancer_enabled(stereo_balancer_enabled_);
@@ -805,22 +808,22 @@ std::shared_ptr<GstEnginePipeline> GstEngine::CreatePipeline() {
ret->AddBufferConsumer(consumer);
}
QObject::connect(ret.get(), &GstEnginePipeline::EndOfStreamReached, this, &GstEngine::EndOfStreamReached);
QObject::connect(ret.get(), &GstEnginePipeline::Error, this, &GstEngine::HandlePipelineError);
QObject::connect(ret.get(), &GstEnginePipeline::MetadataFound, this, &GstEngine::NewMetaData);
QObject::connect(ret.get(), &GstEnginePipeline::BufferingStarted, this, &GstEngine::BufferingStarted);
QObject::connect(ret.get(), &GstEnginePipeline::BufferingProgress, this, &GstEngine::BufferingProgress);
QObject::connect(ret.get(), &GstEnginePipeline::BufferingFinished, this, &GstEngine::BufferingFinished);
QObject::connect(ret.get(), &GstEnginePipeline::VolumeChanged, this, &EngineBase::UpdateVolume);
QObject::connect(ret.get(), &GstEnginePipeline::AboutToFinish, this, &EngineBase::EmitAboutToFinish);
QObject::connect(&*ret, &GstEnginePipeline::EndOfStreamReached, this, &GstEngine::EndOfStreamReached);
QObject::connect(&*ret, &GstEnginePipeline::Error, this, &GstEngine::HandlePipelineError);
QObject::connect(&*ret, &GstEnginePipeline::MetadataFound, this, &GstEngine::NewMetaData);
QObject::connect(&*ret, &GstEnginePipeline::BufferingStarted, this, &GstEngine::BufferingStarted);
QObject::connect(&*ret, &GstEnginePipeline::BufferingProgress, this, &GstEngine::BufferingProgress);
QObject::connect(&*ret, &GstEnginePipeline::BufferingFinished, this, &GstEngine::BufferingFinished);
QObject::connect(&*ret, &GstEnginePipeline::VolumeChanged, this, &EngineBase::UpdateVolume);
QObject::connect(&*ret, &GstEnginePipeline::AboutToFinish, this, &EngineBase::EmitAboutToFinish);
return ret;
}
std::shared_ptr<GstEnginePipeline> GstEngine::CreatePipeline(const QUrl &media_url, const QUrl &stream_url, const QByteArray &gst_url, const qint64 end_nanosec, const double ebur128_loudness_normalizing_gain_db) {
SharedPtr<GstEnginePipeline> GstEngine::CreatePipeline(const QUrl &media_url, const QUrl &stream_url, const QByteArray &gst_url, const qint64 end_nanosec, const double ebur128_loudness_normalizing_gain_db) {
std::shared_ptr<GstEnginePipeline> ret = CreatePipeline();
SharedPtr<GstEnginePipeline> ret = CreatePipeline();
QString error;
if (!ret->InitFromUrl(media_url, stream_url, gst_url, end_nanosec, ebur128_loudness_normalizing_gain_db, error)) {
ret.reset();

View File

@@ -25,7 +25,6 @@
#include "config.h"
#include <memory>
#include <optional>
#include <gst/gst.h>
@@ -39,6 +38,7 @@
#include <QString>
#include <QUrl>
#include "core/shared_ptr.h"
#include "enginebase.h"
#include "gststartup.h"
#include "gstbufferconsumer.h"
@@ -52,7 +52,7 @@ class GstEngine : public EngineBase, public GstBufferConsumer {
Q_OBJECT
public:
explicit GstEngine(TaskManager *task_manager, QObject *parent = nullptr);
explicit GstEngine(SharedPtr<TaskManager> task_manager, QObject *parent = nullptr);
~GstEngine() override;
static const char *kAutoSink;
@@ -131,8 +131,8 @@ class GstEngine : public EngineBase, public GstBufferConsumer {
void StartTimers();
void StopTimers();
std::shared_ptr<GstEnginePipeline> CreatePipeline();
std::shared_ptr<GstEnginePipeline> CreatePipeline(const QUrl &media_url, const QUrl &stream_url, const QByteArray &gst_url, const qint64 end_nanosec, const double ebur128_loudness_normalizing_gain_db);
SharedPtr<GstEnginePipeline> CreatePipeline();
SharedPtr<GstEnginePipeline> CreatePipeline(const QUrl &media_url, const QUrl &stream_url, const QByteArray &gst_url, const qint64 end_nanosec, const double ebur128_loudness_normalizing_gain_db);
void UpdateScope(int chunk_length);
@@ -157,15 +157,15 @@ class GstEngine : public EngineBase, public GstBufferConsumer {
static const qint64 kPreloadGapNanosec;
static const qint64 kSeekDelayNanosec;
TaskManager *task_manager_;
SharedPtr<TaskManager> task_manager_;
GstStartup *gst_startup_;
GstDiscoverer *discoverer_;
int buffering_task_id_;
std::shared_ptr<GstEnginePipeline> current_pipeline_;
std::shared_ptr<GstEnginePipeline> fadeout_pipeline_;
std::shared_ptr<GstEnginePipeline> fadeout_pause_pipeline_;
SharedPtr<GstEnginePipeline> current_pipeline_;
SharedPtr<GstEnginePipeline> fadeout_pipeline_;
SharedPtr<GstEnginePipeline> fadeout_pause_pipeline_;
QList<GstBufferConsumer*> buffer_consumers_;

View File

@@ -21,7 +21,6 @@
#include "config.h"
#include <memory>
#include <cstdint>
#include <cstring>
#include <cmath>
@@ -1655,8 +1654,8 @@ void GstEnginePipeline::StartFader(const qint64 duration_nanosec, const QTimeLin
}
timeline->deleteLater();
});
QObject::connect(fader_.get(), &QTimeLine::valueChanged, this, &GstEnginePipeline::SetFaderVolume);
QObject::connect(fader_.get(), &QTimeLine::finished, this, &GstEnginePipeline::FaderTimelineFinished);
QObject::connect(&*fader_, &QTimeLine::valueChanged, this, &GstEnginePipeline::SetFaderVolume);
QObject::connect(&*fader_, &QTimeLine::finished, this, &GstEnginePipeline::FaderTimelineFinished);
fader_->setDirection(direction);
fader_->setEasingCurve(shape);
fader_->setCurrentTime(static_cast<int>(start_time));

View File

@@ -24,7 +24,6 @@
#include "config.h"
#include <memory>
#include <glib.h>
#include <glib-object.h>
#include <glib/gtypes.h>
@@ -44,6 +43,7 @@
#include <QString>
#include <QUrl>
#include "core/shared_ptr.h"
#include "enginemetadata.h"
class QTimerEvent;
@@ -294,7 +294,7 @@ class GstEnginePipeline : public QObject {
gdouble volume_internal_;
uint volume_percent_;
std::shared_ptr<QTimeLine> fader_;
SharedPtr<QTimeLine> fader_;
QBasicTimer fader_fudge_timer_;
bool use_fudge_timer_;

View File

@@ -32,6 +32,7 @@
#include <QByteArray>
#include <QUrl>
#include "core/shared_ptr.h"
#include "core/taskmanager.h"
#include "core/logging.h"
#include "utilities/timeconstants.h"
@@ -39,7 +40,7 @@
#include "vlcengine.h"
#include "vlcscopedref.h"
VLCEngine::VLCEngine(TaskManager *task_manager, QObject *parent)
VLCEngine::VLCEngine(SharedPtr<TaskManager> task_manager, QObject *parent)
: EngineBase(parent),
instance_(nullptr),
player_(nullptr),

View File

@@ -33,6 +33,8 @@
#include <QString>
#include <QUrl>
#include "core/shared_ptr.h"
#include "enginebase.h"
struct libvlc_event_t;
@@ -43,7 +45,7 @@ class VLCEngine : public EngineBase {
Q_OBJECT
public:
explicit VLCEngine(TaskManager *task_manager, QObject *parent = nullptr);
explicit VLCEngine(SharedPtr<TaskManager> task_manager, QObject *parent = nullptr);
~VLCEngine() override;
Type type() const override { return Type::VLC; }