-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rtmp: support additional Enhanced-RTMP features (#3685)
new features: * Opus and AC-3 tracks * multiple tracks
- Loading branch information
Showing
36 changed files
with
1,434 additions
and
621 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
internal/protocols/rtmp/message/extended_mpeg2ts_sequence_start.go
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
61 changes: 61 additions & 0 deletions
61
internal/protocols/rtmp/message/msg_audio_ex_coded_frames.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package message | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/bluenviron/mediamtx/internal/protocols/rtmp/rawmessage" | ||
) | ||
|
||
// AudioExCodedFrames is a CodedFrames extended message. | ||
type AudioExCodedFrames struct { | ||
ChunkStreamID byte | ||
DTS time.Duration | ||
MessageStreamID uint32 | ||
FourCC FourCC | ||
Payload []byte | ||
} | ||
|
||
func (m *AudioExCodedFrames) unmarshal(raw *rawmessage.Message) error { | ||
if len(raw.Body) < 5 { | ||
return fmt.Errorf("not enough bytes") | ||
} | ||
|
||
m.ChunkStreamID = raw.ChunkStreamID | ||
m.DTS = raw.Timestamp | ||
m.MessageStreamID = raw.MessageStreamID | ||
|
||
m.FourCC = FourCC(raw.Body[1])<<24 | FourCC(raw.Body[2])<<16 | FourCC(raw.Body[3])<<8 | FourCC(raw.Body[4]) | ||
switch m.FourCC { | ||
case FourCCOpus, FourCCAC3, FourCCMP4A: | ||
default: | ||
return fmt.Errorf("unsupported fourCC: %v", m.FourCC) | ||
} | ||
|
||
m.Payload = raw.Body[5:] | ||
|
||
return nil | ||
} | ||
|
||
func (m AudioExCodedFrames) marshalBodySize() int { | ||
return 5 + len(m.Payload) | ||
} | ||
|
||
func (m AudioExCodedFrames) marshal() (*rawmessage.Message, error) { | ||
body := make([]byte, m.marshalBodySize()) | ||
|
||
body[0] = (9 << 4) | byte(AudioExTypeCodedFrames) | ||
body[1] = uint8(m.FourCC >> 24) | ||
body[2] = uint8(m.FourCC >> 16) | ||
body[3] = uint8(m.FourCC >> 8) | ||
body[4] = uint8(m.FourCC) | ||
copy(body[5:], m.Payload) | ||
|
||
return &rawmessage.Message{ | ||
ChunkStreamID: m.ChunkStreamID, | ||
Timestamp: m.DTS, | ||
Type: uint8(TypeAudio), | ||
MessageStreamID: m.MessageStreamID, | ||
Body: body, | ||
}, nil | ||
} |
76 changes: 76 additions & 0 deletions
76
internal/protocols/rtmp/message/msg_audio_ex_multichannel_config.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package message | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/bluenviron/mediamtx/internal/protocols/rtmp/rawmessage" | ||
) | ||
|
||
// AudioExChannelOrder is an audio channel order. | ||
type AudioExChannelOrder uint8 | ||
|
||
// audio channel orders. | ||
const ( | ||
AudioExChannelOrderUnspecified AudioExChannelOrder = 0 | ||
AudioExChannelOrderNative AudioExChannelOrder = 1 | ||
AudioExChannelOrderCustom AudioExChannelOrder = 2 | ||
) | ||
|
||
// AudioExMultichannelConfig is a multichannel config extended message. | ||
type AudioExMultichannelConfig struct { | ||
ChunkStreamID byte | ||
MessageStreamID uint32 | ||
FourCC FourCC | ||
AudioChannelOrder AudioExChannelOrder | ||
ChannelCount uint8 | ||
AudioChannelMapping uint8 // if AudioChannelOrder == AudioExChannelOrderCustom | ||
AudioChannelFlags uint32 // if AudioChannelOrder == AudioExChannelOrderNative | ||
} | ||
|
||
func (m *AudioExMultichannelConfig) unmarshal(raw *rawmessage.Message) error { | ||
if len(raw.Body) < 7 { | ||
return fmt.Errorf("not enough bytes") | ||
} | ||
|
||
m.ChunkStreamID = raw.ChunkStreamID | ||
m.MessageStreamID = raw.MessageStreamID | ||
|
||
m.FourCC = FourCC(raw.Body[1])<<24 | FourCC(raw.Body[2])<<16 | FourCC(raw.Body[3])<<8 | FourCC(raw.Body[4]) | ||
switch m.FourCC { | ||
case FourCCOpus, FourCCAC3, FourCCMP4A: | ||
default: | ||
return fmt.Errorf("unsupported fourCC: %v", m.FourCC) | ||
} | ||
|
||
m.AudioChannelOrder = AudioExChannelOrder(raw.Body[5]) | ||
m.ChannelCount = raw.Body[6] | ||
|
||
switch m.AudioChannelOrder { | ||
case AudioExChannelOrderCustom: | ||
if len(raw.Body) != 8 { | ||
return fmt.Errorf("invalid AudioExMultichannelConfig size") | ||
} | ||
m.AudioChannelMapping = raw.Body[7] | ||
|
||
case AudioExChannelOrderNative: | ||
if len(raw.Body) != 11 { | ||
return fmt.Errorf("invalid AudioExMultichannelConfig size") | ||
} | ||
m.AudioChannelFlags = uint32(raw.Body[7])<<24 | uint32(raw.Body[8])<<16 | | ||
uint32(raw.Body[9])<<8 | uint32(raw.Body[10]) | ||
|
||
case AudioExChannelOrderUnspecified: | ||
if len(raw.Body) != 7 { | ||
return fmt.Errorf("invalid AudioExMultichannelConfig size") | ||
} | ||
|
||
default: | ||
return fmt.Errorf("invalid AudioChannelOrder: %v", m.AudioChannelOrder) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (m AudioExMultichannelConfig) marshal() (*rawmessage.Message, error) { | ||
return nil, fmt.Errorf("TODO") | ||
} |
78 changes: 78 additions & 0 deletions
78
internal/protocols/rtmp/message/msg_audio_ex_multitrack.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package message //nolint:dupl | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/bluenviron/mediamtx/internal/protocols/rtmp/rawmessage" | ||
) | ||
|
||
// AudioExMultitrackType is a multitrack type. | ||
type AudioExMultitrackType uint8 | ||
|
||
// multitrack types. | ||
const ( | ||
AudioExMultitrackTypeOneTrack AudioExMultitrackType = 0 | ||
AudioExMultitrackTypeManyTracks AudioExMultitrackType = 1 | ||
AudioExMultitrackTypeManyTracksManyCodecs AudioExMultitrackType = 2 | ||
) | ||
|
||
// AudioExMultitrack is a multitrack extended message. | ||
type AudioExMultitrack struct { | ||
ChunkStreamID byte | ||
DTS time.Duration | ||
MessageStreamID uint32 | ||
MultitrackType AudioExMultitrackType | ||
TrackID uint8 | ||
Wrapped Message | ||
} | ||
|
||
func (m *AudioExMultitrack) unmarshal(raw *rawmessage.Message) error { | ||
if len(raw.Body) < 7 { | ||
return fmt.Errorf("not enough bytes") | ||
} | ||
|
||
m.ChunkStreamID = raw.ChunkStreamID | ||
m.DTS = raw.Timestamp | ||
m.MessageStreamID = raw.MessageStreamID | ||
|
||
m.MultitrackType = AudioExMultitrackType(raw.Body[1] >> 4) | ||
switch m.MultitrackType { | ||
case AudioExMultitrackTypeOneTrack: | ||
default: | ||
return fmt.Errorf("unsupported multitrack type: %v", m.MultitrackType) | ||
} | ||
|
||
packetType := AudioExType(raw.Body[1] & 0b1111) | ||
switch packetType { | ||
case AudioExTypeSequenceStart: | ||
m.Wrapped = &AudioExSequenceStart{} | ||
|
||
case AudioExTypeMultichannelConfig: | ||
m.Wrapped = &AudioExMultichannelConfig{} | ||
|
||
case AudioExTypeCodedFrames: | ||
m.Wrapped = &AudioExCodedFrames{} | ||
|
||
default: | ||
return fmt.Errorf("unsupported multitrack packet type: %v", packetType) | ||
} | ||
|
||
m.TrackID = raw.Body[6] | ||
|
||
wrappedBody := make([]byte, 5+len(raw.Body[7:])) | ||
copy(wrappedBody[1:], raw.Body[2:]) // fourCC | ||
copy(wrappedBody[5:], raw.Body[7:]) // body | ||
err := m.Wrapped.unmarshal(&rawmessage.Message{ | ||
Body: wrappedBody, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (m AudioExMultitrack) marshal() (*rawmessage.Message, error) { | ||
return nil, fmt.Errorf("TODO") | ||
} |
Oops, something went wrong.