File: avc_au.go

package info (click to toggle)
fq 0.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 106,624 kB
  • sloc: xml: 2,835; makefile: 250; sh: 241; exp: 57; ansic: 21
file content (48 lines) | stat: -rw-r--r-- 955 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package mpeg

// ISO/IEC 14496-15, 5.3.3.1.2 Syntax

import (
	"github.com/wader/fq/format"
	"github.com/wader/fq/pkg/decode"
	"github.com/wader/fq/pkg/interp"
)

var avcNALUFormat decode.Group

func init() {
	interp.RegisterFormat(
		format.AVC_AU,
		&decode.Format{
			Description: "H.264/AVC Access Unit",
			DecodeFn:    avcAUDecode,
			DefaultInArg: format.AVC_AU_In{
				LengthSize: 0,
			},
			RootArray: true,
			RootName:  "access_unit",
			Dependencies: []decode.Dependency{
				{Groups: []*decode.Group{format.AVC_NALU}, Out: &avcNALUFormat},
			},
		})
}

func avcAUDecode(d *decode.D) any {
	var ai format.AVC_AU_In
	d.ArgAs(&ai)

	if ai.LengthSize == 0 {
		// TODO: is annexb the correct name?
		annexBDecode(d, avcNALUFormat)
		return nil
	}

	for d.NotEnd() {
		d.FieldStruct("nalu", func(d *decode.D) {
			l := int64(d.FieldU("length", int(ai.LengthSize)*8)) * 8
			d.FieldFormatLen("nalu", l, &avcNALUFormat, nil)
		})
	}

	return nil
}