aud_player_modis.c 33 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
/*****************************************************************************
*  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_player_modis.c
 *
 * Project:
 * --------
 *   Maui
 *
 * Description:
 * ------------
 *   This file includes primary functions of MoDIS player.
 *
 * 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!
 *
 *------------------------------------------------------------------------------
 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
 *==============================================================================
 *******************************************************************************/

/******************************************************************
 * MODULE
 *    MoDIS Player
 * DESCRIPTION
 *    This module defines related function of MoDIS Player.
 *  
 ******************************************************************/

#ifndef MED_NOT_PRESENT

/*-----------------------------------------------------------------------------
                    include files
-----------------------------------------------------------------------------*/
/* system includes */
//#include "kal_release.h"
#include "kal_trace.h"
#include "kal_general_types.h"
#include "kal_public_api.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 "app_buff_alloc.h" /* Declaration of buffer management API */
//#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"
    
/* local includes */
#include "med_global.h"
#include "med_main.h"
#include "med_utility.h"
#include "aud_player.h"

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

#if !defined(__MTK_TARGET__)

/* win32 */
#include <windows.h>
#include "w32_av_types.h"
#include "w32_av_lib.h"

/*-----------------------------------------------------------------------------
                    macros, defines, typedefs, enums
-----------------------------------------------------------------------------*/
#define _AUD_PLAYER_MODIS_TRACE(x, y, z)   AUD_PLAYER_MODIS_TRACE(x, y, z, __LINE__)
#define MAX_MODIS_AUDIO_HANDLE             (10)

/* MoDIS Player */
typedef struct
{
    med_aud_player_t              itf;            /* Player interfaces */
    kal_uint32                    time_stamp;     /* Time stamp of the constructed player */
    AudioHandle                   aud_handle;     /* Audio handle */
    kal_uint8                     state;          /* Player state */
    kal_uint32                    start_time;     /* Start time */
    med_aud_player_cb_fct         cb_fct;         /* Callback when there is event arisen */
    void*                         cb_param;       /* Callback parameter */
} med_aud_player_modis_t;

/* MoDIS Event */
typedef struct
{
    AudioHandle                   handle;         /* Player handle */
    w32_Audio_Event               event;          /* Event */
    kal_uint32                    time_stamp;     /* Time stamp of the callback event */
} med_aud_player_modis_event_t;

typedef struct
{
    med_aud_player_t*             player_p;       /* Player handle */
    AudioHandle                   aud_handle;     /* Audio handle */
    kal_bool                      is_used;        /* Indicate if the slot is used */
} med_aud_player_modis_handle_t;

/*-----------------------------------------------------------------------------
                    data declaraions
 ----------------------------------------------------------------------------*/
static med_aud_player_modis_handle_t g_player_handle[MAX_MODIS_AUDIO_HANDLE] = { 0 };
static kal_uint8 g_player_count = 0;

/*-----------------------------------------------------------------------------
                    function prototypes
 ----------------------------------------------------------------------------*/ 

/*-----------------------------------------------------------------------------
                    private function declarations
 ----------------------------------------------------------------------------*/
/*****************************************************************************
 * FUNCTION
 *  _aud_player_modis_store_player_handle
 * DESCRIPTION
 *  This function is used store a player handle for a given audio handle.
 * PARAMETERS
 *  player_p       [IN]        Player handle. 
 *  aud_handle     [IN]        Audio handle.
 * RETURNS
 *  void
 *****************************************************************************/
static void _aud_player_modis_store_player_handle(med_aud_player_t* player_p, AudioHandle aud_handle)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint8 i;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    
    /* Put the paired handles to an empty slot */
    for (i = 0; i < MAX_MODIS_AUDIO_HANDLE; i ++)
    {
        if (g_player_handle[i].is_used == KAL_FALSE)
        {
            g_player_handle[i].player_p = player_p;
            g_player_handle[i].aud_handle = aud_handle;
            g_player_handle[i].is_used = KAL_TRUE;
            
            break;
        }
    }
}


