Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
136 changes: 136 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
name: ci

on:
push:
branches: [main]
pull_request:
branches: [main]

permissions:
contents: read

# CI pins the Go release below (Renovate moves it). The go.mod floor is 1.27.4, the release
# govpx v0.5.3 requires.
jobs:
gofmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version: '1.27.4'
- name: gofmt
run: |
unformatted=$(gofmt -l .)
if [ -n "$unformatted" ]; then
echo "::error::these files are not gofmt-clean:"; echo "$unformatted"
exit 1
fi

# Vet, build and race-test on three OSes. The libvpx vectors run in the lane below.
test:
name: test (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version: '1.27.4'
- run: go vet ./...
- run: go build ./...
- run: go test -race ./...

# Tools are modules of their own.
tools:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version: '1.27.4'
- run: cd tools/vpxfetch && go vet ./... && go test ./...
- run: cd tools/portgovpx && go vet ./... && go test ./...

# libvpx's 376 decoder vectors, picture by picture, native and with the SIMD experiment.
vectors:
name: vectors (${{ matrix.label }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- { os: ubuntu-latest, label: amd64, goexperiment: '' }
- { os: ubuntu-latest, label: amd64 simd, goexperiment: simd }
- { os: ubuntu-24.04-arm, label: arm64, goexperiment: '' }
- { os: ubuntu-24.04-arm, label: arm64 simd, goexperiment: simd }
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version: '1.27.4'
- name: cache the vectors
uses: actions/cache@v6.1.0
with:
path: libvpx-vectors
key: libvpx-vectors-${{ hashFiles('testdata/libvpx/*.md5') }}
- name: fetch the vectors
run: cd tools/vpxfetch && go run . --manifests ../../testdata/libvpx --dir ../../libvpx-vectors
- name: decode and compare
env:
GOEXPERIMENT: ${{ matrix.goexperiment }}
LIBVPX_VECTORS_DIR: ${{ github.workspace }}/libvpx-vectors
run: go test -race -timeout 40m -count=1 -v -run 'TestLibvpxVectors$|TestLibvpxVectorsThreaded$' .

# The fuzz corpora run as ordinary tests; this lane runs them on the 32-bit target too, where
# int is 32 bits wide and a size computed in int wraps.
arch-386:
name: arch 386
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version: '1.27.4'
- run: GOARCH=386 go vet ./...
- run: GOARCH=386 go test ./...

arch-qemu:
name: arch ${{ matrix.goarch }} (qemu)
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- { goarch: riscv64, qemu: qemu-riscv64-static }
- { goarch: loong64, qemu: qemu-loongarch64-static }
- { goarch: ppc64le, qemu: qemu-ppc64le-static }
- { goarch: s390x, qemu: qemu-s390x-static }
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version: '1.27.4'
# `qemu-user-static` is a virtual package on Ubuntu 26.04; `qemu-user` ships the dynamic
# `qemu-<arch>` that `go test -exec` needs, and both names are accepted below.
- name: install qemu user-mode emulators
timeout-minutes: 10
run: sudo apt-get update && sudo apt-get install -y qemu-user qemu-user-binfmt
- name: Test under qemu (${{ matrix.goarch }})
run: |
base="${{ matrix.qemu }}"
q=""
for cand in "$base" "${base%-static}"; do
command -v "$cand" >/dev/null 2>&1 && q="$cand" && break
done
# A missing emulator FAILS this lane: a lane that reports success for an
# architecture it never ran is the one outcome this matrix exists to rule out.
if [ -z "$q" ]; then
echo "::error::no qemu user emulator for ${{ matrix.goarch }} (looked for $base and ${base%-static})"
exit 1
fi
echo "running ${{ matrix.goarch }} under $q"
GOARCH=${{ matrix.goarch }} go test -exec="$q" ./...
108 changes: 108 additions & 0 deletions PATENTS
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
Alliance for Open Media Patent License 1.0

1. License Terms.

1.1. Patent License. Subject to the terms and conditions of this License, each
Licensor, on behalf of itself and successors in interest and assigns,
grants Licensee a non-sublicensable, perpetual, worldwide, non-exclusive,
no-charge, royalty-free, irrevocable (except as expressly stated in this
License) patent license to its Necessary Claims to make, use, sell, offer
for sale, import or distribute any Implementation.

1.2. Conditions.

1.2.1. Availability. As a condition to the grant of rights to Licensee to make,
sell, offer for sale, import or distribute an Implementation under
Section 1.1, Licensee must make its Necessary Claims available under
this License, and must reproduce this License with any Implementation
as follows:

a. For distribution in source code, by including this License in the
root directory of the source code with its Implementation.

b. For distribution in any other form (including binary, object form,
and/or hardware description code (e.g., HDL, RTL, Gate Level Netlist,
GDSII, etc.)), by including this License in the documentation, legal
notices, and/or other written materials provided with the
Implementation.

1.2.2. Additional Conditions. This license is directly from Licensor to
Licensee. Licensee acknowledges as a condition of benefiting from it
that no rights from Licensor are received from suppliers, distributors,
or otherwise in connection with this License.

1.3. Defensive Termination. If any Licensee, its Affiliates, or its agents
initiates patent litigation or files, maintains, or voluntarily
participates in a lawsuit against another entity or any person asserting
that any Implementation infringes Necessary Claims, any patent licenses
granted under this License directly to the Licensee are immediately
terminated as of the date of the initiation of action unless 1) that suit
was in response to a corresponding suit regarding an Implementation first
brought against an initiating entity, or 2) that suit was brought to
enforce the terms of this License (including intervention in a third-party
action by a Licensee).

1.4. Disclaimers. The Reference Implementation and Specification are provided
"AS IS" and without warranty. The entire risk as to implementing or
otherwise using the Reference Implementation or Specification is assumed
by the implementer and user. Licensor expressly disclaims any warranties
(express, implied, or otherwise), including implied warranties of
merchantability, non-infringement, fitness for a particular purpose, or
title, related to the material. IN NO EVENT WILL LICENSOR BE LIABLE TO
ANY OTHER PARTY FOR LOST PROFITS OR ANY FORM OF INDIRECT, SPECIAL,
INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER FROM ANY CAUSES OF
ACTION OF ANY KIND WITH RESPECT TO THIS LICENSE, WHETHER BASED ON BREACH
OF CONTRACT, TORT (INCLUDING NEGLIGENCE), OR OTHERWISE, AND WHETHER OR
NOT THE OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

2. Definitions.

2.1. Affiliate. "Affiliate" means an entity that directly or indirectly
Controls, is Controlled by, or is under common Control of that party.

2.2. Control. "Control" means direct or indirect control of more than 50% of
the voting power to elect directors of that corporation, or for any other
entity, the power to direct management of such entity.

2.3. Decoder. "Decoder" means any decoder that conforms fully with all
non-optional portions of the Specification.

2.4. Encoder. "Encoder" means any encoder that produces a bitstream that can
be decoded by a Decoder only to the extent it produces such a bitstream.

2.5. Final Deliverable. "Final Deliverable" means the final version of a
deliverable approved by the Alliance for Open Media as a Final
Deliverable.

2.6. Implementation. "Implementation" means any implementation, including the
Reference Implementation, that is an Encoder and/or a Decoder. An
Implementation also includes components of an Implementation only to the
extent they are used as part of an Implementation.

2.7. License. "License" means this license.

2.8. Licensee. "Licensee" means any person or entity who exercises patent
rights granted under this License.

2.9. Licensor. "Licensor" means (i) any Licensee that makes, sells, offers
for sale, imports or distributes any Implementation, or (ii) a person
or entity that has a licensing obligation to the Implementation as a
result of its membership and/or participation in the Alliance for Open
Media working group that developed the Specification.

2.10. Necessary Claims. "Necessary Claims" means all claims of patents or
patent applications, (a) that currently or at any time in the future,
are owned or controlled by the Licensor, and (b) (i) would be an
Essential Claim as defined by the W3C Policy as of February 5, 2004
(https://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential)
as if the Specification was a W3C Recommendation; or (ii) are infringed
by the Reference Implementation.

2.11. Reference Implementation. "Reference Implementation" means an Encoder
and/or Decoder released by the Alliance for Open Media as a Final
Deliverable.

2.12. Specification. "Specification" means the specification designated by
the Alliance for Open Media as a Final Deliverable for which this
License was issued.

51 changes: 50 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,51 @@
# vpx
VP8 and VP9 decoders in Go (port of govpx v0.5.3, libvpx as oracle)

VP8 and VP9 decoders in pure Go, no cgo. Packages `vp8` and `vp9` decode
packets to planar YUV (VP9 profiles 0 and 1; profiles 2 and 3 return
`vpx.ErrVP9NotImplemented`). The shared `vpx` package holds `Image` and the
error sentinels.

```go
d, err := vp9.New(vp9.Options{MaxWidth: 4096, MaxHeight: 2304, Threads: 4, RowMT: true})
// ...
if err := d.DecodeWithPTS(packet, pts); err == nil {
if img, ok := d.NextFrame(); ok { /* img is valid until the next decode */ }
}
```

## Status: v0.1.0 (M0)

This release is a port of the decoder subset of
[govpx](https://github.com/thesyncim/govpx) v0.5.3 (BSD-3-Clause), extracted by
`tools/portgovpx` (a per-declaration closure of the decoder, written in Go with a
test), so that every later change is made here and measured against libvpx.
The design is in [docs/design/vpx-decoder.md](docs/design/vpx-decoder.md).

At M0 the decoded picture is `vpx.Image`, a view of the decoder's buffers; the
design's `Picture` type replaces it later. The package has no extra behaviour
over govpx v0.5.3: the same 376 libvpx test vectors decode to the same md5 of
every picture, with 0 and with 4 threads.

Changes from govpx v0.5.3 (each is also noted in the file): `internal/vpx/buffers/aligned.go`
rounds up to a power of two with `math/bits`, because govpx's `v >> 32` does not compile
for 32-bit targets.

## Tests

- `LIBVPX_VECTORS_DIR=DIR go test ./...` decodes libvpx's 376 decoder vectors and
compares every picture's md5 with libvpx's. `go run ./tools/vpxfetch
--manifests testdata/libvpx --dir DIR` (a module of its own, in `tools/`)
downloads them. Without the variable the vector tests are skipped and say so.
- Fuzz targets with committed corpora: `FuzzReadBool` (the boolean decoder against
RFC 6386, far past the end of the data), `FuzzVP8Decode` and `FuzzVP9Decode`
(any two packets; the size cap bounds allocation).
- The ported tree (`internal/`) is not held to the 100 % coverage gate of the
sibling repositories: it is measured by the vectors. Hand-written code is.

## Licences

BSD-3-Clause, see `LICENSE`. Derived files cite their govpx path
(`third_party/govpx/`), and where govpx cites a libvpx source file, that file's
licence and patent grant are in `third_party/libvpx/`. The AV1-derived SIMD
kernels carry goav1's licence in `third_party/goav1/` and the AOM patent grant is
`PATENTS`.
Loading
Loading