Figure 5.1 Example scenario for branch playback
#define BSTM_MAX 3 /* Total number of branch streams (BSTM1.MPG, BSTM2.MPG, BSTM3.MPG) */ #define BRANCH_MAX 2 /* Total number of branches (number of arrows in Figure 5.1) */ #define KEY_MAX 2 /* Total number of stream key types */ #define A_BTN 0 /* A button branch number */ #define B_BTN 1 /* B button branch number */ #define BR_NUM 2 /* Number of branches per stream */ #define BSTM1_ID 0 /* BSTM1.MPG branch stream identifier */ #define BSTM2_ID 1 /* BSTM2.MPG branch stream identifier */ #define BSTM3_ID 2 /* Branch stream identifier of BSTM3.MPG */ /* Branch playback library work area */ Sint32 work_bpl[BPL_WORK_SIZE(BSTM_MAX, BRANCH_MAX, KEY_MAX)/sizeof(Sint32)]; void setScenario(void) { StmKey key[KEY_MAX]; /* Area for setting stream key */ Sint32 brtbl[BR_NUM]; /* Area for setting branch destination */ Sint32 fid; /* File identifier */ /* Initialize branch playback */ BPL_Init(BSTM_MAX, BRANCH_MAX, KEY_MAX, work_bpl); /* Setting branch stream information */ STM_KEY_CN(key + 0) = STM_KEY_CIMSK(key + 0) = STM_KEY_NONE; STM_KEY_CN(key + 1) = STM_KEY_CIMSK(key + 1) = STM_KEY_NONE; STM_KEY_SMMSK(key + 0) = STM_KEY_SMVAL(key + 0) = STM_SM_VIDEO; STM_KEY_SMMSK(key + 1) = STM_KEY_SMVAL(key + 1) = STM_SM_AUDIO; fid = GFS_NameToId("BSTM1.MPG"); BPL_SetStmInfo(BSTM1_ID, fid, KEY_MAX, key); fid = GFS_NameToId("BSTM2.MPG"); BPL_SetStmInfo(BSTM2_ID, fid, KEY_MAX, key); fid = GFS_NameToId("BSTM3.MPG"); BPL_SetStmInfo(BSTM3_ID, fid, KEY_MAX, key); /* Setting branch destination information */ brtbl[A_BTN] = BSTM2_ID; /* Branch to BSTM2.MPG when A button is pressed */ brtbl[B_BTN] = BSTM3_ID; /* Branch to BSTM3.MPG when B button is pressed */ BPL_SetBranchInfo(BSTM1_ID, BR_NUM, brtbl); /* Setting the branch destination of BSTM1.MPG */ }
Sint32 work_gfs[GFS_WORK_SIZE(BSTM_MAX*KEY_MAX)/sizeof(Sint32)]; Sint32 work_stm[STM_WORK_SIZE(GRP_MAX, BSTM_MAX*KEY_MAX)/sizeof(Sint32)]; Sint32 brno; /* branch number */ StmHn stmtbl[KEY_MAX]; /* Table of stream handles */ Sint32 bpl_stat; /* Branch playback status */ Sint32 decode_stat; /* Decoder operating status */ DecodeHn dc_hn = NULL; /* Decoder handle */ Bool chgsw = OFF; /* Branch execution switch */ Bool endflag = FALSE; Sint32 ret; /* Initialize each library */ GFS_Init(...); /* Initialize the file system */ STM_Init(...); /* Initialize the stream system */ initDecoder(); /* Initialize the decoder */ setScenario(); /* Set scenario (see 5.1) */ /* Branch playback */ BPL_SetStart(BSTM1_ID); /* Specify playback start stream */ BPL_GetCurStm(KEY_MAX, stmtbl); /* Get first branch stream */ dc_hn = createDecodeHn(stmtbl); /* Create decoder handle */ while (endflag == FALSE) { bpl_stat = BPL_ExecServer(chgsw); /* Execute branch playback server */ chgsw = OFF; STM_ExecServer(); /* Execute stream server */ decode_stat = execDecoder(dc_hn); /* Execute decoder server function */ switch (bpl_stat) { case BPL_SVR_COMPLETED: /* Branch playback completion status */ endflag = TRUE; break; case BPL_SVR_WAITSEL: /* Waiting for branch destination selection */ /* Get pad input (0: A button, 1: B button, if negative: no input */ brno = getPadEvent(); if (brno >= 0) { BPL_SelectBranch(brno); /* Select branch destination */ } break; case BPL_SVR_SELECT: /* Branch destination determination state */ case BPL_SVR_NOBRN: /* No branch destination */ if (decode_stat != COMPLETED) { /* Check for decoding completion */ break; } chgsw = ON; /* Branch execution switch ON */ ret = BPL_GetNextStm(KEY_MAX, stmtbl); /* Get branch destination stream */ if (ret >= 0) { /* If there is a branch destination */ destroyDecodeHn(dc_hn); /* Erase the decoder handle */ dc_hn = createDecodeHn(stmtbl); /* Create decoder handle */ } break; } } destroyDecodeHn(dc_hn); /* Erase the decoder handle */