Skip to main content
← PSoXide SDK guides and examples · SDK 80d1c329e977 · All Cargo features enabled; check feature gates before use.

Module player

Module player 

Source
Expand description

A streaming STR player a game can call: play streams one movie from the disc at double speed, decodes it through the MDEC and shows it, with its interleaved XA audio going straight from the drive to the SPU.

The pipeline is the hello-fmv console test’s, without the test’s sector stamps and overlay:

  1. A polled pump drains every sector the drive has ready into a ring of three frame slots. It runs between every unit of work, including every wait and every two macroblocks of the bitstream decode.
  2. crate::bitstream::decode_frame turns the next frame’s bitstream into one of two run-length buffers while the MDEC decodes the previous frame from the other.
  3. The whole decoded frame comes back over one DMA1 transfer into one of two RAM frame buffers, so the MDEC’s output never waits for the CPU to start the next column. Its 16-pixel columns then go to a free display buffer over DMA2 while the MDEC decodes the next frame into the other RAM buffer.
  4. The flip is queued to the VBlank handler. There are three display buffers, so the MDEC can start the next frame while the last one waits for its flip.

Pacing follows the drive, not the VBlank: a frame is shown Config::latency_vblanks after its last sector arrived. The audio plays as its sectors arrive, so picture and sound keep a fixed offset for the whole movie whatever the display’s refresh rate, and a 25 fps PAL movie plays at 25 fps on a 60 Hz display. A frame completed while an older one still waits for the decoder replaces it (counted in Outcome::skipped).

Why whole frames: at 24 bits a 320x192 frame is 46,080 words and the console MDEC returns a word every 24 cycles, 1,106,000 cycles, which is nearly all of the 1,130,000 that two VBlanks give a 30 fps movie. Fetching a column at a time left the MDEC idle until the CPU noticed each column had arrived (about 7,500 cycles a column, 150,000 a frame), so the player fell behind and dropped a tenth of the frames. One transfer per frame leaves the MDEC no gap; the price is two RAM frame buffers (about 360 KB at 320x192 and 24 bits) instead of two column buffers.

Memory comes from the caller (memory_words says how much), so a game lends a buffer that is idle while the movie plays, such as a level buffer at boot. The player takes over the CD drive, the MDEC, DMA channels 0 to 2, root counter 2, the display and the VRAM under Config::buffers while it runs. No frame of the caller’s may be in flight on the GPU when it starts, and the SPU must already be initialised.

Structs§

Config
Where and how to show it.
Movie
One movie on the disc, as the build measured it.
Outcome
What happened, for logs and tests.

Enums§

Depth
Colour depth of the decoded picture.
Stop
Why play returned.

Constants§

DEFAULT_BUFFERS
Display buffers at (0, 0), (0, 256) and (512, 0): room for 320 pixels at 24 bits (480 halfwords) by up to 256 lines each.
WEDGE_ERRORS
Consecutive MDEC failures that end a movie as Stop::Wedged.

Functions§

find_root_file
Find a file in the disc’s root directory by name: (lba, bytes). Takes the drive over (data mode, double speed) and leaves it stopped.
memory_words
Words of memory play needs for movie at depth.
play
Play movie until it ends or poll returns true (checked once per VBlank, e.g. for a skip button). memory must hold at least memory_words words and is free again on return. At 15 bits the last frame stays on screen (the display start may be any of the three buffers); at 24 bits every buffer is cleared to black and the caller’s display mode is restored. The drive is stopped and the CD audio volume left at 0.