aud_vr_sd.c 42.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331
/*****************************************************************************
*  Copyright Statement:
*  --------------------
*  This software is protected by Copyright and the information contained
*  herein is confidential. The software may not be copied and the information
*  contained herein may not be used or disclosed except with the written
*  permission of MediaTek Inc. (C) 2005
*
*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
*
*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/

/*******************************************************************************
 * Filename:
 * ---------
 * aud_vr_sd.c
 *
 * Project:
 * --------
 *   Maui
 *
 * Description:
 * ------------
 *   This file includes vr sd service functions
 *
 * Author:
 * -------
 * -------
 *
 *==============================================================================
 *             HISTORY
 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
 *------------------------------------------------------------------------------
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 *------------------------------------------------------------------------------
 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
 *==============================================================================
 *******************************************************************************/

#ifndef MED_NOT_PRESENT

/*==== INCLUDES =========*/
//#include "kal_release.h"
//#include "kal_trace.h"
//#include "stack_common.h"
//#include "stack_msgs.h"
//#include "app_ltlcom.h" /* Task message communiction */
//#include "syscomp_config.h"
//#include "task_config.h"        /* Task creation */
//#include "stacklib.h"   /* Basic type for dll, evshed, stacktimer */
//#include "event_shed.h" /* Event scheduler */
//#include "stack_timer.h"        /* Stack timer */

/* global includes */
//#include "l1audio.h"
//#include "device.h"
//#include "resource_audio.h"
//#include "fat_fs.h"
//#include "nvram_enums.h"
//#include "nvram_struct.h"
//#include "nvram_user_defs.h"
//#include "nvram_data_items.h"
//#include "custom_nvram_editor_data_item.h"
//#include "custom_equipment.h"

/* local includes */
#include "med_global.h"
//#include "aud_defs.h"
//#include "med_struct.h"
//#include "med_api.h"
//#include "med_context.h"
//#include "med_main.h"
//#include "aud_main.h"
#include "med_utility.h"

#ifdef __AUD_TRACE_ON__
#include "med_trc.h"
#endif 

#ifdef __MED_VR_MOD__
static const kal_uint16 *hex_0_9_digits = L"0123456789";
static const kal_uint16 *hex_a_f_digits = L"abcdef";
static const kal_uint16 *hex_A_F_digits = L"ABCDEF";
aud_vr_sd_context_struct vr_sd_ctx;

extern aud_vr_context_struct vr_ctx;


/*****************************************************************************
 * FUNCTION
 *  aud_vr_sd_find_word_id
 * DESCRIPTION
 *  vr sd find the index of a word id
 * PARAMETERS
 *  group_id        [IN]        
 *  word_id         [IN]        
 * RETURNS
 *  kal_int32
 *****************************************************************************/
kal_int32 aud_vr_sd_find_word_id(kal_uint16 group_id, kal_uint16 word_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint16 id_length = vr_sd_ctx.id_length[group_id];
    kal_uint16 *id_array = vr_sd_ctx.id_array[group_id];
    kal_int32 i;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    for (i = 0; i < id_length; i++)
    {
        if (id_array[i] == word_id)
        {
            return i;
        }
    }
    return -1;
}


/*****************************************************************************
 * FUNCTION
 *  aud_vr_sd_extract_group_id
 * DESCRIPTION
 *  vr sd parse and extract the group id (a decimal integer) from the assigned folder name (without path)
 * PARAMETERS
 *  filename        [?]     
 * RETURNS
 *  kal_int32
 *****************************************************************************/
kal_int32 aud_vr_sd_extract_group_id(kal_uint16 *filename)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint16 *p;
    kal_uint16 digit_char;
    kal_int32 result;
    kal_int32 filename_len = kal_wstrlen(filename);

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (filename_len < 1)
    {
        return -1;
    }

    for (result = 0; *filename; filename++)
    {
        digit_char = *filename;
        if ((p = kal_wstrchr(hex_0_9_digits, (int)digit_char)) != NULL)
        {
            result = (result * 10) + (p - hex_0_9_digits);
        }
        else
        {
            return -1;
        }
    }

    return result;
}


/*****************************************************************************
 * FUNCTION
 *  aud_vr_sd_extract_word_id
 * DESCRIPTION
 *  vr sd parse and extract the word id (a hexadecimal integer) from the assigned folder name (without path)
 * PARAMETERS
 *  filename        [?]     
 * RETURNS
 *  kal_int32
 *****************************************************************************/
