Modules

pl_mpeg

moduleSource

Available on macOS, Linux, Windows, Wasm

#import "pl_mpeg";

Procedures#

Buffer#

(memory: [] u8, free_when_done: bool) -> *Buffer

Adapted from MIT-licensed PL_MPEG by Dominic Szablewski. Original C input/attribution: third_party/pl_mpeg. This is a separate Jai implementation using layouts and checked bounds/I/O; no Jai port input.

Pixels#

PUT_PIXELsince 0.31.0Source
(RI: s32, GI: s32, BI: s32, y_offset: s32, dest_offset: s32)

IDCT#

(block: *s32)

Two separable integer passes adapted from the licensed public C pl_mpeg implementation. Coefficients use the decoder's premultiplied scale.

Video#

(video: *Video) -> bool

Transactional variable-length parsing: incomplete custom matrices retain the header cursor for a later callback/append, without exposing partial metadata.

Motion#

(video: *Video, r_size: s32, motion: s32) -> s32

Motion reconstruction and integer half-pixel filtering adapted from public C pl_mpeg (MIT); source attribution is in third_party/pl_mpeg/README.md.

(dest: *u8, dest_width: s32, source_width: s32, block_size: s32, code: Code)

Reconstruction#

(video: *Video, block: s32)

Entropy decoding, dequantization and frame ordering adapted from licensed public C pl_mpeg. Reviewed Jai records remain the actual live decoder state.

Synthesis#

(s: [32][3] s32, ss: s32, d: *float, dp: s32)

Direct MPEG synthesis matrix. Kept separate from entropy/sample decoding so a future verified factorization can replace it without changing the public API.

Audio#

Program#

(self: *Plm, time: float64, seek_exact: bool) -> *Frame

Linear seeks retain real decoded frames and work without a side index. The precise/nonprecise frame selection and audio alignment require contract review.

(self: *Plm, time: float64, seek_exact: bool) -> bool

Types#

:: enum
SEQUENCE
SLICE_FIRST
SLICE_LAST
PICTURE
EXTENSION
USER_DATA
PACK
END
SYSTEM
PRIVATE
AUDIO_1
AUDIO_2
AUDIO_3
AUDIO_4
VIDEO_1
NOT_FOUND
VlcstructSource
:: struct
index: s16
value: s16
:: struct
bit_index: s64
capacity: s64
length: s64
total_size: s64
discard_read_bytes: := false
has_ended: := false
free_when_done: := false
close_when_done: := false
file_initted: := false
fh: File
load_callback: Buffer_Load_Callback
load_callback_user_data: *void
bytes: *u8
Planestructsince 0.31.0Source
:: struct

Plane storage and the integer BT.601 transform adapted from the licensed public C pl_mpeg implementation; see third_party/pl_mpeg/README.md.

width: s32
height: s32
data: *u8
Audio_Modeenumsince 0.31.0Source
:: enum
STEREO
JOINT_STEREO
DUAL_CHANNEL
MONO
:: struct

Canonical shapes retain ABI field order.

full_px: s32
is_set: s32
r_size: s32
h: s32
v: s32
:: struct
framerate: float64
time: float64
frames_decoded: s32
width: s32
height: s32
mb_width: s32
mb_height: s32
mb_size: s32
luma_width: s32
luma_height: s32
chroma_width: s32
chroma_height: s32
start_code: Start_Code
picture_type: Picture_Type
motion_forward: Video_Motion
motion_backward: Video_Motion
has_sequence_header: := false
quantizer_scale: s32
slice_begin: := false
macroblock_address: s32
mb_row: s32
mb_col: s32
macroblock_type: s32
macroblock_intra: s32
dc_predictor: [3] s32
buffer: *Buffer
destroy_buffer_when_done: bool
frame_current: Frame
frame_forward: Frame
frame_backward: Frame
frames_data: *u8
block_data: [64] s32
intra_quant_matrix: [64] u8
non_intra_quant_matrix: [64] u8
has_reference_frame: := false
assume_no_b_frames: := false
:: struct
time: float64
samples_decoded: s32
samplerate_index: s32
bitrate_index: s32
version: s32
layer: s32
bound: s32
v_pos: s32
next_frame_data_size: s32
has_header: := false
buffer: *Buffer
destroy_buffer_when_done: bool
allocation: [2][32] *Quantizer_Spec
scale_factor_info: [2][32] u8
scale_factor: [2][32][3] s32
sample: [2][32][3] s32
samples: Samples
D: [1024] float
V: [2][1024] float
U: [32] float
PlmstructSource
:: struct

Canonical high-level playback record. Private demux state is defined below.

demux: *Demux
time: float64
has_ended: bool
loop: bool
has_decoders: bool
video_enabled: := true
video_packet_type: Start_Code
video_buffer: *Buffer
video_decoder: *Video
audio_enabled: := true
audio_stream_index: s32
audio_packet_type: Start_Code
audio_lead_time: float64
audio_buffer: *Buffer
audio_decoder: *Audio
video_decode_callback: Video_Decode_Callback
video_decode_callback_user_data: *void
audio_decode_callback: Audio_Decode_Callback
audio_decode_callback_user_data: *void

