* limitations under the License.
*/
-
-
-
#define LOG_TAG "TIZEN_N_TONE_PLAYER"
#include <sound_manager.h>
#include <sound_manager_internal.h>
#include <tone_player.h>
-#include <mm_sound.h>
-#include <mm_sound_private.h>
#include <stdio.h>
#include <limits.h>
#include <string.h>
#include <unistd.h>
#include <dlog.h>
+#include <gio/gio.h>
+#include <glib.h>
+
+#define PA_BUS_NAME "org.pulseaudio.Server"
+#define PA_TONE_PLAYER_OBJECT_PATH "/org/pulseaudio/TonePlayer"
+#define PA_TONE_PLAYER_INTERFACE "org.pulseaudio.TonePlayer"
+
+#define PA_TONE_PLAYER_METHOD_NAME_TONE_PLAY "TonePlay"
+#define PA_TONE_PLAYER_METHOD_NAME_TONE_STOP "ToneStop"
-static int __convert_tone_player_error_code(const char *func, int code)
+static int _convert_dbus_error(const char *error_msg)
{
- int ret = TONE_PLAYER_ERROR_NONE;
- char *errorstr = NULL;
- switch (code) {
- case MM_ERROR_NONE:
- ret = TONE_PLAYER_ERROR_NONE;
- errorstr = "ERROR_NONE";
- break;
- case TONE_PLAYER_ERROR_INVALID_PARAMETER:
- case MM_ERROR_INVALID_ARGUMENT:
- case MM_ERROR_SOUND_INVALID_POINTER:
- ret = TONE_PLAYER_ERROR_INVALID_PARAMETER;
- errorstr = "INVALID_PARAMETER";
- break;
- case MM_ERROR_SOUND_INTERNAL:
- ret = TONE_PLAYER_ERROR_INVALID_OPERATION;
- errorstr = "INVALID_OPERATION";
- break;
+ if (error_msg && strstr(error_msg, "InvalidArgument"))
+ return TONE_PLAYER_ERROR_INVALID_PARAMETER;
+
+ return TONE_PLAYER_ERROR_INVALID_OPERATION;
+}
+
+static GDBusConnection *__get_dbus_connection(void)
+{
+ GDBusConnection *conn = NULL;
+ GError *err = NULL;
+
+ conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+ if (!conn) {
+ LOGE("g_bus_get_sync() error (%s)", err->message);
+ g_error_free(err);
}
- LOGE("[%s] %s(0x%08x) : core frameworks error code(0x%08x)", func, errorstr, ret, code);
- return ret;
+
+ return conn;
}
+static int __dbus_method_call(const char *method, GVariant *param, GVariant **reply)
+{
+ GDBusConnection *conn = NULL;
+ GVariant * _reply = NULL;
+ GError *err = NULL;
+
+ if (!method || !param) {
+ LOGE("invalid parameter");
+ return TONE_PLAYER_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+ }
+
+ if (!(conn = __get_dbus_connection()))
+ return TONE_PLAYER_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
+
+ _reply = g_dbus_connection_call_sync(conn, PA_BUS_NAME,
+ PA_TONE_PLAYER_OBJECT_PATH,
+ PA_TONE_PLAYER_INTERFACE,
+ method, param, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
+
+ g_object_unref(conn);
+
+ if (!_reply) {
+ int ret;
+
+ LOGE("g_dbus_connection_call_sync() method(%s), err-msg(%s)", method, err->message);
+ ret = _convert_dbus_error(err->message);
+ g_error_free(err);
+ return ret;
+ }
+
+ if (reply)
+ *reply = _reply;
+ else
+ g_variant_unref(_reply);
+
+ return TONE_PLAYER_ERROR_NONE;
+}
+
+
int tone_player_start_new(tone_type_e tone, sound_stream_info_h stream_info, int duration_ms, int *id)
{
int ret;
- int player;
- double vol = 1.0;
char *stream_type = NULL;
int stream_id;
bool result = false;
- if (tone < TONE_TYPE_DEFAULT || tone > TONE_TYPE_USER_DEFINED_HIGH_FRE || stream_info == NULL)
- return __convert_tone_player_error_code(__func__, TONE_PLAYER_ERROR_INVALID_PARAMETER);
+ GVariant *reply = NULL;
+ int handle;
+
+ LOGI("tone(%d), duration_ms(%d)", tone, duration_ms);
+
+ if (tone < TONE_TYPE_DEFAULT || tone > TONE_TYPE_USER_DEFINED_HIGH_FRE || !stream_info) {
+ LOGE("invalid parameter.");
+ return TONE_PLAYER_ERROR_INVALID_PARAMETER;
+ }
ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_TONE_PLAYER, &result);
- if (!result)
- return __convert_tone_player_error_code(__func__, TONE_PLAYER_ERROR_NOT_SUPPORTED_TYPE);
+ if (!result || ret) {
+ LOGE("stream info is not available. ret(0x%x), result(%d)", ret, result);
+ return TONE_PLAYER_ERROR_NOT_SUPPORTED_TYPE;
+ }
ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
- if (ret)
- return __convert_tone_player_error_code(__func__, ret); //LCOV_EXCL_LINE
+ if (ret) {
+ LOGE("can't get stream type. ret(0x%x)", ret);
+ return TONE_PLAYER_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
+ }
ret = sound_manager_get_index_from_stream_information(stream_info, &stream_id);
- if (ret)
- return __convert_tone_player_error_code(__func__, ret); //LCOV_EXCL_LINE
+ if (ret) {
+ LOGE("can't get stream index. ret(0x%x)", ret);
+ return TONE_PLAYER_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
+ }
+
+ ret = __dbus_method_call(PA_TONE_PLAYER_METHOD_NAME_TONE_PLAY,
+ g_variant_new("(uiisi)", tone, duration_ms, getpid(), stream_type, stream_id), &reply);
+ if (ret) {
+ LOGE("__dbus_method_call ret(0x%x)", ret);
+ return ret;
+ }
- ret = mm_sound_play_tone_with_stream_info(tone, stream_type, stream_id, vol, duration_ms, &player);
- if (ret == 0 && id != NULL)
- *id = player;
+ g_variant_get(reply, "(u)", &handle);
+ g_variant_unref(reply);
+ if (id)
+ *id = handle;
- return __convert_tone_player_error_code(__func__, ret);
+ LOGI("handle : %d", handle);
+
+ return TONE_PLAYER_ERROR_NONE;
}
int tone_player_stop(int id)
{
- return __convert_tone_player_error_code(__func__, mm_sound_stop_tone(id));
+ int ret;
+
+ LOGI("handle(%d)", id);
+
+ ret = __dbus_method_call(PA_TONE_PLAYER_METHOD_NAME_TONE_STOP, g_variant_new("(u)", id), NULL);
+ if (ret) {
+ LOGE("__dbus_method_call ret(0x%x)", ret);
+ return ret;
+ }
+
+ return TONE_PLAYER_ERROR_NONE;
}
#include <string.h>
#include <stdlib.h>
#include <getopt.h>
+#include <signal.h>
#include <sound_manager.h>
#define TONE_FIRST TONE_TYPE_DTMF_0
static GMainLoop *g_mainloop;
static GThread *event_thread;
+struct sigaction sig_int_old_action;
+static int gid = -1;
static gpointer _g_mainloop_thread(gpointer data)
{
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);
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);
+ tone_player_start_new(i, stream_info, duration, &gid);
+ g_print("gid(%d) ", gid);
if (duration != sleep_time)
- g_timeout_add(sleep_time, _g_timeout_cb, (void *)id);
+ g_timeout_add(sleep_time, _g_timeout_cb, (void *)gid);
for (j = 0; j < sleep_time / 100; j++) {
g_print(".");
g_main_loop_quit(g_mainloop);
}
+void __sig_handler(int signo)
+{
+ sigset_t old_mask, all_mask;
+ sigfillset(&all_mask);
+ sigprocmask(SIG_BLOCK, &all_mask, &old_mask);
+ sigprocmask(SIG_SETMASK, &old_mask, NULL);
+
+ printf("sig.num(%d)\n", signo);
+
+ switch (signo) {
+ case SIGINT:
+ if (gid > -1) {
+ printf("stop tone-player gid(%d)\n", gid);
+ tone_player_stop(gid);
+ }
+ sigaction(SIGINT, &sig_int_old_action, NULL);
+ raise(signo);
+ break;
+ default:
+ break;
+ }
+}
+
int main(int argc, char **argv)
{
int from = TONE_TYPE_DTMF_0, to = TONE_TYPE_DTMF_S;
int duration = 500, sleep_time = -1;
+ struct sigaction sig_action;
+ sig_action.sa_handler = __sig_handler;
+ sig_action.sa_flags = SA_NOCLDSTOP;
+ sigemptyset(&sig_action.sa_mask);
+ sigaction(SIGINT, &sig_action, &sig_int_old_action);
+
while (1) {
int opt;
int opt_idx = 0;