+++ /dev/null
-/*
-* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#include <stdio.h>
-#include <tone_player.h>
-#include <glib.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <getopt.h>
-#include <sound_manager.h>
-
-#define TONE_FIRST TONE_TYPE_DTMF_0
-#define TONE_LAST TONE_TYPE_USER_DEFINED_HIGH_FRE
-
-static GMainLoop *g_mainloop = NULL;
-static GThread *event_thread;
-
-gpointer GmainThread(gpointer data)
-{
- g_mainloop = g_main_loop_new(NULL, 0);
- g_main_loop_run(g_mainloop);
-
- return NULL;
-}
-
-void help()
-{
- printf("Usage : ");
- printf("multimedia_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"
- " -s, --sleep sleep time after play start(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,
- sound_stream_focus_change_reason_e reason, int sound_behavior, const char *extra_info, void *user_data)
-{
- return;
-}
-
-
-void tone_play_test(int from, int to, int duration, int sleep_time)
-{
- int i;
- sound_stream_info_h stream_info;
-
- printf("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");
- return;
- }
-
- if (sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, stream_focus_cb, NULL, &stream_info)) {
- printf("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);
- }
-
- sound_manager_destroy_stream_information(stream_info);
-}
-
-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;
-
- while (1) {
- int opt;
- int opt_idx = 0;
-
- static struct option long_options[] = {
- {"from", required_argument, 0, 'f'},
- {"to", required_argument, 0, 't'},
- {"duration", required_argument, 0, 'd'},
- {"sleep", required_argument, 0, 's'},
- {"help", no_argument, 0, 'h'},
- {0, 0, 0, 0}
- };
-
- if ((opt = getopt_long(argc, argv, "f:t:d:s:h", long_options, &opt_idx)) == -1)
- break;
-
- switch (opt) {
- case 'f':
- from = atoi(optarg);
- break;
- case 't':
- to = atoi(optarg);
- break;
- case 'd':
- duration = atoi(optarg);
- break;
- case 's':
- sleep_time = atoi(optarg);
- break;
- case 'h':
- default:
- help();
- return 0;
- }
- }
-
- if (sleep_time == -1)
- sleep_time = duration;
-
- if (!g_thread_supported())
- g_thread_init(NULL);
-
- event_thread = g_thread_create(GmainThread, NULL, 1, &gerr);
-
- tone_play_test(from, to, duration, sleep_time);
-
- return 0;
-}
--- /dev/null
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#include <stdio.h>
+#include <tone_player.h>
+#include <glib.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include <sound_manager.h>
+
+#define TONE_FIRST TONE_TYPE_DTMF_0
+#define TONE_LAST TONE_TYPE_USER_DEFINED_HIGH_FRE
+
+static GMainLoop *g_mainloop;
+static GThread *event_thread;
+
+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;
+}
+
+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()
+{
+ 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"
+ " -s, --sleep sleep time after play start(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,
+ 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;
+}
+
+
+static void _tone_play_test(int from, int to, int duration, int sleep_time)
+{
+ int i, j;
+ int id = -1;
+ sound_stream_info_h stream_info = NULL;
+
+ 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) {
+ g_print("Wrong Parameter\n");
+ return;
+ }
+
+ 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++) {
+ 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)
+{
+ int from = TONE_TYPE_DTMF_0, to = TONE_TYPE_DTMF_S;
+ int duration = 500, sleep_time = -1;
+
+ while (1) {
+ int opt;
+ int opt_idx = 0;
+
+ static struct option long_options[] = {
+ {"from", required_argument, 0, 'f'},
+ {"to", required_argument, 0, 't'},
+ {"duration", required_argument, 0, 'd'},
+ {"sleep", required_argument, 0, 's'},
+ {"help", no_argument, 0, 'h'},
+ {0, 0, 0, 0}
+ };
+
+ if ((opt = getopt_long(argc, argv, "f:t:d:s:h", long_options, &opt_idx)) == -1)
+ break;
+
+ 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 's':
+ sleep_time = atoi(optarg);
+ break;
+ case 'h':
+ default:
+ _help();
+ return 0;
+ }
+ }
+
+ if (sleep_time == -1)
+ sleep_time = duration;
+
+ event_thread = g_thread_new(NULL, _g_mainloop_thread, NULL);
+
+ _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;
+}