.AFP & .AVI -- Cinematics & Video

1. Architectural Role & Engine Purpose

The AFP-AVI (Audio File Packet / Audio-Video Interleaved) format streams pre-rendered cinematic cutscenes, the dramatic opening mission insertion videos, and mission debriefings in Project I.G.I. 1.

Innerloop developed a lightweight software video decompressor tuned for Intel MMX instructions. Audio and video frames are interleaved sequentially, allowing smooth 30 FPS playback from CD-ROM drives directly into DirectDraw hardware surfaces with zero frame-dropping.

2. Binary File Layout & Memory Map Diagram

An AFP-AVI file contains a master stream header followed by interleaved video and audio chunks:

AFP-AVI CUTSCENE — INTERLEAVED VIDEO/AUDIO LAYOUT 0x00: Master Video Stream Header (28 Bytes) 28 BYTES Magic "AFP " / "RIFF" | Total Frame Count | Framerate (30 FPS) | Width (640), Height (480) | Audio Rate (44.1k) magic[4], file_size, frame_count, fps, width, height, audio_channels, audio_rate Frame Index Table & Chunk Pointers INDEX Array of byte offsets to interleaved video keyframes and delta frames O(1) Seeking & synchronization timestamps Interleaved Video & Audio Packet Stream INTERLEAVED Consecutive chunks: [Video Frame (Compressed DCT)] followed immediately by [Audio Slice (PCM 1/30s)] Smooth playback from CD-ROM optical drives without buffer starving

3. Video Decompression & DirectDraw Presentation Pipeline Diagram

The streaming engine reads interleaved packets asynchronously into a circular ring buffer:

AFP-AVI CUTSCENE — MMX SOFTWARE PLAYBACK PIPELINE 1. ASYNC STREAM • Read "MOVIES/INTRO.AVI" • 256 KB Circular Buffer • Demux Video & Audio 2. MMX DECOMPRESS • Intel MMX Video Codec • Fast Software IDCT • Zero External VFW Dll 3. AUDIO CLOCK SYNC • Sound Card Master Clock • Push PCM Audio Slice • Drop Frames if Behind 4. DDRAW PRESENT • DirectDraw Surface Flip • 640x480 Smooth 30 FPS • Cinematic Cutscene

4. Architectural Mechanics & Engine Implementation Details

Innerloop designed the video player to avoid external codec dependencies:

  • Zero Codec Hell: Unlike games relying on Windows Media Player or third-party VFW codecs, IGI 1 embedded its custom decompressor directly into IGI.EXE, guaranteeing 100% reliable cutscene playback across all Windows installations.
  • Audio Master Clock: Playback is synchronized against the hardware sound card sample clock. If the CPU experiences temporary frame drops, video frames are dropped gracefully while audio remains unbroken.

5. C++ Struct Definitions

#pragma pack(push, 1)
struct AfpHeader {
    char     magic[4];       // "AFP " or "RIFF"
    uint32_t file_size;      // Size
    uint32_t frame_count;    // Total video frames
    uint16_t fps;            // Frames per second (e.g., 30)
    uint16_t width;          // Video width (640)
    uint16_t height;         // Video height (480)
    uint16_t audio_channels; // 2 = Stereo
    uint32_t audio_rate;     // 44100 Hz
    uint32_t flags;          // Codec flags
};
static_assert(sizeof(AfpHeader) == 28, "AfpHeader must be 28 bytes");
#pragma pack(pop)