📄 med_utility.c
字号:
/*****************************************************************************
* 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:
* ---------
* med_utility.c
*
* Project:
* --------
* Maui
*
* Description:
* ------------
* This file includes common used functions of media task.
*
* 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!
*
*------------------------------------------------------------------------------
* 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 */
/* Buffer Management */
#include "app_buff_alloc.h"
#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 */
/* for tst inject message */
#include "tst_sap.h"
/* global includes */
#include "l1audio.h"
#include "device.h"
#include "resource_audio.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"
/* local includes */
#include "med_main.h"
#include "med_global.h"
#include "aud_defs.h"
#include "med_struct.h"
#include "med_api.h"
#include "med_context.h"
#include "fat_fs.h"
#include "med_smalloc.h"
#include "med_utility.h"
typedef struct
{
eventid event_id;
kal_timer_func_ptr callback_func;
void *arg;
}
timer_table_struct;
timer_table_struct med_timer_table[MAX_NUM_OF_MED_TIMER];
kal_mutexid med_mem_mutex;
#ifndef MED_LOW
const kal_uint8 utf8_bytes_per_char[16] =
{
1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 2, 2, 3, 4
};
/*****************************************************************************
* FUNCTION
* med_util_utf8_to_ucs2
* DESCRIPTION
*
* PARAMETERS
* dest [?]
* dest_size [IN] (>=4)
* src [?]
* src_size [IN] (>=1) it is used to prevent from infinte loop when src data are not utf8
* RETURNS
* kal_int32
*****************************************************************************/
kal_int32 med_util_utf8_to_ucs2(kal_uint8 *dest, kal_uint32 dest_size, kal_uint8 *src, kal_uint32 src_size)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_uint8 cnt, c;
kal_uint16 ucs2;
kal_uint32 dest_count = 0;
kal_uint32 src_count = 0;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
dest_size -= ((dest_size % 2) + 2); /* make it a even number + null terminator */
while (dest_count < dest_size && src_count < src_size && (c = *src))
{
cnt = utf8_bytes_per_char[c >> 4];
switch (cnt)
{
case 1:
dest[dest_count] = c;
dest[dest_count + 1] = 0;
dest_count += 2;
src++;
src_count++;
break;
case 2:
ucs2 = ((kal_uint16) (c & 0x1F) << 6) | (kal_uint16) (src[1] & 0x3F);
dest[dest_count] = ucs2 & 0xFF;
dest[dest_count + 1] = ucs2 >> 8;
dest_count += 2;
src += 2;
src_count += 2;
break;
case 3:
ucs2 =
((kal_uint16) (c & 0x0F) << 12) | ((kal_uint16) (src[1] & 0x3F) << 6) | (kal_uint16) (src[2] &
0x3F);
dest[dest_count] = ucs2 & 0xFF;
dest[dest_count + 1] = ucs2 >> 8;
dest_count += 2;
src += 3;
src_count += 3;
break;
case 4:
src += 4; /* skip it since we don't support UCS4 */
src_count += 4;
break;
case 0:
src++; /* something wrong with the src, skip it */
src_count++;
break;
}
}
dest[dest_count] = 0;
dest[dest_count + 1] = 0;
return dest_count + 2;
}
/*****************************************************************************
* FUNCTION
* med_util_ucs2_to_utf8
* DESCRIPTION
*
* PARAMETERS
* dest [?]
* dest_size [IN] (>=1)
* src [?]
* src_size [IN] (>=2)
* RETURNS
* kal_int32
*****************************************************************************/
kal_int32 med_util_ucs2_to_utf8(kal_uint8 *dest, kal_uint32 dest_size, kal_uint8 *src, kal_uint32 src_size)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_uint8 lb, hb;
kal_uint32 dest_count = 0;
kal_uint32 src_count = 0;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
dest_size -= 1; /* one byte space for null terminator */
lb = src[0];
hb = src[1];
while (dest_count < dest_size && src_count < src_size && /* not exceed limited size */
(lb != 0 || hb != 0)) /* src does not encounter null terminator */
{
if (hb == 0 && (lb & 0x80) == 0)
{
dest[dest_count++] = lb;
}
else
{
if (hb & 0xF8 == 0)
{
dest[dest_count++] = 0xC0 | (hb << 2) | (lb >> 6);
}
else
{
dest[dest_count++] = 0xE0 | (hb >> 4);
dest[dest_count++] = 0x80 | ((hb & 0x0F) << 2) | (lb >> 6);
}
dest[dest_count++] = 0x80 | (lb & 0x3F);
}
src_count += 2;
lb = src[src_count];
hb = src[src_count + 1];
}
dest[dest_count] = 0;
return dest_count + 1;
}
#endif /* MED_LOW */
/*****************************************************************************
* FUNCTION
* med_utility_init
* DESCRIPTION
*
* PARAMETERS
* void
* RETURNS
*
*****************************************************************************/
kal_bool med_utility_init(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_uint8 i;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
for (i = 0; i < MAX_NUM_OF_MED_TIMER; i++)
{
med_timer_table[i].event_id = NULL;
}
/* init internal memory */
med_set_int_memory_pool((unsigned char*)med_context_p->int_mem_p, MED_INT_MEM_SIZE);
/* init external memory */
med_set_ext_memory_pool((unsigned char*)med_context_p->ext_mem_p, MED_EXT_MEM_SIZE);
med_mem_mutex = kal_create_mutex("MED MEM");
return KAL_TRUE;
}
/*****************************************************************************
* FUNCTION
* med_timer_expiry_hdlr
* DESCRIPTION
*
* PARAMETERS
* ilm_ptr [?]
* RETURNS
* void
*****************************************************************************/
void med_timer_expiry_hdlr(ilm_struct *ilm_ptr)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
stack_timer_struct *stack_timer_ptr;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
stack_timer_ptr = (stack_timer_struct*) ilm_ptr->local_para_ptr;
if (stack_timer_ptr->timer_indx == MED_BASE_TIMER_ID)
{
/* Check if the base timer is stopped or not */
if (stack_is_time_out_valid(&med_context_p->base_timer))
{
/* Execute event's timeout handler */
evshed_timer_handler(med_context_p->event_scheduler_ptr);
}
/* Should be paired with stack_is_time_out_valid() */
stack_process_time_out(&med_context_p->base_timer);
}
}
/*****************************************************************************
* FUNCTION
* med_get_buffer_req_hdlr
* DESCRIPTION
*
* PARAMETERS
* ilm_ptr [?]
* RETURNS
* void
*****************************************************************************/
void med_get_buffer_req_hdlr(ilm_struct *ilm_ptr)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
media_get_buffer_req_struct *req_p;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
req_p = (media_get_buffer_req_struct*) ilm_ptr->local_para_ptr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -