wittydvd

package module
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

README

WittyDVD

Plays DVD images and VIDEO_TS folders in WittyMediaServer the way a DVD player does, with their real menus. You need it if your disc libraries hold DVDs.

A DVD's own animated menu in a browser

The disc's own menu, in a browser. Sintel, Blender Foundation, CC BY 3.0, from its original DVD.

A disc's page

A disc's page in WittyMediaServer. Sintel, Blender Foundation, CC BY 3.0.

A disc in the tray

A disc going in. Sintel, Blender Foundation, CC BY 3.0.

The Playback and discs page in Settings

Settings, Playback & discs, in WittyMediaServer.

What it does

  • Plays the disc's own program: first play, menus with highlighted buttons, titles, chapters, angles, audio and subtitle choices, stills, resume points and parental blocks. It runs the disc's commands in a small virtual machine.
  • Reads without mounting: .iso and .img images and VIDEO_TS folders, through WittyDisc.
  • Draws subtitles and button highlights from the disc's own sub-pictures and palette.
  • Copes with damage: each table of an index file is read from whichever copy (IFO or .BUP) has it whole, tables that disagree are mended from the ones that agree, and unreadable sectors are passed over. Malformed tables, commands and sub-pictures are refused rather than trusted. See docs/QUIRKS.md.
  • Refuses scrambled discs. CSS-protected images are detected and refused with a clear message. Nothing is ever decrypted. The server makes its own check as well, whatever a module says.
  • Tells you what's on a disc. The wittydvd command-line tool lists titles and menus, simulates a run through the menus, and reports dead ends.
  • Finds the film among decoys. A scoring engine ranks every title from the unencrypted index and the disc's own commands, and says how sure it is and why. It looks at distinct video, cells replayed, shuffled, hollow, overlapping or missing from the disc's own address tables, title sets with no video, looping chains, where first play and the menu's Play button go, and which titles nothing leads to. It finds a film that only the disc's commands put together, a film cut into several titles, a TV disc's episodes and its play-all title, and the angles and cuts of a film. It doesn't bypass CSS. See docs/TITLE-HEURISTICS.md.

Decoding the video and audio is left to the player: WittyDVD says which bytes to play, when, and what to draw over them. Turning those steps into streams stays with the server.

How to use it is in Help inside WittyMediaServer: see DVDs. How titles are ranked is in docs/TITLE-HEURISTICS.md, and what odd discs do and how each case is handled in docs/QUIRKS.md. None of the title mapping has been run against a physical disc yet: it is tested on synthetic discs that the test code writes.

How to get it

An admin adds it from the module store inside WittyMediaServer: Settings → Modules, then Browse the store, then Add beside WittyDVD. That needs WittyMediaServer 0.6.0-alpha or later, and it works with nothing older. The range this version fits is in module.json: 0.6.0-alpha through 0.6.x.

What it needs

  • FFmpeg, which comes with the server.
  • WittyDisc, which reads the images, and WittyModule, which is how a server talks to it. Both are built in.
  • No media comes with it.

It's written in Go with no cgo, from the published disc structure.

Platforms

A program is built for each system below, and the server uses the right one.

System Where it stands
Linux (x64, arm64, 32-bit ARM, x86) Its tests pass on x64, and a DVD title has played in a browser from a test server with it installed. The other CPUs are only built
Windows (x64, arm64) Built. This version hasn't been run on Windows since it became its own program
macOS (Intel, Apple silicon) Built by the release tool. It has not been run on a real Mac
FreeBSD (amd64, arm64) Cross-compiled only. It has not been run

On macOS and FreeBSD the server has no sandbox for a module's helper: it gets a small environment and a soft memory limit, and nothing more.

Its part of every app

A DVD's page in every WittyMediaServer app comes from this module's own sdui.json (module API 4), kept equal to UI() in sdui.go by a test, so any app that draws the server's interface shows it in every look with no code of its own. Between the title's header and its cast, in this order, each section left out when it has nothing to show:

Section What it shows
This disc can't be played An encrypted disc: what happened, that nothing was changed or copied, and what the disc's index still says
Feature Presentation Play the film (the whole of it, however the disc cuts it up) and how many scenes it has
Scenes The film's chapters as pictures, each playing from its start
Episodes A TV disc's episodes in viewing order
Other versions Other cuts and camera angles than the one Play plays
Bonus material The disc's other titles worth watching, without its decoys
Disc menus Shortcuts straight into the disc's own menus
Why this title Which title is the film, why, how sure the engine is, and the other candidates
Diagnosis What was wrong with this copy and what was mended, and for an administrator Check this disc

Each section's source takes the page's title and answers for a DVD only. The module's service answers them (module API 5, package api), asking the server's host API for what only the server keeps and checks: this module's ranking, read by its helper and checked by the server, and an administrator's choice of film. The names given to its titles are its own, in its own database. Their rows run its own commands (wittydvd.choose, wittydvd.clearChoice, wittydvd.rank), which are its routes under /api/modules/wittydvd/discs/{id}. The player is each app's own: playing the disc, its menus and buttons, and the remote are the app's native player screen, not SDUI; in a browser it is WittyDisc's web part. The module has no settings page: the server's disc settings are WittyDisc's Settings, DVDs and Blu-rays.

