Tizen 2.1 base
[platform/core/multimedia/libmm-sound.git] / server / mm_sound_mgr_codec.c
1 /*
2  * libmm-sound
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Seungbae Shin <seungbae.shin@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <pthread.h>
26
27 #include <mm_source.h>
28 #include <mm_error.h>
29 #include <mm_types.h>
30 #include <mm_debug.h>
31 #include <mm_ipc.h>
32
33 #include "include/mm_sound_mgr_common.h"
34 #include "include/mm_sound_mgr_codec.h"
35 #include "include/mm_sound_plugin_codec.h"
36 #include "include/mm_sound_thread_pool.h"
37
38 #include "include/mm_sound_mgr_asm.h"
39
40
41
42 #define _ENABLE_KEYTONE /* Temporal test code */
43
44 typedef struct {
45         int (*callback)(int, void *, void *);   /* msg_type(pid) client callback & client data info */
46         void *param;
47         int pid;
48         void *msgcallback;
49         void *msgdata;
50         MMHandleType plughandle;
51
52         int pluginid;
53         int status;
54         int session_type;
55         int session_handle;
56  } __mmsound_mgr_codec_handle_t;
57
58 static MMSoundPluginType *g_codec_plugins = NULL;
59 static __mmsound_mgr_codec_handle_t g_slots[MANAGER_HANDLE_MAX];
60 static mmsound_codec_interface_t g_plugins[MM_SOUND_SUPPORTED_CODEC_NUM];
61 static pthread_mutex_t g_slot_mutex;
62
63 static int _MMSoundMgrCodecStopCallback(int param);
64 static int _MMSoundMgrCodecFindKeytoneSlot(int *slotid);
65 static int _MMSoundMgrCodecGetEmptySlot(int *slotid);
66 static int _MMSoundMgrCodecFindLocaleSlot(int *slotid);
67 static int _MMSoundMgrCodecRegisterInterface(MMSoundPluginType *plugin);
68
69 #define STATUS_IDLE 0
70 #define STATUS_KEYTONE 1
71 #define STATUS_LOCALE 2
72 #define STATUS_SOUND 3
73
74 #define SOUND_SLOT_START 0
75
76
77
78 ASM_cb_result_t
79 sound_codec_asm_callback(int handle, ASM_event_sources_t event_src, ASM_sound_commands_t command, unsigned int sound_status, void* cb_data)
80 {
81         int slotid = (int)cb_data;
82         int result = MM_ERROR_NONE;
83         ASM_cb_result_t cb_res = ASM_CB_RES_NONE;
84
85         debug_log("Got audio session callback msg for session_handle %d\n", handle);
86
87         switch(command)
88         {
89         case ASM_COMMAND_STOP:
90         case ASM_COMMAND_PAUSE:
91                 debug_log("Got msg from asm to Stop or Pause %d\n", command);
92                 result = MMSoundMgrCodecStop(slotid);
93                 cb_res = ASM_CB_RES_STOP;
94                 break;
95         case ASM_COMMAND_RESUME:
96         case ASM_COMMAND_PLAY:
97                 debug_log("Got msg from asm to Play or Resume %d\n", command);
98                 cb_res = ASM_CB_RES_NONE;;
99         default:
100                 break;
101         }
102         return cb_res;
103 }
104
105
106 int MMSoundMgrCodecInit(const char *targetdir)
107 {
108         int loop = 0;
109         int count = 0;
110
111         debug_enter("\n");
112
113         memset (g_slots, 0, sizeof(g_slots));
114
115         if(pthread_mutex_init(&g_slot_mutex, NULL)) {
116                 debug_error("pthread_mutex_init failed [%s][%d]\n", __func__, __LINE__);
117                 return MM_ERROR_SOUND_INTERNAL;
118         }
119
120         for (count = 0; count < MANAGER_HANDLE_MAX; count++) {
121                 g_slots[count].status = STATUS_IDLE;
122                 g_slots[count].plughandle = -1;
123         }
124
125         if (g_codec_plugins) {
126                 debug_warning("Please Check Init twice\n");
127                 MMSoundPluginRelease(g_codec_plugins);
128         }
129
130         MMSoundPluginScan(targetdir, MM_SOUND_PLUGIN_TYPE_CODEC, &g_codec_plugins);
131
132         while (g_codec_plugins[loop].type != MM_SOUND_PLUGIN_TYPE_NONE) {
133                 _MMSoundMgrCodecRegisterInterface(&g_codec_plugins[loop++]);
134         }
135
136         debug_leave("\n");
137         return MM_ERROR_NONE;
138 }
139
140 int MMSoundMgrCodecFini(void)
141 {
142         debug_enter("\n");
143
144         memset(g_plugins, 0, sizeof(mmsound_codec_interface_t) * MM_SOUND_SUPPORTED_CODEC_NUM);
145         MMSoundPluginRelease(g_codec_plugins);
146         g_codec_plugins = NULL;
147         pthread_mutex_destroy(&g_slot_mutex);
148
149         debug_leave("\n");
150         return MM_ERROR_NONE;
151 }
152
153
154 int MMSoundMgrCodecPlay(int *slotid, const mmsound_mgr_codec_param_t *param)
155 {
156         int count = 0;
157         mmsound_codec_info_t info;
158         mmsound_codec_param_t codec_param;
159         int err = MM_ERROR_NONE;
160         int errorcode = 0;
161         int need_asm_unregister = 0;
162
163         debug_enter("\n");
164
165         debug_msg("DTMF : [%d]\n",param->tone);
166         debug_msg("Repeat : [%d]\n",param->repeat_count);
167         debug_msg("Volume : [%f]\n",param->volume);
168
169         for (count = 0; g_plugins[count].GetSupportTypes; count++) {
170                 /* Find codec */
171                 if (g_plugins[count].Parse(param->source, &info) == MM_ERROR_NONE)
172                         break;
173         }
174
175         debug_msg("Find plugin codec ::: [%d]\n", count);       /*The count num means codec type WAV, MP3 */
176
177         if (g_plugins[count].GetSupportTypes == NULL) { /* Codec not found */
178                 debug_error("unsupported file type %d\n", count);
179                 err = MM_ERROR_SOUND_UNSUPPORTED_MEDIA_TYPE;
180                 goto cleanup;
181         }
182
183         /* KeyTone */
184         if (param->keytone == 1) {
185                 /* Find keytone slot */
186                 err = _MMSoundMgrCodecFindKeytoneSlot(slotid);
187                 /* Not First connect */
188                 if (err == MM_ERROR_NONE) {
189                         if(g_slots[*slotid].status != STATUS_IDLE) {
190                                 MMSoundMgrCodecStop(*slotid);
191                         }
192                         debug_msg("Key tone : Stop to Play !!!\n");
193                 }
194                 codec_param.keytone = param->keytone;
195         } else if (param->keytone == 2) {
196                 /* Find keytone slot */
197                 err = _MMSoundMgrCodecFindLocaleSlot(slotid);
198                 /* Not First connect */
199                 if (err == MM_ERROR_NONE) {
200                         if(g_slots[*slotid].status != STATUS_IDLE) {
201                                 MMSoundMgrCodecStop(*slotid);
202                         }
203                         debug_msg("Key tone : Stop to Play !!!\n");
204                 }
205                 codec_param.keytone = param->keytone;
206         } else {
207                 debug_msg("Get New handle\n");
208                 codec_param.keytone = 0;
209         }
210
211         err = _MMSoundMgrCodecGetEmptySlot(slotid);
212         if (err != MM_ERROR_NONE) {
213                 debug_error("Empty g_slot is not found\n");
214                 goto cleanup;
215         }
216
217         codec_param.tone = param->tone;
218         codec_param.volume_config = param->volume_config;
219         codec_param.repeat_count = param->repeat_count;
220         codec_param.volume = param->volume;
221         codec_param.source = param->source;
222         codec_param.priority = param->priority;
223         codec_param.stop_cb = _MMSoundMgrCodecStopCallback;
224         codec_param.param = *slotid;
225         codec_param.pid = (int)param->param;
226         codec_param.handle_route = param->handle_route;
227
228         pthread_mutex_lock(&g_slot_mutex);
229         debug_msg("After Slot_mutex LOCK\n");
230
231         /* In case of KEYTONE */
232         if (param->keytone == 1)
233                 g_slots[*slotid].status = STATUS_KEYTONE;
234
235         /* In case of LOCALE */
236         if (param->keytone == 2) /* KeyTone */
237                 g_slots[*slotid].status = STATUS_LOCALE;                
238
239         /*
240          * Register ASM here
241          */
242
243         if(param->session_type != ASM_EVENT_CALL && param->session_type != ASM_EVENT_VIDEOCALL) {
244                 if(!ASM_register_sound_ex((int)param->param, &param->session_handle, param->session_type, ASM_STATE_PLAYING,
245                                                                 sound_codec_asm_callback, (void*)*slotid, ASM_RESOURCE_NONE, &errorcode, __asm_process_message))        {
246                         debug_critical("ASM_register_sound() failed %d\n", errorcode);
247                         pthread_mutex_unlock(&g_slot_mutex);
248                         return MM_ERROR_POLICY_INTERNAL;
249                 }
250         }
251         //
252
253         /* Codec id WAV or MP3 */
254         g_slots[*slotid].pluginid = count;
255         g_slots[*slotid].callback = param->callback;
256         g_slots[*slotid].msgcallback = param->msgcallback;
257         g_slots[*slotid].msgdata = param->msgdata;
258         g_slots[*slotid].param    = param->param;               /* This arg is used callback data */
259         g_slots[*slotid].session_type = param->session_type;
260         g_slots[*slotid].session_handle = param->session_handle;
261         
262         debug_msg("Using Slotid : [%d] Slot Status : [%d]\n", *slotid, g_slots[*slotid].status);
263
264
265
266         err = g_plugins[g_slots[*slotid].pluginid].Create(&codec_param, &info, &(g_slots[*slotid].plughandle));
267         debug_msg("Created audio handle : [%d]\n", g_slots[*slotid].plughandle);
268         if (err != MM_ERROR_NONE) {
269                 debug_error("Plugin create fail : 0x%08X\n", err);
270                 g_slots[*slotid].status = STATUS_IDLE;
271                 pthread_mutex_unlock(&g_slot_mutex);
272                 debug_warning("After Slot_mutex UNLOCK\n");
273                 need_asm_unregister = 1;
274                 goto cleanup;
275         }
276
277         err = g_plugins[g_slots[*slotid].pluginid].Play(g_slots[*slotid].plughandle);
278         if (err != MM_ERROR_NONE) {
279                 debug_error("Fail to play : 0x%08X\n", err);
280                 g_plugins[g_slots[*slotid].pluginid].Destroy(g_slots[*slotid].plughandle);
281                 need_asm_unregister = 1;
282         }
283
284         pthread_mutex_unlock(&g_slot_mutex);
285         debug_msg("After Slot_mutex UNLOCK\n");
286
287 cleanup:
288         if(param->session_type != ASM_EVENT_CALL  && param->session_type != ASM_EVENT_VIDEOCALL && need_asm_unregister == 1) {
289                 if(!ASM_unregister_sound_ex(param->session_handle, param->session_type, &errorcode,__asm_process_message)) {
290                         debug_error("Unregister sound failed 0x%X\n", errorcode);
291                         return MM_ERROR_POLICY_INTERNAL;
292                 }
293         }
294
295         debug_leave("\n");
296
297         return err;
298 }
299
300 #define DTMF_PLUGIN_COUNT 2
301 int MMSoundMgrCodecPlayDtmf(int *slotid, const mmsound_mgr_codec_param_t *param)
302 {
303         int count = 0;
304         int *codec_type;
305         mmsound_codec_info_t info;
306         mmsound_codec_param_t codec_param;
307         int err = MM_ERROR_NONE;
308         
309         debug_enter("\n");
310
311         debug_msg("DTMF : [%d]\n",param->tone);
312         debug_msg("Repeat : [%d]\n",param->repeat_count);
313         debug_msg("Volume : [%f]\n",param->volume);
314         
315         for (count = 0; g_plugins[count].GetSupportTypes; count++) {
316                 /* Find codec */
317                 codec_type = g_plugins[count].GetSupportTypes();
318                 if(codec_type && (MM_SOUND_SUPPORTED_CODEC_DTMF == codec_type[0]))
319                         break;
320         }
321         
322         debug_msg("Find plugin codec ::: [%d]\n", count);       /*The count num means codec type DTMF */
323
324         if (g_plugins[count].GetSupportTypes == NULL) { /* Codec not found */
325                 debug_error("unsupported file type %d\n", count);
326                 printf("unsupported file type %d\n", count);
327                 err = MM_ERROR_SOUND_UNSUPPORTED_MEDIA_TYPE;
328                 goto cleanup;
329         }
330
331         debug_msg("Get New handle\n");
332         codec_param.keytone = 0;
333
334         err = _MMSoundMgrCodecGetEmptySlot(slotid);
335         if(err != MM_ERROR_NONE)
336         {
337                 debug_error("Empty g_slot is not found\n");
338                 goto cleanup;
339         }
340
341         codec_param.tone = param->tone;
342         codec_param.priority = 0;
343         codec_param.volume_config = param->volume_config;
344         codec_param.repeat_count = param->repeat_count;
345         codec_param.volume = param->volume;
346         codec_param.stop_cb = _MMSoundMgrCodecStopCallback;
347         codec_param.param = *slotid;
348         codec_param.pid = (int)param->param;
349
350         pthread_mutex_lock(&g_slot_mutex);
351         debug_msg("After Slot_mutex LOCK\n");
352         
353         //
354         /*
355          * Register ASM here
356          */
357         int errorcode = 0;
358         int need_asm_unregister = 0;
359
360         if(param->session_type != ASM_EVENT_CALL && param->session_type != ASM_EVENT_VIDEOCALL) {
361                 if(!ASM_register_sound_ex((int)param->param, &param->session_handle, param->session_type, ASM_STATE_PLAYING,
362                                                                 sound_codec_asm_callback, (void*)*slotid, ASM_RESOURCE_NONE, &errorcode, __asm_process_message)) {
363                         debug_critical("ASM_register_sound() failed %d\n", errorcode);
364                         pthread_mutex_unlock(&g_slot_mutex);
365                         return MM_ERROR_POLICY_INTERNAL;
366                 }
367         }
368
369         g_slots[*slotid].pluginid = count;
370         g_slots[*slotid].callback = param->callback;
371         g_slots[*slotid].param    = param->param;               /* This arg is used callback data */
372         g_slots[*slotid].session_type = param->session_type;
373         g_slots[*slotid].session_handle = param->session_handle;
374         
375         debug_msg("Using Slotid : [%d] Slot Status : [%d]\n", *slotid, g_slots[*slotid].status);
376
377         err = g_plugins[g_slots[*slotid].pluginid].Create(&codec_param, &info, &(g_slots[*slotid].plughandle));
378         debug_msg("Created audio handle : [%d]\n", g_slots[*slotid].plughandle);
379         if (err != MM_ERROR_NONE) {
380                 debug_error("Plugin create fail : 0x%08X\n", err);
381                 g_slots[*slotid].status = STATUS_IDLE;
382                 pthread_mutex_unlock(&g_slot_mutex);
383                 debug_warning("After Slot_mutex UNLOCK\n");
384                 need_asm_unregister = 1;
385                 goto cleanup;
386         }
387
388         err = g_plugins[g_slots[*slotid].pluginid].Play(g_slots[*slotid].plughandle);
389         if (err != MM_ERROR_NONE) {
390                 debug_error("Fail to play : 0x%08X\n", err);
391                 g_plugins[g_slots[*slotid].pluginid].Destroy(g_slots[*slotid].plughandle);
392                 need_asm_unregister = 1;
393         }
394         
395         pthread_mutex_unlock(&g_slot_mutex);
396
397         debug_msg("Using Slotid : [%d] Slot Status : [%d]\n", *slotid, g_slots[*slotid].status);
398         debug_msg("After Slot_mutex UNLOCK\n")
399
400 cleanup:                
401         debug_leave("\n");
402
403         return err;
404 }
405
406
407 int MMSoundMgrCodecStop(const int slotid)
408 {
409         int err = MM_ERROR_NONE;
410
411         debug_enter("(Slotid : [%d])\n", slotid);
412
413         if (slotid < 0 || MANAGER_HANDLE_MAX <= slotid) {
414                 return MM_ERROR_INVALID_ARGUMENT;
415         }
416
417         pthread_mutex_lock (&g_slot_mutex);
418         debug_msg("After Slot_mutex LOCK\n");
419         if (g_slots[slotid].status == STATUS_IDLE) {
420                 err = MM_ERROR_SOUND_INVALID_STATE;
421                 debug_warning("The playing slots is not found, Slot ID : [%d]\n", slotid);
422                 goto cleanup;
423         }
424         debug_msg("Found slot, Slotid [%d] State [%d]\n", slotid, g_slots[slotid].status);
425
426         err = g_plugins[g_slots[slotid].pluginid].Stop(g_slots[slotid].plughandle);
427         if (err != MM_ERROR_NONE) {
428                 debug_error("Fail to STOP Code : 0x%08X\n", err);
429         }
430         debug_msg("Found slot, Slotid [%d] State [%d]\n", slotid, g_slots[slotid].status);
431 cleanup:
432         pthread_mutex_unlock(&g_slot_mutex);
433         debug_msg("After Slot_mutex UNLOCK\n");
434         debug_leave("(err : 0x%08X)\n", err);
435
436         return err;
437 }
438
439 static int _MMSoundMgrCodecStopCallback(int param)
440 {
441         int err = MM_ERROR_NONE;
442
443         debug_enter("(Slot : %d)\n", param);
444
445         pthread_mutex_lock(&g_slot_mutex);
446         debug_msg("[CODEC MGR] Slot_mutex lock done\n");
447
448
449         /*
450          * Unregister ASM here
451          */
452
453         int errorcode = 0;
454
455         if(g_slots[param].session_type != ASM_EVENT_CALL && g_slots[param].session_type != ASM_EVENT_VIDEOCALL) {
456                 debug_msg("[CODEC MGR] ASM unregister\n");
457                 if(!ASM_unregister_sound_ex(g_slots[param].session_handle, g_slots[param].session_type, &errorcode, __asm_process_message)) {
458                         debug_error("[CODEC MGR] Unregister sound failed 0x%X\n", errorcode);
459                 }
460         }
461
462
463
464         if (g_slots[param].msgcallback) {
465                 debug_msg("[CODEC MGR] msgcallback : %p\n", g_slots[param].msgcallback);
466                 debug_msg("[CODEC MGR] msg data : %p\n", g_slots[param].msgdata);
467                 debug_msg("[CODEC MGR] mgr codec callback : %p\n", g_slots[param].callback);
468                 g_slots[param].callback((int)g_slots[param].param, g_slots[param].msgcallback, g_slots[param].msgdata);         /*param means client msg_type */
469         }
470         debug_msg("Client callback msg_type (instance) : [%d]\n", (int)g_slots[param].param);
471         debug_msg("Handle allocated handle : [0x%08X]\n", g_slots[param].plughandle);
472         err = g_plugins[g_slots[param].pluginid].Destroy(g_slots[param].plughandle);
473         if (err < 0 ) {
474                 debug_critical("[CODEC MGR] Fail to destroy slot number : [%d] err [0x%x]\n", param, err);
475         }
476         memset(&g_slots[param], 0, sizeof(__mmsound_mgr_codec_handle_t));
477         g_slots[param].status = STATUS_IDLE;
478         pthread_mutex_unlock(&g_slot_mutex);
479         debug_msg("[CODEC MGR] Slot_mutex done\n");
480
481         return err;
482 }
483
484 static int _MMSoundMgrCodecFindKeytoneSlot(int *slotid)
485 {
486         int count = 0;
487         int err = MM_ERROR_NONE;
488
489         debug_enter("\n");
490
491         pthread_mutex_lock(&g_slot_mutex);
492         debug_warning("After Slot_mutex LOCK\n");
493
494         for (count = SOUND_SLOT_START; count < MANAGER_HANDLE_MAX ; count++) {
495                 if (g_slots[count].status == STATUS_KEYTONE) {
496                         break;
497                 }
498         }
499         pthread_mutex_unlock(&g_slot_mutex);
500         debug_warning("After Slot_mutex UNLOCK\n");
501         if (count < MANAGER_HANDLE_MAX) {
502                 debug_msg("Found keytone handle allocated (Slot : [%d])\n", count);
503                 *slotid = count;
504                 err =  MM_ERROR_NONE;
505         } else {
506                 debug_warning("Handle is full handle [KEY TONE] : [%d]\n", count);
507                 err =  MM_ERROR_SOUND_INTERNAL;
508         }
509
510         debug_leave("\n");
511
512         return err;
513 }
514
515 static int _MMSoundMgrCodecFindLocaleSlot(int *slotid)
516 {
517         int count = 0;
518         int err = MM_ERROR_NONE;
519
520         debug_enter("\n");
521
522         pthread_mutex_lock(&g_slot_mutex);
523         debug_warning("After Slot_mutex LOCK\n");
524
525         for (count = SOUND_SLOT_START; count < MANAGER_HANDLE_MAX ; count++) {
526                 if (g_slots[count].status == STATUS_LOCALE) {
527                         break;
528                 }
529         }
530         pthread_mutex_unlock(&g_slot_mutex);
531
532         debug_warning("After Slot_mutex UNLOCK\n");
533         if (count < MANAGER_HANDLE_MAX) {
534                 debug_msg("Found locale handle allocated (Slot : [%d])\n", count);
535                 *slotid = count;
536                 err =  MM_ERROR_NONE;
537         } else {
538                 debug_warning("Handle is full handle [KEY TONE] \n");
539                 err =  MM_ERROR_SOUND_INTERNAL;
540         }
541
542         debug_leave("\n");
543
544         return err;
545 }
546
547 static int _MMSoundMgrCodecGetEmptySlot(int *slot)
548 {
549         int count = 0;
550         int err = MM_ERROR_NONE;
551
552         debug_enter("\n");
553         debug_msg("Codec slot ID : [%d]\n", *slot);
554         pthread_mutex_lock(&g_slot_mutex);
555         debug_msg("After Slot_mutex LOCK\n");
556
557         for (count = SOUND_SLOT_START; count < MANAGER_HANDLE_MAX ; count++) {
558                 if (g_slots[count].status == STATUS_IDLE) {
559                         g_slots[count].status = STATUS_SOUND;
560                         break;
561                 }
562         }
563         pthread_mutex_unlock(&g_slot_mutex);
564         debug_msg("After Slot_mutex UNLOCK\n");
565
566         if (count < MANAGER_HANDLE_MAX) {
567                 debug_msg("New handle allocated (codec slot ID : [%d])\n", count);
568                 *slot = count;
569                 err =  MM_ERROR_NONE;
570         } else {
571                 debug_warning("Handle is full handle : [%d]\n", count);
572                 *slot = -1;
573                 /* Temporal code for reset */
574                 while(count--) {
575                         g_slots[count].status = STATUS_IDLE;
576                 }
577                 err =  MM_ERROR_SOUND_INTERNAL;
578         }
579
580         debug_leave("\n");
581
582         return err;
583 }
584
585 static int _MMSoundMgrCodecRegisterInterface(MMSoundPluginType *plugin)
586 {
587         int err = MM_ERROR_NONE;
588         int count = 0;
589         void *getinterface = NULL;
590
591         debug_enter("\n");
592
593         /* find emptry slot */
594         for (count = 0; count < MM_SOUND_SUPPORTED_CODEC_NUM; count++) {
595                 if (g_plugins[count].GetSupportTypes == NULL)
596                         break;
597         }
598
599         if (count == MM_SOUND_SUPPORTED_CODEC_NUM) {
600                 debug_critical("The plugin support type is not valid\n");
601                 return MM_ERROR_COMMON_OUT_OF_RANGE;
602         }
603         
604         debug_msg("Empty slot find : %d\n", count);
605
606         err = MMSoundPluginGetSymbol(plugin, CODEC_GET_INTERFACE_FUNC_NAME, &getinterface);
607         if (err != MM_ERROR_NONE) {
608                 debug_error("Get Symbol CODEC_GET_INTERFACE_FUNC_NAME is fail : %x\n", err);
609                 goto cleanup;
610         }
611         debug_msg("Getinterface name : %s\n", (char*)getinterface );
612
613         err = MMSoundPlugCodecCastGetInterface(getinterface)(&g_plugins[count]);
614         if (err != MM_ERROR_NONE) {
615                 debug_error("Get interface fail : %x\n", err);
616
617 cleanup: 
618                 /* If error occur, clean interface */
619                 memset(&g_plugins[count], 0, sizeof(mmsound_codec_interface_t));
620         } else {
621                 if (g_plugins[count].SetThreadPool)
622                         g_plugins[count].SetThreadPool(MMSoundThreadPoolRun);
623         }
624
625         debug_leave("\n");
626
627         return err;
628 }
629