Japanese
PROGRAMMER'S GUIDEMPEG library
BackForward
MPEG library

4. How to use the library


4.1 Library configuration

MPEG applications are assumed to use the MPEG library and stream system library.

Figure 4.1 Module configuration diagram


application




stream system
Library



MPEG library


MPEG videos are played using the following two steps.

(1) Stream system library
Read data from CD into buffer.

(2)MPEG library
Decodes the data in the CD buffer and outputs it as image data.

The stream system supplies data to the MPEG library through the CD buffer. Therefore, we pass the stream handle generated by the stream system to the MPEG library. The MPEG library retrieves and decodes data from this stream handle.
To use this library, you need to link the following libraries at the same time.

4.2 Capturing MPEG system state

The MPEG library must capture the latest state of the MPEG system in the CD block and update its internal state.
Therefore, call the MPG_CaptStat function at one of the following timings for each VSYNC to capture the MPEG system status.

  1. Clear the MPCM flag with VBLANK-IN interrupt, wait until it turns ON, and then call

  2. Call with VBLANK-OUT interrupt

Note
While the following functions are being executed, executing the MPG_CaptStat function within interrupt handling is prohibited.

《MPEG system control》

《Video playback》

《Still image playback》

4.3 VDP2 output mode

When outputting directly to VDP2, each function of the MPEG library is enabled at the falling edge of VSYNC. Information such as time code can be obtained from the currently displayed information.
Since it is difficult for the application software to obtain the VSYNC timing on this game console, we recommend performing MPEG-related processing from the VBLANK-OUT timing.

Figure 4.2 Processing timing during VDP2 output

Example of processing
  1. Wait for VBLANK-OUT.
  2. Call the MPG_CaptStat function.
  3. Get timecode.
  4. Obtain collision data corresponding to timecode.
  5. Perform hit detection, etc., and configure MPEG-related settings corresponding to the results.
  6. Setting (5) becomes effective in the next frame.

4.4 Host transfer mode

Image data in the frame buffer is transferred to the host area by calling the MPG_WnTrans function. For example, you can animate a sprite's texture by opening a display window in the sprite's texture area and periodically calling the MPG_WnTrans function.

4.5 State transition

The MPEG system is controlled through the MPEG handle.
The MPEG handle holds the video working state and the audio working state. The operating status of both video and audio changes as shown below.
Use the following functions to start and stop playback.

  1. Playback start function
    • MPG_MvStart
    • MPG_SpStart

  2. Playback stop function
    • MPG_MvStop, MPG_MvStopVideo, MPG_MvStopAudio
    • MPG_SpStop

    Figure 4.3 MPEG handle state transition diagram

  3. Behavior of the playback stop function
    1. If you initialize the decoder within the playback stop function, MPEG screen display will be set to ON in the library.
    2. Clear the VBV buffer in the MPG_MvStop function, MPG_MvStopVideo function, and MPG_SpStop function.
    3. When video playback is stopped, the next stream is canceled to the MPEG system.

4.6 Hangup Detection

The MPEG library provides functions to detect hang-ups in MPEG/Video LSI.
Hang-up detection is performed by calling the MPG_ResetHng function once and then calling the MPG_CheckHng function for each VSYNC.
If it hangs, please stop playing the MPEG and then start playing the MPEG again. If the problem does not recover even after performing this action, initialize it using the MPG_Init function.

4.7 Registering user transfer function

In host transfer mode, you can register a transfer function to transfer image data.
The specifications of the transfer function are as follows.

[Format] Sint32 trFunc(void *dst, void *src, Sint32 nbyte)
[Input] dst: Transfer destination address src: Transfer source address nbyte: Number of transfer bytes [Function value] Error code
  1. dst contains the address of the transfer area set by the MPG_WnSetOutputMode function.
  2. The transfer function is called from the MPEG library when you execute the MPG_WnTrans function.
  3. To register a transfer function, use the MPG_WnEntryTrFunc function.
  4. By default, the DMA transfer function on the B-Bus by SCU is registered as a transfer function.
  5. The default transfer function will time out in approximately 2 seconds if the DMA transfer is not completed.

4.8 Precautions for use

The main points to note when using this library are listed below.

(1)Limitations during audio/video synchronized playback
If you call the following function during audio/video synchronous playback, the audio and video will be out of sync.

MPG_MvSetVideoId

To avoid this, stop playing the video before executing the above function, and then resume playback using the MPG_MvStart function after executing the above function.

(2) Restrictions on how to stop audio/video playback
To stop playback during audio/video synchronized playback, call the MPG_MvStop function or follow the steps below. Don't let the video stop first.

  1. Call the MPG_MvStopAudio function.
  2. Verify that audio is stopped using the MPG_MvGetAudioStat function.
  3. Call the MPG_MvStopVideo function.


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