convert Tracks into Medias and Formats (#155)

* split tracks from medias

* move tracks into dedicated package

* move media into dedicated package

* edit Medias.Marshal() in order to return SDP

* add medias.Find() and simplify examples

* improve coverage

* fix rebase errors

* replace TrackIDs with MediaIDs

* implement media-specific and track-specific callbacks for reading RTCP and RTP packets

* rename publish into record, read into play

* add v2 tag

* rename tracks into formats
This commit is contained in:
Alessandro Ros
2022-12-11 22:03:22 +01:00
committed by GitHub
parent 2a5b3e3ee5
commit a1396206b5
177 changed files with 6872 additions and 7333 deletions

View File

@@ -5,13 +5,15 @@ import (
"net"
"time"
"github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/v2"
"github.com/aler9/gortsplib/v2/pkg/format"
"github.com/aler9/gortsplib/v2/pkg/media"
"github.com/pion/rtp"
)
// This example shows how to
// 1. generate RTP/H264 frames from a file with GStreamer
// 2. connect to a RTSP server, announce an H264 track
// 2. connect to a RTSP server, announce an H264 media
// 3. write the frames to the server for 5 seconds
// 4. pause for 5 seconds
// 5. repeat
@@ -36,16 +38,19 @@ func main() {
}
log.Println("stream connected")
// create an H264 track
track := &gortsplib.TrackH264{
PayloadType: 96,
PacketizationMode: 1,
// create a media that contains a H264 format
medi := &media.Media{
Type: media.TypeVideo,
Formats: []format.Format{&format.H264{
PayloadTyp: 96,
PacketizationMode: 1,
}},
}
// connect to the server and start publishing the track
// connect to the server and start recording the media
c := gortsplib.Client{}
err = c.StartPublishing("rtsp://localhost:8554/mystream",
gortsplib.Tracks{track})
err = c.StartRecording("rtsp://localhost:8554/mystream",
media.Medias{medi})
if err != nil {
panic(err)
}
@@ -62,7 +67,7 @@ func main() {
}
// route RTP packet to the server
c.WritePacketRTP(0, &pkt)
c.WritePacketRTP(medi, &pkt)
// read another RTP packet from source
n, _, err = pc.ReadFrom(buf)