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
|
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
|
||||||
|
@@ -6,39 +6,28 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"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) {
|
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) {
|
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)
|
||||||
|
Reference in New Issue
Block a user