Player try resource API to get playback resource

Don't work ; try audioresource instead..
This commit is contained in:
Louis-Joseph Fournier 2016-01-13 14:55:07 +01:00
parent 33eeeda8d6
commit 9ef3931c8c
6 changed files with 144 additions and 7 deletions

View file

@ -1,11 +1,13 @@
QT += qml quick gui multimedia dbus
TARGET = harbour-sailtuner
CONFIG += c++11 link_pkgconfig sailfishapp sailfishapp_i18n sailfishapp_no_deploy_qml
CONFIG += c++11 qt link_pkgconfig sailfishapp sailfishapp_i18n sailfishapp_no_deploy_qml
DEFINES += TARGET=\""$(TARGET")\"
PKGCONFIG += libpulse-simple
## see rpm/Makefile for installing libpulse and libresource
PKGCONFIG += libpulse-simple libresource
RESOURCES += \
qml/sailfish.qrc \
@ -16,6 +18,7 @@ SOURCES += \
src/PitchDetection.cpp \
src/ObjectSaver.cpp \
src/Tuner.cpp \
src/TunerSailfish.cpp \
src/TunerWorker.cpp \
src/audio/FreqPlayer.cpp \
src/audio/LinearFilter.cpp \
@ -28,6 +31,7 @@ HEADERS += \
src/ObjectSaver.hpp \
src/Tuner.cpp \
src/Tuner.hpp \
src/TunerSailfish.hpp \
src/TunerWorker.hpp \
src/audio/FreqPlayer.hpp \
src/audio/LinearFilter.hpp \

View file

@ -2,9 +2,14 @@
# to add pulseaudio dev to MerSDK:
# sudo zypper in pulseaudio-devel
# sb2 -t SailfishOS-i486-x86 -m sdk-install -R zypper in pulseaudio-devel
# sb2 -t SailfishOS-i486 -m sdk-install -R zypper in pulseaudio-devel
# sb2 -t SailfishOS-armv7hl -m sdk-install -R zypper in pulseaudio-devel
# 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
SAILFISHOS_DIR = $(HOME)/SailfishOS
SSH_KEYS_DIR = $(SAILFISHOS_DIR)/vmshare/ssh/private_keys

View file

@ -36,7 +36,7 @@ class Tuner : public QObject {
Q_PROPERTY(QStringList temperament_list READ GetTemperamentList NOTIFY temperamentListChanged)
Q_PROPERTY(double la READ GetLa WRITE SetLa NOTIFY laChanged)
private:
protected:
TunerWorker *worker;
QThread workerThread;
@ -51,7 +51,7 @@ class Tuner : public QObject {
~Tuner();
bool GetPlaying();
void SetPlaying(bool p);
virtual void SetPlaying(bool p);
bool GetRunning();
void SetRunning(bool r);
double GetFreq();

87
src/TunerSailfish.cpp Normal file
View file

@ -0,0 +1,87 @@
/* Copyright 2016 (C) Louis-Joseph Fournier
* louisjoseph.fournier@gmail.com
*
* This file is part of SailTuner.
*
* SailTuner is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SailTuner is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <stdlib.h>
#include <unistd.h> /* for getpid() */
#include <iostream>
#include "TunerSailfish.hpp"
TunerSailfish::~TunerSailfish()
{
// release resource if needed
if (r_set) {
resource_set_destroy(r_set);
r_set = nullptr;
r_granted = false;
}
}
void TunerSailfish::g_advice_cb(resource_set_t *resource_set, uint32_t resources, void *data)
{
((TunerSailfish*) data)->advice_cb(resource_set, resources);
}
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) resource_set;
std::cout << __func__ << " " << resources << 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) {
r_granted = true;
if (playing) worker->SetPlaying(true);
}
else {
r_granted = 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();
}

41
src/TunerSailfish.hpp Normal file
View file

@ -0,0 +1,41 @@
/* Copyright 2016 (C) Louis-Joseph Fournier
* louisjoseph.fournier@gmail.com
*
* This file is part of SailTuner.
*
* SailTuner is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SailTuner is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <resource.h>
#include "Tuner.hpp"
/** Tuner object
* with resource handling for audio playback
*/
class TunerSailfish : public Tuner {
private:
resource_set_t *r_set = nullptr;
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();
public:
~TunerSailfish();
void SetPlaying(bool p);
};

View file

@ -20,7 +20,7 @@
#include <QtQml>
#include <sailfishapp.h>
#include "ObjectSaver.hpp"
#include "Tuner.hpp"
#include "TunerSailfish.hpp"
class Main {
private:
@ -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, "Tuner");
qmlRegisterType<Tuner>("harbour.sailtuner.tuner", 1, 0, "TunerSailfish");
qmlRegisterType<ObjectSaver>("harbour.sailtuner.objectsaver", 1, 0, "ObjectSaver");
Main *appli = new Main(argc, argv);