h264: remove AntiCompetitionAdd

This commit is contained in:
aler9
2022-04-24 22:09:33 +02:00
parent ed0e1fe814
commit f8a351ba39
2 changed files with 21 additions and 70 deletions

View File

@@ -1,43 +1,5 @@
package h264 package h264
// AntiCompetitionAdd adds the anti-competition bytes to a NALU.
func AntiCompetitionAdd(nalu []byte) []byte {
var ret []byte
step := 0
start := 0
for i, b := range nalu {
switch step {
case 0:
if b == 0 {
step++
}
case 1:
if b == 0 {
step++
} else {
step = 0
}
case 2:
switch b {
case 3, 2, 1, 0:
ret = append(ret, nalu[start:i-2]...)
ret = append(ret, []byte{0x00, 0x00, 0x03, b}...)
step = 0
start = i + 1
default:
step = 0
}
}
}
ret = append(ret, nalu[start:]...)
return ret
}
// AntiCompetitionRemove removes the anti-competition bytes from a NALU. // AntiCompetitionRemove removes the anti-competition bytes from a NALU.
func AntiCompetitionRemove(nalu []byte) []byte { func AntiCompetitionRemove(nalu []byte) []byte {
// 0x00 0x00 0x03 0x00 -> 0x00 0x00 0x00 // 0x00 0x00 0x03 0x00 -> 0x00 0x00 0x00

View File

@@ -6,7 +6,8 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
var casesAntiCompetition = []struct { func TestAntiCompetitionRemove(t *testing.T) {
for _, ca := range []struct {
name string name string
unproc []byte unproc []byte
proc []byte proc []byte
@@ -26,19 +27,7 @@ var casesAntiCompetition = []struct {
0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x03, 0x03,
}, },
}, },
} } {
func TestAntiCompetitionAdd(t *testing.T) {
for _, ca := range casesAntiCompetition {
t.Run(ca.name, func(t *testing.T) {
proc := AntiCompetitionAdd(ca.unproc)
require.Equal(t, ca.proc, proc)
})
}
}
func TestAntiCompetitionRemove(t *testing.T) {
for _, ca := range casesAntiCompetition {
t.Run(ca.name, func(t *testing.T) { t.Run(ca.name, func(t *testing.T) {
unproc := AntiCompetitionRemove(ca.proc) unproc := AntiCompetitionRemove(ca.proc)
require.Equal(t, ca.unproc, unproc) require.Equal(t, ca.unproc, unproc)