From c227b1cc962c99ff689bdb6087c08ec36754e499 Mon Sep 17 00:00:00 2001 From: Prince Kr Dubey Date: Thu, 19 Jan 2012 17:45:22 +0530 Subject: [PATCH] [Multisense] Only tizen sound player support added and clean-up. Change-Id: Ibf1513f5ec0e30d72f307a23a33e4ffd65180469 --- AUTHORS | 3 +- Makefile.am | 17 +- configure.ac | 91 ++++++-- debian/changelog | 9 + debian/control | 10 +- debian/edje-multisense-plugin.install | 3 +- sound_haptic.c | 106 --------- src/Makefile.am | 5 + src/tizen_sound_player/Makefile.am | 18 ++ src/tizen_sound_player/tizen_sound_player.c | 323 ++++++++++++++++++++++++++++ 10 files changed, 433 insertions(+), 152 deletions(-) delete mode 100644 sound_haptic.c create mode 100644 src/Makefile.am create mode 100644 src/tizen_sound_player/Makefile.am create mode 100644 src/tizen_sound_player/tizen_sound_player.c diff --git a/AUTHORS b/AUTHORS index 49c7a1c..fa75055 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1 +1,2 @@ -Amit Kumar Singh +Prince Kumar Dubey +Govindaraju SM diff --git a/Makefile.am b/Makefile.am index 801129f..0018e9a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,17 +1,2 @@ -MAINTAINERCLEANFILES = Makefile.in - -AM_CPPFLAGS = \ --I. \ --I$(top_builddir) \ --DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \ --DPACKAGE_LIB_DIR=\"$(libdir)\" \ -@MULTISENSE_PLUGIN_CFLAGS@ - - -pkgdir = $(libdir)/edje/modules/slp_sound_haptic/$(MODULE_ARCH) -pkg_LTLIBRARIES = module.la - -module_la_SOURCES = sound_haptic.c -module_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -module -avoid-version @MULTISENSE_PLUGIN_LIBS@ -module_la_LIBTOOLFLAGS = --tag=disable-static +SUBDIRS = src diff --git a/configure.ac b/configure.ac index 3236316..9056022 100644 --- a/configure.ac +++ b/configure.ac @@ -11,7 +11,7 @@ m4_define([lt_age], v_min) ##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--## ##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--## -AC_INIT([edje-multisense-plugin], [v_ver], [Amit Kumar Singh ]) +AC_INIT([edje-multisense-plugin], [v_ver]) AC_PREREQ([2.52]) AC_CONFIG_SRCDIR([configure.ac]) AC_CONFIG_MACRO_DIR([m4]) @@ -72,13 +72,7 @@ AC_DEFINE_UNQUOTED(MODULE_ARCH, "${MODULE_ARCH}", "Module architecture") ### Checks for programs AC_PROG_CC -# python - -#AM_PATH_PYTHON([2.5], , [:]) -#AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != : ]) - # pkg-config - PKG_PROG_PKG_CONFIG # Check whether pkg-config supports Requires.private @@ -90,23 +84,85 @@ else fi AC_SUBST(pkgconfig_requires_private) +AC_ARG_ENABLE(gcc-werror, + AC_HELP_STRING([--enable-gcc-werror], [enable -Werror in all Makefiles])) -# Dependencies for the library +dnl Use -Wall if we have gcc. +if test "x$ac_cv_prog_gcc" = xyes ; then + CFLAGS="$CFLAGS -Wall" + + if test x$enable_gcc_werror = "xyes" ; then + CFLAGS="$CFLAGS -Werror" + fi +fi + +# Dependencies for the library +PKG_CHECK_MODULES([MINIMAL], + [ + eina >= 1.0.0 + eet >= 1.4.0 + ]) PKG_CHECK_MODULES([MULTISENSE_PLUGIN], [ edje >= 1.0.0 mm-sound >= 1.0 - vconf >= 0.2.12 - devman >= 0.1 - devman_haptic >= 0.1 + remix >= 0.2.4 ]) -MULTISENSE_PLUGIN_LIBS="${MULTISENSE_PLUGIN_LIBS}" +requirement_edje_multisense_plugin="edje >= 1.0.0 mm-sound >= 1.0 ${requirement_edje_multisense_plugin}" + +AC_DEFINE(EAPI, __attribute__ ((visibility("default"))), "Public API Visibility") + +##libremix library +PKG_CHECK_MODULES(LIBREMIX, remix >= 0.2.4, + HAVE_LIB_REMIX="yes", HAVE_LIB_REMIX="no") + +if test "$HAVE_LIB_REMIX" = "yes" ; then + AC_DEFINE([HAVE_LIB_REMIX], [], [Define if libremix version found]) + requirement_edje_multisense_plugin="remix >= 0.2.4 ${requirement_edje_multisense_plugin}" + PACKAGE_PLUGIN_DIR=`pkg-config --variable=libdir remix`"/remix" + AC_SUBST(PACKAGE_PLUGIN_DIR) + AC_DEFINE_UNQUOTED(PACKAGE_PLUGIN_DIR, "$PACKAGE_PLUGIN_DIR", [Set the plugin directory for remix]) + AC_DEFINE(__REMIX_PLUGIN__, 1, "Set to REMIX Plugin type") +else + PACKAGE_PLUGIN_DIR="" + fi +AM_CONDITIONAL(HAVE_LIB_REMIX, test "x${HAVE_LIB_REMIX}" = xyes) + MULTISENSE_PLUGIN_CFLAGS="${MULTISENSE_PLUGIN_CFLAGS}" +MULTISENSE_PLUGIN_LIBS="${MULTISENSE_PLUGIN_LIBS}" + +PKG_CHECK_MODULES(SNDFILE, sndfile >= 1.0.21, + HAVE_LIBSNDFILE1="yes", HAVE_LIBSNDFILE1="no") -requirement_edje_multisense_plugin="edje >= 1.0.0 mm-sound >= 1.0 vconf >= 0.2.12 devman >= 0.1 devman_haptic >= 0.1 ${requirement_edje}" +if test "$HAVE_LIBSNDFILE1" = "yes" ; then + AC_DEFINE([HAVE_LIBSNDFILE1], [], [Define if libsndfile version 1 found]) + AC_SUBST(SNDFILE_LIBS) + AC_SUBST(SNDFILE_CFLAGS) +else + AC_CHECK_LIB(sndfile, sf_open, HAVE_LIBSNDFILE1="maybe") + if test "$HAVE_LIBSNDFILE1" = "maybe" ; then + AC_MSG_ERROR([ +*** +*** libsndfile-1.0.21 or greater seems to exist on your system, however +*** the pkg-config tool cannot find its build information. +*** +*** Please set your PKG_CONFIG_PATH environment variable to include the +*** directory in which sndfile.pc was installed. For example, sndfile.pc +*** is installed in /usr/local/lib/pkgconfig by default; if that is the +*** case do: +*** +*** export PKG_CONFIG_PATH="\$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig" +*** +*** then run this ./configure again. If you configured libsndfile with a +*** different --prefix option, replace /usr/local above with that prefix. +*** +]) + fi +fi +AM_CONDITIONAL(HAVE_LIBSNDFILE1, test "x${HAVE_LIBSNDFILE1}" = xyes) ### Checks for header files AC_CHECK_HEADERS([locale.h]) @@ -116,7 +172,6 @@ AM_PROG_CC_C_O AC_C_CONST AC_PROG_CC_STDC AC_HEADER_STDC -AC_C___ATTRIBUTE__ case "$host_os" in mingw32ce*) @@ -129,7 +184,6 @@ esac ### Checks for linker characteristics - lt_enable_auto_import="" case "$host_os" in mingw* | cegcc*) @@ -151,20 +205,17 @@ case "$host_os" in ;; esac - AC_SUBST(requirement_edje_multisense_plugin) - AC_OUTPUT([ Makefile +src/Makefile +src/tizen_sound_player/Makefile ]) - ##################################################################### ## Info echo -echo -echo echo "------------------------------------------------------------------------" echo "$PACKAGE $VERSION" echo "------------------------------------------------------------------------" diff --git a/debian/changelog b/debian/changelog index 4935689..0b850e6 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,12 @@ +edje-multisense-plugin (0.1.0-3) unstable; urgency=low + + * Refactored Version. + * Sound Player, Eet Sound Reader and Sound Factory modules are added. + * Git: 165.213.149.219:29418/slp/pkgs/e/edje_multisense_plugin + * Tag: edje-multisense-plugin_0.1.0-3 + + -- Prince Kumar Dubey Thu, 19 Jan 2012 19:33:26 +0530 + edje-multisense-plugin (0.1.0-2) unstable; urgency=low * Initial Version. diff --git a/debian/control b/debian/control index 8feca1a..6e54df2 100644 --- a/debian/control +++ b/debian/control @@ -1,14 +1,10 @@ Source: edje-multisense-plugin Section: libs Priority: optional -Maintainer: Amit Kumar Singh, WooHyun Jung -Build-Depends: libedje-dev, libmm-sound-dev, libdevman-dev, libdevman-haptic-dev, pkg-config, libtool +Maintainer: Prince Kumar Dubey +Build-Depends: libedje-dev, libmm-sound-dev, libremix-dev, libsndfile1-dev, pkg-config, libtool Package: edje-multisense-plugin Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends} -Description: EDJE Plugin for sound/haptic support. - - - - +Description: EDJE & libremix Plugins for TIZEN sound/tone play diff --git a/debian/edje-multisense-plugin.install b/debian/edje-multisense-plugin.install index eaf4daa..a78fb13 100644 --- a/debian/edje-multisense-plugin.install +++ b/debian/edje-multisense-plugin.install @@ -1,2 +1 @@ - -debian/edje-multisense-plugin/usr/lib/edje/modules/* +debian/edje-multisense-plugin/usr/lib/remix/*.so.* diff --git a/sound_haptic.c b/sound_haptic.c deleted file mode 100644 index af004ed..0000000 --- a/sound_haptic.c +++ /dev/null @@ -1,106 +0,0 @@ -#include -#include -#include -#include -#include -#include - -int dev_handle = -1 ; -Eina_Bool aui_haptic_play(char* filename,int iteration) -{ - int ret_val=0 ; - int mode=0; - if(dev_handle!=-1)device_haptic_close(dev_handle) ; - dev_handle= device_haptic_open(1,mode); - if(dev_handle < 0)return EINA_FALSE ; - ret_val = device_haptic_play_file(dev_handle,filename,iteration,3); - if(ret_val<0) - return EINA_FALSE ; - return EINA_TRUE ; -} - -EAPI Eina_Bool ems_ui_sound_play(Edje_Sound_Info* sinfo, Edje_Sound_Data* sdata, unsigned int it) - { - int volume_level = 0 ; - int sound_profile; - FILE *f ; - char buf[256] ; - struct stat st; - /*Checking for silent profile */ - if(vconf_get_int(VCONFKEY_SETAPPL_CUR_PROFILE_INT,&sound_profile ) ) ; - if( sound_profile==1 )return EINA_FALSE; - if( vconf_get_int(VCONFKEY_SETAPPL_PROFILE_NORMAL_CALL_VOLUME_INT,&volume_level)==-1)return EINA_FALSE ; - if( sinfo==NULL )return EINA_FALSE ; - snprintf(buf,sizeof(buf),"/tmp/%s",sinfo->name) ; - /* Sound File already present in the /tmp directory */ - if (stat(buf,&st) == 0) - goto PLAY ; - f = fopen(buf,"wb") ; - if (f != NULL) - { - if (fwrite(sdata->sound_data, sdata->sound_size, 1, f) != 1) - return EINA_FALSE ; - fclose(f); - } - else - return EINA_FALSE ; - PLAY: - mm_sound_play_keysound(buf,volume_level) ; - return EINA_TRUE ; - } - -int HexToDec(const char* strHex) -{ - int nFactor = 1; - int nRetVal = 0; - char* p; - for(p = (strHex + strlen(strHex)); p >= strHex; --p) - { - if( p[0] == ' ' || p[0] == 0) continue ; - if(p[0] < 'A') nRetVal += nFactor * (p[0] - '0'); - else if(p[0] < 'a') nRetVal += nFactor * (p[0] - 'A' + 10); - else nRetVal += nFactor * (p[0] - 'a' + 10); - nFactor *= 16; - } - - return nRetVal; -} - -EAPI Eina_Bool ems_ui_haptic_play(Edje_Haptic_Info *haptic, unsigned int iterations) - { - char *pattern =NULL ; - pattern=(char*)malloc(strlen(haptic->pattern)) ; - strcpy(pattern, haptic->pattern); - char *s =pattern ; - int a = 0; - char buf[256] ; - char test[3] ; - test[2]=0 ; - int i=0 ; - - int counter = 0; - char data ; - snprintf(buf,sizeof(buf),"/tmp/%s.ivt",haptic->name) ; - FILE *f=fopen(buf,"w") ; - - while (*s != '\0') - { - if (*s == ',') - counter++; - s++; - } - - while (a <= counter) - { - test[0]= pattern[i] ; - test[1]=pattern[i+1] ; - i = i + 3 ; - data=HexToDec(test) ; - fputc(data,f) ; - a++ ; - } - - fclose(f) ; - if(aui_haptic_play(buf,iterations)==EINA_TRUE) ; - return EINA_TRUE ; - } diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..ef12ce8 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,5 @@ + +if HAVE_LIB_REMIX +SND_PLAYER = tizen_sound_player +endif +SUBDIRS = $(SND_PLAYER) diff --git a/src/tizen_sound_player/Makefile.am b/src/tizen_sound_player/Makefile.am new file mode 100644 index 0000000..c481a10 --- /dev/null +++ b/src/tizen_sound_player/Makefile.am @@ -0,0 +1,18 @@ +## Process this file with automake to produce Makefile.in + +AM_CPPFLAGS = \ +-I. \ +-I$(top_builddir) \ +-DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \ +@MULTISENSE_PLUGIN_CFLAGS@ + +libdir = $(PACKAGE_PLUGIN_DIR) + +REMIXDIR = $(libdir)/../ +REMIX_LIBS = $(REMIXDIR)/libremix.la + +lib_LTLIBRARIES = libtizen_sound_player.la + +libtizen_sound_player_la_SOURCES = tizen_sound_player.c +libtizen_sound_player_la_LDFLAGS = -module -version-info 1:0:0 +libtizen_sound_player_la_LIBADD = $(REMIX_LIBS) -lmmfsound -lsndfile diff --git a/src/tizen_sound_player/tizen_sound_player.c b/src/tizen_sound_player/tizen_sound_player.c new file mode 100644 index 0000000..648dceb --- /dev/null +++ b/src/tizen_sound_player/tizen_sound_player.c @@ -0,0 +1,323 @@ +/* + * Remix Stream Player: TIZEN device output + * + * Govindaraju SM , August 2011 + * Prince Kumar Dubey , August 2011 + */ + +#include "config.h" +#include +#include +#include +#include +#include +#include +#ifdef HAVE_LIBSNDFILE +#include +#endif + +int _edje_multisense_default_log_dom = -1; + +#ifdef ERR +# undef ERR +#endif +#define ERR(...) EINA_LOG_DOM_ERR(_edje_multisense_default_log_dom, __VA_ARGS__) + +#define STREAM_PLAYER_BUFFERLEN 4096 +#define DEFAULT_FORMAT MMSOUND_PCM_S16_LE + +typedef struct _RemixPlayerData RemixPlayerData; +typedef short PLAYER_PCM; + +struct _RemixPlayerData { + RemixPCM databuffer[STREAM_PLAYER_BUFFERLEN]; + PLAYER_PCM *playbuffer; + MMSoundPcmHandle_t handle; + MMSoundPcmChannel_t channel; + unsigned int buffer_size; + int stereo; + int frequency; +}; + +/* Optimisation dependencies: none */ +static RemixBase * remix_player_optimise (RemixEnv * env, RemixBase * base); + +static RemixBase * +remix_player_reset_device (RemixEnv *env, RemixBase *base) +{ + int old_buffer_size; + RemixPlayerData * player_data = remix_base_get_instance_data(env, base); + + if (player_data->handle) + { + mm_sound_pcm_play_close(player_data->handle); + player_data->handle = NULL; + } + old_buffer_size = player_data->buffer_size; + player_data->buffer_size = mm_sound_pcm_play_open(&player_data->handle, + player_data->frequency, + player_data->channel, + DEFAULT_FORMAT, + VOLUME_TYPE_SYSTEM); + if(player_data->buffer_size < 0) + { + remix_set_error (env, REMIX_ERROR_SYSTEM); + return RemixNone; + } + + if( old_buffer_size < player_data->buffer_size) + { + if( player_data->playbuffer ) free(player_data->playbuffer); + player_data->playbuffer = calloc(sizeof(PLAYER_PCM), player_data->buffer_size); + if(!player_data->playbuffer) + { + remix_set_error (env, REMIX_ERROR_SYSTEM); + return RemixNone; + } + } + return base; +} + +static RemixBase * +remix_player_init (RemixEnv * env, RemixBase * base, CDSet * parameters) + { + RemixCount nr_channels; + CDSet * channels; + RemixPlayerData *player_data = calloc(1, sizeof (RemixPlayerData)); + + if (!player_data) + { + remix_set_error(env, REMIX_ERROR_SYSTEM); + return RemixNone; + } + + remix_base_set_instance_data(env, base, player_data); + remix_set_channels(env, REMIX_STEREO); + channels = remix_get_channels (env); + + nr_channels = cd_set_size (env, channels); + if (nr_channels == 1) + { + player_data->stereo = 0; + player_data->channel = MMSOUND_PCM_MONO; + } + else if (nr_channels == 2) + { + player_data->stereo = 1; + player_data->channel = MMSOUND_PCM_STEREO; + } + + player_data->frequency = remix_get_samplerate(env); + player_data->buffer_size = 0; + + remix_player_reset_device (env, (RemixBase *)base); + + base = remix_player_optimise (env, base); + + return base; +} + + +static RemixBase * +remix_player_clone (RemixEnv * env, RemixBase * base) +{ + RemixBase * new_player = remix_base_new (env); + + remix_player_init( env, new_player, NULL); + return new_player; +} + +static int +remix_player_destroy (RemixEnv * env, RemixBase * base) +{ + RemixPlayerData * player_data = remix_base_get_instance_data(env, base); + + if(player_data->handle) + mm_sound_pcm_play_close(player_data->handle); + if(player_data->playbuffer) free(player_data->playbuffer); + free (player_data); + return 0; +} + +static int +remix_player_ready (RemixEnv * env, RemixBase * base) +{ + RemixPlayerData * player_data = remix_base_get_instance_data(env, base); + RemixCount nr_channels; + CDSet * channels; + int samplerate; + + channels = remix_get_channels (env); + samplerate = (int) remix_get_samplerate (env); + + nr_channels = cd_set_size (env, channels); + + return (samplerate == player_data->frequency && + ((nr_channels == 1 && player_data->stereo == 0) || + (nr_channels > 1 && player_data->stereo == 1))); +} + +static RemixBase * +remix_player_prepare (RemixEnv * env, RemixBase * base) +{ + remix_player_reset_device (env, base); + return base; +} + +static RemixCount +remix_player_playbuffer (RemixEnv * env, RemixPlayerData * player, RemixPCM * data, + RemixCount count) +{ + RemixCount i; + RemixPCM value; + int ret = count; + const RemixPCM max_value = (RemixPCM) (SHRT_MAX); + + for (i = 0; i < count; i++) + { + value = *data++ * max_value; + *(player->playbuffer + i) = (PLAYER_PCM) value; + } + + ret = mm_sound_pcm_play_write(player->handle, + player->playbuffer, + 2 * count); + if(ret < 0) + ERR("Write Fail\n"); + + return ret; +} + +/* An RemixChunkFunc for making noise */ +static RemixCount +remix_player_chunk (RemixEnv * env, RemixChunk * chunk, RemixCount offset, + RemixCount count, int channelname, void * data) +{ + RemixPlayerData * player = (RemixPlayerData *)data; + RemixCount remaining = count, written = 0, n, playcount; + RemixPCM * d; + + while (remaining > 0) + { + playcount = MIN (remaining, player->buffer_size); + + d = &chunk->data[offset]; + n = remix_player_playbuffer (env, player, d, playcount); + + if (n == -1) + return -1; + else + n /= sizeof (PLAYER_PCM); + + offset += n; + written += n; + remaining -= n; + } + + return written; +} + +static RemixCount +remix_player_process (RemixEnv * env, RemixBase * base, RemixCount count, + RemixStream * input, RemixStream * output) +{ + RemixPlayerData * player_data = remix_base_get_instance_data(env, base); + RemixCount nr_channels = remix_stream_nr_channels (env, input); + RemixCount remaining = count, processed = 0, n, nn; + + if (nr_channels == 1 && player_data->stereo == 0) + { /* MONO */ + return remix_stream_chunkfuncify (env, input, count, + remix_player_chunk, player_data); + } + else if (nr_channels == 2 && player_data->stereo == 1) + { /* STEREO */ + while (remaining > 0) + { + n = MIN (remaining, (player_data->buffer_size/2) ); + n = remix_stream_interleave_2 (env, input, + REMIX_CHANNEL_LEFT, REMIX_CHANNEL_RIGHT, + player_data->databuffer, n); + nn = 2 * n; + nn = remix_player_playbuffer (env, player_data, + player_data->databuffer, nn); + + processed += n; + remaining -= n; + } + return processed; + } + else + { + ERR("[remix_player_process] unsupported stream/output channel\n"); + ERR ("combination %ld / %d\n", nr_channels, player_data->stereo ? 2 : 1); + return -1; + } +} + +static RemixCount +remix_player_length (RemixEnv * env, RemixBase * base) +{ + return REMIX_COUNT_INFINITE; +} + +static RemixCount +remix_player_seek (RemixEnv * env, RemixBase * base, RemixCount count) +{ + return count; +} + +static int +remix_player_flush (RemixEnv * env, RemixBase * base) +{ + RemixPlayerData * player_data = remix_base_get_instance_data(env, base); + remix_player_reset_device (env, base); + return 0; +} + +static struct _RemixMethods _remix_player_methods = { + remix_player_clone, + remix_player_destroy, + remix_player_ready, + remix_player_prepare, + remix_player_process, + remix_player_length, + remix_player_seek, + remix_player_flush, +}; + +static RemixBase * +remix_player_optimise (RemixEnv * env, RemixBase * base) +{ + remix_base_set_methods (env, base, &_remix_player_methods); + return base; +} + +static struct _RemixMetaText tizen_player_metatext = { + "tizen_snd_player", + "TIZEN Sound Player", + "Output the stream into TIZEN System", + "Copyright (C) 2011, Samsung Electronics Co., Ltd.", + "http://www.samsung.com", + REMIX_ONE_AUTHOR ("govi.sm@samsung.com", "prince.dubey@samsung.com"), +}; + +static struct _RemixPlugin tizen_player_plugin = { + &tizen_player_metatext, + REMIX_FLAGS_NONE, + CD_EMPTY_SET, /* init scheme */ + remix_player_init, + CD_EMPTY_SET, /* process scheme */ + NULL, /* suggests */ + NULL, /* plugin data */ + NULL /* destroy */ +}; + +EAPI CDList * +remix_load (RemixEnv * env) +{ + CDList * plugins = cd_list_new (env); + plugins = cd_list_prepend (env, plugins, + CD_POINTER(&tizen_player_plugin)); + return plugins; +} -- 2.7.4