diff --git a/examples/client-publish-tcp.go b/examples/client-publish-tcp.go index 229909de..419b0f3b 100644 --- a/examples/client-publish-tcp.go +++ b/examples/client-publish-tcp.go @@ -26,28 +26,28 @@ func getRtpH264SPSandPPS(pc net.PacketConn) ([]byte, []byte, error) { return nil, nil, err } - packet := &rtp.Packet{} - err = packet.Unmarshal(buf[:n]) + pkt := &rtp.Packet{} + err = pkt.Unmarshal(buf[:n]) if err != nil { return nil, nil, err } // require h264 - if packet.PayloadType != 96 { + if pkt.PayloadType != 96 { return nil, nil, fmt.Errorf("wrong payload type '%d', expected 96", - packet.PayloadType) + pkt.PayloadType) } // switch by NALU type - switch packet.Payload[0] & 0x1F { + switch pkt.Payload[0] & 0x1F { case 0x07: // sps - sps = append([]byte(nil), packet.Payload...) + sps = append([]byte(nil), pkt.Payload...) if sps != nil && pps != nil { return sps, pps, nil } case 0x08: // pps - pps = append([]byte(nil), packet.Payload...) + pps = append([]byte(nil), pkt.Payload...) if sps != nil && pps != nil { return sps, pps, nil } diff --git a/examples/client-publish-udp.go b/examples/client-publish-udp.go index 989b7c70..802fb496 100644 --- a/examples/client-publish-udp.go +++ b/examples/client-publish-udp.go @@ -26,28 +26,28 @@ func getRtpH264SPSandPPS(pc net.PacketConn) ([]byte, []byte, error) { return nil, nil, err } - packet := &rtp.Packet{} - err = packet.Unmarshal(buf[:n]) + pkt := &rtp.Packet{} + err = pkt.Unmarshal(buf[:n]) if err != nil { return nil, nil, err } // require h264 - if packet.PayloadType != 96 { + if pkt.PayloadType != 96 { return nil, nil, fmt.Errorf("wrong payload type '%d', expected 96", - packet.PayloadType) + pkt.PayloadType) } // switch by NALU type - switch packet.Payload[0] & 0x1F { + switch pkt.Payload[0] & 0x1F { case 0x07: // sps - sps = append([]byte(nil), packet.Payload...) + sps = append([]byte(nil), pkt.Payload...) if sps != nil && pps != nil { return sps, pps, nil } case 0x08: // pps - pps = append([]byte(nil), packet.Payload...) + pps = append([]byte(nil), pkt.Payload...) if sps != nil && pps != nil { return sps, pps, nil } diff --git a/track.go b/track.go index 85990279..0631b2b3 100644 --- a/track.go +++ b/track.go @@ -43,9 +43,35 @@ func NewTrackH264(id int, sps []byte, pps []byte) *Track { "sprop-parameter-sets=" + spropParameterSets + "; " + "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", - Value: "trackID=0", + Key: "rtpmap", + 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), }, }, },