kal_int32 aud_vr_sd_extract_word_id(kal_uint16 *filename, kal_uint16 max_filename_len)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint16 *p;
    kal_uint16 digit_char, i, j;
    kal_int32 result;
    kal_int32 filename_len = kal_wstrlen(filename);

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (filename_len < 8)
    {
        return -1;
    }

    for (result = 0, i = 0, j = (kal_uint16)filename_len - 8; i < 4, j < max_filename_len; i++, j++)
    {
        digit_char = filename[j];
        if ((p = kal_wstrchr(hex_0_9_digits, (int)digit_char)) != NULL)
        {
            result = (result << 4) + (p - hex_0_9_digits);
        }
        else if ((p = kal_wstrchr(hex_a_f_digits, (int)digit_char)) != NULL)
        {
            result = (result << 4) + (p - hex_a_f_digits + 10);
        }
        else if ((p = kal_wstrchr(hex_A_F_digits, (int)digit_char)) != NULL)
        {
            result = (result << 4) + (p - hex_A_F_digits + 10);
        }
        else
        {
            return -1;
        }
    }

    return result;
}


/*****************************************************************************
 * FUNCTION
 *  aud_vr_sd_scan_tags_in_group_folder
 * DESCRIPTION
 *  vr sd scan all tags in a group folder
 * PARAMETERS
 *  group_id        [IN]        
 *  path            [?]         
 * RETURNS
 *  void
 *****************************************************************************/
void aud_vr_sd_scan_tags_in_group_folder(kal_uint16 group_id, kal_uint16 *path)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint16 filename[VR_MAX_DB_PATH_LEN + 1];
    kal_uint16 filename_expr[VR_MAX_DB_PATH_LEN + 1];
    kal_int32 word_id;
    FS_HANDLE fd_cursor;
    FS_DOSDirEntry file_info;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    vr_sd_ctx.id_length[group_id] = 0;
    kal_wsprintf(filename_expr, "%wMTKVR_????.vrd", path);

    if ((fd_cursor = FS_FindFirst(filename_expr, 0, 0, &file_info, filename, (VR_MAX_DB_PATH_LEN + 1) << 1)) >= 0)
    {
        /* loop through all vrd files in a group folder */
        do
        {
            /* filter out folder results */
            if (!(file_info.Attributes & FS_ATTR_DIR))
            {
                /* parse word id and add to id array and increment id length */
                if ((word_id = aud_vr_sd_extract_word_id(filename, VR_MAX_DB_PATH_LEN + 1)) >= 0)
                {
                    vr_sd_ctx.id_array[group_id][vr_sd_ctx.id_length[group_id]++] = word_id;
                }
            }
        } while (FS_FindNext(fd_cursor, &file_info, filename, (VR_MAX_DB_PATH_LEN + 1) << 1) == FS_NO_ERROR);
        FS_FindClose(fd_cursor);
    }
}


/*****************************************************************************
 * FUNCTION
 *  aud_vr_sd_filter_out_not_exist_tags
 * DESCRIPTION
 *  vr sd scan all tags in a group id array and remove non-existing tag ids from the array
 * PARAMETERS
 *  group_id        [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void aud_vr_sd_filter_out_not_exist_tags(kal_uint16 group_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    FS_HANDLE file_handle;
    kal_wchar file_name[VR_MAX_DB_PATH_LEN + 1];
    kal_uint32 i, count;
    kal_uint16 *id_array = vr_sd_ctx.id_array[group_id];
    kal_uint16 id_len = vr_sd_ctx.id_length[group_id];

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* loop through id array */
    for (i = count = 0; i < id_len; i++)
    {
        /* check does each tag file exist */
        kal_wsprintf(file_name, "%wMTKVR_%04x.vrd", vr_ctx.db_path, id_array[i]);
        if ((file_handle = FS_Open(file_name, FS_READ_ONLY | FS_NOBUSY_CHECK_MODE)) >= 0)
        {
            FS_Close(file_handle);
            id_array[count++] = id_array[i];
        }
    }

    /* update id length to the number of exisiting tag files in id array */
    if (count != id_len)
    {
        vr_sd_ctx.id_length[group_id] = count;
    }
}


