Commit fb9c11df authored by Ronan's avatar Ronan

fix(src/components/sound-player/SoundPlayer): handle eof

parent b4739025
......@@ -401,6 +401,7 @@
<file>ui/views/App/Styles/Main/MainWindowStyle.qml</file>
<file>ui/views/App/Styles/Main/ManageAccountsStyle.qml</file>
<file>ui/views/App/Styles/qmldir</file>
<file>ui/views/App/Styles/Settings/SettingsAudioStyle.qml</file>
<file>ui/views/App/Styles/Settings/SettingsSipAccountsEditStyle.qml</file>
<file>ui/views/App/Styles/Settings/SettingsVideoPreviewStyle.qml</file>
<file>ui/views/App/Styles/Settings/SettingsWindowStyle.qml</file>
......
......@@ -29,6 +29,8 @@
#include <QtConcurrent>
#include <QTimer>
#define CBS_CALL_INTERVAL 20
using namespace std;
// =============================================================================
......@@ -66,7 +68,7 @@ void CoreManager::init (QObject *parent, const QString &configPath) {
mInstance = new CoreManager(parent, configPath);
QTimer *timer = mInstance->mCbsTimer = new QTimer(mInstance);
timer->setInterval(20);
timer->setInterval(CBS_CALL_INTERVAL);
QObject::connect(timer, &QTimer::timeout, mInstance, &CoreManager::iterate);
}
......
......@@ -20,11 +20,15 @@
* Author: Ronan Abhamon
*/
#include <QTimer>
#include "../../Utils.hpp"
#include "../core/CoreManager.hpp"
#include "SoundPlayer.hpp"
#define FORCE_CLOSE_TIMER_INTERVAL 20
using namespace std;
// =============================================================================
......@@ -37,7 +41,14 @@ public:
private:
void onEofReached (const shared_ptr<linphone::Player> &) override {
mSoundPlayer->stop();
QMutex &mutex = mSoundPlayer->mForceCloseMutex;
// Workaround.
// This callback is called in a standard thread of mediastreamer, not a QThread.
// Signals, connect functions, timers... are unavailable.
mutex.lock();
mSoundPlayer->mForceClose = true;
mutex.unlock();
}
SoundPlayer *mSoundPlayer;
......@@ -46,6 +57,11 @@ private:
// -----------------------------------------------------------------------------
SoundPlayer::SoundPlayer (QObject *parent) : QObject(parent) {
mForceCloseTimer = new QTimer(this);
mForceCloseTimer->setInterval(FORCE_CLOSE_TIMER_INTERVAL);
QObject::connect(mForceCloseTimer, &QTimer::timeout, this, &SoundPlayer::handleEof);
mHandlers = make_shared<SoundPlayer::Handlers>(this);
mInternalPlayer = CoreManager::getInstance()->getCore()->createLocalPlayer("", "", nullptr);
......@@ -63,6 +79,7 @@ void SoundPlayer::pause () {
return;
}
mForceCloseTimer->stop();
mPlaybackState = SoundPlayer::PausedState;
emit paused();
......@@ -87,6 +104,7 @@ void SoundPlayer::play () {
return;
}
mForceCloseTimer->start();
mPlaybackState = SoundPlayer::PlayingState;
emit playing();
......@@ -97,9 +115,11 @@ void SoundPlayer::stop () {
if (mPlaybackState == SoundPlayer::StoppedState)
return;
mInternalPlayer->close();
mForceCloseTimer->stop();
mPlaybackState = SoundPlayer::StoppedState;
mInternalPlayer->close();
emit stopped();
emit playbackStateChanged(mPlaybackState);
}
......@@ -118,6 +138,19 @@ int SoundPlayer::getPosition () const {
// -----------------------------------------------------------------------------
void SoundPlayer::handleEof () {
mForceCloseMutex.lock();
if (mForceClose) {
mForceClose = false;
stop();
}
mForceCloseMutex.unlock();
}
// -----------------------------------------------------------------------------
void SoundPlayer::setError (const QString &message) {
qWarning() << message;
mInternalPlayer->close();
......
......@@ -25,10 +25,13 @@
#include <memory>
#include <QMutex>
#include <QObject>
// =============================================================================
class QTimer;
namespace linphone {
class Player;
}
......@@ -55,13 +58,13 @@ public:
SoundPlayer (QObject *parent = Q_NULLPTR);
~SoundPlayer () = default;
void pause ();
void play ();
void stop ();
Q_INVOKABLE void pause ();
Q_INVOKABLE void play ();
Q_INVOKABLE void stop ();
void seek (int offset);
Q_INVOKABLE void seek (int offset);
int getPosition () const;
Q_INVOKABLE int getPosition () const;
signals:
void sourceChanged (const QString &source);
......@@ -73,6 +76,8 @@ signals:
void playbackStateChanged (PlaybackState playbackState);
private:
void handleEof ();
void setError (const QString &message);
QString getSource () const;
......@@ -86,6 +91,11 @@ private:
QString mSource;
PlaybackState mPlaybackState = StoppedState;
bool mForceClose = false;
QMutex mForceCloseMutex;
QTimer *mForceCloseTimer;
std::shared_ptr<linphone::Player> mInternalPlayer;
std::shared_ptr<Handlers> mHandlers;
};
......
......@@ -73,7 +73,40 @@ TabContainer {
FileChooserButton {
selectedFile: SettingsModel.ringPath
onAccepted: SettingsModel.ringPath = selectedFile
onAccepted: {
ringPlayer.stop()
SettingsModel.ringPath = selectedFile
}
ActionSwitch {
anchors {
left: parent.right
leftMargin: SettingsAudioStyle.ringPlayer.leftMargin
}
enabled: ringPlayer.playbackState === SoundPlayer.PlayingState
icon: 'pause'
onClicked: {
if (enabled) {
ringPlayer.stop()
} else {
ringPlayer.play()
}
}
SoundPlayer {
id: ringPlayer
source: SettingsModel.ringPath
}
Connections {
target: window
onClosing: ringPlayer.stop()
}
}
}
}
}
......
pragma Singleton
import QtQuick 2.7
// =============================================================================
QtObject {
property QtObject ringPlayer: QtObject {
property int leftMargin: 10
}
}
......@@ -25,6 +25,7 @@ singleton MainWindowMenuBarStyle 1.0 Main/MainWindowMenuBarSty
singleton MainWindowStyle 1.0 Main/MainWindowStyle.qml
singleton ManageAccountsStyle 1.0 Main/ManageAccountsStyle.qml
singleton SettingsAudioStyle 1.0 Settings/SettingsAudioStyle.qml
singleton SettingsSipAccountsEditStyle 1.0 Settings/SettingsSipAccountsEditStyle.qml
singleton SettingsVideoPreviewStyle 1.0 Settings/SettingsVideoPreviewStyle.qml
singleton SettingsWindowStyle 1.0 Settings/SettingsWindowStyle.qml
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment