diff options
Diffstat (limited to 'mobile/common')
-rw-r--r-- | mobile/common/Makefile.am | 24 | ||||
-rw-r--r-- | mobile/common/mm_ipc.c | 151 | ||||
-rw-r--r-- | mobile/common/mm_sound_utils.c | 222 | ||||
-rw-r--r-- | mobile/common/mm_source.c | 299 |
4 files changed, 0 insertions, 696 deletions
diff --git a/mobile/common/Makefile.am b/mobile/common/Makefile.am deleted file mode 100644 index 4a7ff0d..0000000 --- a/mobile/common/Makefile.am +++ /dev/null @@ -1,24 +0,0 @@ - -lib_LTLIBRARIES = libmmfsoundcommon.la - -libmmfsoundcommon_la_SOURCES = mm_ipc.c \ - mm_sound_utils.c \ - mm_source.c - -#libmmfsoundcommon_la_DEPENDENCIES = $(libdir)/libmmfcommon.la - -libmmfsoundcommon_la_CFLAGS = -I$(srcdir)/../include \ - $(MMCOMMON_CFLAGS) \ - $(AVSYSTEM_CFLAGS) \ - $(VCONF_CFLAGS) - -libmmfsoundcommon_la_LIBADD = $(MMCOMMON_LIBS) \ - $(AVSYSTEM_LIBS) \ - $(VCONF_LIBS) - -#libmmfsound_la_LDFLAGS = -version-info 1:0:1 - - -#For logmanager -libmmfsoundcommon_la_CFLAGS += $(MMLOGSVR_CFLAGS) -DMMF_LOG_OWNER=0x020 -DMMF_DEBUG_PREFIX=\"MMF-SOUND\" -libmmfsoundcommon_la_LIBADD += $(MMLOGSVR_LIBS) diff --git a/mobile/common/mm_ipc.c b/mobile/common/mm_ipc.c deleted file mode 100644 index 11a39e0..0000000 --- a/mobile/common/mm_ipc.c +++ /dev/null @@ -1,151 +0,0 @@ -/* - * libmm-sound - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Seungbae Shin <seungbae.shin@samsung.com> - * - * 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 <stdlib.h> -#include <string.h> -#include <errno.h> - -#include <sys/time.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <semaphore.h> -#include <fcntl.h> -#include <unistd.h> - -#include <aio.h> - -#include <mm_ipc.h> -#include <mm_error.h> -#include <mm_debug.h> - -#define FIX_PROCESS 1 - -#include <assert.h> -#include <sys/ipc.h> -#include <sys/msg.h> - -#include <vconf.h> - -#define AUDIO_ROUTE_POLICY_LOCK "audio_route_policy_lock" -#define LOCK_TIMEOUT_SEC 6 - -EXPORT_API -int __mm_sound_lock() -{ - sem_t *sem = NULL; - int ret; - int err = MM_ERROR_NONE; - struct timespec wait_time; - - sem = sem_open(AUDIO_ROUTE_POLICY_LOCK, O_CREAT, 0666, 1); - if (sem == SEM_FAILED) - { - debug_error("Semaphore open Fail! (name:%s, %s)\n", AUDIO_ROUTE_POLICY_LOCK, strerror(errno)); - return MM_ERROR_SOUND_INTERNAL; - } -retry_lock: - wait_time.tv_sec = (long int)(time(NULL)) + LOCK_TIMEOUT_SEC; - wait_time.tv_nsec = 0; - ret = sem_timedwait(sem, &wait_time); - if(ret == -1) - { - switch(errno) - { - case EINTR: - debug_error("Lock RETRY LOCK\n"); - goto retry_lock; - break; - case EINVAL: - debug_error("Invalid semaphore\n"); - err = MM_ERROR_SOUND_INTERNAL; - break; - case EAGAIN: - debug_error("EAGAIN\n"); - err = MM_ERROR_SOUND_INTERNAL; - break; - case ETIMEDOUT: - debug_error("sem_wait leached %d seconds timeout.\n", LOCK_TIMEOUT_SEC); - { - //Recovery of sem_wait lock....in abnormal condition - int sem_value = -1; - if(0 == sem_getvalue(sem, &sem_value)) - { - debug_error("%s sem value is %d\n",AUDIO_ROUTE_POLICY_LOCK, sem_value); - if(sem_value == 0) - { - ret = sem_post(sem); - if(ret == -1) - { - debug_error("sem_post error %s : %d\n", AUDIO_ROUTE_POLICY_LOCK, sem_value); - } - else - { - debug_error("lock recovery success...try lock again\n"); - goto retry_lock; - } - } - else - { - debug_error("sem value is not 0. but failed sem_timedwait so retry.. : %s\n",AUDIO_ROUTE_POLICY_LOCK); - usleep(5); - goto retry_lock; - } - } - else - { - debug_error("sem_getvalue failed : %s\n",AUDIO_ROUTE_POLICY_LOCK); - } - } - err = MM_ERROR_SOUND_INTERNAL; - break; - } - } - sem_close(sem); - return err; -} - -EXPORT_API -int __mm_sound_unlock() -{ - sem_t *sem = NULL; - int ret; - int err = MM_ERROR_NONE; - - sem = sem_open(AUDIO_ROUTE_POLICY_LOCK, O_CREAT, 0666, 1); - if (sem == SEM_FAILED) - { - debug_error("Semaphore open Fail! (name:%s, errno %d)\n", AUDIO_ROUTE_POLICY_LOCK, errno); - return MM_ERROR_SOUND_INTERNAL; - } - - ret = sem_post(sem); - if (ret == -1) - { - debug_error("UNLOCK FAIL\n"); - err = MM_ERROR_SOUND_INTERNAL; - } - - sem_close(sem); - return err; -} - diff --git a/mobile/common/mm_sound_utils.c b/mobile/common/mm_sound_utils.c deleted file mode 100644 index 5100556..0000000 --- a/mobile/common/mm_sound_utils.c +++ /dev/null @@ -1,222 +0,0 @@ -/* - * libmm-sound - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Seungbae Shin <seungbae.shin@samsung.com> - * - * 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 <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <stdlib.h> -#include <stdio.h> -#include <unistd.h> -#include <errno.h> - -#include <vconf.h> -#include <avsys-audio.h> -#include <mm_types.h> -#include <mm_error.h> -#include <mm_debug.h> -#include "../include/mm_sound_private.h" -#include "../include/mm_sound.h" -#include "../include/mm_sound_common.h" -#include "../include/mm_sound_utils.h" - -static mm_sound_route g_valid_route[] = { - MM_SOUND_ROUTE_OUT_SPEAKER, MM_SOUND_ROUTE_OUT_WIRED_ACCESSORY, MM_SOUND_ROUTE_OUT_BLUETOOTH, - MM_SOUND_ROUTE_OUT_DOCK, MM_SOUND_ROUTE_OUT_HDMI, MM_SOUND_ROUTE_OUT_WFD, MM_SOUND_ROUTE_OUT_USB_AUDIO, - MM_SOUND_ROUTE_IN_MIC, MM_SOUND_ROUTE_IN_WIRED_ACCESSORY, MM_SOUND_ROUTE_IN_MIC_OUT_RECEIVER, - MM_SOUND_ROUTE_IN_MIC_OUT_SPEAKER, MM_SOUND_ROUTE_IN_MIC_OUT_HEADPHONE, - MM_SOUND_ROUTE_INOUT_HEADSET, MM_SOUND_ROUTE_INOUT_BLUETOOTH -}; - -#define MM_SOUND_DEFAULT_VOLUME_SYSTEM 5 -#define MM_SOUND_DEFAULT_VOLUME_NOTIFICATION 7 -#define MM_SOUND_DEFAULT_VOLUME_ALARAM 6 -#define MM_SOUND_DEFAULT_VOLUME_RINGTONE 13 -#define MM_SOUND_DEFAULT_VOLUME_MEDIA 7 -#define MM_SOUND_DEFAULT_VOLUME_CALL 7 -#define MM_SOUND_DEFAULT_VOLUME_VOIP 7 -#define MM_SOUND_DEFAULT_VOLUME_ANDROID 0 -#define MM_SOUND_DEFAULT_VOLUME_JAVA 11 -static int g_default_volume[VOLUME_TYPE_MAX] = { - MM_SOUND_DEFAULT_VOLUME_SYSTEM, - MM_SOUND_DEFAULT_VOLUME_NOTIFICATION, - MM_SOUND_DEFAULT_VOLUME_ALARAM, - MM_SOUND_DEFAULT_VOLUME_RINGTONE, - MM_SOUND_DEFAULT_VOLUME_MEDIA, - MM_SOUND_DEFAULT_VOLUME_CALL, - MM_SOUND_DEFAULT_VOLUME_VOIP, - MM_SOUND_DEFAULT_VOLUME_ANDROID, - MM_SOUND_DEFAULT_VOLUME_JAVA, -}; -static char *g_volume_vconf[VOLUME_TYPE_MAX] = { - VCONF_KEY_VOLUME_TYPE_SYSTEM, /* VOLUME_TYPE_SYSTEM */ - VCONF_KEY_VOLUME_TYPE_NOTIFICATION, /* VOLUME_TYPE_NOTIFICATION */ - VCONF_KEY_VOLUME_TYPE_ALARM, /* VOLUME_TYPE_ALARM */ - VCONF_KEY_VOLUME_TYPE_RINGTONE, /* VOLUME_TYPE_RINGTONE */ - VCONF_KEY_VOLUME_TYPE_MEDIA, /* VOLUME_TYPE_MEDIA */ - VCONF_KEY_VOLUME_TYPE_CALL, /* VOLUME_TYPE_CALL */ - VCONF_KEY_VOLUME_TYPE_VOIP, /* VOLUME_TYPE_VOIP */ - VCONF_KEY_VOLUME_TYPE_ANDROID, /* VOLUME_TYPE_FIXED */ - VCONF_KEY_VOLUME_TYPE_JAVA /* VOLUME_TYPE_EXT_JAVA */ -}; -static char *g_volume_str[VOLUME_TYPE_MAX] = { - "SYSTEM", - "NOTIFICATION", - "ALARM", - "RINGTONE", - "MEDIA", - "CALL", - "VOIP", - "FIXED", - "JAVA", -}; - -EXPORT_API -int _mm_sound_get_valid_route_list(mm_sound_route **route_list) -{ - *route_list = g_valid_route; - - return (int)(sizeof(g_valid_route) / sizeof(mm_sound_route)); -} - -EXPORT_API -bool _mm_sound_is_route_valid(mm_sound_route route) -{ - mm_sound_route *route_list = 0; - int route_index = 0; - int route_list_count = 0; - - route_list_count = _mm_sound_get_valid_route_list(&route_list); - for (route_index = 0; route_index < route_list_count; route_index++) { - if (route_list[route_index] == route) - return 1; - } - - return 0; -} - -EXPORT_API -void _mm_sound_get_devices_from_route(mm_sound_route route, mm_sound_device_in *device_in, mm_sound_device_out *device_out) -{ - if (device_in && device_out) { - *device_in = route & 0x00FF; - *device_out = route & 0xFFF00; - } -} - -EXPORT_API -bool _mm_sound_check_hibernation (const char *path) -{ - int fd = -1; - if (path == NULL) { - debug_error ("Path is null\n"); - return false; - } - - fd = open (path, O_RDONLY | O_CREAT, 0644); - if (fd != -1) { - debug_log ("Open [%s] success!!\n", path); - } else { - debug_error ("Can't create [%s] with errno [%d]\n", path, errno); - return false; - } - - close (fd); - return true; -} - -EXPORT_API -int _mm_sound_volume_add_callback(volume_type_t type, void *func, void* user_data) -{ - if (vconf_notify_key_changed(g_volume_vconf[type], func, user_data)) { - debug_error ("vconf_notify_key_changed failed..\n"); - return MM_ERROR_SOUND_INTERNAL; - } - - return MM_ERROR_NONE; -} - -EXPORT_API -int _mm_sound_volume_remove_callback(volume_type_t type, void *func) -{ - if (vconf_ignore_key_changed(g_volume_vconf[type], func)) { - debug_error ("vconf_ignore_key_changed failed..\n"); - return MM_ERROR_SOUND_INTERNAL; - } - - return MM_ERROR_NONE; -} - -EXPORT_API -int _mm_sound_volume_get_value_by_type(volume_type_t type, unsigned int *value) -{ - int vconf_value = 0; - - /* Get volume value from VCONF */ - if (vconf_get_int(g_volume_vconf[type], &vconf_value)) { - debug_error ("vconf_get_int(%s) failed..\n", g_volume_vconf[type]); - return MM_ERROR_SOUND_INTERNAL; - } - - *value = vconf_value; - debug_log("volume_get_value %s %d", g_volume_str[type], *value); - - return MM_ERROR_NONE; -} - -EXPORT_API -int _mm_sound_volume_set_value_by_type(volume_type_t type, unsigned int value) -{ - int vconf_value = 0; - - vconf_value = value; - debug_log("volume_set_value %s %d", g_volume_str[type], value); - - /* Set volume value to VCONF */ - if (vconf_set_int(g_volume_vconf[type], vconf_value)) { - debug_error ("vconf_set_int(%s) failed..\n", g_volume_vconf[type]); - return MM_ERROR_SOUND_INTERNAL; - } - - return MM_ERROR_NONE; -} - -EXPORT_API -int _mm_sound_volume_get_values_on_bootup(int *values) -{ - int i, vconf_value = 0; - - for (i = 0; i < VOLUME_TYPE_MAX; i++) { - if (!vconf_get_int(g_volume_vconf[i], &vconf_value)) { - values[i] = vconf_value; - debug_log("volume_get_value %s %d", g_volume_str[i], values[i]); - } else { - debug_error ("vconf_get_int(%s) failed..\n", g_volume_vconf[i]); - values[i] = g_default_volume[i]; - vconf_value = values[i]; - if (vconf_set_int(g_volume_vconf[i], vconf_value)) { - debug_error ("vconf_set_int(%s) failed..\n", g_volume_vconf[i]); - } - } - } - - return MM_ERROR_NONE; -} - diff --git a/mobile/common/mm_source.c b/mobile/common/mm_source.c deleted file mode 100644 index c4766e9..0000000 --- a/mobile/common/mm_source.c +++ /dev/null @@ -1,299 +0,0 @@ -/* - * libmm-sound - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Seungbae Shin <seungbae.shin@samsung.com> - * - * 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 <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/mman.h> -#include <sys/stat.h> -#include <fcntl.h> - -#include "mm_types.h" -#include "mm_debug.h" -#include "mm_error.h" -#include "mm_source.h" - - -bool _is_drm_file( - const char *filePath -) -{ - if(!filePath || filePath[0] == '\0') - { - debug_error("invalid argument\n"); - return false; - } - char *p = NULL; - p = (char*) strrchr(filePath, '.'); - - if( p && ((strncasecmp(p, ".odf", 4) == 0) || (strncasecmp(p, ".dcf", 4) == 0) || (strncasecmp(p, ".o4a", 4) == 0) || (strncasecmp(p, ".o4v", 4) == 0))) - { - return true; - } - return false; -} - -EXPORT_API -int mm_source_open_file(const char *filename, MMSourceType *source, int drmsupport) -{ - struct stat finfo = {0, }; - int fd = -1; - void *mmap_buf = NULL; - - if(filename == NULL) - { - debug_error("filename is null\n"); - return MM_ERROR_SOUND_INVALID_FILE; - } - if(drmsupport) - { - if(_is_drm_file(filename)) - { - debug_error("%s is DRM contents\n", filename); - return MM_ERROR_SOUND_UNSUPPORTED_MEDIA_TYPE; - } - } - - fd = open(filename, O_RDONLY); - debug_fenter(); - debug_msg("Open file name is %s\n", filename); - unsigned int mediaSize,readSize,offSet=0; - char genStr[20],i; - - if (fd == -1) - { - debug_error("file open fail\n\n"); - return MM_ERROR_SOUND_INTERNAL; - } - if (fstat(fd, &finfo) == -1) - { - debug_error("file get info fail\n"); - close(fd); - return MM_ERROR_SOUND_INTERNAL; - } - - mediaSize = (unsigned int)finfo.st_size; - - { - /* get the extension (3 characters from last including NULL)*/ - strncpy((void *)genStr,(void *)(filename+(strlen(filename)-2)),3); - - debug_msg("ExtName of the Sound file %s\n",genStr); - - - if(strcasecmp (genStr, "dm") == 0) - { - debug_msg("It is DM file going ahead with special decoding\n"); - - /* Vlidation of the DM file */ - readSize = read(fd,(void*)genStr,0x8); - if(readSize != 0x8) - { - debug_error("Error in Reading the file Header %x/0x8\n",readSize); - return MM_ERROR_SOUND_INTERNAL; - } - - genStr[readSize] ='\0'; - - debug_msg("Header details of DM file %s\n",genStr); - - if(strcasecmp (genStr, "--random") != 0) - { - debug_error("It is not a valied DM file"); - return MM_ERROR_SOUND_INTERNAL; - } - - /*checking the Media Type */ - readSize = lseek(fd, 0x32, SEEK_SET); - if(readSize != 0x32) - { - debug_error("Error in Seeking the file to offset %x/0x32\n",readSize); - return MM_ERROR_SOUND_INTERNAL; - } - - readSize = read(fd,(void*)genStr,0xf); - - for(i=0;i<0xf;i++) - { - if(genStr[i] == (char)0xD) - { - genStr[i] ='\0'; - break; - } - } - - debug_msg("Header details of DM file %s\n",genStr); - - /*Finding the Media Offset */ - - if(strcasecmp (genStr, "audio/mpeg") == 0) - { - offSet = 0x63; - } - else if(strcasecmp (genStr, "audio/wav") == 0) - { - offSet = 0x62; - } - else - { - debug_error("It is not MP3/Wav DM file \n"); - return MM_ERROR_SOUND_INTERNAL; - } - - /*Finding the Media Size */ - - mediaSize -= (offSet + 0x28); - - /*Seeking the file to start */ - readSize = lseek(fd, 0x0, SEEK_SET); - - if( readSize != 0x0) - { - debug_error("Error in Seeking the file to offset %x/0x32\n",readSize); - return MM_ERROR_SOUND_INTERNAL; - } - - } - else - { - debug_msg("It is NON DM file going ahead with normal decoding\n"); - } - } - - mmap_buf = mmap(0, finfo.st_size, PROT_READ, MAP_SHARED, fd,0); - - if (mmap_buf == NULL) - { - debug_error("MMAP fail\n"); - close(fd); - return MM_ERROR_SOUND_INTERNAL; - } - source->ptr = mmap_buf+offSet; - source->medOffset = offSet; - debug_msg("source ptr = %p\n", source->ptr); - debug_msg("Med Offset Size : %d",source->medOffset); - source->tot_size = finfo.st_size; - source->cur_size = mediaSize; - source->type = MM_SOURCE_FILE; - source->fd = fd; - - return MM_ERROR_NONE; -} - -EXPORT_API -int mm_source_open_full_memory(const void *ptr, int totsize, int alloc, MMSourceType *source) -{ - int err = MM_ERROR_NONE; - if (ptr == NULL) - { - debug_error("PTR is NULL\n"); - return MM_ERROR_INVALID_ARGUMENT; - } - if (alloc) - { - err = mm_source_open_memory(ptr, totsize, totsize, source); - } - else - { - source->ptr = ptr; - source->tot_size = totsize; - source->cur_size = totsize; - - source->type = MM_SOURCE_MEMORY_NOTALLOC; - source->fd = -1; - } - return err; -} - -EXPORT_API -int mm_source_open_memory(const void *ptr, int totsize, int size, MMSourceType *source) -{ - source->ptr = (unsigned char*) malloc(totsize); - if (source->ptr == NULL) - { - debug_error("memory alloc fail\n"); - return MM_ERROR_SOUND_NO_FREE_SPACE; - } - source->tot_size = totsize; - source->cur_size = 0; - source->type = MM_SOURCE_MEMORY; - source->fd = -1; - - return mm_source_append_memory(ptr, size, source); -} - -EXPORT_API -int mm_source_append_memory(const void *ptr, int size, MMSourceType *source) -{ - if (source->cur_size + size > source->tot_size) - { - debug_error("memory too large\n"); - return MM_ERROR_SOUND_NO_FREE_SPACE; - } - - memcpy(source->ptr + source->cur_size, ptr, size); - source->cur_size += size; - return MM_ERROR_NONE; -} - -EXPORT_API -int mm_source_close(MMSourceType *source) -{ - debug_fenter(); - - ////PREVENT - if(source == NULL) - { - debug_critical("source is null %s\n", __func__); - return MM_ERROR_CLASS; - } - ///// - debug_msg("Source type = %d\n", source->type); - switch(source->type) - { - case MM_SOURCE_FILE: - if(source->ptr != NULL) - { - source->ptr -= source->medOffset; - debug_msg("Med Offset Size : %d/%d",source->medOffset,source->tot_size); - if (munmap(source->ptr, source->tot_size) == -1) { - debug_error("MEM UNMAP fail\n\n"); - } - } - close(source->fd); - break; - case MM_SOURCE_MEMORY: - if(source->ptr != NULL) - free(source->ptr); - break; - case MM_SOURCE_MEMORY_NOTALLOC: - break; - default: - debug_critical("Unknown Source\n"); - break; - } - memset(source, 0, sizeof(MMSourceType)); - return MM_ERROR_NONE; -} - |