/*****************************************************************************
 * FUNCTION
 *  _aud_player_modis_delete_player_handle
 * DESCRIPTION
 *  This function is used delete the player handle for a given audio handle.
 * PARAMETERS
 *  player_p       [IN]      Player handle. 
 * RETURNS
 *  void
 *****************************************************************************/
static void _aud_player_modis_delete_player_handle(AudioHandle aud_handle)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint8 i;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    
    /* Delete player handle per the given player handle */
    for (i = 0; i < MAX_MODIS_AUDIO_HANDLE; i ++)
    {
        if (g_player_handle[i].is_used &&
            g_player_handle[i].aud_handle == aud_handle)
        {
            g_player_handle[i].player_p = NULL;
            g_player_handle[i].aud_handle = AudioHandle_Invalid;
            g_player_handle[i].is_used = KAL_FALSE;
            
            break;
        }
    }
}


/*****************************************************************************
 * FUNCTION
 *  _aud_player_modis_get_player_handle
 * DESCRIPTION
 *  This function is used get the player handle for a given audio handle.
 * PARAMETERS
 *  aud_handle       [IN]      Audio handle. 
 * RETURNS
 *  void
 *****************************************************************************/
static med_aud_player_t* _aud_player_modis_get_player_handle(AudioHandle aud_handle)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint8 i;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    
    /* Get player handle for the given audio handle */
    for (i = 0; i < MAX_MODIS_AUDIO_HANDLE; i ++)
    {
        if (g_player_handle[i].is_used &&
            g_player_handle[i].aud_handle == aud_handle)
        {
            return g_player_handle[i].player_p;
        }
    }
    
    return NULL;
}


/*****************************************************************************
 * FUNCTION
 *  _aud_player_modis_event_callback_hdlr
 * DESCRIPTION
 *  This function is used to handle the callback events from AV Library.
 * PARAMETERS
 *  data_p             [IN]       Media event data.
 *  date_len           [IN]       The length of data.
 * RETURNS
 *  void
 *****************************************************************************/
static void _aud_player_modis_event_callback_hdlr(void* data_p, kal_uint16 date_len)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    med_aud_player_t* player_p;
    med_aud_player_modis_t* self_p;
    med_aud_player_modis_event_t* modis_event_p = (med_aud_player_modis_event_t*)data_p;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MED_ASSERT(modis_event_p->handle != AudioHandle_Invalid);
    
    _AUD_PLAYER_MODIS_TRACE(modis_event_p->handle, modis_event_p->event, -1);
    
    /* Get player handle */
    player_p = _aud_player_modis_get_player_handle(modis_event_p->handle);
    MED_ASSERT(player_p != NULL);

    self_p = PTHIS(player_p, med_aud_player_modis_t, itf);

    /* Validate event */
    if (self_p->state != AUD_MEDIA_PLAY ||
        self_p->aud_handle != modis_event_p->handle ||
        self_p->time_stamp != modis_event_p->time_stamp)
    {
        _AUD_PLAYER_MODIS_TRACE(self_p->state, self_p->aud_handle , self_p->time_stamp);
        return;
    }

    /* Callback client */
    if (self_p->cb_fct)
    {    
        switch (modis_event_p->event)
        {
            case w32_AudioEvent_PlaybackFinished:
                self_p->cb_fct(player_p, MEDIA_END, self_p->cb_param);
                break;
            default:
                self_p->cb_fct(player_p, MEDIA_ERROR, self_p->cb_param);
                break;
        }
    }
}


/*****************************************************************************
 * FUNCTION
 *  _aud_player_modis_event_callback_fct
 * DESCRIPTION
 *  This function is used to receive the callback events from L1Audio.
 * PARAMETERS
 *  handle         [IN]        Audio handle. 
 *  event          [IN]        Audio event.
 * RETURNS
 *  void
 *****************************************************************************/
static void _aud_player_modis_event_callback_fct(AudioHandle handle, w32_Audio_Event event)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    med_aud_player_t* player_p;
    med_aud_player_modis_t* self_p;
    med_aud_player_modis_event_t modis_event;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MED_ASSERT(handle != AudioHandle_Invalid);

    /* Get player handle */
    player_p = _aud_player_modis_get_player_handle(handle);
    MED_ASSERT(player_p != NULL);

    self_p = PTHIS(player_p, med_aud_player_modis_t, itf);
    
    modis_event.handle = handle;
    modis_event.event = event;
    modis_event.time_stamp = self_p->time_stamp;

    aud_util_proc_in_med_ext(kal_get_active_module_id(),
                             _aud_player_modis_event_callback_hdlr,
                             (void*)&modis_event,
                             sizeof(med_aud_player_modis_event_t));
}


/*****************************************************************************
 * FUNCTION
 *  aud_player_modis_close
 * DESCRIPTION
 *  This function is used to close a MoDIS player.
 * PARAMETERS
 *  player_p      [IN]        Player handle.              
 * RETURNS
 *  
 *****************************************************************************/
static kal_int32 _aud_player_modis_close(med_aud_player_t* player_p)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    med_aud_player_modis_t* self_p;
    kal_bool                b_success = KAL_TRUE;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MED_ASSERT(player_p != NULL);
    self_p = PTHIS(player_p, med_aud_player_modis_t, itf);

    /* Free player resources */
    if (self_p->aud_handle != AudioHandle_Invalid)
    {
        /* Close MoDIS player */
        b_success = w32_Audio_CloseFile(self_p->aud_handle);
        _AUD_PLAYER_MODIS_TRACE(b_success, self_p->aud_handle, -1);

        /* Delete player handler */
        _aud_player_modis_delete_player_handle(self_p->aud_handle);

        self_p->aud_handle = AudioHandle_Invalid;
        
        /* Decrease player count */
        g_player_count --;
    }
    
    /* Deinitialize AV when there is no MoDIS player */
    if (g_player_count == 0)
    {
        w32_AV_Uninitialize();
    }

    return (b_success) ? MED_RES_OK : MED_RES_FAIL;
}


/*****************************************************************************
 * FUNCTION
 *  aud_player_modis_open
 * DESCRIPTION
 *  This function is used to open a MoDIS player.
 * PARAMETERS
 *  player_p      [IN]        Player handle.
 *  cfg_p         [IN]        Player configuration.  
 * RETURNS
 *  
 *****************************************************************************/
static kal_int32 _aud_player_modis_open(med_aud_player_t* player_p, med_aud_player_cfg_t* cfg_p)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    med_aud_player_modis_t* self_p;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MED_ASSERT(player_p != NULL);
    self_p = PTHIS(player_p, med_aud_player_modis_t, itf);

    /* Initialize */
    if (g_player_count == 0)
    {
        /* Initalize AV */
        w32_AV_Initialize();
    }
    
    /* Open from file */
    if (cfg_p->file_name != NULL)
    {
        self_p->aud_handle = w32_Audio_OpenFile((LPCWSTR)cfg_p->file_name, _aud_player_modis_event_callback_fct);
        _AUD_PLAYER_MODIS_TRACE(self_p->aud_handle, g_player_count, -1);
        
        if (self_p->aud_handle == AudioHandle_Invalid)
        {
            return MED_RES_FAIL;
        }
    }
    /* Open from buffer */
    else if (cfg_p->data_p != NULL)
    {
        self_p->aud_handle = w32_Audio_OpenBuffer((const char*)cfg_p->data_p,
                                                  (int)cfg_p->data_len,
                                                  _aud_player_modis_event_callback_fct);
        _AUD_PLAYER_MODIS_TRACE(self_p->aud_handle, g_player_count, -1);
        
        if (self_p->aud_handle == AudioHandle_Invalid)
        {
            return MED_RES_FAIL;
        }
    }
    else
    {
        self_p->aud_handle = AudioHandle_Invalid;
        return MED_RES_FAIL;
    }

    /* Increase player count */
    g_player_count ++;
    
    /* Check if reach maximum player count */
    if (g_player_count > MAX_MODIS_AUDIO_HANDLE)
    {
        return MED_RES_FAIL;
    }
    
    /* Store paried player handle and audio handle */
    _aud_player_modis_store_player_handle(player_p, self_p->aud_handle);
    
    /*------------------------ Setup private data ---------------------------*/
    self_p->state      = AUD_MEDIA_IDLE;
    self_p->start_time = 0;
    self_p->cb_fct     = cfg_p->cb_fct;
    self_p->cb_param   = cfg_p->cb_param;
    
    return MED_RES_OK;
}


