mirror of
https://github.com/aler9/gortsplib
synced 2025-10-16 12:10:48 +08:00
Merge branch 'main' into v4
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/pion/rtp"
|
||||
)
|
||||
|
||||
func findClockRate(payloadType uint8, rtpMap string) (int, error) {
|
||||
func findClockRate(payloadType uint8, rtpMap string, isApplication bool) (int, error) {
|
||||
// get clock rate from payload type
|
||||
// https://en.wikipedia.org/wiki/RTP_payload_formats
|
||||
switch payloadType {
|
||||
@@ -34,21 +34,23 @@ func findClockRate(payloadType uint8, rtpMap string) (int, error) {
|
||||
// get clock rate from rtpmap
|
||||
// https://tools.ietf.org/html/rfc4566
|
||||
// a=rtpmap:<payload type> <encoding name>/<clock rate> [/<encoding parameters>]
|
||||
if rtpMap == "" {
|
||||
return 0, fmt.Errorf("attribute 'rtpmap' not found")
|
||||
if rtpMap != "" {
|
||||
if tmp := strings.Split(rtpMap, "/"); len(tmp) >= 2 {
|
||||
v, err := strconv.ParseUint(tmp[1], 10, 31)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return int(v), nil
|
||||
}
|
||||
}
|
||||
|
||||
tmp := strings.Split(rtpMap, "/")
|
||||
if len(tmp) != 2 && len(tmp) != 3 {
|
||||
return 0, fmt.Errorf("invalid rtpmap (%v)", rtpMap)
|
||||
// application format without clock rate.
|
||||
// do not throw an error, but return zero, that disables RTCP sender and receiver reports.
|
||||
if isApplication || rtpMap != "" {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
v, err := strconv.ParseUint(tmp[1], 10, 31)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return int(v), nil
|
||||
return 0, fmt.Errorf("clock rate not found")
|
||||
}
|
||||
|
||||
// Generic is a generic RTP format.
|
||||
@@ -63,16 +65,19 @@ type Generic struct {
|
||||
|
||||
// Init computes the clock rate of the format. It is mandatory to call it.
|
||||
func (f *Generic) Init() error {
|
||||
f.ClockRat, _ = findClockRate(f.PayloadTyp, f.RTPMa)
|
||||
return nil
|
||||
var err error
|
||||
f.ClockRat, err = findClockRate(f.PayloadTyp, f.RTPMa, true)
|
||||
return err
|
||||
}
|
||||
|
||||
func (f *Generic) unmarshal(payloadType uint8, _ string, _ string, rtpmap string, fmtp map[string]string) error {
|
||||
f.PayloadTyp = payloadType
|
||||
f.RTPMa = rtpmap
|
||||
f.FMT = fmtp
|
||||
func (f *Generic) unmarshal(ctx *unmarshalContext) error {
|
||||
f.PayloadTyp = ctx.payloadType
|
||||
f.RTPMa = ctx.rtpMap
|
||||
f.FMT = ctx.fmtp
|
||||
|
||||
return f.Init()
|
||||
var err error
|
||||
f.ClockRat, err = findClockRate(f.PayloadTyp, f.RTPMa, ctx.mediaType == "application")
|
||||
return err
|
||||
}
|
||||
|
||||
// Codec implements Format.
|
||||
|
Reference in New Issue
Block a user