Files
rtsp-simple-server/internal/playback/segment_fmp4_test.go
dependabot[bot] d0a97e47ff build(deps): bump github.com/bluenviron/gohlslib/v2 from 2.2.1 to 2.2.2 (#4763)
Bumps [github.com/bluenviron/gohlslib/v2](https://github.com/bluenviron/gohlslib) from 2.2.1 to 2.2.2.
- [Commits](https://github.com/bluenviron/gohlslib/compare/v2.2.1...v2.2.2)

---
updated-dependencies:
- dependency-name: github.com/bluenviron/gohlslib/v2
  dependency-version: 2.2.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-21 09:55:10 +02:00

77 lines
1.3 KiB
Go

package playback
import (
"io"
"os"
"testing"
"github.com/bluenviron/mediacommon/v2/pkg/codecs/mpeg4audio"
"github.com/bluenviron/mediacommon/v2/pkg/formats/fmp4"
"github.com/bluenviron/mediacommon/v2/pkg/formats/mp4"
"github.com/bluenviron/mediamtx/internal/test"
)
func writeBenchInit(f io.WriteSeeker) {
init := fmp4.Init{
Tracks: []*fmp4.InitTrack{
{
ID: 1,
TimeScale: 90000,
Codec: &mp4.CodecH264{
SPS: test.FormatH264.SPS,
PPS: test.FormatH264.PPS,
},
},
{
ID: 2,
TimeScale: 90000,
Codec: &mp4.CodecMPEG4Audio{
Config: mpeg4audio.AudioSpecificConfig{
Type: mpeg4audio.ObjectTypeAACLC,
SampleRate: 48000,
ChannelCount: 2,
},
},
},
},
}
err := init.Marshal(f)
if err != nil {
panic(err)
}
_, err = f.Write([]byte{
0x00, 0x00, 0x00, 0x10, 'm', 'o', 'o', 'f',
})
if err != nil {
panic(err)
}
}
func BenchmarkFMP4ReadHeader(b *testing.B) {
f, err := os.CreateTemp(os.TempDir(), "mediamtx-playback-fmp4-")
if err != nil {
panic(err)
}
defer os.Remove(f.Name())
writeBenchInit(f)
f.Close()
for n := 0; n < b.N; n++ {
func() {
f, err = os.Open(f.Name())
if err != nil {
panic(err)
}
defer f.Close()
_, _, err = segmentFMP4ReadHeader(f)
if err != nil {
panic(err)
}
}()
}
}