Documentation
¶
Overview ¶
Package dvd implements DVD-Video navigation: IFO parsing, the command virtual machine, the navigator state machine, NAV-pack (PCI/DSI) parsing and sub-picture (SPU) decoding for menu highlights.
It is written from the public DVD-Video structure (the same layout documented by libdvdread/libdvdnav) and never requires a mounted disc: the caller provides IFO bytes and sector-range readers.
Index ¶
- Constants
- Variables
- func PackScrambled(pack []byte) bool
- func YCrCbToRGB(y, cr, cb int) (r, g, b uint8)
- type AudioAttr
- type Button
- type ButtonGroup
- type Cell
- type CellSubs
- type Command
- type DSI
- type Disc
- type Domain
- type FileExtent
- type Instr
- type Jump
- type JumpOp
- type LangUnit
- type Link
- type LinkOp
- type Look
- type MenuButton
- type MenuPicture
- type MenuScanOptions
- type Nav
- func (n *Nav) CellEnded() *Step
- func (n *Nav) Clone() *Nav
- func (n *Nav) Current() *Step
- func (n *Nav) GoUp() *Step
- func (n *Nav) MenuKey(kind string) *Step
- func (n *Nav) NavTimerFired() *Step
- func (n *Nav) NextChapter() *Step
- func (n *Nav) OpenMenu(kind string, vts int) *Step
- func (n *Nav) PlayTitle(ttn, pttn int) *Step
- func (n *Nav) PressButton(btn int, cmd *Command) *Step
- func (n *Nav) PrevChapter() *Step
- func (n *Nav) Registers() *Registers
- func (n *Nav) Resume() *Step
- func (n *Nav) SelectButton(btn int) *Step
- func (n *Nav) SetAngle(a int)
- func (n *Nav) SetAudio(stream int)
- func (n *Nav) SetSubpicture(stream int, on bool)
- func (n *Nav) Start() *Step
- func (n *Nav) SyncTitleCell(pgcn, cellN int) bool
- func (n *Nav) Tick(seconds float64) *Step
- type NavOptions
- type NavPack
- type Opened
- func (o *Opened) CellExtents(sp Space, c Cell) ([]FileExtent, error)
- func (o *Opened) CellRanges(sp Space, c Cell) ([]SectorRange, error)
- func (o *Opened) CellSubpictures(sp Space, cell Cell) (*CellSubs, error)
- func (o *Opened) Close() error
- func (o *Opened) Extents(sp Space) ([]FileExtent, error)
- func (o *Opened) Menu(sp Space, first, last uint32, opt MenuScanOptions) (*MenuPicture, error)
- func (o *Opened) RangeExtents(sp Space, first, last uint32) ([]FileExtent, error)
- func (o *Opened) Reader(sp Space) (SectorReader, error)
- type PCI
- type PGC
- type PGCEntry
- type PTT
- type PackScanner
- type RGBA
- type RegisterOptions
- type Registers
- type Result
- type ResultKind
- type RunOptions
- type SPU
- type SPUUnit
- type SectorRange
- type SectorReader
- type Source
- type Space
- type Step
- type StepKind
- type StreamScan
- type SubpAttr
- type SubpControl
- type TitleCell
- type TitleInfo
- type TitleSearch
- type TitleSummary
- type VMG
- type VTS
- type VideoAttr
Constants ¶
const ( SprmMenuLang = 0 SprmAudio = 1 SprmSubp = 2 SprmAngle = 3 SprmTTN = 4 SprmVTSTTN = 5 SprmTTPGCN = 6 SprmPTTN = 7 SprmHLBTNN = 8 SprmAudioMix = 11 SprmCountry = 12 SprmParental = 13 SprmVideoMode = 14 SprmAudioCap = 15 SprmAudioLang = 16 SprmAudioExt = 17 SprmSubpLang = 18 SprmSubpExt = 19 SprmRegion = 20 )
SPRM indexes.
const MaxIFOBytes = 16 << 20
MaxIFOBytes bounds how much of an IFO we read.
const Sector = 2048
const VideoStreamID = 0x1e0
VideoStreamID is the MPEG-PS stream id of a DVD's video, as ffmpeg reports it.
Variables ¶
var ErrBadIFO = errors.New("dvd: malformed IFO")
var ErrSPU = errors.New("dvd: malformed sub-picture")
var MenuTypes = map[string]int{"title": 2, "root": 3, "subpicture": 4, "audio": 5, "angle": 6, "chapter": 7}
MenuTypes maps menu names to the entry PGC menu type codes.
Functions ¶
func PackScrambled ¶
PackScrambled reports CSS scrambling on the first PES of a pack.
func YCrCbToRGB ¶
YCrCbToRGB converts a DVD palette entry (ITU-R BT.601 limited range).
Types ¶
type AudioAttr ¶
type AudioAttr struct {
Codec string `json:"codec"`
Language string `json:"language,omitempty"`
Channels int `json:"channels"`
Extension int `json:"extension"`
AppMode int `json:"appMode"`
}
AudioAttr describes an audio stream.
type Button ¶
type Button struct {
N int `json:"n"`
Group int `json:"group"`
X0, Y0 int `json:"-"`
X1, Y1 int `json:"-"`
Up, Down int `json:"-"`
Left, Right int `json:"-"`
Auto bool `json:"auto"`
Cmd Command `json:"-"`
ColorScheme int `json:"-"`
Select Look `json:"-"`
Action Look `json:"-"`
}
Button is one highlight button from a PCI.
type ButtonGroup ¶
type ButtonGroup struct {
N int `json:"n"`
Type int `json:"type"`
Mode string `json:"mode"` // normal | letterbox | panscan
}
ButtonGroup describes one of up to three button groups (per display mode).
type Cell ¶
type Cell struct {
BlockMode int `json:"blockMode"` // 0 normal, 1 first of angle block, 2 middle, 3 last
BlockType int `json:"blockType"` // 1 = angle block
Seamless bool `json:"seamless"`
Interleaved bool `json:"interleaved"`
STCDiscontinuity bool `json:"stcDiscontinuity"`
SeamlessAngle bool `json:"seamlessAngle"`
Restricted bool `json:"restricted"`
StillTime int `json:"stillTime"` // seconds, 0xff = infinite
Command int `json:"command"` // 1-based index into PGC cell commands, 0 none
Duration float64 `json:"durationSec"`
FirstSector uint32 `json:"firstSector"`
FirstILVUEnd uint32 `json:"firstIlvuEndSector"`
LastVOBUStart uint32 `json:"lastVobuStartSector"`
LastSector uint32 `json:"lastSector"`
VOBID int `json:"vobId"`
CellID int `json:"cellId"`
}
Cell is one cell of a PGC (cell playback info + position).
type CellSubs ¶
type CellSubs struct {
// BasePTM is the presentation time of the cell's first VOBU; unit PTS
// minus BasePTM is the offset into the cell.
BasePTM uint32
Units []SPUUnit
}
CellSubs are the sub-picture units of one cell, all streams.
type DSI ¶
type DSI struct {
SCR uint32
LBN uint32
VOBUEnd uint32 // relative end address: VOBU spans LBN..LBN+VOBUEnd
VOBID int
CellID int
}
DSI is the parsed data search information of a NAV pack.
type Disc ¶
Disc bundles the parsed IFOs of one DVD.
func (*Disc) MainTitle ¶
func (d *Disc) MainTitle() *TitleSummary
MainTitle guesses the feature: the longest title.
func (*Disc) Region ¶
Region returns the lowest region number the disc allows (1-8), or 1 if all-region.
func (*Disc) Title ¶
func (d *Disc) Title(number int) *TitleSummary
Title flattens one title by number.
func (*Disc) TitleAngle ¶
func (d *Disc) TitleAngle(number, angle int) *TitleSummary
TitleAngle flattens a title for one camera angle (1-based); cells inside angle blocks are replaced by that angle's cell.
func (*Disc) Titles ¶
func (d *Disc) Titles() []TitleSummary
Titles flattens every title (following PGC chains in program order).
type FileExtent ¶
type FileExtent struct {
File string `json:"file"`
Offset int64 `json:"offset"`
Length int64 `json:"length"`
}
FileExtent is a byte range in a named file.
type Jump ¶
type Jump struct {
Op JumpOp
TTN int
PTTN int
Domain Domain
Menu int // menu type for JumpSS/CallSS
VTS int
PGCN int
HasPGCN bool
RsmCell int
}
Jump is a decoded jump/call target.
type LangUnit ¶
type LangUnit struct {
Language string `json:"language"`
Exists int `json:"exists"`
PGCs []PGCEntry `json:"pgcs"`
}
LangUnit is a menu language unit.
type Link ¶
type Link struct {
Op LinkOp
N int // PGCN / PTTN / PGN / CN
Button int // button to highlight (0 = unchanged)
}
Link is a decoded link target.
type MenuButton ¶
type MenuButton struct {
N int `json:"n"`
X0 int `json:"x0"`
Y0 int `json:"y0"`
X1 int `json:"x1"`
Y1 int `json:"y1"`
Up int `json:"up"`
Down int `json:"down"`
Left int `json:"left"`
Right int `json:"right"`
Auto bool `json:"auto"`
Cmd Command `json:"-"`
CmdText string `json:"cmd"`
Select *RGBA `json:"-"`
Action *RGBA `json:"-"`
Inert bool `json:"inert,omitempty"` // no visible highlight and no command
}
MenuButton is a button in frame coordinates with its highlight artwork.
type MenuPicture ¶
type MenuPicture struct {
FrameW, FrameH int
Aspect float64 // 4/3 or 16/9
Buttons []MenuButton
DefaultButton int
Normal *RGBA // sub-picture as shown with nothing selected
ButtonsFromSec float64
HasHighlights bool
Scrambled bool
NoButtons bool
// ForcedSelect is the button the disc highlights when the menu appears
// (FOSL_BTNN); it wins over SPRM8. 0 = none.
ForcedSelect int
// ForcedAction is the button the disc activates by itself when button
// selection ends (FOAC_BTNN) at ActionAtSec into the cell. 0 = none.
ForcedAction int
ActionAtSec float64
}
MenuPicture is everything a client needs to draw and operate a menu.
func ScanMenu ¶
func ScanMenu(rd SectorReader, first, last uint32, o MenuScanOptions) (*MenuPicture, error)
ScanMenu finds the highlight information for the cell [first,last] by hopping NAV pack to NAV pack, then reads the surrounding VOBUs for the sub-picture that carries the button artwork.
func (*MenuPicture) WithDefault ¶
func (p *MenuPicture) WithDefault(navButton int) *MenuPicture
WithDefault returns a copy whose DefaultButton follows the DVD rules: a forced selection first, then the navigator's SPRM8 highlight, then the first usable button.
type MenuScanOptions ¶
type MenuScanOptions struct {
Palette [16]uint32
Video VideoAttr
SubpControl *SubpControl // from the PGC, picks the SPU stream per display mode
Wide bool // viewer wants 16:9 presentation
MaxHops int
ReadAhead int // sectors to read once buttons are found
}
MenuScanOptions tune ScanMenu.
type Nav ¶
type Nav struct {
// contains filtered or unexported fields
}
Nav is a DVD navigator for one viewer.
func (*Nav) Clone ¶
Clone returns an independent navigator in the same state (for what-if exploration such as `wms dvd crawl`).
func (*Nav) GoUp ¶
GoUp is the remote's RETURN key: follow the PGC's go-up link, or resume the title when there is none.
func (*Nav) NavTimerFired ¶
NavTimerFired handles SPRM9 expiry: jump to the PGC named in SPRM10.
func (*Nav) NextChapter ¶
NextChapter / PrevChapter move within the current title.
func (*Nav) OpenMenu ¶
OpenMenu starts the disc directly in one of its menus ("title" for the disc's title menu, or root/chapter/audio/subpicture/angle of title set vts). Discs that insist on running first-play before their menus fall back to a normal start.
func (*Nav) PressButton ¶
PressButton activates button n with its 8-byte command (from the PCI).
func (*Nav) PrevChapter ¶
func (*Nav) SelectButton ¶
SelectButton highlights button n without activating it.
func (*Nav) SetSubpicture ¶
func (*Nav) SyncTitleCell ¶
SyncTitleCell tells the navigator which cell of the current title the viewer has reached. Clients play a whole title as one stream, so without this the navigator would still think it is on the first cell when the viewer calls a menu (and Resume would restart from there).
type Opened ¶
type Opened struct {
Disc *Disc
Source Source
Label string
Format string
// contains filtered or unexported fields
}
Opened is a DVD ready for navigation and playback.
func (*Opened) CellExtents ¶
func (o *Opened) CellExtents(sp Space, c Cell) ([]FileExtent, error)
CellExtents maps a cell (following interleaving) onto file byte extents.
func (*Opened) CellRanges ¶
func (o *Opened) CellRanges(sp Space, c Cell) ([]SectorRange, error)
CellRanges returns the sectors that belong to one cell. Ordinary cells are one contiguous range; interleaved cells are the VOBUs carrying their ids.
func (*Opened) CellSubpictures ¶
CellSubpictures reads a cell once and returns its sub-picture units (cached per disc). The read is sequential in 1 MiB chunks; the cost is a single pass over the cell's bytes.
func (*Opened) Extents ¶
func (o *Opened) Extents(sp Space) ([]FileExtent, error)
Extents returns the VOB address space extents (cached).
func (*Opened) Menu ¶
func (o *Opened) Menu(sp Space, first, last uint32, opt MenuScanOptions) (*MenuPicture, error)
Menu scans a cell for its highlight information, caching the result per disc so revisiting a menu (or moving the highlight) never touches the disk.
func (*Opened) RangeExtents ¶
func (o *Opened) RangeExtents(sp Space, first, last uint32) ([]FileExtent, error)
RangeExtents maps sectors [first,last] of a space onto file byte extents.
type PCI ¶
type PCI struct {
VOBUStartPTM uint32
VOBUEndPTM uint32
HLStatus int // 0 none, 1 new, 2 same, 3 same but commands differ
HLStartPTM uint32
HLEndPTM uint32
SelectEndPTM uint32
Groups []ButtonGroup
ButtonCount int
FirstButton int
NumericButtons int
ForcedSelect int
ForcedAction int
Buttons []Button
Schemes [3]struct{ Select, Action Look }
}
PCI is the parsed presentation control information of a NAV pack.
type PGC ¶
type PGC struct {
Duration float64 `json:"durationSec"`
Programs []int `json:"programs"` // entry cell number (1-based) per program
Cells []Cell `json:"cells"`
AudioControl [8]int `json:"audioControl"` // stream number or -1
SubpControl [32]*SubpControl `json:"-"`
Palette [16]uint32 `json:"palette"` // 0x00YYCrCb
UOPs uint32 `json:"uops"`
NextPGCN int `json:"nextPgcn"`
PrevPGCN int `json:"prevPgcn"`
GoUpPGCN int `json:"goUpPgcn"`
StillTime int `json:"stillTime"`
PlaybackMode int `json:"playbackMode"`
Pre []Command `json:"-"`
Post []Command `json:"-"`
CellCmds []Command `json:"-"`
}
PGC is a program chain.
func (*PGC) SetsHighlight ¶
SetsHighlight reports whether the PGC's pre-commands select a button (SetHL_BTNN) before its cells play, the mark of an interactive screen inside a title (voting, games). Links that merely carry a button number for the menu the title returns to (common at the end of features) don't count.
type PGCEntry ¶
type PGCEntry struct {
Entry bool `json:"entry"`
TitleNumber int `json:"titleNumber"` // VTS title number (title domain)
MenuType int `json:"menuType"` // menu domain: 2 title,3 root,4 subp,5 audio,6 angle,7 chapter
BlockMode int `json:"blockMode"`
BlockType int `json:"blockType"`
PGC *PGC `json:"-"`
}
PGCEntry is a PGCIT row: a PGC plus its category.
type PackScanner ¶
type PackScanner struct {
Out *StreamScan
// Streams limits SPU collection to these sub-picture stream numbers
// (bit n = stream n); 0 collects every stream.
Streams uint32
NoNav bool
// contains filtered or unexported fields
}
PackScanner walks MPEG-PS packs incrementally and pulls out NAV packs and complete SPU units. Units may span calls to Feed, so a long cell can be read in chunks without holding it all in memory.
func NewPackScanner ¶
func NewPackScanner() *PackScanner
NewPackScanner returns a scanner with an empty result.
func (*PackScanner) Feed ¶
func (ps *PackScanner) Feed(buf []byte, firstSector uint32)
Feed scans whole sectors of buf; firstSector labels the results.
type RGBA ¶
RGBA is a premultiplied-free 8-bit RGBA bitmap.
type RegisterOptions ¶
type RegisterOptions struct {
MenuLanguage string
AudioLanguage string
SubtitleLanguage string
Region int // 1-8
Angle int // initial camera angle (0 = 1)
Rand func() float64
}
RegisterOptions seeds player preferences.
type Registers ¶
type Registers struct {
GPRM [16]uint16
Counter [16]bool // GPRM counter mode (increments once per second)
SPRM [24]uint16
Rand func() float64
// contains filtered or unexported fields
}
Register file of the DVD virtual machine.
func NewRegisters ¶
func NewRegisters(o RegisterOptions) *Registers
NewRegisters builds a register file with spec defaults.
type Result ¶
type Result struct {
Kind ResultKind
Link *Link
Jump *Jump
Reason string
Steps int
}
Result of running a command list.
type ResultKind ¶
type ResultKind int
ResultKind says how a command list ended.
const ( ResultEnd ResultKind = iota // ran off the end ResultBreak // Break ResultExit // Exit ResultLink ResultJump ResultStop // invalid command / runaway )
type RunOptions ¶
type RunOptions struct {
Start int // 0-based first instruction
Once bool // run exactly one instruction (cell commands, button commands)
}
RunOptions tune Run.
type SPU ¶
type SPU struct {
X, Y int
Width, Height int
Pixels []byte // one code (0..3) per pixel
Color [4]int
Contrast [4]int
Forced bool
StartSec float64
StopSec float64 // <0 when absent
Truncated bool
}
SPU is a decoded sub-picture: a 2-bit indexed bitmap plus its default look.
func (*SPU) RenderRect ¶
RenderRect paints the part of the SPU inside the given frame rectangle (inclusive, frame coordinates) with the look. Pixels outside the SPU stay transparent. Result coordinates are the clipped rectangle.
type SectorRange ¶
type SectorRange struct{ First, Last uint32 }
SectorRange is an inclusive run of sectors in a VOB address space.
type SectorReader ¶
SectorReader reads sectors of a VOB address space (menu VOB or the concatenated title VOBs of a title set).
type Source ¶
type Source interface {
ReadIFO(name string) ([]byte, error)
// VOBExtents returns the byte extents (in the backing file(s)) of the VOB
// address space, in order. Each extent names its file.
VOBExtents(sp Space) ([]FileExtent, error)
Close() error
Describe() string
}
Source abstracts an ISO image or a VIDEO_TS folder.
type Step ¶
type Step struct {
Kind StepKind `json:"kind"`
Domain Domain `json:"-"`
DomainName string `json:"domain"`
VTS int `json:"vts"`
PGCN int `json:"pgcn"`
CellN int `json:"cellN"`
FirstSector uint32 `json:"firstSector"`
LastSector uint32 `json:"lastSector"`
StillSec float64 `json:"stillSec"` // +Inf = wait for the viewer
Loop bool `json:"loop"`
Palette [16]uint32 `json:"palette"`
DefaultButton int `json:"defaultButton"`
Serial int `json:"serial"`
Reason string `json:"reason,omitempty"`
Hold bool `json:"hold,omitempty"`
Resumed bool `json:"resumed,omitempty"`
Title *TitleInfo `json:"title,omitempty"`
CellDuration float64 `json:"cellDurationSec"`
}
Step is the navigator's instruction to the presentation layer.
type StreamScan ¶
StreamScan is the result of scanning a run of VOB sectors.
func ScanSectors ¶
func ScanSectors(buf []byte, firstSector uint32) *StreamScan
ScanSectors walks MPEG-PS packs and pulls out NAV packs and SPU units. firstSector is only used to label results.
type SubpAttr ¶
type SubpAttr struct {
Language string `json:"language,omitempty"`
Extension int `json:"extension"`
}
SubpAttr describes a sub-picture stream.
type SubpControl ¶
type SubpControl struct {
Narrow, Wide, Letterbox, PanScan int
}
SubpControl says which sub-picture stream to use per display mode.
type TitleInfo ¶
type TitleInfo struct {
TTN int `json:"ttn"`
VTSTTN int `json:"vtsTtn"`
PTTN int `json:"pttn"`
Cells []Cell `json:"-"`
CellNums []int `json:"cellNums"`
Duration float64 `json:"durationSec"`
}
TitleInfo describes the title being played in a title step.
type TitleSearch ¶
type TitleSearch struct {
Number int `json:"number"`
VTS int `json:"vts"`
VTSTitle int `json:"vtsTitle"`
Angles int `json:"angles"`
Chapters int `json:"chapters"`
Parental int `json:"parental"`
PlayType int `json:"playType"`
VTSSector uint32
}
TitleSearch is one TT_SRPT row.
type TitleSummary ¶
type TitleSummary struct {
Number int `json:"number"`
VTS int `json:"vts"`
VTSTitle int `json:"vtsTitle"`
Duration float64 `json:"durationSec"`
Chapters []float64 `json:"chapters"` // chapter start offsets in seconds
Angles int `json:"angles"`
Audio []AudioAttr `json:"audio"`
Subp []SubpAttr `json:"subtitles"`
Video VideoAttr `json:"video"`
Cells []TitleCell `json:"-"`
}
TitleSummary is a flattened view of one title.
type VMG ¶
type VMG struct {
Version int
RegionMask int // bit set = region prohibited
NumTitleSets int
Provider string
FirstPlay *PGC
Titles []TitleSearch
Menus []LangUnit
MenuVideo VideoAttr
MenuAudio []AudioAttr
MenuSubp []SubpAttr
MenuVOBSec uint32
}
VMG is VIDEO_TS.IFO.
type VTS ¶
type VTS struct {
Number int
Version int
Menus []LangUnit
PGCs []PGCEntry
PTT [][]PTT // per VTS title (1-based title - 1)
MenuVideo VideoAttr
MenuAudio []AudioAttr
MenuSubp []SubpAttr
Video VideoAttr
Audio []AudioAttr
Subp []SubpAttr
MenuVOBSec uint32
TitleVOBSec uint32
}
VTS is VTS_xx_0.IFO.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
wittydvd
command
Command wittydvd inspects DVD-Video images and VIDEO_TS folders with the WittyDVD engine: titles, menus and languages, the disc's program, a simulated run through its menus, and the menu artwork.
|
Command wittydvd inspects DVD-Video images and VIDEO_TS folders with the WittyDVD engine: titles, menus and languages, the disc's program, a simulated run through its menus, and the menu artwork. |
|
wittydvdplayer
module
|