Japanese
PROGRAMMER'S GUIDEBranch playback library
BackForward
Branch playback library

3. Mechanism of branch playback library


3.1 Process flow

The branch playback library reads the stream according to the scenario and tells the application which stream handle to decode.
Figure 3.1 shows the main processing flow.

Figure 3.1 Process flow

3.2 Scenario

A scenario is information that indicates how branch playback is to be performed (in what order streams are played back) as time passes.
Branch streams are specified in file units. Data such as audio and video can be extracted by channel interleaving within the file.

Figure 3.2 Stream branching

  1. In this scenario, the first branch stream to read is bstm1. The branch playback library starts loading bstm1.

  2. The application retrieves the currently loading branch stream and sets it to the decoder.

  3. After reading bstm1, the branch playback library starts reading branch candidates (branch streams that may be retrieved next) bstm2, bstm3, bstm4, and bstm5. By pre-reading the stream of branch candidates in this way, the CD buffer can be used effectively and smooth branching is possible.

  4. The application obtains events from pad input, etc., and selects a branch destination. If branches to bstm2, bstm3, bstm4, and bstm5 are assigned branch numbers 0 to 3, and 1 is specified, loading of bstm2, bstm4, and bstm5 that are no longer needed will be stopped. If necessary, the application retrieves the branched stream and sets it in the decoder.

  5. Once bstm1 has been extracted, bstm3 will begin to be extracted. When the application specifies branch execution to the branch playback server, the branch playback library starts loading bstm9, bstm10, and bstm11 in the same way as in (c).
 [Note] The same stream must not exist within one branch candidate. This is because opening the same stream with different stream handles does not read data at the same time. The stream opened later is connected to the end of the aperture, so data can be retrieved from the stream opened earlier. Therefore, the same stream as the current one may exist in the branch candidate. 《Example in Figure 3.2》 - The same stream must not be duplicated in bstm6 to bstm8, but it is okay to have the same stream as bstm2.

3.3 Branch playback state transition

Table 3.1 shows the branch playback status, and Figure 3.3 shows the branch playback state transition.

Table 3.1 Branch playback status
 situation
 explanation
 Branch playback ends
 Branch playback has ended.
Stream groups and streams opened by the branch playback library
(current stream and branch candidates) are all closed.
 Waiting for branch destination selection
 A branch candidate is being read ahead, but the branch destination has not been selected.
All streams of branch candidates are subject to read-ahead.
Only the current stream can be retrieved, not the branched stream.
 Branch destination decision
 The branch destination has been selected from among the branch candidates.
Only the selected branch destination will be prefetched.
You can get both the current stream and the branch destination stream.
 No branch destination
 There are no branch candidates or branch destinations for the current stream.
The last stream is being played.

The branch playback status can be obtained using the server function.

Figure 3.3 State transition diagram of branch playback

* ON/OFF: Branch execution switch for branch playback server function (BPL_ExecServer)
If you specify ON in the branch destination selected state/no branch destination state, branch playback ends.
If you specify ON in the branch destination determination state, the branch stream will be switched.

3.4 Branch execution (branch stream switching process)

(1) Execution of branch
When a branch is executed with the branch destination determined (turning on the branch execution switch on the branch playback server), the following branch stream switching process is performed.

  1. Closes the current stream A.
    (Aborts reading of A and erases any remaining data in the CD buffer.)

  2. The branch destination stream B becomes the new current stream.

  3. The branch destination stream is undetermined.

Table 3.2 Switching branch streams by executing branches
 branch stream
 Before branch execution
 After branch execution (after switching process)
 current stream
(obtained with BPL_GetCurStm function)
 A
 B
(A is closed)
 branch destination stream
(obtained with BPL_GetNextStm function)
 B
 Undecided until next branch destination is selected
(Select/determine using the BPL_SelectBranch function)

Selection of a branch destination always precedes branch execution (switching), but selection and switching operations are basically asynchronous.

(2) Opening and closing streams
The streams opened by the branch playback library are the current stream and branch candidate streams. The opening/closing procedure is shown below.

  1. The playback start stream specified by the BPL_SetStart function is first opened as the current stream.

  2. Once the current stream starts reading, branch candidate streams are opened.

  3. When a branch destination is selected, other branch candidates are closed and only the branch destination is prefetched.

  4. Executing a branch closes the current stream.
    The branch destination stream switches to the current stream, and steps (b) to (d) are repeated.

  5. When branch playback ends, the stream group is closed.

(3) Branch stream switching timing
The switching timing of branch streams is classified as shown in Table 3.3.

Table 3.3 Branch stream switching timing
 timing
 explanation
 natural switching
 When stream A is finished decoding, switch to stream B, which is the branch destination.
 Forced switch
 Even if stream A is in the middle of being decoded, it will forcibly switch to the branch destination stream B.

Once the branch destination has been determined, the branch should not be executed until the decoder has finished processing the current stream. (This is to prevent stream data being interrupted during decoding.)
For both natural and forced switching, execute the switching process for the decoder first, and then turn on the branch execution switch after that process is complete.


BackForward
PROGRAMMER'S GUIDEBranch playback library
Copyright SEGA ENTERPRISES, LTD., 1997