Playing works on Jolla device

but still problems with low notes
This commit is contained in:
Louis-Joseph Fournier 2016-01-13 15:20:35 +01:00
parent 9ef3931c8c
commit 176ff48ce3
6 changed files with 34 additions and 56 deletions

View file

@ -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 \

View file

@ -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

View file

@ -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();
}
}

View file

@ -15,7 +15,7 @@
*
*/
#include <resource.h>
#include <audioresource.h>
#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);
};

View file

@ -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

View file

@ -53,7 +53,7 @@ Q_DECL_EXPORT int main(int argc, char* argv[])
TunerWorker::set_record(argv[2]);
}
qmlRegisterType<Tuner>("harbour.sailtuner.tuner", 1, 0, "TunerSailfish");
qmlRegisterType<TunerSailfish>("harbour.sailtuner.tuner", 1, 0, "Tuner");
qmlRegisterType<ObjectSaver>("harbour.sailtuner.objectsaver", 1, 0, "ObjectSaver");
Main *appli = new Main(argc, argv);