Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor and much better test coverage #380

Merged
merged 22 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ffd27f0
doc: update changelog with fix
tobbee Nov 8, 2024
f631294
test: match SEI types and strings
tobbee Nov 1, 2024
365fd18
refactor: refactor and improve testing for mp4ff-decrypt
tobbee Nov 2, 2024
831e861
refactor: refactor and improve mp4ff-encrypt with good test coverage
tobbee Nov 2, 2024
b4436d9
refactor: refactor and improve mp4ff-info with good test coverage
tobbee Nov 2, 2024
b4497b9
refactor: refactor and improve mp4ff-nallister
tobbee Nov 2, 2024
7637bbc
fix: pslister
tobbee Nov 3, 2024
ca7485b
refactor: refactor and improve mp4ff-crop with good test coverage
tobbee Nov 3, 2024
5ae005d
refactor: refactor and improve mp4ff-subslister with good test coverage
tobbee Nov 3, 2024
7da1b81
test: enhance unit tests for av1
tobbee Nov 3, 2024
519a1bc
refactor: refactor and improve example/initcreator with good test cov…
tobbee Nov 3, 2024
820ec0a
refactor: refactor and improve example/combine-segs with good test co…
tobbee Nov 3, 2024
f4b67a8
refactor: refactor and improve example/add-sidx with good test coverage
tobbee Nov 3, 2024
460d642
refactor: refactor and add unit tests to examples/resegmenter
tobbee Nov 3, 2024
000d1be
refactor: refactor and add unit tests to examples/segmenter
tobbee Nov 3, 2024
3eaf4a8
test: add goveralls Github action
tobbee Nov 4, 2024
d1ec470
test: more unit tests
tobbee Nov 4, 2024
29a895f
test: add more unit tests to avc package
tobbee Nov 5, 2024
33a237c
test: add a little more HEVC testing
tobbee Nov 5, 2024
3d4d84d
test: add unit tests to mp4/fragment and mp4/edts
tobbee Nov 6, 2024
c57ef5f
test: better test coverage for initsegment.go
tobbee Nov 7, 2024
8463870
fix: ExtractInitProtectData was broken for video
tobbee Nov 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Coverage

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
coverage:
runs-on: ubuntu-latest
steps:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.22
- name: Checkout
uses: actions/checkout@v4
- run: go test -v -coverprofile=profile.cov ./...
- uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: profile.cov
5 changes: 3 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:
runs-on: ${{ matrix.platform }}
steps:
- name: Setup Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Download Go dependencies
run: go mod download
Expand All @@ -32,3 +32,4 @@ jobs:

- name: Test
run: go test -v ./...

3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- NTP64 struct with methods to convert to time.Time
- Constants for PrftBox flags
- Unittest to all commands and examples

### Fixed

- Allow missing optional DecoderSpecificInfo
- Avoid mp4.File.Mdat pointing to an empty mdat box
- `cmd/mp4ff-encrypt` did not parse command line
- `SeigSampleGroupEntry` calculated skipBytes incorrectly
- `cmd/mp4ff-pslister` did not parse annex B HEVC correctly

### Removed

Expand Down
11 changes: 11 additions & 0 deletions av1/av1codecconfigurationrecord_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package av1

import (
"bytes"
"encoding/hex"
"testing"

Expand Down Expand Up @@ -37,4 +38,14 @@ func TestDecodeAV1DecConfRec(t *testing.T) {
if diff := deep.Equal(got, wanted); diff != nil {
t.Error(diff)
}

encBuf := bytes.Buffer{}
err = got.Encode(&encBuf)
if err != nil {
t.Error("Error encoding Av1DecoderConfigRecord")
}
encBytes := encBuf.Bytes()
if diff := deep.Equal(encBytes, byteData); diff != nil {
t.Error(diff)
}
}
12 changes: 12 additions & 0 deletions avc/annexb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package avc
import (
"bytes"
"math/rand"
"os"
"testing"

"github.com/go-test/deep"
Expand Down Expand Up @@ -233,6 +234,17 @@ func TestGetFirstAVCVideoNALUFromByteStream(t *testing.T) {
}
}

func TestConvertByteStreamToNaluSample(t *testing.T) {
data, err := os.ReadFile("testdata/two-frames.264")
if err != nil {
t.Fatalf("Read: %v", err)
}
sample := ConvertByteStreamToNaluSample(data)
if len(sample) != len(data) {
t.Errorf("got %d, wanted %d", len(sample), len(data))
}
}

func BenchmarkByteStreamToNaluSample(b *testing.B) {
l := 1024 * 1024
data := make([]byte, l)
Expand Down
8 changes: 4 additions & 4 deletions avc/avc.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ func GetNaluType(naluHeader byte) NaluType {

// FindNaluTypes - find list of NAL unit types in sample
func FindNaluTypes(sample []byte) []NaluType {
naluList := make([]NaluType, 0)
length := len(sample)
if length < 4 {
return naluList
return nil
}
naluList := make([]NaluType, 0, 2)
var pos uint32 = 0
for pos < uint32(length-4) {
naluLength := binary.BigEndian.Uint32(sample[pos : pos+4])
Expand All @@ -79,11 +79,11 @@ func FindNaluTypes(sample []byte) []NaluType {

// FindNaluTypesUpToFirstVideoNALU - find list of NAL unit types in sample
func FindNaluTypesUpToFirstVideoNALU(sample []byte) []NaluType {
naluList := make([]NaluType, 0)
length := len(sample)
if length < 4 {
return naluList
return nil
}
naluList := make([]NaluType, 0)
var pos uint32 = 0
for pos < uint32(length-4) {
naluLength := binary.BigEndian.Uint32(sample[pos : pos+4])
Expand Down
22 changes: 22 additions & 0 deletions avc/avc_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package avc

import (
"strings"
"testing"

"github.com/go-test/deep"
Expand Down Expand Up @@ -29,6 +30,27 @@ func TestGetNaluTypes(t *testing.T) {
if diff := deep.Equal(got, tc.wanted); diff != nil {
t.Errorf("%s: %v", tc.name, diff)
}
for _, w := range tc.wanted {
if !ContainsNaluType(tc.input, w) {
t.Errorf("%s: wanted %v in %v", tc.name, w, tc.input)
}
if w == NALU_IDR && !IsIDRSample(tc.input) {
t.Errorf("%s: wanted IDR in %v", tc.name, tc.input)
}
}
}
}

func TestNaluTypeStrings(t *testing.T) {
named := make([]int, 0, 9)
for i := 0; i < 14; i++ {
nt := NaluType(i)
if !strings.HasPrefix(nt.String(), "Other") {
named = append(named, i)
}
}
if len(named) != 9 {
t.Errorf("Expected 9 named NaluTypes, got %d", len(named))
}
}

Expand Down
27 changes: 27 additions & 0 deletions avc/avcdecoderconfig_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package avc

import (
"bytes"
"encoding/hex"
"os"
"testing"

"github.com/go-test/deep"
Expand Down Expand Up @@ -35,4 +37,29 @@ func TestAvcDecoderConfigRecord(t *testing.T) {
if diff := deep.Equal(got, wanted); diff != nil {
t.Error(diff)
}

enc := bytes.Buffer{}
err = got.Encode(&enc)
if err != nil {
t.Error("Error encoding AVCDecoderConfigurationRecord")
}
if !bytes.Equal(enc.Bytes(), byteData) {
t.Error("Error encoding AVCDecoderConfigurationRecord")
}
}

func TestCreateAVCDecConfRec(t *testing.T) {
data, err := os.ReadFile("testdata/blackframe.264")
if err != nil {
t.Error("Error reading file")
}
spss := ExtractNalusOfTypeFromByteStream(NALU_SPS, data, true)
ppss := ExtractNalusOfTypeFromByteStream(NALU_PPS, data, true)
if len(spss) != 1 || len(ppss) != 1 {
t.Error("Error extracting SPS/PPS")
}
_, err = CreateAVCDecConfRec(spss, ppss, true)
if err != nil {
t.Error("Error creating AVCDecoderConfigurationRecord")
}
}
6 changes: 3 additions & 3 deletions avc/nalus.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import (

// GetNalusFromSample - get nalus by following 4 byte length fields
func GetNalusFromSample(sample []byte) ([][]byte, error) {
naluList := make([][]byte, 0)
length := len(sample)
if length < 4 {
return naluList, fmt.Errorf("Less than 4 bytes, No NALUs")
return nil, fmt.Errorf("less than 4 bytes, No NALUs")
}
naluList := make([][]byte, 0, 2)
var pos uint32 = 0
for pos < uint32(length-4) {
naluLength := binary.BigEndian.Uint32(sample[pos : pos+4])
pos += 4
if int(pos+naluLength) > len(sample) {
return nil, fmt.Errorf("NAL length fields are bad. Not video?")
return nil, fmt.Errorf("NALU length fields are bad. Not video?")
}
naluList = append(naluList, sample[pos:pos+naluLength])
pos += naluLength
Expand Down
3 changes: 0 additions & 3 deletions avc/pps.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,6 @@ func ParsePPSNALUnit(data []byte, spsMap map[uint32]*SPS) (*PPS, error) {
sizeOfScalingList = 64 // 8x8 for i >= 6
}
pps.PicScalingLists[i] = readScalingList(reader, sizeOfScalingList)
if err != nil {
return nil, err
}
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions avc/sps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,13 @@ func TestSPSParser3(t *testing.T) {
t.Error(diff)
}
}

func TestCodecString(t *testing.T) {
spsRaw, _ := hex.DecodeString(sps1nalu)
sps, _ := ParseSPSNALUnit(spsRaw, true)
codec := CodecString("avc3", sps)
expected := "avc3.640020"
if codec != expected {
t.Errorf("expected codec: %q, got %q", expected, codec)
}
}
Loading
Loading