Why these sections are SDUI, and the rest isn't. A disc module doesn't need SDUI to work. These sections are SDUI only because they are plain rows of a title's page that every app already knows how to draw: as SDUI, the iPhone, Apple TV and Android apps show a DVD's feature, scenes, episodes, versions and why this title with no code of their own, and the same words as the web. What stays each app's own, on purpose:

  • Playing the disc, its menus and buttons, and the remote: drawn frame by frame from the disc, with timing and focus no page description could carry.
  • Disc settings and naming titles and scenes: an administrator's dialogs on the web's title page (Manage this title, WittyDisc's), writing to the server's PUT /api/items/{id} and this module's PUT /api/modules/wittydvd/discs/{id}/labels.
  • The server-wide disc settings: WittyDisc's hand-built Settings, DVDs and Blu-rays.
  • WittyMediaPlayer's disc screens: the desktop player draws its own.

Building and testing

You need Go 1.26 or newer. In a worktree, first run the copy of dev-modules.mjs kept above the repositories (node D:/projects/dev-modules.mjs on the development machine). It writes a go.work that git ignores, so the checkout builds against the repositories beside it. Never run go work use.

go vet ./...
go test ./... -count=1
go run github.com/wittywilla/wittymodule/cmd/wittymodule check .

The parsers are fuzzed. Each target's seeds run with every test; to explore further, one target at a time:

go test -run '^$' -fuzz '^FuzzOpenDisc$' -fuzztime 1m .

The targets are FuzzParseVMG, FuzzParseVTS, FuzzOpenDisc, FuzzNavPack, FuzzVOB, FuzzSPU, FuzzVM, FuzzNav, FuzzRankTitles and FuzzParsers, and FuzzDecode in ./wire.

The last one checks the manifest. On the same tool, pack -targets linux/amd64 -out release . builds a release for one system. CI also builds for every system.

To look at a disc by hand:

go run ./cmd/wittydvd info MY_DISC.ISO
Command What it shows
wittydvd info <disc> Titles, menus, languages and the first-play program
wittydvd rank <disc> [json] Which title is the film, the episodes and decoys, how sure it is and why
wittydvd walk <disc> [button...] Simulates inserting the disc, then pressing menu buttons by number
wittydvd crawl <disc> Presses every button of every menu and reports dead ends
wittydvd pgc <disc> <fp, vmgm, vtsm or vts> <vts> <pgcn> The commands of one program chain
wittydvd render <disc> <dir> The first menu's highlight pictures
wittydvd disc ls <disc> The files inside the image

To use it as a library, wittydvd.Open opens an image or folder, and wittydvd.NewNav gives a navigator: Start, PressButton, CellEnded and the rest return what to do next. Disc.MainTitle, Disc.RankTitles, Disc.Episodes and Disc.Explain say which title is which, and Opened.Analyze adds the menus' buttons and gives the whole answer: the pick with its confidence and evidence, what to play for it, its versions, and the episodes. A server gets the same from the helper's analyze call.

wittydvdplayer/ is the same engine as a program of its own for WittyMediaPlayer, with its own go.mod and manifest.

Licence

GNU Affero General Public License v3.0 (or later): see LICENSE and NOTICE. If you redistribute it or build on it, please keep the NOTICE attribution. It's an original implementation and contains no code from other disc libraries. Each release archive carries a THIRD-PARTY-NOTICES.txt for what its programs link.

WittyDVD is an independent open-source project. It isn't associated with, sponsored by or endorsed by the DVD format's owners, any film studio or any other player project. “DVD” is a trademark of DVD Format/Logo Licensing Corporation; WittyDVD isn't a licensed or certified DVD product and uses no DVD logo. CSS-scrambled discs are refused, nothing is decrypted, and no media comes with it: you're responsible for having the rights to what you open. Any third-party names here only describe what it works with, and belong to their owners. It's provided “as is”, with no warranty; see LICENSE. Local law applies to how you use it. This isn't legal advice.

Releasing

A version tag builds a program for every platform, signs the checksum list, and publishes a release that servers can install.

Versions move in small steps as work lands. go run github.com/wittywilla/wittymodule/cmd/wittymodule@v0.4.0 bump . raises it everywhere it is written (add -part minor for a bigger step). A bump isn't a release: nothing is tagged or published until you tag it. CI fails when code changed since the last tag and the version didn't, because tags never move.

To release:

  1. Check that version in module.json is the one to publish, with the bump committed.
  2. Tag that commit and push the tag: git tag vX.Y.Z, then git push origin vX.Y.Z. A tag with a suffix, such as v1.2.0-beta, is published as a prerelease.
  3. Watch the Actions tab. The signing step uses the WMS_SIGNING_KEY secret of the release environment, and nothing is published without it.

To take a version back, run the withdraw workflow from the Actions tab. It adds the version to a signed list on the release tagged withdrawals, which servers read.

Licensed under AGPL-3.0-or-later: see LICENSE and NOTICE.

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

View Source
const (
	ClassMain       = "main"
	ClassPlayAll    = "playAll"
	ClassEpisode    = "episode"
	ClassDecoy      = "decoy"
	ClassDuplicate  = "duplicate"
	ClassAlternate  = "alternate"
	ClassPart       = "part"
	ClassIntro      = "intro"
	ClassStub       = "stub"
	ClassTrailer    = "trailer"
	ClassFeaturette = "featurette"
	ClassExtra      = "extra"
)

Title classes.

View Source
const (
	SourceFeature  = ModuleID + ".feature"
	SourceScenes   = ModuleID + ".scenes"
	SourceEpisodes = ModuleID + ".episodes"
	SourceVersions = ModuleID + ".versions"
	SourceBonus    = ModuleID + ".bonus"
	SourceMenus    = ModuleID + ".menus"
	SourceWhy      = ModuleID + ".why"
	SourceCopy     = ModuleID + ".copy"
	SourceRefusal  = ModuleID + ".refusal"
)

The sources of a DVD's sections on its page. Each takes the page's title ($item) and answers only for a DVD: on any other title its sections are left out. WittyDVD's service answers them (package api; the commands are package commands, with no networking, for the player), asking the server's host API for what only the server keeps: the disc's ranking from this module's helper, checked there, and an administrator's choice of film. The names given to its titles are WittyDVD's own.

View Source
const (
	SprmMenuLang  = 0
	SprmAudio     = 1
	SprmSubp      = 2
	SprmAngle     = 3
	SprmTTN       = 4
	SprmVTSTTN    = 5
	SprmTTPGCN    = 6
	SprmPTTN      = 7
	SprmHLBTNN    = 8
	SprmNavTimer  = 9
	SprmNavPGCN   = 10
	SprmAudioMix  = 11
	SprmCountry   = 12
	SprmParental  = 13
	SprmVideoMode = 14
	SprmAudioCap  = 15
	SprmAudioLang = 16
	SprmAudioExt  = 17
	SprmSubpLang  = 18
	SprmSubpExt   = 19
	SprmRegion    = 20
)

SPRM indexes.

View Source
const MaxIFOBytes = 16 << 20

MaxIFOBytes bounds how much of an IFO we read.

View Source
const ModuleID = "wittydvd"

ModuleID is this module's ID, the same as module.json's.

View Source
const Sector = 2048
View Source
const VideoStreamID = 0x1e0

VideoStreamID is the MPEG-PS stream id of a DVD's video, as ffmpeg reports it.

Variables

View Source
var DefaultWeights = Weights{
	DistinctPerMinute: 1,
	OutOfRangeAny:     -10,
	OutOfRangeShare:   -20,
	Repeats:           -30,
	BackJumpAny:       -5,
	BackJumpShare:     -35,
	Shuffled:          -25,
	Duplicate:         -0.5,
	CellSpam:          -30,
	AbsurdCell:        -20,
	Loop:              -15,
	BadChapters:       -10,
	RegularChapters:   3,
	AudioMatch:        2,
	SubpMatch:         1,
	LargestVTS:        5,
	FirstPlay:         15,
	MenuReference:     4,
	MenuPlay:          25,
	UnlistedAny:       -8,
	UnlistedShare:     -25,
	OffVOBUShare:      -10,
	HollowShare:       -20,
	Overlap:           -15,
	Unreachable:       -25,
	FirstMenuJump:     6,
	TimeMismatch:      -3,
	NoVideo:           -60,

	FirstPlayPerMinute: 0.25,
	MenuPlayPerMinute:  0.35,
	Scrambled:          -25,
	NoAudio:            -20,
}

DefaultWeights are the weights MainTitle uses.

View Source
var ErrBadIFO = errors.New("dvd: malformed IFO")
View Source
var ErrNoNav = errors.New("dvd: no NAV pack at cell start")
View Source
var ErrSPU = errors.New("dvd: malformed sub-picture")
View Source
var ManifestJSON []byte

ManifestJSON is this module's manifest (docs/MODULES.md, "The manifest").

View Source
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

func PackScrambled(pack []byte) bool

PackScrambled reports CSS scrambling on the first PES of a pack.

func UI added in v0.4.0

func UI() *sdui.Module

UI is WittyDVD's part of every app (module API 5, WittyMediaServer docs/SDUI-MODULES.md), written to sdui.json beside module.json: a DVD's sections on its page, in every look (Design 2's "discpage", "whytitle" and "discrefuse" boards), the TV apps' among them, and the commands its rows run (choosing the film, ranking again), each one of its own routes. The player, with the disc's own menus and the remote, is WittyDisc's in a browser and each app's own screen elsewhere.

func YCrCbToRGB

func YCrCbToRGB(y, cr, cb int) (r, g, b uint8)

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.

func (AudioAttr) Karaoke added in v0.3.0

func (a AudioAttr) Karaoke() bool

Karaoke says the stream is a karaoke mix: backing on the front channels, the guide melody and vocals on the others.

func (AudioAttr) Purpose

func (a AudioAttr) Purpose() string

Purpose names an audio stream's code extension (empty for plain audio).

func (AudioAttr) StreamID

func (a AudioAttr) StreamID(n int) int

StreamID is the MPEG-PS stream id ffmpeg gives physical audio stream n of this format (0 when the format has no fixed id).

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 ButtonCommand added in v0.4.0

type ButtonCommand struct {
	Domain Domain  `json:"domain"` // DomainVMGM or DomainVTSM
	VTS    int     `json:"vts"`    // 0 for the VMGM
	Unit   int     `json:"unit"`   // language unit, 0-based
	PGCN   int     `json:"pgcn"`
	Cmd    Command `json:"cmd"`
}

ButtonCommand is the command of one menu button, with the program chain whose cell shows it.

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 Candidate added in v0.4.0

type Candidate struct {
	TitleNum int      `json:"title"`
	VTS      int      `json:"vts"`
	VTSTitle int      `json:"vtsTitle"`
	PGC      int      `json:"pgc"` // the title's first PGC
	Duration float64  `json:"durationSec"`
	Distinct float64  `json:"distinctSec"` // each readable cell counted once
	Chapters int      `json:"chapters"`
	Cells    int      `json:"cells"`
	Score    float64  `json:"score"`
	Class    string   `json:"class"`
	Flags    Flag     `json:"flags"`
	Reasons  []string `json:"reasons"`
	// Evidence is Reasons in a form a program can read: one entry per
	// signal, with its points.
	Evidence []Evidence `json:"evidence,omitempty"`
	// Path says how the title's cells were found: "chapters" (its chapter
	// table and next-PGC links) or "commands" (a dry run of its own
	// commands, where that shows more of the film).
	Path string `json:"path,omitempty"`
	// ChapterSource says where the chapter times come from (see
	// TitleSummary.ChapterSource).
	ChapterSource string `json:"chapterSource,omitempty"`
	// Angles is how many camera angles the title has.
	Angles int `json:"angles,omitempty"`
	// Continues is the title the disc goes on to by itself when this one
	// ends, and PartOf the title a feature in several parts starts at.
	Continues int `json:"continues,omitempty"`
	PartOf    int `json:"partOf,omitempty"`
	// contains filtered or unexported fields
}

Candidate is one title as the engine scored it.

func (Candidate) Summary added in v0.4.0

func (c Candidate) Summary() *TitleSummary

Summary is the flattened title the candidate was scored from.

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 CellAddr added in v0.4.0

type CellAddr struct {
	VOBID  int    `json:"vobId"`
	CellID int    `json:"cellId"`
	First  uint32 `json:"firstSector"`
	Last   uint32 `json:"lastSector"`
}

CellAddr is one row of a cell address table: a piece of a cell and the sectors it occupies in its VOB. An interleaved cell has several rows.

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 ColConColumn added in v0.3.0

type ColConColumn struct {
	Column   int
	Color    [4]int
	Contrast [4]int
}

ColConColumn is one pixel-control entry of a CHG_COLCON line range.

type ColConLines added in v0.3.0

type ColConLines struct {
	FirstLine, LastLine int
	Columns             []ColConColumn
}

ColConLines is one CHG_COLCON line range: from each column rightwards (to the next one) pixels take that entry's colours and contrasts.

type Command

type Command [8]byte

Command is one 8-byte VM instruction.

type DSI

type DSI struct {
	SCR     uint32
	LBN     uint32
	VOBUEnd uint32 // relative end address: VOBU spans LBN..LBN+VOBUEnd
	// FirstRefEnd is the relative end of the VOBU's first reference
	// picture; 0 when the VOBU carries no video at all (audio-only VOBUs
	// after a cell's picture has ended).
	FirstRefEnd uint32
	VOBID       int
	CellID      int
	// NoVideoAhead is set when the VOBU search information says no later
	// VOBU of the cell carries video (sri_nvwv = 0xbfffffff).
	NoVideoAhead bool
}

DSI is the parsed data search information of a NAV pack.

func ParseDSI

func ParseDSI(b []byte) *DSI

ParseDSI parses a DSI substream payload.

type Decision added in v0.4.0

type Decision struct {
	// Kind is what was decided: main (which title is the feature), feature
	// (what the feature is made of, when it isn't simply one title's
	// chapters), episodes, decoys or chapters (where the main title's
	// chapter times come from).
	Kind       string  `json:"kind"`
	Titles     []int   `json:"titles,omitempty"`
	Confidence float64 `json:"confidence"` // 0 to 1
	Level      string  `json:"level"`      // high, medium or low
	Summary    string  `json:"summary"`
	// Because and Against are the evidence for and against, strongest first.
	Because []Evidence `json:"because,omitempty"`
	Against []Evidence `json:"against,omitempty"`
	// RunnerUp is the best title that is something else than the pick, and
	// Margin how far behind it is, in points (kind main).
	RunnerUp int     `json:"runnerUp,omitempty"`
	Margin   float64 `json:"margin,omitempty"`
}

Decision is one thing the engine decided, how sure it is, and why.

type Disc

type Disc struct {
	VMG *VMG
	VTS map[int]*VTS
	// IFOReports says, per index file, whether the IFO or its .BUP backup
	// was used and why (filled by Open; empty for discs built by hand).
	IFOReports []IFOReport
	// Repairs lists where the disc's tables disagreed with each other, and
	// what was mended from which table (filled by Open; see CrossCheck).
	Repairs []Repair
}

Disc bundles the parsed IFOs of one DVD.

func (*Disc) Analyze added in v0.4.0

func (d *Disc) Analyze(opt RankOptions) *Ranking

Analyze scores and classifies every title.

func (*Disc) CrossCheck added in v0.4.0

func (d *Disc) CrossCheck() []Repair

CrossCheck compares the tables of the disc with each other, mends what one table can mend in another, and returns what it found. Open has already called it (see Disc.Repairs); calling it again finds nothing left to mend.

func (*Disc) Episodes added in v0.4.0

func (d *Disc) Episodes() []Episode

Episodes lists the episodes of a TV disc in viewing order; nil when the disc doesn't look like one.

func (*Disc) Explain added in v0.4.0

func (d *Disc) Explain() string

Explain words the ranking for people: the pick, why, and warnings.

func (*Disc) MainTitle

func (d *Disc) MainTitle() *TitleSummary

MainTitle guesses the feature with the title scoring engine (see Analyze): the title with the most distinct, readable video, marked down for the signs of decoys (cells replayed many times over or in scrambled order, cells outside the title VOB, zero-length cell spam, looping PGC chains) and up for what the disc's own first play reaches. It reads the IFOs only.

func (*Disc) ParentalMask added in v0.3.0

func (d *Disc) ParentalMask(country uint16, level, vts int) uint16

ParentalMask is the parental ID mask PTL_MAIT gives title set vts for a country (SPRM12) and parental level (SPRM13). Without parental control (level 15) the player acts at level 8, which permits everything; a country the table does not list uses the first entry. 0 means the disc has no table.

func (*Disc) RankTitles added in v0.4.0

func (d *Disc) RankTitles() []Candidate

RankTitles scores every title, best first, from the IFOs alone.

func (*Disc) Region

func (d *Disc) Region() int

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 Domain

type Domain int

Domain of playback.

const (
	DomainFP Domain = iota
	DomainVMGM
	DomainVTSM
	DomainVTS
)

func (Domain) String

func (d Domain) String() string

type Episode added in v0.4.0

type Episode struct {
	Index    int     `json:"index"` // 1-based viewing order
	Title    int     `json:"title"`
	VTS      int     `json:"vts"`
	PGC      int     `json:"pgc"`
	Duration float64 `json:"durationSec"`
	// StartSec and FirstChapter say where the episode begins inside Title.
	// They are 0 and 1 for a title that is one episode; a play-all title
	// that is the only way to the episodes is split, and they say where.
	StartSec     float64 `json:"startSec"`
	FirstChapter int     `json:"firstChapter"`
	// Source says how the episode was found: "titles" (a title of its own),
	// "pgcs" (one program chain of a play-all title) or "vobs" (one VOB of a
	// play-all title).
	Source string `json:"source"`
}

Episode is one episode of a TV disc, in viewing order.

type Evidence added in v0.4.0

type Evidence struct {
	Signal string  `json:"signal"`
	Points float64 `json:"points"`
	Detail string  `json:"detail"`
}

Evidence is one thing the engine weighed for a title: which signal, how many points it was worth (in minutes of video; 0 for a remark) and, in words, what was seen. Signal names are stable, for a server to key on.

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 Flag added in v0.4.0

type Flag uint32

Flag marks what the engine found out about a title.

const (
	FlagMain        Flag = 1 << iota // the engine's pick
	FlagDecoy                        // structure-protection decoy or junk
	FlagMenuTarget                   // a menu or first-play command jumps here
	FlagMenuPlay                     // the first menu's default ("Play") button plays this
	FlagFirstPlay                    // first play reaches this long title by itself
	FlagIntro                        // a short title first play passes on its way
	FlagEpisode                      // one episode of a TV disc
	FlagPlayAll                      // plays the episodes one after another
	FlagDuplicate                    // the same cells in the same order as a lower-numbered title
	FlagShuffled                     // another title's cells in a scrambled order
	FlagOutOfRange                   // cells outside the title VOB
	FlagRepeats                      // replays the same cells many times
	FlagCellSpam                     // many zero or sub-second cells
	FlagLoop                         // its PGC chain links back on itself
	FlagAbsurd                       // impossible cell durations
	FlagBadChapters                  // chapter table names PGCs or programs that don't exist
	FlagFromBackup                   // its title set was read from the .BUP copy
	FlagAlternate                    // mostly the main title's video (another cut)
	FlagUnlisted                     // cells the cell address table doesn't hold
	FlagHollow                       // cells that claim far more time than their sectors can hold
	FlagOverlap                      // cells that lie over each other on the disc
	FlagUnreachable                  // no command or button on the disc leads to it
	FlagAssembled                    // its cells are put together by commands, not its chapter table
	FlagPart                         // one part of a feature that runs on through several titles
	FlagNoVideo                      // its title set has no video files
	FlagTruncated                    // lists more cells than were read
)

func (Flag) Has added in v0.4.0

func (f Flag) Has(g Flag) bool

Has reports whether every flag in g is set.

func (Flag) MarshalJSON added in v0.4.0

func (f Flag) MarshalJSON() ([]byte, error)

MarshalJSON writes the flags as a list of names.

func (Flag) Names added in v0.4.0

func (f Flag) Names() []string

Names lists the flags set, in a fixed order.

func (Flag) String added in v0.4.0

func (f Flag) String() string

func (*Flag) UnmarshalJSON added in v0.4.0

func (f *Flag) UnmarshalJSON(b []byte) error

UnmarshalJSON reads a list of flag names; unknown names are ignored.

type IFOReport added in v0.4.0

type IFOReport struct {
	Name     string `json:"name"` // VIDEO_TS or VTS_nn_0
	VTS      int    `json:"vts"`  // 0 for the VMG
	Used     string `json:"used"` // IFO or BUP
	Mismatch bool   `json:"mismatch,omitempty"`
	Note     string `json:"note,omitempty"`
	// Tables says how each table read and which copy it was taken from: a
	// table damaged in one copy is taken from the other.
	Tables []TableReport `json:"tables,omitempty"`
}

IFOReport is what reading one IFO and its backup found.

type Instr

type Instr struct {
	Raw     Command
	Type    int
	Invalid string
	// contains filtered or unexported fields
}

Instr is a decoded VM instruction.

func Decode

func Decode(c Command) Instr

Decode decodes one 8-byte command.

func (Instr) String

func (in Instr) String() string

String renders a human readable form (for diagnostics).

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.

func (*Jump) String

func (j *Jump) String() string

type JumpOp

type JumpOp int

JumpOp enumerates jump/call commands.

const (
	JumpNone JumpOp = iota
	JumpExit
	JumpTT
	JumpVTSTT
	JumpVTSPTT
	JumpSS
	CallSS
)

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 struct {
	Op     LinkOp
	N      int // PGCN / PTTN / PGN / CN
	Button int // button to highlight (0 = unchanged)
}

Link is a decoded link target.

func (*Link) String

func (l *Link) String() string

type LinkOp

type LinkOp int

LinkOp enumerates link commands.

const (
	LinkNone LinkOp = iota
	LinkTopCell
	LinkNextCell
	LinkPrevCell
	LinkTopPG
	LinkNextPG
	LinkPrevPG
	LinkTopPGC
	LinkNextPGC
	LinkPrevPGC
	LinkGoUpPGC
	LinkTailPGC
	LinkRSM
	LinkPGCN
	LinkPTTN
	LinkPGN
	LinkCN
)

type Look

type Look struct {
	Color    [4]int
	Contrast [4]int
}

Look is a color+contrast table for pixel codes 0..3.

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 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
	// ButtonsUntilSec is when the buttons stop working, measured like
	// ButtonsFromSec: the earlier of the highlight end (HLI_E_PTM) and the
	// end of button selection (BTN_SL_E_PTM). 0 = until the cell ends.
	ButtonsUntilSec 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 (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 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
	NavButton   int          // SPRM8 highlight to prefer as default
	MaxHops     int
	ReadAhead   int // sectors to read once buttons are found
}

MenuScanOptions tune ScanMenu.

type Nav struct {
	Disc *Disc
	// contains filtered or unexported fields
}

Nav is a DVD navigator for one viewer.

func NewNav

func NewNav(d *Disc, o NavOptions) *Nav

NewNav creates a navigator over parsed IFOs.

func (n *Nav) CellEnded() *Step

CellEnded tells the navigator the shown cell (and still) finished.

func (n *Nav) Clone() *Nav

Clone returns an independent navigator in the same state, for what-if exploration.

func (n *Nav) Current() *Step

Current returns the last step.

func (n *Nav) GoUp() *Step

GoUp is the remote's RETURN key: follow the PGC's go-up link, or resume the title when there is none.

func (n *Nav) MenuKey(kind string) *Step

MenuKey handles the remote's TITLE / MENU (root) / etc. keys.

func (n *Nav) NavTimerFired() *Step

NavTimerFired handles SPRM9 expiry: jump to the PGC named in SPRM10.

func (n *Nav) NextChapter() *Step

NextChapter / PrevChapter move within the current title.

func (n *Nav) OpenMenu(kind string, vts int) *Step

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 (n *Nav) PlayTitle(ttn, pttn int) *Step

PlayTitle jumps straight to a title (and optional chapter).

func (n *Nav) PressButton(btn int, cmd *Command) *Step

PressButton activates button n with its 8-byte command (from the PCI).

func (n *Nav) PrevChapter() *Step
func (n *Nav) Registers() *Registers

Registers exposes the live register file (read-only use recommended).

func (n *Nav) Resume() *Step

Resume returns to the title that called the menu.

func (n *Nav) SelectButton(btn int) *Step

SelectButton highlights button n without activating it.

func (n *Nav) SetAngle(a int)
func (n *Nav) SetAudio(stream int)

SetAudio / SetSubpicture / SetAngle change the viewer's streams.

func (n *Nav) SetSubpicture(stream int, on bool)
func (n *Nav) Start() *Step

Start runs first-play and returns what to show.

func (n *Nav) StepPGC(st *Step) *PGC

StepPGC returns the program chain a step plays, resolved the way the navigator does (menu language unit, first play).

func (n *Nav) SyncTitleCell(pgcn, cellN int) bool

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).

func (n *Nav) Tick(seconds float64) *Step

Tick advances timers; returns a new step if the nav timer fired.

type NavOptions struct {
	RegisterOptions
}

NavOptions configure a navigator.

type NavPack struct {
	Sector uint32 // relative to the scan start
	PCI    *PCI
	DSI    *DSI
}

NavPack is the PCI+DSI found at the start of a VOBU.

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 Open

func Open(p string) (*Opened, error)

Open opens an ISO/IMG image or a VIDEO_TS directory.

func (*Opened) Analyze added in v0.4.0

func (o *Opened) Analyze() *Ranking

Analyze ranks the titles of an opened disc. On top of what the IFOs say (Disc.Analyze), it reads the real sizes of the VOB files and the menus' buttons from their NAV packs, which are never scrambled, and dry-runs the first menu's buttons in the disc's own VM. No video is decrypted: on a disc whose menus are scrambled the menu signals are simply missing.

The answer is worked out once and kept: an opened disc doesn't change.

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

func (o *Opened) CellSubpictures(sp Space, cell Cell) (*CellSubs, error)

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) Close