/*****************************************************************************
 * FUNCTION
 *  aud_player_modis_play
 * DESCRIPTION
 *  This function is used to start MoDIS playback.
 * PARAMETERS
 *  player_p      [IN]        Player handle. 
 * RETURNS
 *  
 *****************************************************************************/
static kal_int32 _aud_player_modis_play(med_aud_player_t* player_p)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    med_aud_player_modis_t* self_p;
    kal_bool                b_success;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MED_ASSERT(player_p != NULL);
    self_p = PTHIS(player_p, med_aud_player_modis_t, itf);
    MED_ASSERT(self_p->aud_handle != AudioHandle_Invalid);

    /* Directly return if the player is not in idle state */
    if (self_p->state != AUD_MEDIA_IDLE)
    {
        return MED_RES_FAIL;
    }

    b_success = w32_Audio_Play(self_p->aud_handle);
    _AUD_PLAYER_MODIS_TRACE(b_success, self_p->aud_handle, -1);

    if (b_success)
    {
        self_p->state = AUD_MEDIA_PLAY;
    }
    
    return (b_success) ? MED_RES_OK : MED_RES_FAIL;
}


/*****************************************************************************
 * FUNCTION
 *  aud_player_modis_stop
 * DESCRIPTION
 *  This function is used to stop MoDIS playback.
 * PARAMETERS
 *  player_p      [IN]        Player handle. 
 * RETURNS
 *  
 *****************************************************************************/
static kal_int32 _aud_player_modis_stop(med_aud_player_t* player_p)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    med_aud_player_modis_t* self_p;
    kal_bool                b_success;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MED_ASSERT(player_p != NULL);
    self_p = PTHIS(player_p, med_aud_player_modis_t, itf);
    MED_ASSERT(self_p->aud_handle != AudioHandle_Invalid);

    b_success = w32_Audio_Stop(self_p->aud_handle);
    _AUD_PLAYER_MODIS_TRACE(b_success, self_p->aud_handle, -1);

    if (b_success)
    {
        /* Seek to the beginning */
        b_success = w32_Audio_Seek(self_p->aud_handle, 0);
        _AUD_PLAYER_MODIS_TRACE(b_success, self_p->aud_handle, -1);
        
        self_p->state = AUD_MEDIA_IDLE;
    }
    
    return (b_success) ? MED_RES_OK : MED_RES_FAIL;
}


/*****************************************************************************
 * FUNCTION
 *  aud_player_modis_pause
 * DESCRIPTION
 *  This function is used to pause MoDIS playback.
 * PARAMETERS
 *  player_p      [IN]        Player handle. 
 * RETURNS
 *  
 *****************************************************************************/
static kal_int32 _aud_player_modis_pause(med_aud_player_t* player_p)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    med_aud_player_modis_t* self_p;
    kal_int64               position;
    kal_bool                b_success;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MED_ASSERT(player_p != NULL);
    self_p = PTHIS(player_p, med_aud_player_modis_t, itf);
    MED_ASSERT(self_p->aud_handle != AudioHandle_Invalid);

    /* Get current time */
    b_success = w32_Audio_GetCurrentPosition(self_p->aud_handle, &position);

    if (b_success)
    {
        self_p->state = AUD_MEDIA_PLAY_PAUSED;
    }

    /* Stop the play */
    b_success = w32_Audio_Stop(self_p->aud_handle);
    _AUD_PLAYER_MODIS_TRACE(b_success, self_p->aud_handle, -1);
    
    return (b_success) ? MED_RES_OK : MED_RES_FAIL;
}


