mirror of
https://github.com/aler9/gortsplib
synced 2025-10-07 16:10:59 +08:00
rename aac examples into mpeg4audio examples
This commit is contained in:
@@ -45,7 +45,7 @@ Features:
|
|||||||
* Utilities
|
* Utilities
|
||||||
* Parse RTSP elements: requests, responses, SDP
|
* Parse RTSP elements: requests, responses, SDP
|
||||||
* Parse H264 elements and formats: RTP/H264, Annex-B, AVCC, anti-competition, DTS
|
* Parse H264 elements and formats: RTP/H264, Annex-B, AVCC, anti-competition, DTS
|
||||||
* Parse AAC elements and formats: RTP/AAC, ADTS, MPEG-4 audio configurations
|
* Parse MPEG4-audio (AAC) elements and formats: RTP/MPEG4-audio, ADTS, MPEG4-audio configurations
|
||||||
|
|
||||||
## Table of contents
|
## Table of contents
|
||||||
|
|
||||||
@@ -57,16 +57,16 @@ Features:
|
|||||||
|
|
||||||
* [client-query](examples/client-query/main.go)
|
* [client-query](examples/client-query/main.go)
|
||||||
* [client-read](examples/client-read/main.go)
|
* [client-read](examples/client-read/main.go)
|
||||||
* [client-read-codec-aac](examples/client-read-codec-aac/main.go)
|
|
||||||
* [client-read-codec-h264](examples/client-read-codec-h264/main.go)
|
* [client-read-codec-h264](examples/client-read-codec-h264/main.go)
|
||||||
* [client-read-codec-h264-convert-to-jpeg](examples/client-read-codec-h264-convert-to-jpeg/main.go)
|
* [client-read-codec-h264-convert-to-jpeg](examples/client-read-codec-h264-convert-to-jpeg/main.go)
|
||||||
* [client-read-codec-h264-save-to-disk](examples/client-read-codec-h264-save-to-disk/main.go)
|
* [client-read-codec-h264-save-to-disk](examples/client-read-codec-h264-save-to-disk/main.go)
|
||||||
|
* [client-read-codec-mpeg4audio](examples/client-read-codec-mpeg4audio/main.go)
|
||||||
* [client-read-partial](examples/client-read-partial/main.go)
|
* [client-read-partial](examples/client-read-partial/main.go)
|
||||||
* [client-read-options](examples/client-read-options/main.go)
|
* [client-read-options](examples/client-read-options/main.go)
|
||||||
* [client-read-pause](examples/client-read-pause/main.go)
|
* [client-read-pause](examples/client-read-pause/main.go)
|
||||||
* [client-read-republish](examples/client-read-republish/main.go)
|
* [client-read-republish](examples/client-read-republish/main.go)
|
||||||
* [client-publish-codec-aac](examples/client-publish-codec-aac/main.go)
|
|
||||||
* [client-publish-codec-h264](examples/client-publish-codec-h264/main.go)
|
* [client-publish-codec-h264](examples/client-publish-codec-h264/main.go)
|
||||||
|
* [client-publish-codec-mpeg4audio](examples/client-publish-codec-mpeg4audio/main.go)
|
||||||
* [client-publish-codec-opus](examples/client-publish-codec-opus/main.go)
|
* [client-publish-codec-opus](examples/client-publish-codec-opus/main.go)
|
||||||
* [client-publish-codec-pcma](examples/client-publish-codec-pcma/main.go)
|
* [client-publish-codec-pcma](examples/client-publish-codec-pcma/main.go)
|
||||||
* [client-publish-codec-pcmu](examples/client-publish-codec-pcmu/main.go)
|
* [client-publish-codec-pcmu](examples/client-publish-codec-pcmu/main.go)
|
||||||
|
@@ -10,19 +10,19 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// This example shows how to
|
// This example shows how to
|
||||||
// 1. generate RTP/AAC packets with GStreamer
|
// 1. generate RTP/MPEG4-audio packets with GStreamer
|
||||||
// 2. connect to a RTSP server, announce an AAC track
|
// 2. connect to a RTSP server, announce an MPEG4-audio track
|
||||||
// 3. route the packets from GStreamer to the server
|
// 3. route the packets from GStreamer to the server
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// open a listener to receive RTP/AAC packets
|
// open a listener to receive RTP/MPEG4-audio packets
|
||||||
pc, err := net.ListenPacket("udp", "localhost:9000")
|
pc, err := net.ListenPacket("udp", "localhost:9000")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
defer pc.Close()
|
defer pc.Close()
|
||||||
|
|
||||||
log.Println("Waiting for a RTP/AAC stream on UDP port 9000 - you can send one with GStreamer:\n" +
|
log.Println("Waiting for a RTP/MPEG4-audio stream on UDP port 9000 - you can send one with GStreamer:\n" +
|
||||||
"gst-launch-1.0 audiotestsrc freq=300 ! audioconvert ! audioresample ! audio/x-raw,rate=48000" +
|
"gst-launch-1.0 audiotestsrc freq=300 ! audioconvert ! audioresample ! audio/x-raw,rate=48000" +
|
||||||
" ! avenc_aac bitrate=128000 ! rtpmp4gpay ! udpsink host=127.0.0.1 port=9000")
|
" ! avenc_aac bitrate=128000 ! rtpmp4gpay ! udpsink host=127.0.0.1 port=9000")
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
log.Println("stream connected")
|
log.Println("stream connected")
|
||||||
|
|
||||||
// create an AAC track
|
// create an MPEG4-audio track
|
||||||
track := &gortsplib.TrackMPEG4Audio{
|
track := &gortsplib.TrackMPEG4Audio{
|
||||||
PayloadType: 96,
|
PayloadType: 96,
|
||||||
Config: &mpeg4audio.Config{
|
Config: &mpeg4audio.Config{
|
@@ -10,8 +10,8 @@ import (
|
|||||||
|
|
||||||
// This example shows how to
|
// This example shows how to
|
||||||
// 1. connect to a RTSP server and read all tracks on a path
|
// 1. connect to a RTSP server and read all tracks on a path
|
||||||
// 2. check if there's an AAC track
|
// 2. check if there's an MPEG4-audio track
|
||||||
// 3. get AAC AUs of that track
|
// 3. get access units of that track
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
c := gortsplib.Client{}
|
c := gortsplib.Client{}
|
||||||
@@ -35,8 +35,8 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// find the AAC track
|
// find the MPEG4-audio track
|
||||||
aacTrack, aacTrackID := func() (*gortsplib.TrackMPEG4Audio, int) {
|
mpeg4audioTrack, mpeg4audioTrackID := func() (*gortsplib.TrackMPEG4Audio, int) {
|
||||||
for i, track := range tracks {
|
for i, track := range tracks {
|
||||||
if tt, ok := track.(*gortsplib.TrackMPEG4Audio); ok {
|
if tt, ok := track.(*gortsplib.TrackMPEG4Audio); ok {
|
||||||
return tt, i
|
return tt, i
|
||||||
@@ -44,26 +44,26 @@ func main() {
|
|||||||
}
|
}
|
||||||
return nil, -1
|
return nil, -1
|
||||||
}()
|
}()
|
||||||
if aacTrack == nil {
|
if mpeg4audioTrack == nil {
|
||||||
panic("AAC track not found")
|
panic("MPEG4-audio track not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup decoder
|
// setup decoder
|
||||||
dec := &rtpmpeg4audio.Decoder{
|
dec := &rtpmpeg4audio.Decoder{
|
||||||
SampleRate: aacTrack.Config.SampleRate,
|
SampleRate: mpeg4audioTrack.Config.SampleRate,
|
||||||
SizeLength: aacTrack.SizeLength,
|
SizeLength: mpeg4audioTrack.SizeLength,
|
||||||
IndexLength: aacTrack.IndexLength,
|
IndexLength: mpeg4audioTrack.IndexLength,
|
||||||
IndexDeltaLength: aacTrack.IndexDeltaLength,
|
IndexDeltaLength: mpeg4audioTrack.IndexDeltaLength,
|
||||||
}
|
}
|
||||||
dec.Init()
|
dec.Init()
|
||||||
|
|
||||||
// called when a RTP packet arrives
|
// called when a RTP packet arrives
|
||||||
c.OnPacketRTP = func(ctx *gortsplib.ClientOnPacketRTPCtx) {
|
c.OnPacketRTP = func(ctx *gortsplib.ClientOnPacketRTPCtx) {
|
||||||
if ctx.TrackID != aacTrackID {
|
if ctx.TrackID != mpeg4audioTrackID {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// decode AAC AUs from the RTP packet
|
// decode MPEG4-audio AUs from the RTP packet
|
||||||
aus, _, err := dec.Decode(ctx.Packet)
|
aus, _, err := dec.Decode(ctx.Packet)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@@ -71,7 +71,7 @@ func main() {
|
|||||||
|
|
||||||
// print AUs
|
// print AUs
|
||||||
for _, au := range aus {
|
for _, au := range aus {
|
||||||
log.Printf("received AAC AU of size %d\n", len(au))
|
log.Printf("received MPEG4-audio AU of size %d\n", len(au))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue
Block a user