func (o *Opened) Close() error

Close releases the reader file handles and the source.

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.

func (*Opened) RankOptions added in v0.4.0

func (o *Opened) RankOptions() RankOptions

RankOptions gathers what an opened disc can add to the ranking: the sizes of the VOB files, the commands of the menus' buttons, and what the first menu's buttons play.

func (*Opened) ReadStats added in v0.4.0

func (o *Opened) ReadStats() ReadStats

ReadStats says how many sectors have been unreadable so far.

func (*Opened) Reader

func (o *Opened) Reader(sp Space) (SectorReader, error)

Reader returns a SectorReader over a space. Readers are shared and keep their file handles open until the disc is closed.

func (*Opened) TitleRuns added in v0.3.0

func (o *Opened) TitleRuns(sp Space, cells []TitleCell) ([]TitleRun, error)

TitleRuns groups the cells of a title (see Disc.Title) into runs. Cells join a run when they follow each other on the disc in one VOB and their times carry on; interleaved cells (angles, seamless branching) and anything the disc marks as a new time base stand alone.

type PCI

type PCI struct {
	NavLBN       uint32
	VOBUStartPTM uint32
	VOBUEndPTM   uint32
	// SeqEndPTM is the end of the video when this VOBU ends a video
	// sequence (sequence_end_code): a still picture the player holds.
	SeqEndPTM      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.

func ParsePCI

func ParsePCI(b []byte) *PCI

ParsePCI parses a PCI substream payload.

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:"-"`
	// contains filtered or unexported fields
}

PGC is a program chain.

func (*PGC) SetsHighlight

func (p *PGC) SetsHighlight() bool

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"`   // parental block: 1 first, 2 middle, 3 last
	BlockType   int  `json:"blockType"`   // 1 = parental block (alternative versions of a scene)
	// ParentalMask names the parental IDs this PGC is for; inside a parental
	// block the player plays the PGC whose mask matches PTL_MAIT for its level.
	ParentalMask int `json:"parentalMask"`
	// Damaged says the chain could not be read at all: PGC is then an empty
	// stand-in that keeps the row's number.
	Damaged bool `json:"damaged,omitempty"`
	PGC     *PGC `json:"-"`
}

