streaming

Media streaming and broadcast systems in Go
Log | Files | Refs | README | LICENSE

example_test.go (1269B)


      1 package sdp_test
      2 
      3 import (
      4 	"fmt"
      5 	"net/netip"
      6 
      7 	"github.com/untangledco/streaming/rtp"
      8 	"github.com/untangledco/streaming/sdp"
      9 )
     10 
     11 // A simple Session describing transmission of uncompressed linear PCM
     12 // audio in RTP starts by setting the mandatory fields Origin and Name.
     13 // The Media field contains information about the audio such as the sample rate
     14 // and the number of audio channels.
     15 // Session implements encoding.TextMarshaler;
     16 // to encode a Session in the SDP text format, use Session.MarshalText().
     17 func Example() {
     18 	session := sdp.Session{
     19 		Origin: sdp.Origin{
     20 			ID:      3930287268, // example only; use sdp.Now()
     21 			Version: 3930287268, // example only; use sdp.Now()
     22 			Address: netip.MustParseAddr("2001:db8::1"),
     23 		},
     24 		Name: "A call from me to you",
     25 		Media: []sdp.Media{
     26 			{
     27 				Type:      sdp.MediaTypeAudio,
     28 				Port:      6969,
     29 				Transport: sdp.ProtoRTP,
     30 				Format:    []string{rtp.PayloadL16Mono.String()},
     31 				Attributes: []string{
     32 					"rtpmap:" + rtp.PayloadL16Mono.String(),
     33 					"L16/22050",
     34 				},
     35 			},
     36 		},
     37 	}
     38 	text, _ := session.MarshalText()
     39 	fmt.Printf("%s", text)
     40 	// Output:
     41 	// v=0
     42 	// o=- 3930287268 3930287268 IN IP6 2001:db8::1
     43 	// s=A call from me to you
     44 	// t=0 0
     45 	// m=audio 6969 RTP/AVP 11
     46 	// a=rtpmap:11 L16/22050
     47 }