mirror of
https://github.com/aler9/gortsplib
synced 2025-10-06 07:37:07 +08:00
merge format and formatdecenc into formats (#222)
This commit is contained in:
@@ -1,104 +0,0 @@
|
||||
package format
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/pion/rtp"
|
||||
)
|
||||
|
||||
func findClockRate(payloadType uint8, rtpMap string) (int, error) {
|
||||
// get clock rate from payload type
|
||||
// https://en.wikipedia.org/wiki/RTP_payload_formats
|
||||
switch payloadType {
|
||||
case 0, 1, 2, 3, 4, 5, 7, 8, 9, 12, 13, 15, 18:
|
||||
return 8000, nil
|
||||
|
||||
case 6:
|
||||
return 16000, nil
|
||||
|
||||
case 10, 11:
|
||||
return 44100, nil
|
||||
|
||||
case 14, 25, 26, 28, 31, 32, 33, 34:
|
||||
return 90000, nil
|
||||
|
||||
case 16:
|
||||
return 11025, nil
|
||||
|
||||
case 17:
|
||||
return 22050, nil
|
||||
}
|
||||
|
||||
// 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")
|
||||
}
|
||||
|
||||
tmp := strings.Split(rtpMap, "/")
|
||||
if len(tmp) != 2 && len(tmp) != 3 {
|
||||
return 0, fmt.Errorf("invalid rtpmap (%v)", rtpMap)
|
||||
}
|
||||
|
||||
v, err := strconv.ParseInt(tmp[1], 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return int(v), nil
|
||||
}
|
||||
|
||||
// Generic is a generic format.
|
||||
type Generic struct {
|
||||
PayloadTyp uint8
|
||||
RTPMap string
|
||||
FMTP map[string]string
|
||||
|
||||
// clock rate of the format. Filled automatically.
|
||||
ClockRat int
|
||||
}
|
||||
|
||||
// Init computes the clock rate of the format. It it mandatory to call it.
|
||||
func (t *Generic) Init() error {
|
||||
t.ClockRat, _ = findClockRate(t.PayloadTyp, t.RTPMap)
|
||||
return nil
|
||||
}
|
||||
|
||||
// String returns a description of the format.
|
||||
func (t *Generic) String() string {
|
||||
return "Generic"
|
||||
}
|
||||
|
||||
// ClockRate implements Format.
|
||||
func (t *Generic) ClockRate() int {
|
||||
return t.ClockRat
|
||||
}
|
||||
|
||||
// PayloadType implements Format.
|
||||
func (t *Generic) PayloadType() uint8 {
|
||||
return t.PayloadTyp
|
||||
}
|
||||
|
||||
func (t *Generic) unmarshal(
|
||||
payloadType uint8, clock string, codec string,
|
||||
rtpmap string, fmtp map[string]string,
|
||||
) error {
|
||||
t.PayloadTyp = payloadType
|
||||
t.RTPMap = rtpmap
|
||||
t.FMTP = fmtp
|
||||
|
||||
return t.Init()
|
||||
}
|
||||
|
||||
// Marshal implements Format.
|
||||
func (t *Generic) Marshal() (string, map[string]string) {
|
||||
return t.RTPMap, t.FMTP
|
||||
}
|
||||
|
||||
// PTSEqualsDTS implements Format.
|
||||
func (t *Generic) PTSEqualsDTS(*rtp.Packet) bool {
|
||||
return true
|
||||
}
|
Reference in New Issue
Block a user