PGCEntry is a PGCIT row: a PGC plus its category.

type PTT

type PTT struct {
	PGCN int `json:"pgcn"`
	PGN  int `json:"pgn"`
}

PTT is one chapter entry: PGC number and program number.

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 skips PCI/DSI parsing except for the first NAV pack.
	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 ParentalCountry added in v0.3.0

type ParentalCountry struct {
	Country string
	Masks   [8][]uint16
}

ParentalCountry is one country's parental management masks: Masks[level-1] holds one parental ID mask for the VMG (index 0) and each title set.

type Playlist added in v0.4.0

type Playlist struct {
	// Titles are the titles it runs through: one, unless the disc chains
	// several into one film.
	Titles   []int   `json:"titles"`
	Duration float64 `json:"durationSec"`
	// Source says how it was found: "chapters" (the title's chapter table),
	// "commands" (a dry run of the title's commands) or "chain" (several
	// titles the disc plays in a row).
	Source   string            `json:"source"`
	Segments []PlaylistSegment `json:"segments"`
}

Playlist is exactly what to play for a feature, in order.

type PlaylistSegment added in v0.4.0

type PlaylistSegment struct {
	Title       int     `json:"title"`
	VTS         int     `json:"vts"`
	PGC         int     `json:"pgc"`
	FirstCell   int     `json:"firstCell"`
	LastCell    int     `json:"lastCell"`
	StartSec    float64 `json:"startSec"`
	Duration    float64 `json:"durationSec"`
	FirstSector uint32  `json:"firstSector"`
	LastSector  uint32  `json:"lastSector"`
}