/*****************************************************************************
 * FUNCTION
 *  aud_vr_sd_delete_one_tag
 * DESCRIPTION
 *  vr sd delete a tag id with its file and its id in the array
 * PARAMETERS
 *  group_id        [IN]        
 *  word_id         [IN]        
 * RETURNS
 *  kal_bool
 *****************************************************************************/
kal_bool aud_vr_sd_delete_one_tag(kal_uint16 group_id, kal_uint16 word_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint16 *id_length_p = &vr_sd_ctx.id_length[group_id];
    kal_uint16 *id_array = vr_sd_ctx.id_array[group_id];
    kal_int32 i, j;
    kal_wchar filename[VR_MAX_DB_PATH_LEN + 1];
    kal_bool result;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* find the index of word id in id array */
    if ((j = aud_vr_sd_find_word_id(group_id, word_id)) >= 0)
    {
        /* delete tag file */
        kal_wsprintf(filename, "%c:\\VRDB\\ISD\\%d\\MTKVR_%04x.vrd", (kal_uint8) vr_ctx.db_drive, group_id, word_id);
        if (FS_Delete(filename) == FS_NO_ERROR)
        {
            /* left shift rest word ids in id array */
            (*id_length_p)--;
            for (i = j; i < *id_length_p; i++)
            {
                id_array[i] = id_array[i + 1];
            }
            result = KAL_TRUE;
        }
        else
        {
            result = KAL_FALSE;
        }
    }
    else
    {
        result = KAL_TRUE;
    }

    return result;
}


/*****************************************************************************
 * FUNCTION
 *  aud_vr_sd_rcg_callback
 * DESCRIPTION
 *  vr sd recognition call back function, send a message to media task itself and process then
 * PARAMETERS
 *  data        [?]     
 * RETURNS
 *  void
 *****************************************************************************/
void aud_vr_sd_rcg_callback(void *data)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    aud_send_ilm(MOD_MED, MSG_ID_MEDIA_VR_RCG_PROCESS_REQ, NULL, NULL);
}


/*****************************************************************************
 * FUNCTION
 *  aud_vr_sd_trn_callback
 * DESCRIPTION
 *  vr sd training call back function, send a message to media task itself and process then
 * PARAMETERS
 *  data        [?]     
 * RETURNS
 *  void
 *****************************************************************************/
void aud_vr_sd_trn_callback(void *data)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    aud_send_ilm(MOD_MED, MSG_ID_MEDIA_VR_TRN_PROCESS_REQ, NULL, NULL);
}


/*****************************************************************************
 * FUNCTION
 *  aud_vr_sd_rcg_process
 * DESCRIPTION
 *  vr sd recognition call back process function
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void aud_vr_sd_rcg_process(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_int32 med_res;
    kal_uint16 id_array[VR_MAX_RCG_RESULT_NUM];
    kal_uint16 id_length = 0;
    VR_Result result;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    AUD_FUNC_ENTRY(AUD_VR_VOICE_IN_RCG_CALLBACK);

    if (vr_ctx.state != AUD_VR_STATE_RCG_SESSION)
        return;

    kal_mem_set(id_array, 0, VR_MAX_RCG_RESULT_NUM * sizeof(kal_uint16));

    result = VR_Process(&vr_ctx.word_id);

    AUD_VALUE_TRACE(result, vr_ctx.state, vr_sd_ctx.stage);

    switch (result)
    {
        case VR_OK:
            return;
        case VR_NO_SOUND:
            med_res = MED_RES_NO_SOUND;
            aud_vr_sd_abort();
            break;
        case VR_TOO_LONG:
            med_res = MED_RES_SPEAK_TOO_LONG;
            aud_vr_sd_abort();
            break;
        case VR_TOO_SHORT:
            med_res = MED_RES_SPEAK_TOO_SHORT;
            aud_vr_sd_abort();
            break;
        case VR_FAILED:
            med_res = MED_RES_NO_MATCH;
            aud_vr_sd_abort();
            break;
        case VR_FINISHED:
            med_res = MED_RES_OK;
            id_array[0] = vr_ctx.word_id;
            id_length = 1;
            med_free_asm_mem(vr_sd_ctx.app_id, (void **)&vr_sd_ctx.buffer);
            /* finish a session naturely */
            vr_ctx.state = AUD_VR_STATE_IDLE;
            vr_sd_ctx.stage = AUD_VR_SD_SESSION_STAGE_NOT_READY;
            break;
        default:    /* other error cases */
            med_res = MED_RES_FAIL;
            aud_vr_sd_abort();
            break;
    }

    aud_send_vr_rcg_result_ind(vr_ctx.src_mod, vr_ctx.session_id, med_res, id_length, id_array);
}


