Skip to content

Commit 5412074

Browse files
authored
[audioplayers] Remove Ecore API (#1033)
1 parent 0c7d2d5 commit 5412074

5 files changed

Lines changed: 72 additions & 32 deletions

File tree

packages/audioplayers/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.1.4
2+
3+
* Remove Ecore API.
4+
15
## 3.1.3
26

37
* Adds compatibility with `http` 1.0 in example.

packages/audioplayers/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This package is not an _endorsed_ implementation of `audioplayers`. Therefore, y
1111
```yaml
1212
dependencies:
1313
audioplayers: ^6.6.0
14-
audioplayers_tizen: ^3.1.3
14+
audioplayers_tizen: ^3.1.4
1515

1616
```
1717

packages/audioplayers/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: audioplayers_tizen
22
description: Tizen implementation of the audioplayers plugin.
33
homepage: https://github.com/flutter-tizen/plugins
44
repository: https://github.com/flutter-tizen/plugins/tree/master/packages/audioplayers
5-
version: 3.1.3
5+
version: 3.1.4
66

77
environment:
88
sdk: ^3.6.0

packages/audioplayers/tizen/src/audio_player.cc

Lines changed: 61 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
#include "audio_player_error.h"
88
#include "log.h"
99

10+
namespace {
11+
12+
struct IdleData {
13+
AudioPlayer *player;
14+
std::shared_ptr<bool> is_alive;
15+
};
16+
17+
} // namespace
18+
1019
AudioPlayer::AudioPlayer(const std::string &player_id,
1120
PreparedListener prepared_listener,
1221
DurationListener duration_listener,
@@ -30,10 +39,11 @@ AudioPlayer::~AudioPlayer() {
3039
player_destroy(player_);
3140
player_ = nullptr;
3241
}
33-
if (timer_) {
34-
ecore_timer_del(timer_);
35-
timer_ = nullptr;
42+
if (timer_id_ != 0) {
43+
g_source_remove(timer_id_);
44+
timer_id_ = 0;
3645
}
46+
*is_alive_ = false;
3747
}
3848

3949
void AudioPlayer::Play() {
@@ -343,28 +353,34 @@ player_state_e AudioPlayer::GetPlayerState() {
343353
}
344354

345355
void AudioPlayer::OnPrepared(void *data) {
356+
auto *self = reinterpret_cast<AudioPlayer *>(data);
346357
// On TV devices, callbacks are not executed on the main loop. Therefore
347358
// we explicitly transfer the callback to the main loop to avoid any race
348359
// conditions and to allow creating timer objects in StartPositionUpdates.
349-
ecore_main_loop_thread_safe_call_async(
350-
[](void *data) {
351-
auto *player = reinterpret_cast<AudioPlayer *>(data);
360+
g_idle_add_full(
361+
G_PRIORITY_DEFAULT_IDLE,
362+
[](gpointer data) -> gboolean {
363+
auto *idle = static_cast<IdleData *>(data);
364+
if (!*idle->is_alive) {
365+
return G_SOURCE_REMOVE;
366+
}
367+
auto *player = idle->player;
352368
player->preparing_ = false;
353369

354370
try {
355371
player->duration_listener_(player->player_id_, player->GetDuration());
356372
player->prepared_listener_(player->player_id_, true);
357373
} catch (const AudioPlayerError &error) {
358374
player->log_listener_(player->player_id_, error.code());
359-
return;
375+
return G_SOURCE_REMOVE;
360376
}
361377
player_set_playback_rate(player->player_, player->playback_rate_);
362378

363379
if (player->should_play_) {
364380
int ret = player_start(player->player_);
365381
if (ret != PLAYER_ERROR_NONE) {
366382
player->log_listener_(player->player_id_, "player_start failed.");
367-
return;
383+
return G_SOURCE_REMOVE;
368384
}
369385
player->StartPositionUpdates();
370386
player->should_play_ = false;
@@ -374,48 +390,66 @@ void AudioPlayer::OnPrepared(void *data) {
374390
player->seeking_ = true;
375391
int ret =
376392
player_set_play_position(player->player_, player->should_seek_to_,
377-
true, OnSeekCompleted, data);
393+
true, OnSeekCompleted, player);
378394
if (ret != PLAYER_ERROR_NONE) {
379395
player->seeking_ = false;
380396
player->log_listener_(player->player_id_,
381397
"player_set_play_position failed.");
382-
return;
398+
return G_SOURCE_REMOVE;
383399
}
384400
player->should_seek_to_ = -1;
385401
}
402+
return G_SOURCE_REMOVE;
386403
},
387-
data);
404+
new IdleData{self, self->is_alive_},
405+
[](gpointer data) { delete static_cast<IdleData *>(data); });
388406
}
389407

390408
void AudioPlayer::OnSeekCompleted(void *data) {
409+
auto *self = reinterpret_cast<AudioPlayer *>(data);
391410
// On TV devices, callbacks are not executed on the main loop. Therefore
392411
// we explicitly transfer the callback to the main loop to avoid any race
393412
// conditions.
394-
ecore_main_loop_thread_safe_call_async(
395-
[](void *data) {
396-
auto *player = reinterpret_cast<AudioPlayer *>(data);
413+
g_idle_add_full(
414+
G_PRIORITY_DEFAULT_IDLE,
415+
[](gpointer data) -> gboolean {
416+
auto *idle = static_cast<IdleData *>(data);
417+
if (!*idle->is_alive) {
418+
return G_SOURCE_REMOVE;
419+
}
420+
auto *player = idle->player;
397421
player->seek_completed_listener_(player->player_id_);
398422
player->seeking_ = false;
423+
return G_SOURCE_REMOVE;
399424
},
400-
data);
425+
new IdleData{self, self->is_alive_},
426+
[](gpointer data) { delete static_cast<IdleData *>(data); });
401427
}
402428

403429
void AudioPlayer::OnPlayCompleted(void *data) {
430+
auto *self = reinterpret_cast<AudioPlayer *>(data);
404431
// On TV devices, callbacks are not executed on the main loop. Therefore
405432
// we explicitly transfer the callback to the main loop to avoid any race
406433
// conditions.
407-
ecore_main_loop_thread_safe_call_async(
408-
[](void *data) {
409-
auto *player = reinterpret_cast<AudioPlayer *>(data);
434+
g_idle_add_full(
435+
G_PRIORITY_DEFAULT_IDLE,
436+
[](gpointer data) -> gboolean {
437+
auto *idle = static_cast<IdleData *>(data);
438+
if (!*idle->is_alive) {
439+
return G_SOURCE_REMOVE;
440+
}
441+
auto *player = idle->player;
410442
try {
411443
player->Seek(0);
412444
player->Stop();
413445
player->play_completed_listener_(player->player_id_);
414446
} catch (const AudioPlayerError &error) {
415447
player->log_listener_(player->player_id_, error.code());
416448
}
449+
return G_SOURCE_REMOVE;
417450
},
418-
data);
451+
new IdleData{self, self->is_alive_},
452+
[](gpointer data) { delete static_cast<IdleData *>(data); });
419453
}
420454

421455
void AudioPlayer::OnInterrupted(player_interrupted_code_e code, void *data) {
@@ -433,27 +467,27 @@ void AudioPlayer::OnError(int code, void *data) {
433467
}
434468

435469
void AudioPlayer::StartPositionUpdates() {
436-
if (!timer_) {
470+
if (timer_id_ == 0) {
437471
// The audioplayers app facing package expects position
438472
// update events to fire roughly every 200 milliseconds.
439-
const double kTimeInterval = 0.2;
440-
timer_ = ecore_timer_add(kTimeInterval, OnPositionUpdate, this);
441-
if (!timer_) {
473+
const guint kTimeInterval = 200;
474+
timer_id_ = g_timeout_add(kTimeInterval, OnPositionUpdate, this);
475+
if (timer_id_ == 0) {
442476
log_listener_(player_id_, "Failed to add a position update timer.");
443477
}
444478
}
445479
}
446480

447-
Eina_Bool AudioPlayer::OnPositionUpdate(void *data) {
481+
gboolean AudioPlayer::OnPositionUpdate(gpointer data) {
448482
auto *player = reinterpret_cast<AudioPlayer *>(data);
449483
try {
450484
if (player->IsPlaying()) {
451485
player->duration_listener_(player->player_id_, player->GetDuration());
452-
return ECORE_CALLBACK_RENEW;
486+
return G_SOURCE_CONTINUE;
453487
}
454488
} catch (const AudioPlayerError &error) {
455489
player->log_listener_(player->player_id_, "Failed to update position.");
456490
}
457-
player->timer_ = nullptr;
458-
return ECORE_CALLBACK_CANCEL;
491+
player->timer_id_ = 0;
492+
return G_SOURCE_REMOVE;
459493
}

packages/audioplayers/tizen/src/audio_player.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
#ifndef FLUTTER_PLUGIN_AUDIO_PLAYER_H_
66
#define FLUTTER_PLUGIN_AUDIO_PLAYER_H_
77

8-
#include <Ecore.h>
8+
#include <glib.h>
99
#include <player.h>
1010

1111
#include <functional>
12+
#include <memory>
1213
#include <string>
1314
#include <vector>
1415

@@ -71,7 +72,7 @@ class AudioPlayer {
7172
static void OnPlayCompleted(void *data);
7273
static void OnInterrupted(player_interrupted_code_e code, void *data);
7374
static void OnError(int code, void *data);
74-
static Eina_Bool OnPositionUpdate(void *data);
75+
static gboolean OnPositionUpdate(gpointer data);
7576

7677
player_h player_ = nullptr;
7778
const std::string player_id_;
@@ -84,7 +85,8 @@ class AudioPlayer {
8485
bool preparing_ = false;
8586
bool seeking_ = false;
8687
bool should_play_ = false;
87-
Ecore_Timer *timer_ = nullptr;
88+
guint timer_id_ = 0;
89+
std::shared_ptr<bool> is_alive_ = std::make_shared<bool>(true);
8890

8991
PreparedListener prepared_listener_;
9092
DurationListener duration_listener_;

0 commit comments

Comments
 (0)