diff --git a/pkg/h264/anticompetition.go b/pkg/h264/anticompetition.go index 3dcc7359..3270589d 100644 --- a/pkg/h264/anticompetition.go +++ b/pkg/h264/anticompetition.go @@ -1,43 +1,5 @@ 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. func AntiCompetitionRemove(nalu []byte) []byte { // 0x00 0x00 0x03 0x00 -> 0x00 0x00 0x00 diff --git a/pkg/h264/anticompetition_test.go b/pkg/h264/anticompetition_test.go index 214dca46..efc6aa0b 100644 --- a/pkg/h264/anticompetition_test.go +++ b/pkg/h264/anticompetition_test.go @@ -6,39 +6,28 @@ import ( "github.com/stretchr/testify/require" ) -var casesAntiCompetition = []struct { - name string - unproc []byte - proc []byte -}{ - { - "base", - []byte{ - 0x00, 0x00, 0x00, - 0x00, 0x00, 0x01, - 0x00, 0x00, 0x02, - 0x00, 0x00, 0x03, - }, - []byte{ - 0x00, 0x00, 0x03, 0x00, - 0x00, 0x00, 0x03, 0x01, - 0x00, 0x00, 0x03, 0x02, - 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 { + for _, ca := range []struct { + name string + unproc []byte + proc []byte + }{ + { + "base", + []byte{ + 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, + 0x00, 0x00, 0x02, + 0x00, 0x00, 0x03, + }, + []byte{ + 0x00, 0x00, 0x03, 0x00, + 0x00, 0x00, 0x03, 0x01, + 0x00, 0x00, 0x03, 0x02, + 0x00, 0x00, 0x03, 0x03, + }, + }, + } { t.Run(ca.name, func(t *testing.T) { unproc := AntiCompetitionRemove(ca.proc) require.Equal(t, ca.unproc, unproc)