PROGRAMMER'S GUIDEStream system library
BackForward
Stream system library

5. Stream access example


5.1 Basic program

(1) Reading the stream
Read streams A, B, C into a_buf, b_buf, c_buf.
(A_BUFSIZE, B_BUFSIZE, C_BUFSIZE are the buffer sizes per sector)

Uint8 work [STM_WORK_SIZE (STMGRP_OPEN_MAX, STM_OPEN_MAX)]; / * Work area * /
Sint32 a_id, b_id, c_id; / * File identifier * /
StmGrpHn abc_grp; / * Stream group handle * /
StmHn a_stm, b_stm, c_stm; / * Stream handle * /
StmKey key; / * Stream key * /
Uint8 a_buf [A_BUFSIZE * STM_UNIT_FORM1]; / * Transfer area A * /
Uint8 b_buf [B_BUFSIZE * STM_UNIT_FORM2]; / * Transfer area B * /
Uint8 c_buf [C_BUFSIZE * STM_UNIT_FORM1]; / * Transfer area C * /

GFS_Init (...); / * File system initialization * / STM_Init (STMGRP_OPEN_MAX, STM_OPEN_MAX, work); / * Stream system initialization * / a_id = GFS_NameToId (・ ・ ・); / * Get file identifier * / ・ ・ ・ abc_grp = STM_OpenGrp (); / * Open stream group * / / * Stream key settings * / STM_KEY_CN (& key) = STM_KEY_NONE; / * Channel number * / STM_KEY_CIMSK (& key) = STM_KEY_CIVAL (& key) = STM_KEY_NONE; / * Coding information * / / * Opening a stream by file identifier * / STM_KEY_SMMSK (& key) = STM_KEY_SMVAL (& key) = STM_SM_VIDEO; / * Video stream * / a_stm = STM_OpenFid (abc_grp, a_id, & key, STM_LOOP_NOREAD); / * Stream A * / STM_KEY_SMMSK (& key) = STM_KEY_SMVAL (& key) = STM_SM_AUDIO; / * Audio stream * / b_stm = STM_OpenFid (abc_grp, b_id, & key, STM_LOOP_NOREAD); / * Stream B * / STM_KEY_SMMSK (& key) = STM_KEY_SMVAL (& key) = STM_SM_DATA; / * Data stream * / c_stm = STM_OpenFid (abc_grp, c_id, & key, STM_LOOP_NOREAD); / * Stream C * /

/ * Transfer area settings * / STM_SetTrBuf (a_stm, a_buf, A_BUFSIZE, STM_UNIT_FORM1); STM_SetTrBuf (b_stm, b_buf, B_BUFSIZE, STM_UNIT_FORM2); STM_SetTrBuf (c_stm, c_buf, C_BUFSIZE, STM_UNIT_FORM1);

/ * Stream access * / STM_SetExecGrp (abc_grp); / * Execution group setting * / while (1) { if (STM_ExecServer () == STM_EXEC_COMPLETED) { break; / * End of stream access * / } user (); / * User processing * / } STM_CloseGrp (abc_grp); / * Close stream group * /


(2) Transfer area setting
The following two processing methods are different when setting the transfer area.

(a) STM_SetTrBuf (stm, buffer, A_BUFSIZE, STM_UNIT_FORM1)

(b) STM_SetTrBuf (stm, buffer, A_BUFSIZE * STM_UNIT_FORM1, STM_UNIT_WORD)

(a) When the size of the transfer area is in sector units
Since the number of sectors that can be extracted from the partition in the CD block is known in advance, it can be processed as follows.

Figure 5.1 Transfer processing in sector units

(b) When the size of the transfer area is not in sector units
Since the number of sectors that can be extracted from the partition in the CD block is unknown, process as follows.

Figure 5.2 Transfer processing when not in sector units

You cannot transfer the next stream while repeating the dotted loop. Therefore, when accessing two or more streams at the same time, it should be transferred by the method (a) except in special cases.
If Form1 sector and Form2 sector are mixed in one stream, there is no choice but to transfer by the method (b).

(3) Transfer function settings
When transferring the data of stream B to read_buf while expanding it using the function "decodeFunc" in program (1), change as follows.

(a) Change STM_SetTrBuf in the dotted line to STM_SetTrFunc.

STM_SetTrFunc (b_stm, decodeFunc, read_buf);

This causes decodeFunc to start every time the server function STM_ExecServer attempts to transfer stream B data.

(b) "decodeFunc" is as follows.

Uint8 read_buf [READBUF_SIZE];

Sint32 decodeFunc (void * obj, StmHn stm, Sint32 nsct)
{
	Sint32 i;
	Sint32 read_len; / * Number of long words transferred by subFunc * /
	Sint32 nlongword; / * Number of long words transferred * /
	Uint32 * src; / * Forwarding address * /
	Sint32 dadr; / * 1 Address / change for each longword transfer * /
	Uint32 * buffer; / * Transfer area * /

	/ * Conversion from number of sectors to number of words (call before transfer starts) * /
	nlongword = STM_SctToWord (stm, nsct) / 2;

	src = STM_StartTrans (stm, & dadr); / * Start transfer * /
	buffer = (Uint8 *) obj; / * obj is passed the third argument of STM_SetTrFunc * /

	for (i = 0; i <nlongword; i + = read_len) {

		/ * Function that returns the number of expanded bytes * /
		buffer + = subFunc (src, dadr, buffer, & read_len);
		src + = read_len * dadr;
	}
	return (nsct); / * Returns the number of sectors transferred * /
}

(c) It must be transferred in sector units.

(d) If the data has not been transferred at the end of decodeFunc, (-1) must be returned.
In this case, no other stream can be transferred until the data has been transferred. When the data has been transferred, the number of transferred sectors is returned. During this time, do not call STM_StartTrans.

Figure 5.3 Behavior when using the transfer function

(4) Close the stream that registers the transfer function

If you close the stream immediately after the transfer function returns (-1), the stream system keeps calling the transfer function until the transfer function returns a value greater than or equal to 0. Return a value greater than or equal to 0 when the transfer is complete.

5.2 Combined use with file system

If you want the file system to read from a CD while using the stream system, you need to pause the drive. There are two ways to do this:

(a) Execute STM_SetExecGrp (NULL). (Return to completion)

(b) Execute STM_NwSetExecGrp (NULL) and call the server function until the function value of STM_ExecServer becomes STM_EXEC_TSKEND. (Immediate return) After that, when the reading by the file system is finished, the reading of the stream is restarted by STM_SetExecGrp (grp).

<Example> Transfer the pre-read stream data while reading by the file system.
         ・
         ・ / * Look ahead to the stream * /
STM_SetExecGrp (NULL); / * Pause drive * /
GFS_NwFread (………);
while (1) {
	if (GFS_NwExecOne (gfs) == GFS_SVR_COMPLETED) / * Read file * /
		break;
	STM_ExecTrans (stm); / * Transfer stream data * /
}
STM_SetExecGrp (grp); / * Resume reading stream * /


BackForward
PROGRAMMER'S GUIDEStream system library
Copyright SEGA ENTERPRISES, LTD., 1997