mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 23:26:54 +08:00
add NewTrackAac
This commit is contained in:
@@ -26,28 +26,28 @@ func getRtpH264SPSandPPS(pc net.PacketConn) ([]byte, []byte, error) {
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
packet := &rtp.Packet{}
|
pkt := &rtp.Packet{}
|
||||||
err = packet.Unmarshal(buf[:n])
|
err = pkt.Unmarshal(buf[:n])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// require h264
|
// require h264
|
||||||
if packet.PayloadType != 96 {
|
if pkt.PayloadType != 96 {
|
||||||
return nil, nil, fmt.Errorf("wrong payload type '%d', expected 96",
|
return nil, nil, fmt.Errorf("wrong payload type '%d', expected 96",
|
||||||
packet.PayloadType)
|
pkt.PayloadType)
|
||||||
}
|
}
|
||||||
|
|
||||||
// switch by NALU type
|
// switch by NALU type
|
||||||
switch packet.Payload[0] & 0x1F {
|
switch pkt.Payload[0] & 0x1F {
|
||||||
case 0x07: // sps
|
case 0x07: // sps
|
||||||
sps = append([]byte(nil), packet.Payload...)
|
sps = append([]byte(nil), pkt.Payload...)
|
||||||
if sps != nil && pps != nil {
|
if sps != nil && pps != nil {
|
||||||
return sps, pps, nil
|
return sps, pps, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
case 0x08: // pps
|
case 0x08: // pps
|
||||||
pps = append([]byte(nil), packet.Payload...)
|
pps = append([]byte(nil), pkt.Payload...)
|
||||||
if sps != nil && pps != nil {
|
if sps != nil && pps != nil {
|
||||||
return sps, pps, nil
|
return sps, pps, nil
|
||||||
}
|
}
|
||||||
|
@@ -26,28 +26,28 @@ func getRtpH264SPSandPPS(pc net.PacketConn) ([]byte, []byte, error) {
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
packet := &rtp.Packet{}
|
pkt := &rtp.Packet{}
|
||||||
err = packet.Unmarshal(buf[:n])
|
err = pkt.Unmarshal(buf[:n])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// require h264
|
// require h264
|
||||||
if packet.PayloadType != 96 {
|
if pkt.PayloadType != 96 {
|
||||||
return nil, nil, fmt.Errorf("wrong payload type '%d', expected 96",
|
return nil, nil, fmt.Errorf("wrong payload type '%d', expected 96",
|
||||||
packet.PayloadType)
|
pkt.PayloadType)
|
||||||
}
|
}
|
||||||
|
|
||||||
// switch by NALU type
|
// switch by NALU type
|
||||||
switch packet.Payload[0] & 0x1F {
|
switch pkt.Payload[0] & 0x1F {
|
||||||
case 0x07: // sps
|
case 0x07: // sps
|
||||||
sps = append([]byte(nil), packet.Payload...)
|
sps = append([]byte(nil), pkt.Payload...)
|
||||||
if sps != nil && pps != nil {
|
if sps != nil && pps != nil {
|
||||||
return sps, pps, nil
|
return sps, pps, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
case 0x08: // pps
|
case 0x08: // pps
|
||||||
pps = append([]byte(nil), packet.Payload...)
|
pps = append([]byte(nil), pkt.Payload...)
|
||||||
if sps != nil && pps != nil {
|
if sps != nil && pps != nil {
|
||||||
return sps, pps, nil
|
return sps, pps, nil
|
||||||
}
|
}
|
||||||
|
30
track.go
30
track.go
@@ -43,9 +43,35 @@ func NewTrackH264(id int, sps []byte, pps []byte) *Track {
|
|||||||
"sprop-parameter-sets=" + spropParameterSets + "; " +
|
"sprop-parameter-sets=" + spropParameterSets + "; " +
|
||||||
"profile-level-id=" + profileLevelId,
|
"profile-level-id=" + profileLevelId,
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewTrackAac initializes an AAC track.
|
||||||
|
func NewTrackAac(id int, sampleRate int, channelCount int, config []byte) *Track {
|
||||||
|
return &Track{
|
||||||
|
Id: id,
|
||||||
|
Media: &sdp.MediaDescription{
|
||||||
|
MediaName: sdp.MediaName{
|
||||||
|
Media: "audio",
|
||||||
|
Protos: []string{"RTP", "AVP"},
|
||||||
|
Formats: []string{"97"},
|
||||||
|
},
|
||||||
|
Attributes: []sdp.Attribute{
|
||||||
{
|
{
|
||||||
Key: "control",
|
Key: "rtpmap",
|
||||||
Value: "trackID=0",
|
Value: "97 MPEG4-GENERIC/" + strconv.FormatInt(int64(sampleRate), 10) +
|
||||||
|
"/" + strconv.FormatInt(int64(channelCount), 10),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: "fmtp",
|
||||||
|
Value: "97 profile-level-id=1; " +
|
||||||
|
"mode=AAC-hbr; " +
|
||||||
|
"sizelength=13; " +
|
||||||
|
"indexlength=3; " +
|
||||||
|
"indexdeltalength=3; " +
|
||||||
|
"config=" + hex.EncodeToString(config),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user