#define TONE_FIRST TONE_TYPE_DTMF_0
#define TONE_LAST TONE_TYPE_USER_DEFINED_HIGH_FRE
-static GMainLoop *g_mainloop = NULL;
+static GMainLoop *g_mainloop;
static GThread *event_thread;
-gpointer GmainThread(gpointer data)
+static gpointer _g_mainloop_thread(gpointer data)
{
g_mainloop = g_main_loop_new(NULL, 0);
+
+ g_print("now run mainloop %p\n", g_mainloop);
g_main_loop_run(g_mainloop);
+ g_print("mainloop %p quit...\n", g_mainloop);
+
+ g_main_loop_unref(g_mainloop);
return NULL;
}
-void help()
+static gboolean _g_timeout_cb(gpointer data)
+{
+ int id = (int)data;
+ int ret = 0;
+
+ g_print("< Stopping id(%d), ", id);
+ ret = tone_player_stop(id);
+ g_print("Done! ret=0x%X >", ret);
+
+ return FALSE;
+}
+
+
+static void _help()
{
- printf("Usage : ");
- printf("multimedia_tone_player_test [OPTION]\n\n"
+ g_print("Usage : ");
+ g_print("tone_player_test [OPTION]\n\n"
" -f, --from from which tone type\n"
" -t, --to to which tone type\n"
" -d, --duration duration(ms)\n"
" -h, --help help\n");
}
-static void stream_focus_cb(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask, sound_stream_focus_state_e focus_state,
+static void _stream_focus_cb(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask, sound_stream_focus_state_e focus_state,
sound_stream_focus_change_reason_e reason, int sound_behavior, const char *extra_info, void *user_data)
{
+ g_print("stream focus callback invoked...\n");
return;
}
-void tone_play_test(int from, int to, int duration, int sleep_time)
+static void _tone_play_test(int from, int to, int duration, int sleep_time)
{
- int i;
- sound_stream_info_h stream_info;
+ int i, j;
+ int id = -1;
+ sound_stream_info_h stream_info = NULL;
- printf("From : %2d, To : %2d, Duration : %4d, sleep_time : %4d\n", from, to, duration, sleep_time);
+ g_print("From : %2d, To : %2d, Duration : %4d, sleep_time : %4d\n", from, to, duration, sleep_time);
if (from < TONE_FIRST || to < TONE_FIRST || duration < 0 || from > to || from > TONE_LAST || to > TONE_LAST || sleep_time < 0) {
- printf("Wrong Parameter\n");
+ g_print("Wrong Parameter\n");
return;
}
-
- if (sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, stream_focus_cb, NULL, &stream_info)) {
- printf("failed to create stream info\n");
+
+ if (sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, _stream_focus_cb, NULL, &stream_info)) {
+ g_print("failed to create stream info\n");
return;
}
for (i = from; i <= to; i++) {
- printf("Play Tone : %d\n", i);
- tone_player_start_new(i, stream_info, duration, NULL);
- usleep(sleep_time * 1000);
+ g_print("* Playing Tone : %3d -> ", i);
+ tone_player_start_new(i, stream_info, duration, &id);
+ g_print("id(%d) ", id);
+
+ if (duration != sleep_time)
+ g_timeout_add(sleep_time, _g_timeout_cb, (void *)id);
+
+ for (j = 0; j < sleep_time / 100; j++) {
+ g_print(".");
+ usleep(100*1000);
+ }
+
+ usleep(1000*1000);
+ g_print(" *\n");
}
-
+
sound_manager_destroy_stream_information(stream_info);
+
+ g_main_loop_quit(g_mainloop);
}
int main(int argc, char **argv)
{
- GError *gerr = NULL;
int from = TONE_TYPE_DTMF_0, to = TONE_TYPE_DTMF_S;
int duration = 500, sleep_time = -1;
switch (opt) {
case 'f':
from = atoi(optarg);
+ if (from < TONE_FIRST)
+ from = TONE_FIRST;
+ else if (from > TONE_LAST)
+ from = TONE_LAST;
break;
case 't':
to = atoi(optarg);
+ if (to < TONE_FIRST)
+ to = TONE_FIRST;
+ else if (to > TONE_LAST)
+ to = TONE_LAST;
break;
case 'd':
duration = atoi(optarg);
break;
case 'h':
default:
- help();
+ _help();
return 0;
}
}
if (sleep_time == -1)
sleep_time = duration;
- if (!g_thread_supported())
- g_thread_init(NULL);
+ event_thread = g_thread_new(NULL, _g_mainloop_thread, NULL);
- event_thread = g_thread_create(GmainThread, NULL, 1, &gerr);
+ _tone_play_test(from, to, duration, sleep_time);
- tone_play_test(from, to, duration, sleep_time);
+ g_print("Now join the thread, ");
+ g_thread_join(event_thread);
+ g_print("Done, QUIT testsuite\n");
return 0;
}