/*****************************************************************************
 * FUNCTION
 *  aud_player_modis_resume
 * DESCRIPTION
 *  This function is used to resume MoDIS playback.
 * PARAMETERS
 *  player_p      [IN]        Player handle. 
 * RETURNS
 *  
 *****************************************************************************/
static kal_int32 _aud_player_modis_resume(med_aud_player_t* player_p)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    med_aud_player_modis_t* self_p;
    kal_bool                b_success;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MED_ASSERT(player_p != NULL);
    self_p = PTHIS(player_p, med_aud_player_modis_t, itf);
    MED_ASSERT(self_p->aud_handle != AudioHandle_Invalid);
    
    /* Start the play. The player will auto resume from last stopped
     * position. I.e. no seeking is requried.
     */
    b_success = w32_Audio_Play(self_p->aud_handle);
    _AUD_PLAYER_MODIS_TRACE(b_success, self_p->aud_handle, -1);

    if (b_success)
    {
        self_p->state = AUD_MEDIA_PLAY;
    }
    
    return (b_success) ? MED_RES_OK : MED_RES_FAIL;
}


/*****************************************************************************
 * FUNCTION
 *  aud_player_modis_set
 * DESCRIPTION
 *  This function is used to set parameters to an MoDIS player.
 * PARAMETERS
 *  player_p      [IN]        Player handle.
 *  set_type      [IN]        Set command.
 *  data_p        [IN]        The data relative to the command.
 *  date_len      [IN]        The length of the data.
 * RETURNS
 *  
 *****************************************************************************/
static kal_int32 _aud_player_modis_set(med_aud_player_t*    player_p,
                                       med_aud_player_set_t set_type,
                                       void*                data_p)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    med_aud_player_modis_t* self_p;
    kal_bool                b_success;
    kal_int32               result = MED_RES_OK;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MED_ASSERT(player_p != NULL);
    self_p = PTHIS(player_p, med_aud_player_modis_t, itf);
    MED_ASSERT(self_p->aud_handle != AudioHandle_Invalid);

    _AUD_PLAYER_MODIS_TRACE(set_type, (kal_uint32)data_p, -1);
    
    switch (set_type)
    {
        case AUD_PLAYER_SET_START_TIME:
        {
            kal_uint32 start_time = (kal_uint32)data_p;
            
            b_success = w32_Audio_Seek(self_p->aud_handle, (kal_int64)start_time * 10000);
            _AUD_PLAYER_MODIS_TRACE(b_success, start_time, self_p->aud_handle);
            
            if (b_success)
            {
                self_p->start_time = start_time;
                result = MED_RES_OK;
            }
            else
            {
                result = MED_RES_FAIL;
            }
            
            break;
        }
        /* Unsupported commands */
        case AUD_PLAYER_SET_CACHE_TABLE:
        case AUD_PLAYER_SET_BUFFER:
        case AUD_PLAYER_SET_STOP_TIME:
        case AUD_PLAYER_SET_LEVEL:
        case AUD_PLAYER_SET_STORE_FLAG:
        case AUD_PLAYER_SET_FILE_OFFSET:
        default:
            result = MED_RES_UNSUPPORTED_OPERATION;
            break;
    }
    
    return result;
}


/*****************************************************************************
 * FUNCTION
 *  aud_player_modis_get
 * DESCRIPTION
 *  This function is used to get parameters from an MoDIS player.
 * PARAMETERS
 *  player_p      [IN]        Player handle.
 *  get_type      [IN]        Get command.
 *  data_p        [OUT]       The data relative to the command.
 *  data_len      [IN]        Indicats the length of the data buffer.
 * RETURNS
 *  
 *****************************************************************************/
