mirror of
https://github.com/KDE/kasts.git
synced 2024-12-19 12:03:21 +01:00
Use qCDebug in AudioManager
This commit is contained in:
parent
28b461da07
commit
3983e09634
@ -21,11 +21,13 @@ set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
|
||||
|
||||
include(FeatureSummary)
|
||||
include(ECMSetupVersion)
|
||||
include(ECMQtDeclareLoggingCategory)
|
||||
include(KDEInstallDirs)
|
||||
include(KDEClangFormat)
|
||||
include(KDECMakeSettings)
|
||||
include(KDECompilerSettings NO_POLICY_SCOPE)
|
||||
|
||||
|
||||
ecm_setup_version(${PROJECT_VERSION}
|
||||
VARIABLE_PREFIX KASTS
|
||||
VERSION_HEADER ${CMAKE_CURRENT_BINARY_DIR}/kasts-version.h
|
||||
|
@ -25,6 +25,13 @@ set(SRCS_base
|
||||
resources.qrc
|
||||
)
|
||||
|
||||
ecm_qt_declare_logging_category(SRCS_base
|
||||
HEADER "audiologging.h"
|
||||
IDENTIFIER "kastsAudio"
|
||||
CATEGORY_NAME "org.kde.kasts.audio"
|
||||
DEFAULT_SEVERITY Info
|
||||
)
|
||||
|
||||
if(ANDROID)
|
||||
set (SRCS ${SRCS_base})
|
||||
else()
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <QtMath>
|
||||
#include <algorithm>
|
||||
|
||||
#include "audiologging.h"
|
||||
#include "datamanager.h"
|
||||
#include "powermanagementinterface.h"
|
||||
#include "settingsmanager.h"
|
||||
@ -109,7 +110,7 @@ QUrl AudioManager::source() const
|
||||
QMediaPlayer::Error AudioManager::error() const
|
||||
{
|
||||
if (d->m_player.error() != QMediaPlayer::NoError) {
|
||||
qDebug() << "AudioManager::error" << d->m_player.errorString();
|
||||
qCDebug(kastsAudio) << "AudioManager::error" << d->m_player.errorString();
|
||||
// Some error occured: probably best to unset the lastPlayingEntry to
|
||||
// avoid a deadlock when starting up again.
|
||||
DataManager::instance().setLastPlayingEntry(QStringLiteral("none"));
|
||||
@ -186,11 +187,11 @@ void AudioManager::setEntry(Entry *entry)
|
||||
// First check if the previous track needs to be marked as read
|
||||
// TODO: make grace time a setting in SettingsManager
|
||||
if (d->m_entry) {
|
||||
// qDebug() << "Checking previous track";
|
||||
// qDebug() << "Left time" << (duration()-position());
|
||||
// qDebug() << "MediaStatus" << d->m_player.mediaStatus();
|
||||
qCDebug(kastsAudio) << "Checking previous track";
|
||||
qCDebug(kastsAudio) << "Left time" << (duration()-position());
|
||||
qCDebug(kastsAudio) << "MediaStatus" << d->m_player.mediaStatus();
|
||||
if (((duration() - position()) < 15000) || (d->m_player.mediaStatus() == QMediaPlayer::EndOfMedia)) {
|
||||
// qDebug() << "Mark as read:" << d->m_entry->title();
|
||||
qCDebug(kastsAudio) << "Mark as read:" << d->m_entry->title();
|
||||
d->m_entry->setRead(true);
|
||||
d->m_entry->enclosure()->setPlayPosition(0);
|
||||
d->m_entry->setQueueStatus(false); // i.e. remove from queue TODO: make this a choice in settings
|
||||
@ -198,27 +199,27 @@ void AudioManager::setEntry(Entry *entry)
|
||||
}
|
||||
}
|
||||
|
||||
// qDebug() << entry->hasEnclosure() << entry->enclosure() << entry->enclosure()->status();
|
||||
qCDebug(kastsAudio) << entry->hasEnclosure() << entry->enclosure() << entry->enclosure()->status();
|
||||
|
||||
// do some checks on the new entry to see whether it's valid and not corrupted
|
||||
if (entry != nullptr && entry->hasEnclosure() && entry->enclosure() && entry->enclosure()->status() == Enclosure::Downloaded) {
|
||||
// qDebug() << "Going to change source";
|
||||
qCDebug(kastsAudio) << "Going to change source";
|
||||
d->m_entry = entry;
|
||||
Q_EMIT entryChanged(entry);
|
||||
// the gst-pipeline is required to make sure that the pitch is not
|
||||
// changed when speeding up the audio stream
|
||||
// TODO: find a solution for Android (GStreamer not available on android by default)
|
||||
#if !defined Q_OS_ANDROID && !defined Q_OS_WIN
|
||||
// qDebug() << "use custom pipeline";
|
||||
qCDebug(kastsAudio) << "use custom pipeline";
|
||||
d->m_player.setMedia(QUrl(QStringLiteral("gst-pipeline: playbin uri=file://") + d->m_entry->enclosure()->path()
|
||||
+ QStringLiteral(" audio_sink=\"scaletempo ! audioconvert ! audioresample ! autoaudiosink\" video_sink=\"fakevideosink\"")));
|
||||
#else
|
||||
// qDebug() << "regular audio backend";
|
||||
qCDebug(kastsAudio) << "regular audio backend";
|
||||
d->m_player.setMedia(QUrl(QStringLiteral("file://") + d->m_entry->enclosure()->path()));
|
||||
#endif
|
||||
// save the current playing track in the settingsfile for restoring on startup
|
||||
DataManager::instance().setLastPlayingEntry(d->m_entry->id());
|
||||
// qDebug() << "Changed source to" << d->m_entry->title();
|
||||
qCDebug(kastsAudio) << "Changed source to" << d->m_entry->title();
|
||||
|
||||
d->prepareAudioStream();
|
||||
d->m_readyToPlay = true;
|
||||
@ -229,11 +230,11 @@ void AudioManager::setEntry(Entry *entry)
|
||||
Q_EMIT canGoNextChanged();
|
||||
d->m_isSeekable = true;
|
||||
Q_EMIT seekableChanged(true);
|
||||
// qDebug() << "Duration" << d->m_player.duration()/1000 << d->m_entry->enclosure()->duration();
|
||||
qCDebug(kastsAudio) << "Duration" << d->m_player.duration()/1000 << d->m_entry->enclosure()->duration();
|
||||
// Finally, check if duration mentioned in enclosure corresponds to real duration
|
||||
if ((d->m_player.duration() / 1000) != d->m_entry->enclosure()->duration()) {
|
||||
d->m_entry->enclosure()->setDuration(d->m_player.duration() / 1000);
|
||||
// qDebug() << "Correcting duration of" << d->m_entry->id() << "to" << d->m_player.duration()/1000;
|
||||
qCDebug(kastsAudio) << "Correcting duration of" << d->m_entry->id() << "to" << d->m_player.duration()/1000;
|
||||
}
|
||||
if (continuePlayback) play();
|
||||
} else {
|
||||
@ -264,7 +265,7 @@ void AudioManager::setMuted(bool muted)
|
||||
|
||||
void AudioManager::setVolume(qreal volume)
|
||||
{
|
||||
// qDebug() << "AudioManager::setVolume" << volume;
|
||||
qCDebug(kastsAudio) << "AudioManager::setVolume" << volume;
|
||||
|
||||
auto realVolume = static_cast<qreal>(QAudio::convertVolume(volume / 100.0, QAudio::LogarithmicVolumeScale, QAudio::LinearVolumeScale));
|
||||
d->m_player.setVolume(qRound(realVolume * 100));
|
||||
@ -273,7 +274,7 @@ void AudioManager::setVolume(qreal volume)
|
||||
/*
|
||||
void AudioManager::setSource(const QUrl &source)
|
||||
{
|
||||
//qDebug() << "AudioManager::setSource" << source;
|
||||
//qCDebug(kastsAudio) << "AudioManager::setSource" << source;
|
||||
|
||||
d->m_player.setMedia({source});
|
||||
}
|
||||
@ -281,21 +282,21 @@ void AudioManager::setSource(const QUrl &source)
|
||||
|
||||
void AudioManager::setPosition(qint64 position)
|
||||
{
|
||||
// qDebug() << "AudioManager::setPosition" << position;
|
||||
qCDebug(kastsAudio) << "AudioManager::setPosition" << position;
|
||||
|
||||
d->m_player.setPosition(position);
|
||||
}
|
||||
|
||||
void AudioManager::setPlaybackRate(const qreal rate)
|
||||
{
|
||||
// qDebug() << "AudioManager::setPlaybackRate" << rate;
|
||||
qCDebug(kastsAudio) << "AudioManager::setPlaybackRate" << rate;
|
||||
|
||||
d->m_player.setPlaybackRate(rate);
|
||||
}
|
||||
|
||||
void AudioManager::play()
|
||||
{
|
||||
// qDebug() << "AudioManager::play";
|
||||
qCDebug(kastsAudio) << "AudioManager::play";
|
||||
|
||||
d->prepareAudioStream();
|
||||
d->m_player.play();
|
||||
@ -306,7 +307,7 @@ void AudioManager::play()
|
||||
|
||||
void AudioManager::pause()
|
||||
{
|
||||
// qDebug() << "AudioManager::pause";
|
||||
qCDebug(kastsAudio) << "AudioManager::pause";
|
||||
|
||||
d->m_isSeekable = true;
|
||||
d->m_player.pause();
|
||||
@ -323,7 +324,7 @@ void AudioManager::playPause()
|
||||
|
||||
void AudioManager::stop()
|
||||
{
|
||||
// qDebug() << "AudioManager::stop";
|
||||
qCDebug(kastsAudio) << "AudioManager::stop";
|
||||
|
||||
d->m_player.stop();
|
||||
d->m_isSeekable = false;
|
||||
@ -333,20 +334,20 @@ void AudioManager::stop()
|
||||
|
||||
void AudioManager::seek(qint64 position)
|
||||
{
|
||||
// qDebug() << "AudioManager::seek" << position;
|
||||
qCDebug(kastsAudio) << "AudioManager::seek" << position;
|
||||
|
||||
d->m_player.setPosition(position);
|
||||
}
|
||||
|
||||
void AudioManager::skipForward()
|
||||
{
|
||||
// qDebug() << "AudioManager::skipForward";
|
||||
qCDebug(kastsAudio) << "AudioManager::skipForward";
|
||||
seek(std::min((position() + SKIP_STEP), duration()));
|
||||
}
|
||||
|
||||
void AudioManager::skipBackward()
|
||||
{
|
||||
// qDebug() << "AudioManager::skipBackward";
|
||||
qCDebug(kastsAudio) << "AudioManager::skipBackward";
|
||||
seek(std::max((qint64)0, (position() - SKIP_STEP)));
|
||||
}
|
||||
|
||||
@ -360,7 +361,7 @@ bool AudioManager::canGoNext() const
|
||||
if (index < DataManager::instance().queue().count() - 1) {
|
||||
Entry *next_entry = DataManager::instance().getEntry(DataManager::instance().queue()[index + 1]);
|
||||
if (next_entry->enclosure()) {
|
||||
// qDebug() << "Enclosure status" << next_entry->enclosure()->path() << next_entry->enclosure()->status();
|
||||
qCDebug(kastsAudio) << "Enclosure status" << next_entry->enclosure()->path() << next_entry->enclosure()->status();
|
||||
if (next_entry->enclosure()->status() == Enclosure::Downloaded) {
|
||||
return true;
|
||||
}
|
||||
@ -376,19 +377,19 @@ void AudioManager::next()
|
||||
if (canGoNext()) {
|
||||
QMediaPlayer::State previousTrackState = playbackState();
|
||||
int index = DataManager::instance().queue().indexOf(d->m_entry->id());
|
||||
// qDebug() << "Skipping to" << DataManager::instance().queue()[index+1];
|
||||
qCDebug(kastsAudio) << "Skipping to" << DataManager::instance().queue()[index+1];
|
||||
setEntry(DataManager::instance().getEntry(DataManager::instance().queue()[index + 1]));
|
||||
if (previousTrackState == QMediaPlayer::PlayingState)
|
||||
play();
|
||||
} else {
|
||||
// qDebug() << "Next track cannot be played, changing entry to nullptr";
|
||||
qCDebug(kastsAudio) << "Next track cannot be played, changing entry to nullptr";
|
||||
setEntry(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioManager::mediaStatusChanged()
|
||||
{
|
||||
// qDebug() << "AudioManager::mediaStatusChanged" << d->m_player.mediaStatus();
|
||||
qCDebug(kastsAudio) << "AudioManager::mediaStatusChanged" << d->m_player.mediaStatus();
|
||||
|
||||
// File has reached the end and has stopped
|
||||
if (d->m_player.mediaStatus() == QMediaPlayer::EndOfMedia) {
|
||||
@ -413,7 +414,7 @@ void AudioManager::mediaStatusChanged()
|
||||
|
||||
void AudioManager::playerStateChanged()
|
||||
{
|
||||
// qDebug() << "AudioManager::playerStateChanged" << d->m_player.state();
|
||||
qCDebug(kastsAudio) << "AudioManager::playerStateChanged" << d->m_player.state();
|
||||
|
||||
switch (d->m_player.state()) {
|
||||
case QMediaPlayer::State::StoppedState:
|
||||
@ -435,7 +436,7 @@ void AudioManager::playerStateChanged()
|
||||
|
||||
void AudioManager::playerVolumeChanged()
|
||||
{
|
||||
// qDebug() << "AudioManager::playerVolumeChanged" << d->m_player.volume();
|
||||
qCDebug(kastsAudio) << "AudioManager::playerVolumeChanged" << d->m_player.volume();
|
||||
|
||||
QTimer::singleShot(0, this, [this]() {
|
||||
Q_EMIT volumeChanged();
|
||||
@ -444,7 +445,7 @@ void AudioManager::playerVolumeChanged()
|
||||
|
||||
void AudioManager::playerMutedChanged()
|
||||
{
|
||||
// qDebug() << "AudioManager::playerMutedChanged";
|
||||
qCDebug(kastsAudio) << "AudioManager::playerMutedChanged";
|
||||
|
||||
QTimer::singleShot(0, this, [this]() {
|
||||
Q_EMIT mutedChanged(muted());
|
||||
@ -460,7 +461,7 @@ void AudioManager::savePlayPosition(qint64 position)
|
||||
}
|
||||
}
|
||||
}
|
||||
// qDebug() << d->m_player.mediaStatus();
|
||||
qCDebug(kastsAudio) << d->m_player.mediaStatus();
|
||||
}
|
||||
|
||||
void AudioManagerPrivate::prepareAudioStream()
|
||||
@ -474,7 +475,7 @@ void AudioManagerPrivate::prepareAudioStream()
|
||||
* Unfortunately, this will produce an audible glitch with the current
|
||||
* QMediaPlayer backend.
|
||||
*/
|
||||
// qDebug() << "voodoo happening";
|
||||
qCDebug(kastsAudio) << "voodoo happening";
|
||||
qint64 startingPosition = m_entry->enclosure()->playPosition();
|
||||
m_player.play();
|
||||
if (!m_player.isSeekable()) {
|
||||
@ -484,7 +485,7 @@ void AudioManagerPrivate::prepareAudioStream()
|
||||
timer.setInterval(2000);
|
||||
loop.connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
|
||||
loop.connect(&m_player, &QMediaPlayer::seekableChanged, &loop, &QEventLoop::quit);
|
||||
// qDebug() << "Starting waiting loop";
|
||||
qCDebug(kastsAudio) << "Starting waiting loop";
|
||||
loop.exec();
|
||||
}
|
||||
if (m_player.mediaStatus() != QMediaPlayer::BufferedMedia) {
|
||||
@ -494,9 +495,9 @@ void AudioManagerPrivate::prepareAudioStream()
|
||||
timer.setInterval(2000);
|
||||
loop.connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
|
||||
loop.connect(&m_player, &QMediaPlayer::mediaStatusChanged, &loop, &QEventLoop::quit);
|
||||
// qDebug() << "Starting waiting loop on media status" << d->m_player.mediaStatus();
|
||||
qCDebug(kastsAudio) << "Starting waiting loop on media status" << m_player.mediaStatus();
|
||||
loop.exec();
|
||||
} // qDebug() << "Changing position";
|
||||
} qCDebug(kastsAudio) << "Changing position";
|
||||
if (startingPosition > 1000)
|
||||
m_player.setPosition(startingPosition);
|
||||
m_player.pause();
|
||||
|
Loading…
Reference in New Issue
Block a user