From 176ff48ce39bbd876f0eae08e6808cdbe85fd44f Mon Sep 17 00:00:00 2001 From: Louis-Joseph Fournier Date: Wed, 13 Jan 2016 15:20:35 +0100 Subject: [PATCH] Playing works on Jolla device but still problems with low notes --- harbour-sailtuner.pro | 4 +-- rpm/Makefile | 4 +-- src/TunerSailfish.cpp | 62 +++++++++++++++---------------------------- src/TunerSailfish.hpp | 16 +++++------ src/TunerWorker.cpp | 2 +- src/sailfish.cpp | 2 +- 6 files changed, 34 insertions(+), 56 deletions(-) diff --git a/harbour-sailtuner.pro b/harbour-sailtuner.pro index 1c3fce6..bdfe7a3 100644 --- a/harbour-sailtuner.pro +++ b/harbour-sailtuner.pro @@ -5,9 +5,9 @@ CONFIG += c++11 qt link_pkgconfig sailfishapp sailfishapp_i18n sailfishapp_no_de DEFINES += TARGET=\""$(TARGET")\" -## see rpm/Makefile for installing libpulse and libresource +## see rpm/Makefile for installing libpulse and libaudioresource -PKGCONFIG += libpulse-simple libresource +PKGCONFIG += libpulse-simple audioresource RESOURCES += \ qml/sailfish.qrc \ diff --git a/rpm/Makefile b/rpm/Makefile index 8edc2e6..94cdb75 100644 --- a/rpm/Makefile +++ b/rpm/Makefile @@ -7,8 +7,8 @@ # for libresource: # sudo zypper in libresource-devel -# sb2 -t SailfishOS-i486 -m sdk-install -R zypper in libresource-devel -# sb2 -t SailfishOS-armv7hl -m sdk-install -R zypper in libresource-devel +# sb2 -t SailfishOS-i486 -m sdk-install -R zypper in libaudioresource-devel +# sb2 -t SailfishOS-armv7hl -m sdk-install -R zypper in libaudioresource-devel SAILFISHOS_DIR = $(HOME)/SailfishOS diff --git a/src/TunerSailfish.cpp b/src/TunerSailfish.cpp index cd7974e..c830b4d 100644 --- a/src/TunerSailfish.cpp +++ b/src/TunerSailfish.cpp @@ -21,67 +21,49 @@ #include "TunerSailfish.hpp" +TunerSailfish::TunerSailfish() +{ + r_set = audioresource_init(AUDIO_RESOURCE_MEDIA, g_grant_cb, this); +} + TunerSailfish::~TunerSailfish() { - // release resource if needed - if (r_set) { - resource_set_destroy(r_set); - r_set = nullptr; - r_granted = false; - } + audioresource_free(r_set); } -void TunerSailfish::g_advice_cb(resource_set_t *resource_set, uint32_t resources, void *data) +void TunerSailfish::g_grant_cb(audioresource_t *resource_set, bool acquired, void *data) { - ((TunerSailfish*) data)->advice_cb(resource_set, resources); + ((TunerSailfish*) data)->grant_cb(resource_set, acquired); } -void TunerSailfish::g_grant_cb(resource_set_t *resource_set, uint32_t resources, void *data) -{ - ((TunerSailfish*) data)->grant_cb(resource_set, resources); -} - -void TunerSailfish::advice_cb(resource_set_t *resource_set, uint32_t resources) +void TunerSailfish::grant_cb(audioresource_t *resource_set, bool acquired) { (void) resource_set; - std::cout << __func__ << " " << resources << std::endl; -} + std::cout << __func__ << " " << acquired << std::endl; -void TunerSailfish::grant_cb(resource_set_t *resource_set, uint32_t resources) -{ - (void) resource_set; - std::cout << __func__ << " " << resources << std::endl; - - if (resources & RESOURCE_AUDIO_PLAYBACK) { + if (acquired) { r_granted = true; if (playing) worker->SetPlaying(true); + emit playingChanged(); } else { r_granted = false; - if (!playing) worker->SetPlaying(false); + if (playing) worker->SetPlaying(false); } } -void TunerSailfish::get_resource() -{ - if (r_set) return; - r_set = resource_set_create("player", RESOURCE_AUDIO_PLAYBACK, 0, 0, g_grant_cb, this); - resource_set_configure_advice_callback(r_set, g_advice_cb, this); - resource_set_configure_audio (r_set, "player", getpid(), "*"); - resource_set_acquire (r_set); -} - void TunerSailfish::SetPlaying(bool p) { if (p == playing) return; playing = p; - // get resource only the first playback start - if (p && !r_set) get_resource(); - - // if not granted, don't start, and don't stop because not started - if (!r_granted) return; - - worker->SetPlaying(p); - emit playingChanged(); + if (p) { + audioresource_acquire(r_set); + } + else { + if (r_granted) worker->SetPlaying(p); + audioresource_release(r_set); + r_granted = false; + emit playingChanged(); + } } diff --git a/src/TunerSailfish.hpp b/src/TunerSailfish.hpp index 2b35a5c..e2a7c9b 100644 --- a/src/TunerSailfish.hpp +++ b/src/TunerSailfish.hpp @@ -15,7 +15,7 @@ * */ -#include +#include #include "Tuner.hpp" /** Tuner object @@ -23,19 +23,15 @@ */ class TunerSailfish : public Tuner { private: - resource_set_t *r_set = nullptr; + audioresource_t *r_set; bool r_granted = false; - /// callbacks from resource system - static void g_advice_cb(resource_set_t *resource_set, uint32_t resources, void *data); - static void g_grant_cb(resource_set_t *resource_set, uint32_t resources, void *data); - void advice_cb(resource_set_t *resource_set, uint32_t resources); - void grant_cb(resource_set_t *resource_set, uint32_t resources); - - /// main function to get resources - void get_resource(); + /// callback from resource system + static void g_grant_cb(audioresource_t *resource_set, bool acquired, void *data); + void grant_cb(audioresource_t *resource_set, bool acquired); public: + TunerSailfish(); ~TunerSailfish(); void SetPlaying(bool p); }; diff --git a/src/TunerWorker.cpp b/src/TunerWorker.cpp index e04b089..5998e02 100644 --- a/src/TunerWorker.cpp +++ b/src/TunerWorker.cpp @@ -281,7 +281,7 @@ void TunerWorker::Entry() if (pa_simple_write(p_play, buffer, nbSampleBuffer << 1, nullptr) < 0) { cerr << "audio write failed" << endl; } - else cout << "audio written" << endl; + //else cout << "audio written" << endl; } // playing // prevent screen blanking diff --git a/src/sailfish.cpp b/src/sailfish.cpp index bd76a62..654f924 100644 --- a/src/sailfish.cpp +++ b/src/sailfish.cpp @@ -53,7 +53,7 @@ Q_DECL_EXPORT int main(int argc, char* argv[]) TunerWorker::set_record(argv[2]); } - qmlRegisterType("harbour.sailtuner.tuner", 1, 0, "TunerSailfish"); + qmlRegisterType("harbour.sailtuner.tuner", 1, 0, "Tuner"); qmlRegisterType("harbour.sailtuner.objectsaver", 1, 0, "ObjectSaver"); Main *appli = new Main(argc, argv);