move codec-related constants into formatprocessor (#3595)

This commit is contained in:
Alessandro Ros 2024-08-01 16:42:53 +02:00 committed by GitHub
parent 0230aa0a9c
commit 59ae3add7e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 72 additions and 39 deletions

View File

@ -13,6 +13,13 @@ import (
"github.com/bluenviron/mediamtx/internal/unit"
)
// AV1-related parameters
var (
AV1DefaultSequenceHeader = []byte{
8, 0, 0, 0, 66, 167, 191, 228, 96, 13, 0, 64,
}
)
type formatProcessorAV1 struct {
udpMaxPayloadSize int
format *format.AV1

View File

@ -14,6 +14,17 @@ import (
"github.com/bluenviron/mediamtx/internal/unit"
)
// H264-related parameters
var (
H264DefaultSPS = []byte{ // 1920x1080 baseline
0x67, 0x42, 0xc0, 0x28, 0xd9, 0x00, 0x78, 0x02,
0x27, 0xe5, 0x84, 0x00, 0x00, 0x03, 0x00, 0x04,
0x00, 0x00, 0x03, 0x00, 0xf0, 0x3c, 0x60, 0xc9, 0x20,
}
H264DefaultPPS = []byte{0x08, 0x06, 0x07, 0x08}
)
// extract SPS and PPS without decoding RTP packets
func rtpH264ExtractParams(payload []byte) ([]byte, []byte) {
if len(payload) < 1 {

View File

@ -14,6 +14,30 @@ import (
"github.com/bluenviron/mediamtx/internal/unit"
)
// H265-related parameters
var (
H265DefaultVPS = []byte{
0x40, 0x01, 0x0c, 0x01, 0xff, 0xff, 0x02, 0x20,
0x00, 0x00, 0x03, 0x00, 0xb0, 0x00, 0x00, 0x03,
0x00, 0x00, 0x03, 0x00, 0x7b, 0x18, 0xb0, 0x24,
}
H265DefaultSPS = []byte{
0x42, 0x01, 0x01, 0x02, 0x20, 0x00, 0x00, 0x03,
0x00, 0xb0, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03,
0x00, 0x7b, 0xa0, 0x07, 0x82, 0x00, 0x88, 0x7d,
0xb6, 0x71, 0x8b, 0x92, 0x44, 0x80, 0x53, 0x88,
0x88, 0x92, 0xcf, 0x24, 0xa6, 0x92, 0x72, 0xc9,
0x12, 0x49, 0x22, 0xdc, 0x91, 0xaa, 0x48, 0xfc,
0xa2, 0x23, 0xff, 0x00, 0x01, 0x00, 0x01, 0x6a,
0x02, 0x02, 0x02, 0x01,
}
H265DefaultPPS = []byte{
0x44, 0x01, 0xc0, 0x25, 0x2f, 0x05, 0x32, 0x40,
}
)
// extract VPS, SPS and PPS without decoding RTP packets
func rtpH265ExtractParams(payload []byte) ([]byte, []byte, []byte) {
if len(payload) < 2 {

View File

@ -13,6 +13,15 @@ import (
"github.com/bluenviron/mediamtx/internal/unit"
)
// MPEG-1 video related parameters
var (
MPEG1VideoDefaultConfig = []byte{
0x00, 0x00, 0x01, 0xb3, 0x78, 0x04, 0x38, 0x35,
0xff, 0xff, 0xe0, 0x18, 0x00, 0x00, 0x01, 0xb5,
0x14, 0x4a, 0x00, 0x01, 0x00, 0x00,
}
)
type formatProcessorMPEG1Video struct {
udpMaxPayloadSize int
format *format.MPEG1Video

View File

@ -15,6 +15,18 @@ import (
"github.com/bluenviron/mediamtx/internal/unit"
)
// MPEG-4 video related parameters
var (
MPEG4VideoDefaultConfig = []byte{
0x00, 0x00, 0x01, 0xb0, 0x01, 0x00, 0x00, 0x01,
0xb5, 0x89, 0x13, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x01, 0x20, 0x00, 0xc4, 0x8d, 0x88, 0x00,
0xf5, 0x3c, 0x04, 0x87, 0x14, 0x63, 0x00, 0x00,
0x01, 0xb2, 0x4c, 0x61, 0x76, 0x63, 0x35, 0x38,
0x2e, 0x31, 0x33, 0x34, 0x2e, 0x31, 0x30, 0x30,
}
)
type formatProcessorMPEG4Video struct {
udpMaxPayloadSize int
format *format.MPEG4Video

View File

@ -20,8 +20,8 @@ import (
"github.com/bluenviron/mediacommon/pkg/formats/fmp4"
"github.com/bluenviron/mediamtx/internal/defs"
"github.com/bluenviron/mediamtx/internal/formatprocessor"
"github.com/bluenviron/mediamtx/internal/logger"
"github.com/bluenviron/mediamtx/internal/test"
"github.com/bluenviron/mediamtx/internal/unit"
)
@ -145,9 +145,7 @@ func (f *formatFMP4) initialize() {
switch forma := forma.(type) {
case *rtspformat.AV1:
codec := &fmp4.CodecAV1{
SequenceHeader: []byte{
8, 0, 0, 0, 66, 167, 191, 228, 96, 13, 0, 64,
},
SequenceHeader: formatprocessor.AV1DefaultSequenceHeader,
}
track := addTrack(forma, codec)
@ -278,26 +276,9 @@ func (f *formatFMP4) initialize() {
vps, sps, pps := forma.SafeParams()
if vps == nil || sps == nil || pps == nil {
vps = []byte{
0x40, 0x01, 0x0c, 0x01, 0xff, 0xff, 0x02, 0x20,
0x00, 0x00, 0x03, 0x00, 0xb0, 0x00, 0x00, 0x03,
0x00, 0x00, 0x03, 0x00, 0x7b, 0x18, 0xb0, 0x24,
}
sps = []byte{
0x42, 0x01, 0x01, 0x02, 0x20, 0x00, 0x00, 0x03,
0x00, 0xb0, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03,
0x00, 0x7b, 0xa0, 0x07, 0x82, 0x00, 0x88, 0x7d,
0xb6, 0x71, 0x8b, 0x92, 0x44, 0x80, 0x53, 0x88,
0x88, 0x92, 0xcf, 0x24, 0xa6, 0x92, 0x72, 0xc9,
0x12, 0x49, 0x22, 0xdc, 0x91, 0xaa, 0x48, 0xfc,
0xa2, 0x23, 0xff, 0x00, 0x01, 0x00, 0x01, 0x6a,
0x02, 0x02, 0x02, 0x01,
}
pps = []byte{
0x44, 0x01, 0xc0, 0x25, 0x2f, 0x05, 0x32, 0x40,
}
vps = formatprocessor.H265DefaultVPS
sps = formatprocessor.H265DefaultSPS
pps = formatprocessor.H265DefaultPPS
}
codec := &fmp4.CodecH265{
@ -375,8 +356,8 @@ func (f *formatFMP4) initialize() {
sps, pps := forma.SafeParams()
if sps == nil || pps == nil {
sps = test.FormatH264.SPS
pps = test.FormatH264.PPS
sps = formatprocessor.H264DefaultSPS
pps = formatprocessor.H264DefaultPPS
}
codec := &fmp4.CodecH264{
@ -446,14 +427,7 @@ func (f *formatFMP4) initialize() {
config := forma.SafeParams()
if config == nil {
config = []byte{
0x00, 0x00, 0x01, 0xb0, 0x01, 0x00, 0x00, 0x01,
0xb5, 0x89, 0x13, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x01, 0x20, 0x00, 0xc4, 0x8d, 0x88, 0x00,
0xf5, 0x3c, 0x04, 0x87, 0x14, 0x63, 0x00, 0x00,
0x01, 0xb2, 0x4c, 0x61, 0x76, 0x63, 0x35, 0x38,
0x2e, 0x31, 0x33, 0x34, 0x2e, 0x31, 0x30, 0x30,
}
config = formatprocessor.MPEG4VideoDefaultConfig
}
codec := &fmp4.CodecMPEG4Video{
@ -506,11 +480,7 @@ func (f *formatFMP4) initialize() {
case *rtspformat.MPEG1Video:
codec := &fmp4.CodecMPEG1Video{
Config: []byte{
0x00, 0x00, 0x01, 0xb3, 0x78, 0x04, 0x38, 0x35,
0xff, 0xff, 0xe0, 0x18, 0x00, 0x00, 0x01, 0xb5,
0x14, 0x4a, 0x00, 0x01, 0x00, 0x00,
},
Config: formatprocessor.MPEG1VideoDefaultConfig,
}
track := addTrack(forma, codec)