static kal_int32 _aud_player_modis_get(med_aud_player_t*    player_p,
                                       med_aud_player_get_t get_type,
                                       void*                data_p)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    med_aud_player_modis_t* self_p;
    kal_int32               result = MED_RES_PARAM_ERROR;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MED_ASSERT(player_p != NULL && data_p != NULL);
    self_p = PTHIS(player_p, med_aud_player_modis_t, itf);
    MED_ASSERT(self_p->aud_handle != AudioHandle_Invalid);

    switch (get_type)
    {
        case AUD_PLAYER_GET_START_TIME:
        {
            {
                *((kal_uint32*)data_p) = self_p->start_time;
                result = MED_RES_OK;
            }
            
            break;
        }            
        case AUD_PLAYER_GET_CURRENT_TIME:
        case AUD_PLAYER_GET_LAST_TIME:
        {
            kal_int64 position = 0;

            {
                w32_Audio_GetCurrentPosition(self_p->aud_handle, &position);
                _AUD_PLAYER_MODIS_TRACE(position, self_p->aud_handle, -1);
                
                *((kal_uint32*)data_p) = (kal_uint32)(position / 10000);

                result = MED_RES_OK;
            }
                
            break;
        }
        case AUD_PLAYER_GET_DURATION:
        {
            kal_int64 duration = 0;

            {
                w32_Audio_GetDuration(self_p->aud_handle, &duration);
                _AUD_PLAYER_MODIS_TRACE(duration, self_p->aud_handle, -1);
                
                *((kal_uint32*)data_p) = (kal_uint32)(duration / 10000);

                result = MED_RES_OK;
            }
            
            break;
        }
        /* Unsupported commands */
        case AUD_PLAYER_GET_STOP_TIME:
        case AUD_PLAYER_GET_LEVEL:
        case AUD_PLAYER_GET_CONTENT_DESC:
        case AUD_PLAYER_GET_LAST_OFFSET:
        default:
            result = MED_RES_UNSUPPORTED_OPERATION;
            break;
    }

    _AUD_PLAYER_MODIS_TRACE(get_type, result, *((kal_uint32*)data_p));
    
    return result;
}


/*****************************************************************************
 * FUNCTION
 *  aud_player_modis_destroy
 * DESCRIPTION
 *  This function is used to destroy a MoDIS player. Once called, all the 
 *  allocated interfaces of the player will be freed.
 * PARAMETERS
 *  player_p      [IN]        Player handle. 
 * RETURNS
 *  
 *****************************************************************************/
static kal_int32 _aud_player_modis_destroy(med_aud_player_t* player_p)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    med_aud_player_modis_t* self_p;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MED_ASSERT(player_p != NULL);
    self_p = PTHIS(player_p, med_aud_player_modis_t, itf);
    
    AUD_PLAYER_FREE_AUD_MEM(self_p);
    
    return MED_RES_OK;
}
#endif /* __MTK_TARGET__ */

/*-----------------------------------------------------------------------------
                    public functions
 ----------------------------------------------------------------------------*/
/*****************************************************************************
 * FUNCTION
 *  aud_player_modis_construct
 * DESCRIPTION
 *  This function is used to construct a MoDIS player.
 * PARAMETERS
 *  void
 * RETURNS
 *  Player handle.
 *****************************************************************************/
med_aud_player_t* aud_player_modis_construct(void)
{
#if !defined(__MTK_TARGET__)
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    med_aud_player_modis_t* self_p;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    self_p = (med_aud_player_modis_t*) med_alloc_aud_mem(sizeof(med_aud_player_modis_t));
    MED_ASSERT(self_p != NULL);

    kal_mem_set(self_p, 0, sizeof(*self_p));

    self_p->itf.open     = _aud_player_modis_open;
    self_p->itf.close    = _aud_player_modis_close;
    self_p->itf.play     = _aud_player_modis_play;
    self_p->itf.stop     = _aud_player_modis_stop;
    self_p->itf.pause    = _aud_player_modis_pause;
    self_p->itf.resume   = _aud_player_modis_resume;
    self_p->itf.set      = _aud_player_modis_set;
    self_p->itf.get      = _aud_player_modis_get;
    self_p->itf.destroy  = _aud_player_modis_destroy;

    kal_get_time(&self_p->time_stamp);

    return &self_p->itf;
#else
    return NULL;
#endif /* __MTK_TARGET__ */
}

#endif /* MED_NOT_PRESENT */