mirror of
https://github.com/aler9/gortsplib
synced 2025-10-09 00:50:24 +08:00
h264: remove AntiCompetitionAdd
This commit is contained in:
@@ -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
|
||||
|
@@ -6,7 +6,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var casesAntiCompetition = []struct {
|
||||
func TestAntiCompetitionRemove(t *testing.T) {
|
||||
for _, ca := range []struct {
|
||||
name string
|
||||
unproc []byte
|
||||
proc []byte
|
||||
@@ -26,19 +27,7 @@ var casesAntiCompetition = []struct {
|
||||
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) {
|
||||
unproc := AntiCompetitionRemove(ca.proc)
|
||||
require.Equal(t, ca.unproc, unproc)
|
||||
|
Reference in New Issue
Block a user