Playing works on Jolla device
but still problems with low notes
This commit is contained in:
parent
9ef3931c8c
commit
176ff48ce3
6 changed files with 34 additions and 56 deletions
|
@ -5,9 +5,9 @@ CONFIG += c++11 qt link_pkgconfig sailfishapp sailfishapp_i18n sailfishapp_no_de
|
||||||
|
|
||||||
DEFINES += TARGET=\""$(TARGET")\"
|
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 += \
|
RESOURCES += \
|
||||||
qml/sailfish.qrc \
|
qml/sailfish.qrc \
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
|
|
||||||
# for libresource:
|
# for libresource:
|
||||||
# sudo zypper in libresource-devel
|
# sudo zypper in libresource-devel
|
||||||
# sb2 -t SailfishOS-i486 -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 libresource-devel
|
# sb2 -t SailfishOS-armv7hl -m sdk-install -R zypper in libaudioresource-devel
|
||||||
|
|
||||||
SAILFISHOS_DIR = $(HOME)/SailfishOS
|
SAILFISHOS_DIR = $(HOME)/SailfishOS
|
||||||
|
|
||||||
|
|
|
@ -21,67 +21,49 @@
|
||||||
|
|
||||||
#include "TunerSailfish.hpp"
|
#include "TunerSailfish.hpp"
|
||||||
|
|
||||||
|
TunerSailfish::TunerSailfish()
|
||||||
|
{
|
||||||
|
r_set = audioresource_init(AUDIO_RESOURCE_MEDIA, g_grant_cb, this);
|
||||||
|
}
|
||||||
|
|
||||||
TunerSailfish::~TunerSailfish()
|
TunerSailfish::~TunerSailfish()
|
||||||
{
|
{
|
||||||
// release resource if needed
|
audioresource_free(r_set);
|
||||||
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)
|
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)
|
void TunerSailfish::grant_cb(audioresource_t *resource_set, bool acquired)
|
||||||
{
|
|
||||||
((TunerSailfish*) data)->grant_cb(resource_set, resources);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TunerSailfish::advice_cb(resource_set_t *resource_set, uint32_t resources)
|
|
||||||
{
|
{
|
||||||
(void) resource_set;
|
(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)
|
if (acquired) {
|
||||||
{
|
|
||||||
(void) resource_set;
|
|
||||||
std::cout << __func__ << " " << resources << std::endl;
|
|
||||||
|
|
||||||
if (resources & RESOURCE_AUDIO_PLAYBACK) {
|
|
||||||
r_granted = true;
|
r_granted = true;
|
||||||
if (playing) worker->SetPlaying(true);
|
if (playing) worker->SetPlaying(true);
|
||||||
|
emit playingChanged();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
r_granted = false;
|
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)
|
void TunerSailfish::SetPlaying(bool p)
|
||||||
{
|
{
|
||||||
if (p == playing) return;
|
if (p == playing) return;
|
||||||
playing = p;
|
playing = p;
|
||||||
|
|
||||||
// get resource only the first playback start
|
if (p) {
|
||||||
if (p && !r_set) get_resource();
|
audioresource_acquire(r_set);
|
||||||
|
}
|
||||||
// if not granted, don't start, and don't stop because not started
|
else {
|
||||||
if (!r_granted) return;
|
if (r_granted) worker->SetPlaying(p);
|
||||||
|
audioresource_release(r_set);
|
||||||
worker->SetPlaying(p);
|
r_granted = false;
|
||||||
emit playingChanged();
|
emit playingChanged();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <resource.h>
|
#include <audioresource.h>
|
||||||
#include "Tuner.hpp"
|
#include "Tuner.hpp"
|
||||||
|
|
||||||
/** Tuner object
|
/** Tuner object
|
||||||
|
@ -23,19 +23,15 @@
|
||||||
*/
|
*/
|
||||||
class TunerSailfish : public Tuner {
|
class TunerSailfish : public Tuner {
|
||||||
private:
|
private:
|
||||||
resource_set_t *r_set = nullptr;
|
audioresource_t *r_set;
|
||||||
bool r_granted = false;
|
bool r_granted = false;
|
||||||
|
|
||||||
/// callbacks from resource system
|
/// callback from resource system
|
||||||
static void g_advice_cb(resource_set_t *resource_set, uint32_t resources, void *data);
|
static void g_grant_cb(audioresource_t *resource_set, bool acquired, void *data);
|
||||||
static void g_grant_cb(resource_set_t *resource_set, uint32_t resources, void *data);
|
void grant_cb(audioresource_t *resource_set, bool acquired);
|
||||||
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:
|
public:
|
||||||
|
TunerSailfish();
|
||||||
~TunerSailfish();
|
~TunerSailfish();
|
||||||
void SetPlaying(bool p);
|
void SetPlaying(bool p);
|
||||||
};
|
};
|
||||||
|
|
|
@ -281,7 +281,7 @@ void TunerWorker::Entry()
|
||||||
if (pa_simple_write(p_play, buffer, nbSampleBuffer << 1, nullptr) < 0) {
|
if (pa_simple_write(p_play, buffer, nbSampleBuffer << 1, nullptr) < 0) {
|
||||||
cerr << "audio write failed" << endl;
|
cerr << "audio write failed" << endl;
|
||||||
}
|
}
|
||||||
else cout << "audio written" << endl;
|
//else cout << "audio written" << endl;
|
||||||
} // playing
|
} // playing
|
||||||
|
|
||||||
// prevent screen blanking
|
// prevent screen blanking
|
||||||
|
|
|
@ -53,7 +53,7 @@ Q_DECL_EXPORT int main(int argc, char* argv[])
|
||||||
TunerWorker::set_record(argv[2]);
|
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");
|
qmlRegisterType<ObjectSaver>("harbour.sailtuner.objectsaver", 1, 0, "ObjectSaver");
|
||||||
|
|
||||||
Main *appli = new Main(argc, argv);
|
Main *appli = new Main(argc, argv);
|
||||||
|
|
Loading…
Reference in a new issue