Expect MM_SESSION_TYPE_REPLACED_BY_STREAM to skip working on backward compatibility...
[platform/core/api/audio-io.git] / test / audio_io_test.c
1 /*
2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <unistd.h>
21 #include <math.h>
22 #include <sound_manager.h>
23 #include <audio_io.h>
24
25 #ifndef M_PI
26 #define M_PI  (3.14159265)
27 #endif
28
29 #define TABLE_SIZE   (200)
30 typedef struct {
31         float sine[TABLE_SIZE];
32         int left_channel;
33         int right_channel;
34 } test_wav_t;
35 test_wav_t test_wav;
36
37 static int ch_table[3] = { 0, AUDIO_CHANNEL_MONO, AUDIO_CHANNEL_STEREO };
38
39 void play_file(char *file, int length, int ch)
40 {
41         audio_out_h output;
42         FILE *fp = fopen(file, "r");
43         if (fp == NULL) {
44                 printf("fopen failed\n");
45                 return;
46         }
47
48         char *buf = malloc(length);
49         if (buf == NULL) {
50                 printf("malloc failed\n");
51                 fclose(fp);
52                 return;
53         }
54
55         printf("start to play [%s][%d][%d]\n", file, length, ch);
56         //audio_out_create(44100, ch_table[ch] ,AUDIO_SAMPLE_TYPE_S16_LE, SOUND_TYPE_MEDIA, &output);
57         audio_out_create_new(44100, ch_table[ch], AUDIO_SAMPLE_TYPE_S16_LE, &output);
58         if (fread(buf, 1, length, fp) != length) {
59                 printf("error!!!!\n");
60         }
61
62         audio_out_prepare(output);
63         audio_out_write(output, buf, length);
64         audio_out_unprepare(output);
65
66         audio_out_destroy(output);
67
68         fclose(fp);
69
70         printf("play done\n");
71 }
72
73 #define DUMP_FILE "/root/test.raw"
74
75 void play_file_sample(char *file, int frequency, int ch, int type)
76 {
77         audio_out_h output;
78         int file_size = 0;
79         int read_bytes = 0;
80         int buffer_size = 0;
81         char *buf = NULL;
82
83         if (ch < 0 || ch > 2) {
84                 ch = 0;
85         }
86
87         FILE *fp = fopen(file, "r");
88         if (fp == NULL) {
89                 printf("open failed\n");
90                 return;
91         }
92         /*Get the size */
93         fseek(fp, 0, SEEK_END);
94         file_size = ftell(fp);
95         fseek(fp, 0, SEEK_SET);
96
97         printf("start to play [%s] of size [%d] with [%d][%d][%d]\n", file, file_size, frequency, ch, type);
98         if (type) {
99                 //audio_out_create(frequency, ch_table[ch] ,AUDIO_SAMPLE_TYPE_S16_LE, SOUND_TYPE_MEDIA, &output);
100                 audio_out_create_new(frequency, ch_table[ch], AUDIO_SAMPLE_TYPE_S16_LE, &output);
101         } else {
102                 //audio_out_create(frequency, ch_table[ch] ,AUDIO_SAMPLE_TYPE_U8, SOUND_TYPE_MEDIA, &output);
103                 audio_out_create_new(frequency, ch_table[ch], AUDIO_SAMPLE_TYPE_U8, &output);
104         }
105         audio_out_prepare(output);
106         audio_out_get_buffer_size(output, &buffer_size);
107
108         buf = (char *)malloc(buffer_size);
109         if (buf == NULL) {
110                 printf("malloc failed\n");
111                 audio_out_unprepare(output);
112                 audio_out_destroy(output);
113                 fclose(fp);
114                 return;
115         }
116         //audio_out_prepare(output);
117
118         while (file_size > 0) {
119                 read_bytes = fread(buf, 1, buffer_size, fp);
120                 printf("Read %d Requested - %d\n", read_bytes, buffer_size);
121                 audio_out_write(output, buf, read_bytes);
122                 file_size = file_size - read_bytes;
123         }
124
125         audio_out_unprepare(output);
126         audio_out_destroy(output);
127
128         free(buf);
129         fclose(fp);
130         printf("play done\n");
131 }
132
133 int audio_io_test(int length, int num, int ch)
134 {
135         int ret, size, i;
136         audio_in_h input;
137         if ((ret = audio_in_create(44100, ch_table[ch], AUDIO_SAMPLE_TYPE_S16_LE, &input)) == AUDIO_IO_ERROR_NONE) {
138                 ret = audio_in_ignore_session(input);
139                 if (ret != 0) {
140                         printf("ERROR, set session mix\n");
141                         audio_in_destroy(input);
142                         return 0;
143                 }
144
145                 ret = audio_in_prepare(input);
146                 if (ret != 0) {
147                         printf("ERROR, prepare\n");
148                         audio_in_destroy(input);
149                         return 0;
150                 }
151
152                 FILE *fp = fopen(DUMP_FILE, "wb+");
153
154                 if (fp == NULL) {
155                         printf("ERROR, file open failed\n");
156                         audio_in_destroy(input);
157                         return 0;
158                 }
159
160                 if ((ret = audio_in_get_buffer_size(input, &size)) == AUDIO_IO_ERROR_NONE) {
161                         size = length;
162                         char *buffer = alloca(size);
163
164                         for (i = 0; i < num; i++) {
165                                 printf("### loop = %d ============== \n", i);
166                                 if ((ret = audio_in_read(input, (void *)buffer, size)) > AUDIO_IO_ERROR_NONE) {
167                                         fwrite(buffer, size, sizeof(char), fp);
168                                         printf("PASS, size=%d, ret=%d\n", size, ret);
169                                 } else {
170                                         printf("FAIL, size=%d, ret=%d\n", size, ret);
171                                 }
172                         }
173                 }
174
175                 fclose(fp);
176
177                 audio_in_destroy(input);
178         }
179
180         play_file(DUMP_FILE, length * num, ch);
181
182         return 1;
183 }
184
185 int audio_io_loopback_in_test()
186 {
187         int ret, size;
188         audio_in_h input;
189         FILE *fp = fopen("/tmp/dump_test.raw", "wb+");
190
191         if (fp == NULL) {
192                 printf("open failed \n");
193                 return 0;
194         }
195
196         if ((ret = audio_in_create(16000, AUDIO_CHANNEL_MONO, AUDIO_SAMPLE_TYPE_S16_LE, &input)) == AUDIO_IO_ERROR_NONE) {
197                 ret = audio_in_ignore_session(input);
198                 if (ret != 0) {
199                         printf("ERROR, set session mix\n");
200                         goto exit;
201                 }
202
203                 ret = audio_in_prepare(input);
204                 if (ret != 0) {
205                         printf("ERROR, prepare\n");
206                         goto exit;
207                 }
208
209                 ret = audio_in_get_buffer_size(input, &size);
210                 if (ret != AUDIO_IO_ERROR_NONE) {
211                         printf("audio_in_get_buffer_size failed.\n");
212                         goto exit;
213                 }
214
215                 while (1) {
216                         char *buffer = alloca(size);
217                         if ((ret = audio_in_read(input, (void *)buffer, size)) > AUDIO_IO_ERROR_NONE) {
218                                 fwrite(buffer, size, sizeof(char), fp);
219                                 printf("PASS, size=%d, ret=%d\n", size, ret);
220                         } else {
221                                 printf("FAIL, size=%d, ret=%d\n", size, ret);
222                         }
223                 }
224         }
225
226  exit:
227         audio_in_destroy(input);
228
229         fclose(fp);
230
231         return ret;
232
233 }
234
235 int audio_io_loopback_test()
236 {
237         int ret, size;
238         audio_in_h input;
239         audio_out_h output;
240         char *buffer = NULL;
241
242         ret = audio_in_create(16000, AUDIO_CHANNEL_MONO, AUDIO_SAMPLE_TYPE_S16_LE, &input);
243         if (ret != AUDIO_IO_ERROR_NONE) {
244                 printf("audio_in_create_ex failed. \n");
245                 return 0;
246         }
247         //ret = audio_out_create(16000, AUDIO_CHANNEL_MONO , AUDIO_SAMPLE_TYPE_S16_LE, SOUND_TYPE_CALL, &output);
248         ret = audio_out_create_new(16000, AUDIO_CHANNEL_MONO, AUDIO_SAMPLE_TYPE_S16_LE, &output);
249         if (ret != AUDIO_IO_ERROR_NONE) {
250                 printf("audio_out_create failed. \n");
251                 return 0;
252         }
253
254         ret = audio_in_prepare(input);
255         if (ret != 0) {
256                 printf("audio_in_prepare failed.\n");
257                 audio_in_destroy(input);
258                 return 0;
259         } else {
260                 ret = audio_in_get_buffer_size(input, &size);
261                 if (ret != AUDIO_IO_ERROR_NONE) {
262                         printf("audio_in_get_buffer_size failed.\n");
263                         return 0;
264                 } else {
265                         printf("size(%d)\n", size);
266                         buffer = alloca(size);
267                 }
268         }
269
270         ret = audio_out_prepare(output);
271         if (ret != 0) {
272                 printf("audio_out_prepare failed.\n");
273                 audio_out_destroy(output);
274                 return 0;
275         }
276
277         if (buffer == NULL) {
278                 printf("buffer is null\n");
279                 return 0;
280         }
281
282         while (1) {
283                 ret = audio_in_read(input, (void *)buffer, size);
284                 if (ret > AUDIO_IO_ERROR_NONE) {
285                         ret = audio_out_write(output, buffer, size);
286                         if (ret > AUDIO_IO_ERROR_NONE) {
287                                 printf("audio read/write success. buffer(%p), size(%d)\n", buffer, size);
288                         } else {
289                                 printf("audio read success, write failed. buffer(%p), size(%d)\n", buffer, size);
290                         }
291                 } else
292                         printf("audio read/write failed. buffer(%p), size(%d)\n", buffer, size);
293         }
294
295 }
296
297 audio_in_h input;
298 audio_out_h output;
299
300 FILE *fp_w = NULL;
301
302 sound_stream_info_h g_stream_info_read_h = NULL;
303 sound_stream_info_h g_stream_info_write_h = NULL;
304
305 static void focus_callback(sound_stream_info_h stream_info, sound_stream_focus_change_reason_e reason_for_change, const char *additional_info, void *user_data)
306 {
307         int ret = 0;
308         sound_stream_focus_state_e playback_focus_state;
309         sound_stream_focus_state_e recording_focus_state;
310         printf("*** focus_callback_read is called, stream_info(%p, read(%p)/write(%p)) ***\n", stream_info, g_stream_info_read_h, g_stream_info_write_h);
311         printf(" - reason_for_change(%d), additional_info(%s), user_data(%p)\n", reason_for_change, additional_info, user_data);
312         ret = sound_manager_get_focus_state(stream_info, &playback_focus_state, &recording_focus_state);
313         if (!ret)
314                 printf(" - focus_state(playback_focus:%d, recording_focus:%d)\n", playback_focus_state, recording_focus_state);
315
316         return;
317 }
318
319 static void _audio_io_stream_read_cb(audio_in_h handle, size_t nbytes, void *user_data)
320 {
321         const void *buffer = NULL;
322         unsigned int len = (unsigned int)nbytes;
323
324         //printf("_audio_io_stream_read_cb : handle=%p, nbytes=%d, user_data=%p\n", handle, nbytes, user_data);
325
326         if (len > 0) {
327                 audio_in_peek(handle, &buffer, &len);
328                 if (fp_w) {
329                         fwrite(buffer, sizeof(char), len, fp_w);
330                 }
331                 audio_in_drop(handle);
332         }
333 }
334
335 static void _audio_io_stream_write_cb(audio_out_h handle, size_t nbytes, void *user_data)
336 {
337         short *buffer = NULL;
338         int ret = 0;
339         int i = 0;
340
341         //printf("_audio_io_stream_write_cb : handle=%p, nbytes=%d, user_data=%p\n", handle, nbytes, user_data);
342
343         if (nbytes > 0) {
344                 buffer = (short *)malloc(nbytes);
345                 if (buffer == NULL) {
346                         printf("malloc failed\n");
347                         return;
348                 }
349                 memset(buffer, 0, nbytes);
350
351                 for (i = 0; i < nbytes / 2; i += 2) {
352                         buffer[i] = (short)32768 *test_wav.sine[test_wav.left_channel]; /* left */
353                         buffer[i + 1] = (short)32768 *test_wav.sine[test_wav.right_channel];    /* right */
354                         test_wav.left_channel += 1;
355                         if (test_wav.left_channel >= TABLE_SIZE)
356                                 test_wav.left_channel -= TABLE_SIZE;
357                         test_wav.right_channel += 3;
358                         if (test_wav.right_channel >= TABLE_SIZE)
359                                 test_wav.right_channel -= TABLE_SIZE;
360                 }
361
362                 ret = audio_out_write(handle, buffer, nbytes);
363                 if (ret > AUDIO_IO_ERROR_NONE) {
364                         //printf("audio write success. buffer(%p), nbytes(%d)\n", buffer, nbytes);
365                 }
366
367                 free(buffer);
368         }
369 }
370
371 static void _audio_in_state_cb(audio_in_h handle, audio_io_state_e previous, audio_io_state_e current, bool by_policy, void *user_data)
372 {
373         printf(">>> _audio_in_state_cb() : handle(%p), current(%d), previous(%d), by_policy(%d), user_data(%p)\n", handle, current, previous, by_policy, user_data);
374 }
375
376 static void _audio_out_state_cb(audio_in_h handle, audio_io_state_e previous, audio_io_state_e current, bool by_policy, void *user_data)
377 {
378         printf(">>> _audio_out_state_cb() : handle(%p), current(%d), previous(%d), by_policy(%d), user_data(%p)\n", handle, current, previous, by_policy, user_data);
379 }
380
381 int _convert_cmd_and_run(char cmd, int mode)
382 {
383         int ret = 0;
384         switch (cmd) {
385         case 'P':
386                 if (mode & 0x01)
387                         ret = audio_out_prepare(output);
388                 if (mode & 0x02)
389                         ret = audio_in_prepare(input);
390                 break;
391         case 'u':
392                 if (mode & 0x01)
393                         ret = audio_out_unprepare(output);
394                 if (mode & 0x02)
395                         ret = audio_in_unprepare(input);
396                 break;
397         case 'p':
398                 if (mode & 0x01)
399                         ret = audio_out_pause(output);
400                 if (mode & 0x02)
401                         ret = audio_in_pause(input);
402                 break;
403         case 'r':
404                 if (mode & 0x01)
405                         ret = audio_out_resume(output);
406                 if (mode & 0x02)
407                         ret = audio_in_resume(input);
408                 break;
409         case 'd':
410                 if (mode & 0x01)
411                         ret = audio_out_drain(output);
412                 //if (mode & 0x02)  ret = audio_in_drain(input);
413                 break;
414         case 'f':
415                 if (mode & 0x01)
416                         ret = audio_out_flush(output);
417                 if (mode & 0x02)
418                         ret = audio_in_flush(input);
419                 break;
420         case 'i':
421                 ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, focus_callback, NULL, &g_stream_info_write_h);
422                 if (ret) {
423                         printf("fail to sound_manager_create_stream_information(), ret(0x%x)\n", ret);
424                 }
425                 break;
426         case 'q':                                       /* quit */
427                 ret = 1;
428                 break;
429         default:
430                 ret = 1;
431                 break;
432         }
433         return ret;
434 }
435
436 int audio_io_async_test(int mode)
437 {
438         int ret, size;
439         char *buffer = NULL;
440         int i = 0;
441
442         char cmd = 0;
443         int cmd_ret;
444
445         int write_mode = (mode & 0x01);
446         int read_mode = (mode & 0x02);
447
448         sound_stream_focus_state_e playback_focus_state;
449         sound_stream_focus_state_e recording_focus_state;
450
451         if ((write_mode == 0) && (read_mode == 0)) {
452                 printf("not vaild mode.\n");
453                 return 0;
454         }
455
456         if (read_mode) {
457
458                 printf("audio_in_create\n");
459                 ret = audio_in_create(44100, AUDIO_CHANNEL_STEREO, AUDIO_SAMPLE_TYPE_S16_LE, &input);
460                 if (ret != AUDIO_IO_ERROR_NONE) {
461                         printf("audio_in_create_ex failed. \n");
462                         return 0;
463                 }
464                 printf("audio_in_create success!!! [%p]\n", input);
465
466                 ret = audio_in_set_stream_cb(input, _audio_io_stream_read_cb, NULL);
467                 if (ret != AUDIO_IO_ERROR_NONE) {
468                         printf("audio_in_set_stream_cb failed. \n");
469                         goto EXIT;
470                 }
471                 printf("audio_in_set_stream_cb success!!! [%p]\n", input);
472
473                 ret = audio_in_set_state_changed_cb(input, _audio_in_state_cb, NULL);
474                 if (ret != AUDIO_IO_ERROR_NONE) {
475                         printf("audio_out_set_state_changed_cb failed. \n");
476                         goto EXIT;
477                 }
478                 printf("audio_out_set_state_changed_cb success!!! [%p]\n", input);
479
480                 ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, focus_callback, NULL, &g_stream_info_read_h);
481                 if (ret) {
482                         printf("fail to sound_manager_create_stream_information(), ret(0x%x)\n", ret);
483                         goto EXIT;
484                 }
485                 ret = audio_in_set_stream_info(input, g_stream_info_read_h);
486                 if (ret)
487                         printf("fail to audio_in_set_stream_info(), ret(0x%x)\n", ret);
488
489                 ret = sound_manager_acquire_focus(g_stream_info_read_h, SOUND_STREAM_FOCUS_FOR_RECORDING, NULL);
490                 if (ret) {
491                         printf("fail to sound_manager_acquire_focus() for RECORDING, ret(0x%x)\n", ret);
492                         goto EXIT;
493                 }
494
495                 fp_w = fopen("/tmp/pcm_w.raw", "w");
496         }
497
498         if (write_mode) {
499                 printf("before audio_out_create\n");
500                 getchar();
501
502                 printf("audio_out_create\n");
503                 //ret = audio_out_create(44100, AUDIO_CHANNEL_STEREO , AUDIO_SAMPLE_TYPE_S16_LE, SOUND_TYPE_MEDIA, &output);
504                 ret = audio_out_create_new(44100, AUDIO_CHANNEL_STEREO, AUDIO_SAMPLE_TYPE_S16_LE, &output);
505                 if (ret != AUDIO_IO_ERROR_NONE) {
506                         printf("audio_out_create failed. \n");
507                         goto EXIT;
508                 }
509                 printf("audio_out_create success!!! [%p]\n", output);
510
511                 ret = audio_out_set_stream_cb(output, _audio_io_stream_write_cb, NULL);
512                 if (ret != AUDIO_IO_ERROR_NONE) {
513                         printf("audio_out_set_stream_cb failed. \n");
514                         goto EXIT;
515                 }
516                 printf("audio_out_set_stream_cb success!!! [%p]\n", output);
517
518                 ret = audio_out_set_state_changed_cb(output, _audio_out_state_cb, NULL);
519                 if (ret != AUDIO_IO_ERROR_NONE) {
520                         printf("audio_out_set_state_changed_cb failed. \n");
521                         goto EXIT;
522                 }
523                 printf("audio_out_set_state_changed_cb success!!! [%p]\n", output);
524
525                 ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, focus_callback, NULL, &g_stream_info_write_h);
526                 if (ret) {
527                         printf("fail to sound_manager_create_stream_information(), ret(0x%x)\n", ret);
528                         goto EXIT;
529                 }
530                 ret = audio_out_set_stream_info(output, g_stream_info_write_h);
531                 if (ret)
532                         printf("fail to audio_out_set_stream_info(), ret(0x%x)\n", ret);
533
534                 ret = sound_manager_acquire_focus(g_stream_info_write_h, SOUND_STREAM_FOCUS_FOR_PLAYBACK, NULL);
535                 if (ret) {
536                         printf("fail to sound_manager_acquire_focus() for PLAYBACK, ret(0x%x)\n", ret);
537                         goto EXIT;
538                 }
539
540                 //generate wave data
541                 for (i = 0; i < TABLE_SIZE; i++) {
542                         test_wav.sine[i] = 0.9 * (float)sin(((double)i / (double)TABLE_SIZE) * M_PI * 2.);
543                 }
544                 test_wav.left_channel = test_wav.right_channel = 0;
545         }
546
547         if (read_mode) {
548                 printf("before audio_in_prepare\n");
549                 getchar();
550                 printf("audio_in_prepare\n");
551                 ret = audio_in_prepare(input);
552                 if (ret != 0) {
553                         printf("audio_in_prepare failed.\n");
554                         audio_in_destroy(input);
555                         goto EXIT;
556                 } else {
557                         ret = audio_in_get_buffer_size(input, &size);
558                         if (ret != AUDIO_IO_ERROR_NONE) {
559                                 printf("audio_in_get_buffer_size failed.\n");
560                                 goto EXIT;
561                         } else {
562                                 printf("size(%d)\n", size);
563                                 buffer = alloca(size);
564                         }
565                 }
566
567                 if (buffer == NULL) {
568                         printf("buffer is null\n");
569                         goto EXIT;
570                 }
571         }
572
573         if (write_mode) {
574                 printf("before audio_out_prepare\n");
575                 getchar();
576                 printf("audio_out_prepare\n");
577                 ret = audio_out_prepare(output);
578                 if (ret != 0) {
579                         printf("audio_out_prepare failed.\n");
580                         audio_out_destroy(output);
581                         goto EXIT;
582                 }
583         }
584
585         do {
586                 printf("command(q:quit) : ");
587                 cmd = (char)getchar();
588                 if (cmd != '\n')
589                         getchar();
590                 cmd_ret = _convert_cmd_and_run(cmd, mode);
591                 printf("  - result code : %d\n", cmd_ret);
592         } while (cmd != 'q');
593
594         //printf ("loop start\n");
595         //for (i=0; i<10; i++) {
596         //    printf ("-------- %d -------\n",i);
597         //    usleep (1000000);
598         //}
599
600         //getchar();
601
602 EXIT:
603         if (read_mode) {
604                 if (input) {
605                         printf("audio_in_unprepare\n");
606                         audio_in_unprepare(input);
607                         printf("audio_in_destroy\n");
608                         audio_in_destroy(input);
609                         input = NULL;
610                 }
611
612                 if (fp_w) {
613                         fclose(fp_w);
614                         fp_w = NULL;
615                 }
616
617                 if (g_stream_info_read_h) {
618                         ret = sound_manager_get_focus_state(g_stream_info_read_h, NULL, &recording_focus_state);
619                         if (recording_focus_state == SOUND_STREAM_FOCUS_STATE_ACQUIRED) {
620                                 ret = sound_manager_release_focus(g_stream_info_read_h, SOUND_STREAM_FOCUS_FOR_RECORDING, NULL);
621                                 if (ret)
622                                         printf("fail to sound_manager_release_focus() for recording, ret(0x%x)\n", ret);
623                         }
624                         ret = sound_manager_destroy_stream_information(g_stream_info_read_h);
625                         if (ret)
626                                 printf("fail to sound_manager_destroy_stream_information(), ret(0x%x)\n", ret);
627                         g_stream_info_read_h = NULL;
628                 }
629         }
630         //getchar();
631
632         if (write_mode) {
633                 if (output) {
634                         printf("audio_out_unprepare\n");
635                         audio_out_unprepare(output);
636                         printf("audio_out_destroy\n");
637                         audio_out_destroy(output);
638                 }
639
640                 if (g_stream_info_write_h) {
641                         ret = sound_manager_get_focus_state(g_stream_info_write_h, &playback_focus_state, NULL);
642                         if (playback_focus_state == SOUND_STREAM_FOCUS_STATE_ACQUIRED) {
643                                 ret = sound_manager_release_focus(g_stream_info_write_h, SOUND_STREAM_FOCUS_FOR_PLAYBACK, NULL);
644                                 if (ret)
645                                         printf("fail to sound_manager_release_focus() for playback, ret(0x%x)\n", ret);
646                         }
647                         ret = sound_manager_destroy_stream_information(g_stream_info_write_h);
648                         if (ret)
649                                 printf("fail to sound_manager_destroy_stream_information(), ret(0x%x)\n", ret);
650                         g_stream_info_write_h = NULL;
651                 }
652         }
653
654         return 0;
655 }
656
657 int main(int argc, char **argv)
658 {
659         if (argc == 2 && !strcmp(argv[1], "call-forwarding-loop")) {
660                 audio_io_loopback_test();
661         } else if (argc == 2 && !strcmp(argv[1], "call-forwarding-in")) {
662                 audio_io_loopback_in_test();
663         } else if (argc == 3 && !strcmp(argv[1], "async")) {
664                 audio_io_async_test(atoi(argv[2]));
665         } else if (argc == 4) {
666                 printf("run with [%s][%s][%s]\n", argv[1], argv[2], argv[3]);
667                 audio_io_test(atoi(argv[1]), atoi(argv[2]), atoi(argv[3]));
668         } else if (argc == 6) {
669                 play_file_sample(argv[2], atoi(argv[3]), atoi(argv[4]), atoi(argv[5]));
670         } else {
671                 printf("1. usage : audio_io_test call-forwarding-loop\n");
672                 printf("2. usage : audio_io_test call-forwarding-in\n");
673                 printf("3. usage : audio_io_test [length to read] [number of iteration] [channels]\n");
674                 printf("4. usage : audio_io_test async [write(1) | read(2)]\n");
675                 printf("5. Uasge : audio_io_test play [filename] [sample rate] [channels] [type(0:U8)]\n");
676         }
677         return 0;
678 }