Constants#

:: float.[0.000, 23.976, 24.000, 25.000, 29.970, 30.000, 50.000, 59.940, 60.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000]
:: u8.[0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5, 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28, 35, 42, 49, 56, 57, 50, 43, 36, 29, 22 ...
:: u8.[8, 16, 19, 22, 26, 27, 29, 34, 16, 16, 22, 24, 27, 29, 34, 37, 19, 22, 26, 27, 29, 34, 34, 38, 22, 22, 26, 27, 29, 34, 37, 40, 22, 26, 27, 29, 32, 35, 40, 4 ...
:: u8.[16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ...
:: u8.[32, 44, 42, 38, 32, 25, 17, 9, 44, 62, 58, 52, 44, 35, 24, 12, 42, 58, 55, 49, 42, 33, 23, 12, 38, 52, 49, 44, 38, 30, 20, 10, 32, 44, 42, 38, 32, 25, 17, 9 ...
:: Vlc.[.{ 1 << 1, 0 }, .{ 2 << 1, 0 }, .{ 0, 1 }, .{ 0, 2 }, .{ 3 << 1, 0 }, .{ 4 << 1, 0 }, .{ 0, 0 }, .{ 0, 3 }, .{ 0, 4 }, .{ 5 << 1, 0 }, .{ 0, 5 }, .{ 6 << 1 ...
:: Vlc.[.{ 1 << 1, 0 }, .{ 2 << 1, 0 }, .{ 0, 0 }, .{ 0, 1 }, .{ 0, 2 }, .{ 3 << 1, 0 }, .{ 0, 3 }, .{ 4 << 1, 0 }, .{ 0, 4 }, .{ 5 << 1, 0 }, .{ 0, 5 }, .{ 6 << 1 ...
:: Vlc_Uint.[ .{ 1 << 1, 0 }, .{ 0, 0x0001 }, .{ 2 << 1, 0 }, .{ 3 << 1, 0 }, .{ 4 << 1, 0 }, .{ 5 << 1, 0 }, .{ 6 << 1, 0 }, .{ 0, 0x0101 }, .{ 7 << 1, 0 }, .{ 8 ...
:: Vlc.[.{ 1 << 1, 0 }, .{ 0, 0 }, .{ 2 << 1, 0 }, .{ 3 << 1, 0 }, .{ 4 << 1, 0 }, .{ 5 << 1, 0 }, .{ 0, 1 }, .{ 0, -1 }, .{ 6 << 1, 0 }, .{ 7 << 1, 0 }, .{ 0, 2 } ...
:: Vlc.[.{ 1 << 1, 0 }, .{ 2 << 1, 0 }, .{ 3 << 1, 0 }, .{ 4 << 1, 0 }, .{ 5 << 1, 0 }, .{ 6 << 1, 0 }, .{ 7 << 1, 0 }, .{ 8 << 1, 0 }, .{ 9 << 1, 0 }, .{ 10 << 1, ...
:: Vlc.[.{ 1 << 1, 0 }, .{ 0, 1 }, .{ 2 << 1, 0 }, .{ 3 << 1, 0 }, .{ 4 << 1, 0 }, .{ 5 << 1, 0 }, .{ 0, 3 }, .{ 0, 2 }, .{ 6 << 1, 0 }, .{ 7 << 1, 0 }, .{ 0, 5 }, ...
:: Vlc.[.{ 1 << 1, 0 }, .{ 0, 0x0a }, .{ 2 << 1, 0 }, .{ 0, 0x02 }, .{ 3 << 1, 0 }, .{ 0, 0x08 }, .{ 4 << 1, 0 }, .{ 5 << 1, 0 }, .{ 6 << 1, 0 }, .{ 0, 0x12 }, .{ ...
:: Vlc.[.{ 1 << 1, 0 }, .{ 2 << 1, 0 }, .{ 3 << 1, 0 }, .{ 4 << 1, 0 }, .{ 0, 0x0c }, .{ 0, 0x0e }, .{ 5 << 1, 0 }, .{ 6 << 1, 0 }, .{ 0, 0x04 }, .{ 0, 0x06 }, .{ ...
:: s16.[32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160]
:: [16] u8).[.[0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0], .[0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 0, 0]]
:: [32] u8).[.[0x44, 0x44, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ...
:: [16] u8).[.[0, 1, 2, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], .[0, 1, 2, 3, 4, 5, 6, 17, 0, 0, 0, 0, 0, 0, 0, 0], .[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ...
:: Quantizer_Spec.[.{ 3, 1, 5 }, .{ 5, 1, 7 }, .{ 7, 0, 3 }, .{ 9, 1, 10 }, .{ 15, 0, 4 }, .{ 31, 0, 5 }, .{ 63, 0, 6 }, .{ 127, 0, 7 }, .{ 255, 0, 8 }, .{ 511, 0, ...
:: float.[ 0.0, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -1.0, -1.0, -1.0, -1.0, -1.5, -1.5, -2.0, -2.0, -2.5, -2.5, -3.0, -3.5, -3.5, -4.0, -4.5, -5.0, -5.5, -6.5, -7. ...