PlaylistSegment is a run of consecutive cells of one program chain.

type RGBA

type RGBA struct {
	X, Y          int
	Width, Height int
	Pix           []byte // 4 bytes per pixel
}

RGBA is a premultiplied-free 8-bit RGBA bitmap.

func (*RGBA) Crop

func (r *RGBA) Crop() *RGBA

Crop returns the bitmap trimmed to its visible pixels (zero size when nothing is visible). Subtitle units usually cover the whole frame.

func (*RGBA) Opaque

func (r *RGBA) Opaque() bool

Opaque reports whether any pixel is visible.

type RankOptions added in v0.4.0

type RankOptions struct {
	// MenuPlay is the title the first menu's default button plays (0 unknown).
	MenuPlay int
	// MenuTargets are titles any button of the first menu plays.
	MenuTargets []int
	// FileSectors is the real size of each title set's title VOBs in
	// sectors. By itself it only adds reasons (an incomplete copy), never
	// changes a score, so MainTitle's pick doesn't depend on it.
	FileSectors map[int]uint32
	// FilesKnown says FileSectors is the whole truth about the VOB files: a
	// title set missing from it has no video at all, and a cell that starts
	// past the end of its files can't be played. Those then count against a
	// title, as they should when a disc carries title sets that are only an
	// index.
	FilesKnown bool
	// Buttons are the commands of the menus' buttons, read from the menu
	// VOBs' NAV packs. ButtonsComplete says every menu cell was read, so a
	// title no command and no button leads to really is unreachable.
	Buttons         []ButtonCommand
	ButtonsComplete bool
	Weights         *Weights
}

