PlayMode.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:12k
- /****************************************************************************************
- * Copyright (c) 2002 ZORAN Corporation, All Rights Reserved
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ZORAN CORPORATION
- *
- * File: $Workfile: PlayMode.c $
- *
- * Description:
- * ============
- *
- *
- * Log:
- * ====
- * $Revision: 10 $
- * Last Modified by $Author: Jerryc $ at $Modtime: 04-03-16 9:41 $
- ****************************************************************************************
- * Updates:
- ****************************************************************************************
- * $Log: /I76/I76_Common/I76_Reference/Playcore/PlayMode/PlayMode.c $
- *
- * 10 04-03-16 9:42 Jerryc
- * fix sacd repeat mode.
- *
- * 9 04-03-04 14:04 Jerryc
- * add support for sacd program mode.
- *
- * 8 2/26/04 6:30p Leonh
- * enable the shuffle beyond 255
- *
- * 7 2/20/04 6:21p Glenl
- * Merged S1 code
- *
- * 6 2/10/04 3:58p Leonh
- * rewrite the shuffle, rename the old one as random
- *
- * 5 03-04-28 10:41 Jerryc
- * take care of the case "shuffle program list which has no entries."
- *
- * 4 03-03-07 19:11 Jerryc
- * jerryc, add support for random play mode.
- *
- * 3 10/30/02 17:49 Rond
- *
- * 4 23/04/02 9:35 Nirm
- * - Added dependency in "Config.h".
- *
- * 3 16/01/02 12:33 Atai
- * Change debug printing
- *
- * 2 9/01/02 16:47 Nirm
- * Corrected Include-Paths.
- ****************************************************************************************/
- #include "Config.h" // Global Configuration - do not remove!
- #ifdef _DEBUG
- #undef IFTRACE
- #define IFTRACE if (gTraceCore)
- #include "DebugDbgMain.h"
- #endif
- #include "Includesysdefs.h"
- #include "Kernelker_api.h"
- #include "Kerneleventdef.h"
- #include "PlaycoreScPadscmgr.h"
- #include "PlaycorePlayModeplaymode.h"
- #include "Playcorenav_cddaPE_CD.h"
- /////////////////////////////////////////////////////////////////////////////////////////////////
- // Global Variables
- PlayModeInfo g_PlayModeInfo={0};
- /////////////////////////////////////////////////////////////////////////////////////////////////
- // Public Services
- BYTE PM_GetPlaybackMode(void)
- {
- return g_PlayModeInfo.iPlaybackMode;
- }
- void PM_SetPlaybackMode(BYTE iPlaybackMode)
- {
- g_PlayModeInfo.iPlaybackMode &= PM_PBC_MASK; // Clear the existing Mode
- g_PlayModeInfo.iPlaybackMode |= iPlaybackMode; // Set the new Mode
- return;
- }
- void PM_SetPBC(BOOL bEnable)
- {
- if (bEnable)
- g_PlayModeInfo.iPlaybackMode |= PM_PBC_MASK;
- else
- g_PlayModeInfo.iPlaybackMode &= ~((BYTE)PM_PBC_MASK);
- return;
- }
- BOOL PM_IsRepeatSingle(void)
- {
- return ((g_PlayModeInfo.iRepeatMode & PM_REPEAT_SINGLE) ? TRUE : FALSE);
- }
- #ifdef S1_GUI
- BOOL PM_IsRepeat10SEC(void)
- {
- return ((g_PlayModeInfo.iRepeatMode & PM_REPEAT_10SEC) ? TRUE : FALSE);
- }
- void PM_SetRepeat10SEC(BOOL bEnable)
- {
- if (bEnable){
- g_PlayModeInfo.iRepeatMode = PM_REPEAT_10SEC;
- }
- else
- g_PlayModeInfo.iRepeatMode &= ~((BYTE)PM_REPEAT_10SEC);
- return;
- }
- #endif
- BOOL PM_IsRepeatAll(void)
- {
- return ((g_PlayModeInfo.iRepeatMode & PM_REPEAT_ALL) ? TRUE : FALSE);
- }
- BYTE PM_GetRepeatAB(void)
- {
- return (g_PlayModeInfo.iRepeatMode & PM_REPEAT_AB_MASK);
- }
- BOOL PM_IsRepeatFolder(void)
- {
- return ((g_PlayModeInfo.iRepeatMode & PM_REPEAT_FOLDER) ? TRUE : FALSE);
- }
- void PM_SetRepeatSingle(BOOL bEnable)
- {
- if (bEnable){
- //Cancel Repeat All first
- g_PlayModeInfo.iRepeatMode &= ~((BYTE)PM_REPEAT_ALL);
- g_PlayModeInfo.iRepeatMode = PM_REPEAT_SINGLE;
- }
- else
- g_PlayModeInfo.iRepeatMode &= ~((BYTE)PM_REPEAT_SINGLE);
- #if D_SUPPORT_SACD
- ie_send(IE_CORE_SEAMLESS_MODE_CHANGE);
- #endif
- return;
- }
- void PM_SetRepeatAll(BOOL bEnable)
- {
- if (bEnable){
- //cancel repeat single first
- g_PlayModeInfo.iRepeatMode &= ~((BYTE)PM_REPEAT_SINGLE);
- g_PlayModeInfo.iRepeatMode = PM_REPEAT_ALL;
- }
- else
- g_PlayModeInfo.iRepeatMode &= ~((BYTE)PM_REPEAT_ALL);
- #if D_SUPPORT_SACD
- ie_send(IE_CORE_SEAMLESS_MODE_CHANGE);
- #endif
- return;
- }
- void PM_SetRepeatFolder(BOOL bEnable)
- {
- if (bEnable){
- //Cancel Repeat Single/All first
- g_PlayModeInfo.iRepeatMode &= ~((BYTE)PM_REPEAT_SINGLE | PM_REPEAT_ALL);
- g_PlayModeInfo.iRepeatMode = PM_REPEAT_FOLDER;
- }
- else
- g_PlayModeInfo.iRepeatMode &= ~((BYTE)PM_REPEAT_FOLDER);
- return;
- }
- void PM_ClearRepeat(void)
- {
- g_PlayModeInfo.iRepeatMode = 0;
- #if D_SUPPORT_SACD
- ie_send(IE_CORE_SEAMLESS_MODE_CHANGE);
- #endif
- return;
- }
- void PM_SetRepeatAB(BYTE iRepeatAB)
- {
- if (0 == iRepeatAB)
- g_PlayModeInfo.iRepeatMode &= ~((BYTE)PM_REPEAT_AB_MASK);
- else
- g_PlayModeInfo.iRepeatMode |= iRepeatAB;
- return;
- }
- #ifdef D_PM_BOOKDESC //stivenz_1116_2004_Mem_Opt: Remove since it never use.
- LPSTR PM_GetBookmarkDescription(WORD uBookmarkNumber)
- {
- if (uBookmarkNumber >= PM_MAX_BOOKMARKS)
- return NULL;
- return (g_PlayModeInfo.aBookmarkDescription[uBookmarkNumber]);
- }
- void PM_SetBookmarkDescription(WORD uBookmarkNumber, LPSTR lpszDescription)
- {
- if (uBookmarkNumber >= PM_MAX_BOOKMARKS)
- return;
- g_PlayModeInfo.aBookmarkDescription[uBookmarkNumber]= lpszDescription;
-
- return;
- }
- #endif //D_PM_BOOKDESC
- void PM_InitializeProgramList()
- {
- WORD wSP_Offset= SC_PROGLIST_ADDR;
- DWORD dwDummy= 0;
- g_PlayModeInfo.uProgramListSize= 0;
- while (wSP_Offset < (SC_PROGLIST_ADDR + SC_PROGLIST_SZ)) {
- sc_Write(wSP_Offset++, 1, (Sc_cont *)&dwDummy);
- }
- #if D_SUPPORT_SACD
- if(DEC_DISC_TYPE_SACD == g_disc_type)
- memset(&(SACD_GLOBALS.ProgramList), 0, sizeof(SACD_GLOBALS.ProgramList));
- #endif
- return;
- }
- WORD PM_GetProgramSize()
- {
- return g_PlayModeInfo.uProgramListSize;
- }
- void PM_SetProgramListEntry(WORD uEntryNumber, WORD wContents)
- {
- WORD wSP_Offset= (WORD)(SC_PROGLIST_ADDR + (uEntryNumber/2));
- DWORD dwData;
- if (g_PlayModeInfo.uProgramListSize < (uEntryNumber+1))
- g_PlayModeInfo.uProgramListSize= (uEntryNumber + 1);
- sc_Read(wSP_Offset, 1, (Sc_cont *)&dwData);
- if (0 == (uEntryNumber % 2)) {
- dwData &= 0x0000FFFF;
- dwData |= ((DWORD)wContents << 16);
- }
- else {
- dwData &= 0xFFFF0000L;
- dwData |= (DWORD)wContents;
- }
- sc_Write(wSP_Offset, 1, (Sc_cont *)&dwData);
- #if D_SUPPORT_SACD
- if(DEC_DISC_TYPE_SACD == g_disc_type)
- {
- SACD_GLOBALS.ProgramList.tracks[(BYTE)uEntryNumber] = (BYTE)wContents;
- SACD_GLOBALS.ProgramList.NumberOfTracks = g_PlayModeInfo.uProgramListSize;
- }
- #endif
- return;
- }
- WORD PM_GetProgramListEntry(WORD uEntryNumber)
- {
- WORD wSP_Offset= (WORD)(SC_PROGLIST_ADDR + (uEntryNumber/2));
- DWORD dwData;
- if (uEntryNumber > (g_PlayModeInfo.uProgramListSize - 1))
- return 0xFFFF;
- sc_Read(wSP_Offset, 1, (Sc_cont *)&dwData);
- if (0 == (uEntryNumber % 2))
- return (WORD)(dwData >> 16);
- else
- return (WORD)(dwData & 0xFFFF);
- }
- //<<<Leon.He_1001_2004_a: rewrite the shuffle, rename the old one as random
- void PM_RandomProgramList(BOOL bExcludePivot, WORD uPivotEntryNumber)
- {
- WORD uCurrItem;
- WORD uItemsLeft;
- WORD wSP_Token;
- WORD wSP_Offset;
- DWORD dwContents;
- if(0 == g_PlayModeInfo.uProgramListSize)
- {
- dbg_printf(("no play items for Shuffling.n"));
- return;
- }
- uItemsLeft= (g_PlayModeInfo.uProgramListSize - 1);
- wSP_Token= sc_Malloc(uItemsLeft);
- wSP_Offset= wSP_Token;
- if (0xFFFF == wSP_Token) {
- dbg_printf(("Failed to allocate Scratch-Pad space for Shuffling.n"));
- return;
- }
- if (bExcludePivot) {
- dwContents= (DWORD) PM_GetProgramListEntry(uPivotEntryNumber);
- // Set the first Entry in the Shuffled result to the contents of the Pivot
- sc_Write(wSP_Offset++, 1, (Sc_cont *)&dwContents);
- // Fill the Pivot's place in the original Program-List with the last Item,
- // unless the Pivot is already the last Item
- if (uPivotEntryNumber != uItemsLeft)
- PM_SetProgramListEntry(uPivotEntryNumber, PM_GetProgramListEntry(uItemsLeft));
- uItemsLeft--;
- }
- // Start build the random list
- while (uItemsLeft) {
- // Draw a random Entry-Number in the range: [1 .. uItemsLeft]
- uCurrItem= (WORD) (1 + (rand() % uItemsLeft));
- // Extract the contents of the randomly-selected Item
- dwContents= (DWORD) PM_GetProgramListEntry(uCurrItem);
- // Place the randomly-selected Item in the next slot of the result
- sc_Write(wSP_Offset++, 1, (Sc_cont *)&dwContents);
- // Swap between the last Item on the Program-List and the one just used
- if (uCurrItem != uItemsLeft) {
- PM_SetProgramListEntry(uCurrItem, PM_GetProgramListEntry(uItemsLeft));
- }
- uItemsLeft--;
- }
- // Now copy the result to the Program-List
- wSP_Offset= wSP_Token;
- for (uCurrItem=1; uCurrItem <= (g_PlayModeInfo.uProgramListSize - 1); uCurrItem++) {
- sc_Read(wSP_Offset++, 1, (Sc_cont *)&dwContents);
- PM_SetProgramListEntry(uCurrItem, (WORD)dwContents);
- }
- sc_Free(wSP_Token, (g_PlayModeInfo.uProgramListSize - 1));
- #ifdef _DEBUG
- // Print the result
- dbg_printf(("Random result: "));
- for (uCurrItem=1; uCurrItem <= (g_PlayModeInfo.uProgramListSize-1); uCurrItem++) {
- dbg_printf(("%d ", PM_GetProgramListEntry(uCurrItem)));
- }
- dbg_printf(("n"));
- #endif //_DEBUG
- return;
- }
- void PM_ShuffleProgramList(BOOL bExcludePivot, WORD uPivotEntryNumber)
- {
- WORD uListSize,uTempItemNums;
- WORD uTempEntry1,uTempEntry2;
- WORD uTempidx1,uTempidx2;
- WORD i,r_i,s_i;
-
- if(0 == g_PlayModeInfo.uProgramListSize)
- {
- dbg_printf(("no play items for Shuffling.n"));
- return;
- }
- //playlist is start from 1, ignore the item 0
- uListSize = (g_PlayModeInfo.uProgramListSize - 1);
-
- //If need exclude the current item, we need exchange it with the item 1
- if(bExcludePivot)
- {
- s_i = 2;//shuffle will start from the item 2
- uTempItemNums = uListSize -1;
- uTempEntry1 = PM_GetProgramListEntry(1);
- uTempEntry2 = PM_GetProgramListEntry(uPivotEntryNumber);
- PM_SetProgramListEntry(1, uTempEntry2);
- PM_SetProgramListEntry(uPivotEntryNumber, uTempEntry1);
- }
- else
- {
- s_i = 1;
- uTempItemNums = uListSize;
- }
-
- for (i=s_i;i<uListSize;i++)
- {
- r_i = (BYTE)(rand() % uTempItemNums); // r_i range is 0 .. uListSize-1
- uTempidx1 = i;
- uTempidx2 = uTempidx1 + r_i;
- uTempEntry1 = PM_GetProgramListEntry(uTempidx1);
- uTempEntry2 = PM_GetProgramListEntry(uTempidx2);
- PM_SetProgramListEntry(uTempidx1, uTempEntry2);
- PM_SetProgramListEntry(uTempidx2, uTempEntry1);
- uTempItemNums--;
- if(uTempItemNums == 0)
- uTempItemNums = uListSize-(i+1);
- }
- #ifdef _DEBUG
- dbg_printf(("Shuffle result: "));
- for (i=1; i <= (g_PlayModeInfo.uProgramListSize-1); i++) {
- dbg_printf(("%d ", PM_GetProgramListEntry(i)));
- }
- dbg_printf(("n"));
- #endif //_DEBUG
- return;
- }
- //>>>Leon.He_1001_2004_a: rewrite the shuffle, rename the old one as random
- BOOL PM_IsLastProgramListEntry(WORD wContents)
- {
- WORD wSP_Offset= (WORD)(SC_PROGLIST_ADDR + ((g_PlayModeInfo.uProgramListSize - 1)/2));
- DWORD dwData;
- sc_Read(wSP_Offset, 1, (Sc_cont *)&dwData);
- if (0 == ((g_PlayModeInfo.uProgramListSize - 1) % 2))
- dwData = (WORD)(dwData >> 16);
- else
- dwData = (WORD)(dwData & 0xFFFF);
- if (wContents == dwData)
- return TRUE;
- else
- return FALSE;
- }
- // <<< ZRN SH0713:Added this function to merge changes from ZCH
- // This function is used to reintialize the program list for program to shuffle
- void PM_ReConstructProgramListEntry(void)
- {
- int iItemNum;
- for (iItemNum=1; iItemNum <= (WORD) PE_CD_GetTracksCnt(); iItemNum++)
- {
- switch (g_disc_type)
- {
- case DEC_DISC_TYPE_CDDA:
- PM_SetProgramListEntry((WORD)iItemNum, (WORD)iItemNum);
- break;
- case DEC_DISC_TYPE_VCD:
- case DEC_DISC_TYPE_SVCD:
- if(iItemNum != PE_CD_GetTracksCnt())
- PM_SetProgramListEntry((WORD)iItemNum, (WORD)iItemNum+1);
- break;
- }
- }
- }
- WORD PM_GetRandomItemFromProgramList(void)
- {
- WORD uNumOfItems= (g_PlayModeInfo.uProgramListSize - 1);
-
- if(uNumOfItems)
- return ((WORD) (1 + (rand() % uNumOfItems)));
- else
- return 0;
-
- }
- // >>>
- /////////////////////////////////////////////////////////////////////////////////////////////////
- // Private Services