/*****************************************************************************
 * FUNCTION
 *  aud_vr_sd_trn_process
 * DESCRIPTION
 *  vr sd training call back process function
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void aud_vr_sd_trn_process(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_int32 med_res;
    VR_Result result;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    AUD_FUNC_ENTRY(AUD_VR_VOICE_IN_TRN_CALLBACK);

    if (vr_ctx.state != AUD_VR_STATE_TRN_SESSION)
        return;

    result = VR_Process(&vr_ctx.word_id);

    AUD_VALUE_TRACE(result, vr_ctx.state, vr_sd_ctx.stage);

    switch (result)
    {
        case VR_OK:
            return;
        case VR_NO_SOUND:
            med_res = MED_RES_NO_SOUND;
            aud_vr_sd_abort();
            break;
        case VR_TOO_DIFF:
            med_res = MED_RES_TOO_DIFFERENT;
            aud_vr_sd_abort();
            break;
        case VR_TOO_SIM:
            med_res = MED_RES_TOO_SIMILAR;
            aud_vr_sd_abort();
            break;
        case VR_FLASH_DISK_FULL:
            med_res = MED_RES_DISC_FULL;
            aud_vr_sd_abort();
            break;
        case VR_FLASH_ERROR:
            med_res = MED_RES_FAIL;
            aud_vr_sd_abort();
            break;
        case VR_TOO_LONG:
            med_res = MED_RES_SPEAK_TOO_LONG;
            aud_vr_sd_abort();
            break;
        case VR_TOO_SHORT:
            med_res = MED_RES_SPEAK_TOO_SHORT;
            aud_vr_sd_abort();
            break;
        case VR_FAILED:
            med_res = MED_RES_FAIL;
            aud_vr_sd_abort();
            break;
        case VR_CONTINUE:
            med_res = MED_RES_TRAINING_CONTINUE;
            vr_sd_ctx.stage = AUD_VR_SD_SESSION_STAGE_WAIT;
            break;
        case VR_FINISHED:
            med_res = MED_RES_OK;
            if (aud_vr_sd_find_word_id(vr_ctx.group_id, vr_ctx.word_id) < 0)
            {
                vr_sd_ctx.id_array[vr_ctx.group_id][vr_sd_ctx.id_length[vr_ctx.group_id]++] = vr_ctx.word_id;
            }
            med_free_asm_mem(vr_sd_ctx.app_id, (void **)&vr_sd_ctx.buffer);
            /* finish a session naturely */
            vr_ctx.state = AUD_VR_STATE_IDLE;
            vr_sd_ctx.stage = AUD_VR_SD_SESSION_STAGE_NOT_READY;
            break;
        default:    /* other error cases */
            med_res = MED_RES_FAIL;
            aud_vr_sd_abort();
            break;
    }

    aud_send_vr_trn_result_ind(vr_ctx.src_mod, vr_ctx.session_id, med_res);
}


/*****************************************************************************
 * FUNCTION
 *  aud_vr_sd_startup
 * DESCRIPTION
 *  initialize vr sd module
 * PARAMETERS
 *  void
 * RETURNS
 *  kal_bool
 *****************************************************************************/
kal_bool aud_vr_sd_startup(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint16 filename[VR_MAX_DB_PATH_LEN + 1];
    kal_uint16 filepath[VR_MAX_DB_PATH_LEN + 1];
    kal_int32 group_id;
    FS_HANDLE fd_cursor;
    FS_DOSDirEntry file_info;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    vr_sd_ctx.buffer = NULL;
    vr_sd_ctx.stage = AUD_VR_SD_SESSION_STAGE_NOT_READY;
    kal_mem_set(vr_sd_ctx.id_length, 0, VR_SD_MAX_GROUP_NUM << 1);
    kal_wsprintf(filepath, "%c:\\VRDB\\ISD\\*", (kal_uint8) vr_ctx.db_drive);

#ifdef __NVRAM_IN_USB_MS__
    if (stack_query_boot_mode() == USBMS_BOOT)
    {
        return KAL_FALSE;
    }
#endif /* __NVRAM_IN_USB_MS__ */ 

    if ((fd_cursor = FS_FindFirst(filepath, 0, 0, &file_info, filename, (VR_MAX_DB_PATH_LEN + 1) << 1)) >= 0)
    {
        /* loop through each group folder */
        do
        {
            /* filter out non-folder results */
            if (file_info.Attributes & FS_ATTR_DIR)
            {
                /* parse group id */
                group_id = aud_vr_sd_extract_group_id(filename);
                
                if ((group_id >= 0) && (group_id < VR_SD_MAX_GROUP_NUM))
                {
                    /* scan all tag files in each group folder */
                    kal_wsprintf(filepath, "%c:\\VRDB\\ISD\\%d\\", (kal_uint8) vr_ctx.db_drive, group_id);
                    aud_vr_sd_scan_tags_in_group_folder((kal_uint16) group_id, filepath);
                }
            }
        } while (FS_FindNext(fd_cursor, &file_info, filename, (VR_MAX_DB_PATH_LEN + 1) << 1) == FS_NO_ERROR);
        FS_FindClose(fd_cursor);
    }

    return KAL_TRUE;
}


/*****************************************************************************
 * FUNCTION
 *  aud_vr_sd_init_rcg
 * DESCRIPTION
 *  vr sd initialize a recognition session
 * PARAMETERS
 *  void
 * RETURNS
 *  kal_int32
 *****************************************************************************/
kal_int32 aud_vr_sd_init_rcg(kal_uint16 app_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint32 buff_size;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (vr_ctx.state != AUD_VR_STATE_IDLE)
    {
        return MED_RES_BUSY;
    }

    /* scan and filter out non-exisiting tag files in id array */
    aud_vr_sd_filter_out_not_exist_tags(vr_ctx.group_id);

    /* detect memory leakage */
    MED_ASSERT(vr_sd_ctx.buffer == NULL);

    /* get buffer size and alloc buffer */
    vr_sd_ctx.app_id = app_id;
    buff_size = VR_GetBufferSize();
    if ((vr_sd_ctx.buffer = (kal_uint8*) med_alloc_asm_mem(app_id, buff_size)) == NULL)
    {
        return MED_RES_MEM_INSUFFICIENT;
    }
    VR_SetBuffer(vr_sd_ctx.buffer);

    /* set database dir */
    VR_SetDatabaseDir((kal_uint8*) vr_ctx.db_path);

    /* start a session */
    vr_ctx.state = AUD_VR_STATE_RCG_SESSION;
    vr_sd_ctx.stage = AUD_VR_SD_SESSION_STAGE_READY;

    return MED_RES_OK;
}


/*****************************************************************************
 * FUNCTION
 *  aud_vr_sd_init_trn
 * DESCRIPTION
 *  vr sd initialize a training session
 * PARAMETERS
 *  void
 * RETURNS
 *  kal_int32
 *****************************************************************************/
kal_int32 aud_vr_sd_init_trn(kal_uint16 app_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint32 buff_size;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (vr_ctx.state != AUD_VR_STATE_IDLE)
    {
        return MED_RES_BUSY;
    }

    /* scan and filter out non-exisiting tag files in id array */
    aud_vr_sd_filter_out_not_exist_tags(vr_ctx.group_id);
    /*
     * if( aud_vr_sd_find_word_id( vr_ctx.group_id, vr_ctx.word_id ) >= 0 )
     * return MED_RES_ID_EXIST;
     */
    /* detect memory leakage */
    MED_ASSERT(vr_sd_ctx.buffer == NULL);

    /* get buffer size and alloc buffer */
    vr_sd_ctx.app_id = app_id;
    buff_size = VR_GetBufferSize();
    if ((vr_sd_ctx.buffer = (kal_uint8*) med_alloc_asm_mem(app_id, buff_size)) == NULL)
    {
        return MED_RES_MEM_INSUFFICIENT;
    }
    VR_SetBuffer(vr_sd_ctx.buffer);

    /* set database dir */
    VR_SetDatabaseDir((kal_uint8*) vr_ctx.db_path);

    /* start a session */
    vr_ctx.state = AUD_VR_STATE_TRN_SESSION;
    vr_sd_ctx.stage = AUD_VR_SD_SESSION_STAGE_READY;

    return MED_RES_OK;
}


/*****************************************************************************
 * FUNCTION
 *  aud_vr_sd_rcg_voice_in
 * DESCRIPTION
 *  vr sd voice in notification in a recognition session
 * PARAMETERS
 *  void
 * RETURNS
 *  kal_int32
 *****************************************************************************/
kal_int32 aud_vr_sd_rcg_voice_in(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_int32 result;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    AUD_FUNC_ENTRY(AUD_VR_SD_RCG_VOICE_IN_REQ_HDLR);
    AUD_VALUE2_TRACE(vr_ctx.state, vr_sd_ctx.stage);

    if (vr_sd_ctx.stage == AUD_VR_SD_SESSION_STAGE_READY)
    {
        if (VR_RCG_Start(
                vr_sd_ctx.id_array[vr_ctx.group_id],
                &vr_sd_ctx.id_length[vr_ctx.group_id],
                aud_vr_sd_rcg_callback) == VR_OK)
        {
            result = MED_RES_OK;
            vr_sd_ctx.stage = AUD_VR_SD_SESSION_STAGE_PROCESS;
        }
        else
        {
            result = MED_RES_FAIL;
            aud_vr_sd_abort();
        }
    }
    else
    {
        result = MED_RES_FAIL;
    }

    return result;
}


/*****************************************************************************
 * FUNCTION
 *  aud_vr_sd_trn_voice_in
 * DESCRIPTION
 *  vr sd voice in notification in a training session
 * PARAMETERS
 *  seq_no      [IN]        
 * RETURNS
 *  kal_int32
 *****************************************************************************/
kal_int32 aud_vr_sd_trn_voice_in(kal_uint8 seq_no)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_int32 result, i, j;
    kal_uint16 *word_id_list_p;
    kal_uint16 word_id_list[VR_SD_MAX_GROUP_TAG_NUM];
    kal_uint16 word_id_length;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    AUD_FUNC_ENTRY(AUD_VR_SD_TRN_VOICE_IN_REQ_HDLR);
    AUD_VALUE_TRACE(vr_ctx.state, vr_sd_ctx.stage, seq_no);

    if (vr_sd_ctx.stage == AUD_VR_SD_SESSION_STAGE_READY && seq_no == 0)
    {
        /* copy word id list except the training word id */
        word_id_list_p = vr_sd_ctx.id_array[vr_ctx.group_id];
        word_id_length = vr_sd_ctx.id_length[vr_ctx.group_id];
        for (j = 0, i = word_id_length - 1; i >= 0; i--)
        {
            if (word_id_list_p[i] == vr_ctx.word_id)
            {
                word_id_length--;
            }
            else
            {
                word_id_list[j++] = word_id_list_p[i];
            }
        }
        /* 1st training sample */
        if (VR_TRA_Start(vr_ctx.word_id, word_id_list, &word_id_length, aud_vr_sd_trn_callback) == VR_OK)
        {
            result = MED_RES_OK;
            vr_sd_ctx.stage = AUD_VR_SD_SESSION_STAGE_PROCESS;
        }
        else
        {
            result = MED_RES_FAIL;
            aud_vr_sd_abort();
        }
    }
    else if (vr_sd_ctx.stage == AUD_VR_SD_SESSION_STAGE_WAIT && seq_no == 1)
    {
        /* 2nd training sample */
        if (VR_TRA2Start() == VR_OK)
        {
            result = MED_RES_OK;
            vr_sd_ctx.stage = AUD_VR_SD_SESSION_STAGE_PROCESS_2ND;
        }
        else
        {
            result = MED_RES_FAIL;
            aud_vr_sd_abort();
        }
    }
    else
    {
        result = MED_RES_FAIL;
    }

    return result;
}


/*****************************************************************************
 * FUNCTION
 *  aud_vr_sd_sync_db
 * DESCRIPTION
 *  vr sd sync database
 * PARAMETERS
 *  group_id        [IN]        
 *  id_length_p     [?]         
 *  id_array        [?]         
 * RETURNS
 *  kal_int32
 *****************************************************************************/
kal_int32 aud_vr_sd_sync_db(kal_uint16 group_id, kal_uint16 *id_length_p, kal_uint16 *id_array)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_bool found;
    kal_int32 i, j, id_length;
    kal_uint16 *target_list = vr_sd_ctx.id_array[group_id];
    kal_uint16 *target_length_p = &(vr_sd_ctx.id_length[group_id]);
    kal_wchar filename[VR_MAX_DB_PATH_LEN + 1];

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* eliminate tags which found in source list, but not in target list or its file doesn't exist */
    for (i = id_length = 0; i < *id_length_p; i++)
    {
        if (aud_vr_sd_find_word_id(group_id, id_array[i]) >= 0)
        {
            id_array[id_length++] = id_array[i];
        }
    }
    *id_length_p = id_length;

    if (id_length != *target_length_p)
    {
        /* delete tag files whose id not in target list */
        for (i = 0; i < *target_length_p; i++)
        {
            found = KAL_FALSE;
            for (j = 0; j < id_length; j++)
            {
                if (id_array[j] == target_list[i])
                {
                    found = KAL_TRUE;
                    break;
                }
            }
            if (!found)
            {
                /* delete tag file */
                kal_wsprintf(
                    filename,
                    "%c:\\VRDB\\ISD\\%d\\MTKVR_%04x.vrd",
                    (kal_uint8) vr_ctx.db_drive,
                    group_id,
                    target_list[i]);
                FS_Delete(filename);
            }
        }

        /* copy id_array to target list and update target id length */
        *target_length_p = id_length;
        if (id_length > 0)
        {
            memcpy(target_list, id_array, id_length << 1);
        }
    }

    return MED_RES_OK;
}


/*****************************************************************************
 * FUNCTION
 *  aud_vr_sd_delete_tag
 * DESCRIPTION
 *  vr sd delete tag
 * PARAMETERS
 *  group_id        [IN]        
 *  word_id         [IN]        
 * RETURNS
 *  kal_int32
 *****************************************************************************/
kal_int32 aud_vr_sd_delete_tag(kal_uint16 group_id, kal_uint16 word_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_bool done;
    kal_uint16 *id_length_p = &vr_sd_ctx.id_length[group_id];
    kal_uint16 *id_array = vr_sd_ctx.id_array[group_id];
    kal_uint16 id_list[VR_SD_MAX_GROUP_TAG_NUM];
    kal_uint16 i, count;
    kal_int32 result = MED_RES_FAIL;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (word_id == 0xFFFF)  /* delete all */
    {
        if (*id_length_p > 0)
        {
            /* bcoz we need to delete tags in id array, we'd better copy id array to another array and loop throgh it */
            count = *id_length_p;
            memcpy(id_list, id_array, count << 1);
            done = KAL_TRUE;
            for (i = 0; i < count; i++)
            {
                if (!aud_vr_sd_delete_one_tag(group_id, id_list[i]))
                {
                    done = KAL_FALSE;
                }
            }
            if (done)
            {
                result = MED_RES_OK;
            }
        }
        else
        {
            result = MED_RES_OK;
        }
    }
    else    /* delete one */
    {
        if (aud_vr_sd_delete_one_tag(group_id, word_id))
        {
            result = MED_RES_OK;
        }
    }
    return result;
}


/*****************************************************************************
 * FUNCTION
 *  aud_vr_sd_add_tag
 * DESCRIPTION
 *  vr sd add tags
 * PARAMETERS
 *  group_id        [IN]        
 *  cid_array       [?]         
 *  cid_length      [IN]        
 * RETURNS
 *  kal_int32
 *****************************************************************************/
kal_int32 aud_vr_sd_add_tag(kal_uint16 group_id, kal_uint16 *cid_array, kal_uint16 cid_length)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    FS_HANDLE file_handle;
    kal_wchar filename[VR_MAX_DB_PATH_LEN + 1];
    kal_uint16 *id_length_p = &vr_sd_ctx.id_length[group_id];
    kal_uint16 *id_array = vr_sd_ctx.id_array[group_id];
    kal_uint16 i, j;
    kal_int32 result = MED_RES_OK;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* loop through src id array */
    for (i = 0; i < cid_length; i++)
    {
        /* try to find the corresponding index in target id array */
        for (j = 0; j < *id_length_p; j++)
        {
            if (id_array[j] == cid_array[i])
            {
                result = MED_RES_ID_EXIST;
                break;
            }
        }
        if (j == *id_length_p)  /* not found */
        {
            /* check does the tag file exist */
            kal_wsprintf(
                filename,
                "%c:\\VRDB\\ISD\\%d\\MTKVR_%04x.vrd",
                (kal_uint8) vr_ctx.db_drive,
                group_id,
                cid_array[i]);
            if ((file_handle = FS_Open(filename, FS_READ_ONLY | FS_NOBUSY_CHECK_MODE)) >= 0)
            {
                FS_Close(file_handle);
                id_array[(*id_length_p)++] = cid_array[i];
            }
            else
            {
                result = MED_RES_ID_MISMATCH;
            }
        }
    }

    return result;
}


/*****************************************************************************
 * FUNCTION
 *  aud_vr_sd_play_tag
 * DESCRIPTION
 *  vr sd play a tag
 * PARAMETERS
 *  void
 * RETURNS
 *  kal_int32
 *****************************************************************************/
kal_int32 aud_vr_sd_play_tag(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_int32 result;
    kal_wchar filename[VR_MAX_DB_PATH_LEN + 1];
    aud_media_player_play_req_t req;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (aud_context_p->speech_on)
    {
        result = MED_RES_BUSY;
    }
    else
    {
        aud_context_p->src_mod = vr_ctx.src_mod;
        aud_context_p->src_id = 0;

        /* if keytone is playing, stop it */
        aud_keytone_stop();

        /* if tone is playing, stop it */
        if (aud_context_p->tone_playing)
        {
            aud_tone_stop();
        }

    #if defined( __MED_MMA_MOD__)&&(!defined(__MED_SLIM_MMA__))
        /* close all mma tasks */
        aud_mma_close_all();
    #endif /* __MED_MMA_MOD__ */ 

        if (aud_context_p->state != AUD_MEDIA_RECORD &&
            aud_context_p->state != AUD_MEDIA_RECORD_PAUSED &&
            aud_context_p->state != AUD_MEDIA_WAIT_RECORD &&
            aud_context_p->state != AUD_VM_RECORD)
        {
            aud_stop_unfinished_process();

            /* Get file name */
            kal_wsprintf(
                filename,
                "%c:\\VRDB\\ISD\\%d\\MTKVR_%04x.vrd",
                (kal_uint8) vr_ctx.db_drive,
                vr_ctx.group_id,
                vr_ctx.word_id);

            /* Configure play request */
            req.source_type  = AUD_FILE;
            req.play_mode    = AUD_MEDIA_PLAY_AS_SONG;
            req.file_name    = filename;
            req.data_p       = NULL;
            req.data_len     = 0;
            req.format       = MED_TYPE_VR;
            req.play_style   = DEVICE_AUDIO_PLAY_ONCE;
            req.volume       = aud_get_volume_level(aud_context_p->audio_mode, AUD_VOLUME_MEDIA);
            req.output_path  = AUDIO_DEVICE_SPEAKER2;
            req.identifier   = 0;
            req.start_offset = 0;
            req.end_offset   = 0;
            req.cache_p      = NULL;
            req.is_restore   = KAL_FALSE;

            /* Play with the request */
            result = aud_media_player_play_req(&req);
        }
        else
        {
            result = MED_RES_BUSY;
        }
    }
    return result;
}


/*****************************************************************************
 * FUNCTION
 *  aud_vr_sd_abort
 * DESCRIPTION
 *  vr sd abort a session
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void aud_vr_sd_abort(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    VR_Stop();
    vr_ctx.state = AUD_VR_STATE_IDLE;
    vr_sd_ctx.stage = AUD_VR_SD_SESSION_STAGE_NOT_READY;
    if (vr_sd_ctx.buffer != NULL)
    {
        med_free_asm_mem(vr_sd_ctx.app_id, (void **)&vr_sd_ctx.buffer);
    }
}


/*****************************************************************************
 * FUNCTION
 *  aud_vr_sd_is_active
 * DESCRIPTION
 *  This function is used to check if VRSD is being active.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
kal_bool aud_vr_sd_is_active(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (vr_ctx.state == AUD_VR_STATE_IDLE)
    {
        return KAL_FALSE;
    }
    else
    {
        return KAL_TRUE;
    }
}

#endif /* __MED_VR_MOD__ */ 

#endif /* MED_NOT_PRESENT */