RankOptions add what only an opened disc can tell.

type Ranking added in v0.4.0

type Ranking struct {
	Candidates []Candidate `json:"candidates"` // best first
	Main       int         `json:"main"`       // 0 when the disc has no title
	PlayAll    int         `json:"playAll,omitempty"`
	Episodes   []Episode   `json:"episodes,omitempty"`
	Decoys     []int       `json:"decoys,omitempty"`
	FirstPlay  int         `json:"firstPlay,omitempty"` // long title first play reaches
	MenuPlay   int         `json:"menuPlay,omitempty"`
	Warnings   []string    `json:"warnings,omitempty"`
	// Confidence is how sure the pick of the main title is, from 0 to 1, and
	// Level the same in a word: high, medium or low.
	Confidence float64 `json:"confidence"`
	Level      string  `json:"level,omitempty"`
	// Why is the pick of the main title explained: what spoke for it, what
	// against, and who came second. Decisions holds it together with the
	// other things decided (episodes, decoys, chapters, the feature's parts).
	Why       *Decision  `json:"why,omitempty"`
	Decisions []Decision `json:"decisions,omitempty"`
	// Feature is exactly what to play for the main feature: its cells in
	// order, across titles when the disc chains several into one film.
	Feature *Playlist `json:"feature,omitempty"`
	// Versions lists the ways the main feature can be seen: camera angles,
	// the cuts parental levels choose, and other titles that are mostly the
	// same video (another cut).
	Versions []Version `json:"versions,omitempty"`
	// Reachable lists the titles the disc's own commands can get to from
	// first play, by a static reading of every command. ButtonsRead says the
	// menus' button commands were part of that reading; without them a
	// title may be missing here only because a button names it.
	Reachable   []int `json:"reachable,omitempty"`
	ButtonsRead bool  `json:"buttonsRead,omitempty"`
}

Ranking is the engine's full answer for a disc.

func (*Ranking) Candidate added in v0.4.0

func (r *Ranking) Candidate(title int) *Candidate

Candidate returns the scored title by number, or nil.

func (*Ranking) Explain added in v0.4.0

func (r *Ranking) Explain() string

Explain words a ranking for people: the pick, the top candidates with their reasons, and the warnings.

type ReadStats added in v0.4.0

type ReadStats struct {
	// BadSectors is how many sectors could not be read and were handed on
	// as zeros, the way a copying tool pads what a scratched disc won't give.
	BadSectors int64 `json:"badSectors"`
	// Retries is how many reads were tried again after a fault.
	Retries int64 `json:"retries"`
}

ReadStats counts what reading the VOBs of an opened disc has cost so far.

type RegisterOptions

type RegisterOptions struct {
	MenuLanguage     string
	AudioLanguage    string
	SubtitleLanguage string
	Region           int    // 1-8
	Parental         int    // 1-8; 0 = no limit
	Country          string // two letters; "" = US
	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.

func (*Registers) Clone

func (r *Registers) Clone() *Registers

Clone copies the register file.

func (*Registers) Run

func (r *Registers) Run(cmds []Command, o RunOptions) Result

Run executes a command list against the registers.

func (*Registers) Tick

func (r *Registers) Tick(seconds float64) bool

Tick advances the wall clock: counter GPRMs increment, the navigation timer counts down. Returns true when the nav timer just expired.

type Repair added in v0.4.0

type Repair struct {
	VTS   int    `json:"vts"`             // 0 for the VMG
	Title int    `json:"title,omitempty"` // the title concerned, when it is one
	Table string `json:"table"`           // the table that is wrong
	From  string `json:"from,omitempty"`  // the table it was mended from
	Fixed bool   `json:"fixed"`           // false: reported only
	Note  string `json:"note"`
}

Repair is one disagreement between tables, and what was done about it.

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
	// ColCon are CHG_COLCON regions: other colours and contrasts for parts
	// of the picture (karaoke wipes, two-colour subtitles, menu artwork).
	ColCon    []ColConLines
	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 DecodeSPU

func DecodeSPU(unit []byte) (*SPU, error)

DecodeSPU decodes one sub-picture unit as it first appears: the state at its first start-display command (or, for units that never start, the state they leave), with StopSec the time it next changes or stops.

func DecodeSPUFrames added in v0.3.0

func DecodeSPUFrames(unit []byte) ([]*SPU, error)

DecodeSPUFrames decodes every picture a sub-picture unit shows over time. A unit carries a chain of display control sequences, each applied at its own delay: subtitles that change colour, move, blink or show another part of the bitmap come out as one SPU per state, each with its own start and stop time (StopSec < 0: shown until the next unit replaces it).

func (*SPU) Render

func (s *SPU) Render(palette [16]uint32, look *Look) *RGBA

Render paints the whole SPU with the given look (nil look = the SPU's own).

func (*SPU) RenderRect

func (s *SPU) RenderRect(palette [16]uint32, look *Look, x0, y0, x1, y1 int) *RGBA

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.

With the SPU's own look, CHG_COLCON regions recolour their part of the picture; a button's look (a highlight) replaces them inside the button.

type SPUUnit

type SPUUnit struct {
	Stream int
	Sector uint32
	PTS    int64
	Bytes  []byte
}

SPUUnit is a complete sub-picture unit with its presentation time.

type SectorRange

type SectorRange struct{ First, Last uint32 }

SectorRange is an inclusive run of sectors in a VOB address space.

type SectorReader

type SectorReader interface {
	ReadSectors(first uint32, count int) ([]byte, error)
}

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 Space

type Space struct {
	Domain Domain
	VTS    int
}

Space names a VOB address space.

func SpaceFor

func SpaceFor(domain Domain, vts int) Space

SpaceFor maps a step to its VOB address space.

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 StepKind

type StepKind string

StepKind is what the navigator wants shown.

const (
	StepMenu  StepKind = "menu"
	StepTitle StepKind = "title"
	StepStop  StepKind = "stop"
)

type StreamScan

type StreamScan struct {
	Navs      []NavPack
	SPUs      []SPUUnit
	Scrambled bool
}

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.

func (SubpAttr) Purpose

func (s SubpAttr) Purpose() string

Purpose names a sub-picture stream's code extension.

type SubpControl

type SubpControl struct {
	Narrow, Wide, Letterbox, PanScan int
}

SubpControl says which sub-picture stream to use per display mode.

type TableReport added in v0.4.0

type TableReport struct {
	Name  string `json:"name"`
	State string `json:"state"` // ok, missing or damaged
	From  string `json:"from"`  // IFO or BUP
	Note  string `json:"note,omitempty"`
}

TableReport is how one table of an index file read, and which copy of the file it was taken from.

type TitleCell

type TitleCell struct {
	PGCN  int
	CellN int
	Cell  Cell
	Start float64
}

TitleCell is one cell of a flattened title with its PGC.

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 TitleRun added in v0.3.0

type TitleRun struct {
	Extents []FileExtent
	// Duration is how long the run plays, in seconds.
	Duration float64
	// StartPTS is the presentation time of its first picture (90 kHz); 0 when
	// the disc doesn't say.
	StartPTS uint32
	// Lead is how long before its first picture the run's earliest packet lies,
	// in seconds: the sound stored ahead of the picture (see scanLead).
	Lead float64
	// FirstCell and Cells say which of the given cells it plays.
	FirstCell, Cells int
}

TitleRun is a stretch of a title that can be read straight through.

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:"-"`
	// ChapterSource says where the chapter times come from: "chapterTable"
	// (VTS_PTT_SRPT), "programs" (the table names nothing this title plays,
	// so each program is a chapter) or "" (no chapters).
	ChapterSource string `json:"chapterSource,omitempty"`
	// Estimated says some cells give no play time of their own, and theirs
	// was worked out from the time map or their share of the sectors.
	Estimated bool `json:"timesEstimated,omitempty"`
	// Truncated says the title lists more cells than any real title has, and
	// only the first of them were read.
	Truncated bool `json:"truncated,omitempty"`
	// Path says how the cells were found: "chapters" (the chapter table and
	// next-PGC links) or "commands" (a dry run of the title's own commands).
	Path string `json:"path,omitempty"`
}

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
	// MenuVOBSectors is the size of VIDEO_TS.VOB in sectors according to
	// the IFO (0 when the IFO does not say).
	MenuVOBSectors uint32
	// Parental is the parental management table (PTL_MAIT), per country.
	Parental []ParentalCountry
	// MenuCellAddrs is the menu VOB's cell address table (VMGM_C_ADT).
	MenuCellAddrs []CellAddr
	// contains filtered or unexported fields
}

VMG is VIDEO_TS.IFO.

func ParseVMG

func ParseVMG(b []byte) (*VMG, error)

ParseVMG parses VIDEO_TS.IFO. It fails only when the file isn't a VMG at all: a table that is missing or damaged is left empty.

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
	// Sizes of the menu and title VOBs in sectors according to the IFO
	// (0 when unknown). Cells that start beyond them are junk.
	MenuVOBSectors  uint32
	TitleVOBSectors uint32
	// CellAddrs is the cell address table of the title VOBs (VTS_C_ADT):
	// where each cell the title set really holds lies. MenuCellAddrs is the
	// same for the menu VOB. Both are empty when the IFO has no such table.
	CellAddrs     []CellAddr
	MenuCellAddrs []CellAddr
	// VOBUs is how many VOBUs the title VOBs hold according to
	// VTS_VOBU_ADMAP (0 when the IFO has no such table).
	VOBUs int
	// contains filtered or unexported fields
}

VTS is VTS_xx_0.IFO.

func ParseVTS

func ParseVTS(b []byte, number int) (*VTS, error)

ParseVTS parses VTS_xx_0.IFO. It fails only when the file isn't a VTS at all: a table that is missing or damaged is left empty, and Open then looks for it in the backup copy.

type Version added in v0.4.0

type Version struct {
	Kind  string `json:"kind"`  // angle, parental or cut
	Title int    `json:"title"` // the title that plays it
	// Angle is the camera angle (kind angle), Levels the parental levels
	// that get this cut (kind parental).
	Angle    int     `json:"angle,omitempty"`
	Levels   []int   `json:"parentalLevels,omitempty"`
	Duration float64 `json:"durationSec"`
	Cells    int     `json:"cells"`
	// Shared is how much of this version's video the main title also plays,
	// from 0 to 1 (kind cut).
	Shared float64 `json:"shared,omitempty"`
	Label  string  `json:"label"`
}

Version is one way the main feature can be seen.

type VideoAttr

type VideoAttr struct {
	MPEG        int    `json:"mpeg"`
	Standard    string `json:"standard"` // ntsc | pal
	Wide        bool   `json:"wide"`     // 16:9
	Letterbox   bool   `json:"letterbox"`
	PictureSize int    `json:"pictureSize"`
	PermittedDF int    `json:"permittedDf"`
}

VideoAttr describes a video stream.

func (VideoAttr) Size

func (a VideoAttr) Size() (int, int)

Width/Height of the coded picture.

type Weights added in v0.4.0

type Weights struct {
	DistinctPerMinute float64 // per minute of distinct, readable video
	OutOfRangeAny     float64 // any cell starts outside the title VOB
	OutOfRangeShare   float64 // times the share of such cells
	Repeats           float64 // times the share of play time spent on repeats
	BackJumpAny       float64 // any jump back on the disc between cells
	BackJumpShare     float64 // times the share of steps that jump back
	Shuffled          float64 // another title's cells in scrambled order
	Duplicate         float64 // identical to a lower-numbered title (tie breaker)
	CellSpam          float64 // most cells are zero or under a second long
	AbsurdCell        float64 // a cell claims more than four hours
	Loop              float64 // the PGC chain links back on itself
	BadChapters       float64 // the chapter table points nowhere
	RegularChapters   float64 // three or more chapters of sensible, even length
	AudioMatch        float64 // its title set has the most audio streams
	SubpMatch         float64 // its title set has the most subtitle streams
	LargestVTS        float64 // its title set holds the most video
	FirstPlay         float64 // first play reaches it by itself
	MenuReference     float64 // a menu or first-play command jumps to it
	MenuPlay          float64 // the first menu's default button plays it
	UnlistedAny       float64 // any cell is missing from the cell address table
	UnlistedShare     float64 // times the share of such cells
	OffVOBUShare      float64 // times the share of cells that don't start at a VOBU
	HollowShare       float64 // times the share of play time in cells too small to hold it
	Overlap           float64 // cells lie over each other on the disc
	Unreachable       float64 // nothing on the disc leads to it (buttons read)
	FirstMenuJump     float64 // the first title jump of the first menu names it
	TimeMismatch      float64 // a program chain's play time isn't the sum of its cells
	NoVideo           float64 // its title set has no video files
	// What the disc does by itself is worth more the more video it leads
	// to: these are added per minute of the title's distinct video.
	FirstPlayPerMinute float64
	MenuPlayPerMinute  float64
	Scrambled          float64 // a quarter or more of its steps jump back on the disc
	NoAudio            float64 // its program chain turns on no audio stream, where others of its title set do
}

Weights tune the scoring. Scores are in "minutes of distinct video": a weight of 15 is worth as much as a quarter of an hour of unique cells.

Directories

Path Synopsis
Package api is a disc module's own HTTP API and SDUI sources (module API 5): a disc's page, why a title is its film and the choice of another, the names given to its titles and chapters, and its sections on a title's page in every app.
Package api is a disc module's own HTTP API and SDUI sources (module API 5): a disc's page, why a title is its film and the choice of another, the names given to its titles and chapters, and its sections on a title's page in every app.
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.
wittydvd-module command
Command wittydvd-module is WittyDVD as a helper process, one for each open disc, so a new version of the engine can reach a server without a new server.
Command wittydvd-module is WittyDVD as a helper process, one for each open disc, so a new version of the engine can reach a server without a new server.
Package commands is the disc module's own commands, as its sdui.json declares them.
Package commands is the disc module's own commands, as its sdui.json declares them.
Package wire is what a WittyDVD helper process and a server say to each other about one open disc: the names of the calls and the form their answers travel in.
Package wire is what a WittyDVD helper process and a server say to each other about one open disc: the names of the calls and the form their answers travel in.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL