### RTSP Server Examples (Go) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.1_tab=importedby Provides examples of setting up and running an RTSP server using the gortsplib library. Includes basic server setup, TLS configuration, and saving H.264 streams to disk. ```Go package main import ( "fmt" "os" "github.com/ranulldd/gortsplib/v2" "github.com/ranulldd/gortsplib/v2/pkg/server" ) func main() { // Example: Basic Server server := server.NewServer("0.0.0.0:8554", nil) server.OnRequest(func(ctx *server.RequestCtx) { fmt.Printf("Received request: %s %s\n", ctx.Request.Method, ctx.Request.URL) ctx.Response.Header.Set("Server", "gortsplib") ctx.Response.WriteHeader(&base.StatusOK) }) fmt.Println("Starting RTSP server on :8554") err := server.ListenAndServe() if err != nil { fmt.Printf("Error: %v\n", err) os.Exit(1) } // Example: Server TLS // ... (implementation for TLS server) // Example: Server H.264 Save to Disk // ... (implementation for saving H.264) } ``` -------------------------------- ### RTSP Server Examples (gortsplib) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.2_tab=importedby Provides examples of RTSP server implementations, including basic server setup, authentication, playing back media (H264 from disk), recording media (H264 to disk), and secure server configurations. These examples demonstrate how to handle client connections and media streams on the server side. ```Go package main import ( "fmt" "github.com/ChinasMr/gortsplib/v5/examples/server" ) func main() { fmt.Println("Running basic RTSP server example...") // This is a placeholder for the actual example execution // server.Run() } ``` ```Go package main import ( "fmt" "github.com/ChinasMr/gortsplib/v5/examples/server-auth" ) func main() { fmt.Println("Running RTSP server with authentication example...") // This is a placeholder for the actual example execution // serverauth.Run() } ``` ```Go package main import ( "fmt" "github.com/ChinasMr/gortsplib/v5/examples/server-play-backchannel" ) func main() { fmt.Println("Running RTSP server with backchannel playback example...") // This is a placeholder for the actual example execution // serverplaybackchannel.Run() } ``` ```Go package main import ( "fmt" "github.com/ChinasMr/gortsplib/v5/examples/server-play-format-h264-from-disk" ) func main() { fmt.Println("Running RTSP server H264 playback from disk example...") // This is a placeholder for the actual example execution // serverplayformath264fromdisk.Run() } ``` ```Go package main import ( "fmt" "github.com/ChinasMr/gortsplib/v5/examples/server-record-format-h264-to-disk" ) func main() { fmt.Println("Running RTSP server H264 recording to disk example...") // This is a placeholder for the actual example execution // serverrecordformath264todisk.Run() } ``` ```Go package main import ( "fmt" "github.com/ChinasMr/gortsplib/v5/examples/server-secure" ) func main() { fmt.Println("Running secure RTSP server example...") // This is a placeholder for the actual example execution // serversecure.Run() } ``` -------------------------------- ### RTSP Server Examples (Go) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.10_tab=importedby Illustrates how to build an RTSP server using the gortsplib library. Examples include basic server setup, authentication, and serving different media formats. ```Go package main import ( "fmt" "github.com/loweyequeue/gortsplib/v4/examples/server" "github.com/loweyequeue/gortsplib/v4/examples/server-auth" "github.com/loweyequeue/gortsplib/v4/examples/server-play-format-h264-from-disk" ) func main() { // Conceptual examples of different server functionalities fmt.Println("Server Example:", server.Run) fmt.Println("Server Auth Example:", server_auth.Run) fmt.Println("Server Play H264 Example:", server_play_format_h264_from_disk.Run) } ``` -------------------------------- ### RTSP Server Examples in Go Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.1_tab=importedby Demonstrates how to set up an RTSP server using the gortsplib library. Includes examples for basic proxying, TLS connections, and saving H.264 streams to disk. These examples are useful for understanding RTSP server functionalities. ```go package main import ( "fmt" "github.com/p4xx07/gortsplib/v4/examples/proxy" ) func main() { fmt.Println("RTSP Proxy Example") // proxy.Run() } ``` ```go package main import ( "fmt" "github.com/p4xx07/gortsplib/v4/examples/server" ) func main() { fmt.Println("RTSP Server Example") // server.Run() } ``` ```go package main import ( "fmt" "github.com/p4xx07/gortsplib/v4/examples/server-h264-save-to-disk" ) func main() { fmt.Println("RTSP Server H264 Save to Disk Example") // server_h264_save_to_disk.Run() } ``` ```go package main import ( "fmt" "github.com/p4xx07/gortsplib/v4/examples/server-tls" ) func main() { fmt.Println("RTSP Server TLS Example") // server_tls.Run() } ``` -------------------------------- ### RTSP Server Examples (gortsplib) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.7_tab=importedby Provides examples for setting up and managing an RTSP server using the gortsplib library. Includes basic server setup, TLS configuration, and saving H.264 streams to disk. ```Go package main import ( "fmt" "github.com/pion/rtsp/v3" "github.com/pion/rtsp/v3/pkg/url" ) func main() { // Example for server fmt.Println("Example: server") // ... actual code for basic server ... // Example for server-h264-save-to-disk fmt.Println("Example: server-h264-save-to-disk") // ... actual code for saving H.264 to disk ... // Example for server-tls fmt.Println("Example: server-tls") // ... actual code for TLS server configuration ... } ``` -------------------------------- ### RTSP Server Examples (Go) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.3_tab=importedby Provides examples of RTSP server implementations, including basic server setup, authentication, serving media in specific formats (H264 from disk), and handling backchannel communication. These examples leverage the pion/rtp library. ```Go package main import ( "fmt" "github.com/pion/rtp" "github.com/pion/rtsp/v3" "github.com/pion/rtsp/v3/server" ) func main() { // Example for server fmt.Println("RTSP server example") // Actual code would involve setting up an RTSP server, handling client connections, // and managing media streams. // Example for server-auth fmt.Println("RTSP server example with authentication") // Actual code would involve implementing authentication mechanisms for clients. // ... other examples ... } ``` -------------------------------- ### RTSP Server Example in Go Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.8_tab=importedby An example demonstrating how to set up an RTSP server using the gortsplib library. This includes handling client connections and serving media streams. ```Go package main import ( "log" "github.com/moon-wind/gortsplib/v2" "github.com/moon-wind/gortsplib/v2/pkg/media" "github.com/moon-wind/gortsplib/v2/pkg/server" ) func main() { medias := media.Medias{ media.NewPCMAudio(90000, base.PT96), } // Create a new RTSP server. server := server.NewServer(medias, server.Options{}) // Start the server. log.Printf("Listening on :8554") err := server.ListenAndServe("0.0.0.0:8554") if err != nil { log.Fatal(err) } } ``` -------------------------------- ### RTSP Server Example (Go) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.10_tab=importedby This is a basic example of an RTSP server using gortsplib. It demonstrates the fundamental setup for an RTSP server. ```Go package main import ( "fmt" "github.com/bluenviron/gortsplib/v5" "github.com/bluenviron/gortsplib/v5/pkg/media" "github.com/bluenviron/gortsplib/v5/pkg/url" ) func main() { // Example usage - actual code would involve setting up the server fmt.Println("RTSP server example") // Placeholder for media description medias := media.Medias{ { name: media.TransportRTSP, formats: []media.Format{}, // Add formats here }, } _ = medias // Placeholder for URL parsing url, _ := url.Parse("rtsp://localhost:8554/live") _ = url // Placeholder for server creation server := &gortsplib.Server{} _ = server } ``` -------------------------------- ### gortsplib Examples: RTSP Server Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.5_tab=importedby Illustrates how to implement an RTSP server using the gortsplib library. These examples cover basic server setup, authentication, and serving media streams. ```Go package main import ( "fmt" "github.com/loweyequeue/gortsplib/v4/examples/server" ) func main() { fmt.Println("gortsplib server examples demonstrate setting up an RTSP server.") // To run the basic server example: // go run ./examples/server/main.go // Examples also cover server-auth for authentication and serving specific formats like H.264. } ``` -------------------------------- ### RTSP Client Record Options Example (Go) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.1_tab=importedby Demonstrates how to retrieve and display RTSP session options for recording using the gortsplib library. This example is similar to the play options example but focuses on the recording context. ```Go package main import ( "fmt" "github.com/voicecom/gortsplib/v4" "github.com/voicecom/gortsplib/v4/pkg/url" ) func main() { // Example: client-record-options // This example demonstrates how to retrieve RTSP session options for recording. // Replace with your RTSP server URL url, _ := url.Parse("rtsp://localhost:8554/live/stream") // Create a new RTSP client client := gortsplib.NewClient(url) // Connect to the server and retrieve options err := client.Start() if err != nil { panic(err) } defer client.Close() // Print the supported options for recording fmt.Printf("Supported RTSP record options: %v\n", client.Options()) } ``` -------------------------------- ### RTSP Server Example in Go (gortsplib) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.1_tab=importedby Demonstrates how to implement an RTSP server that can serve media streams. It includes examples for different playback and recording scenarios. ```go package main import ( "fmt" "github.com/loweyequeue/gortsplib/v4" "github.com/loweyequeue/gortsplib/v4/pkg/formats" "github.com/loweyequeue/gortsplib/v4/pkg/media" "github.com/loweyequeue/gortsplib/v4/pkg/sdp" "os" "time" ) func main() { // Example RTSP server server := &gortsplib.Server{} // Create an SDP description for the stream medias := []*sdp.Media{ { Type: sdp.MediaAudio, Protocols: []string{"RTP/AVP"}, Formats: []sdp.Format{ formats.Opus, }, Attributes: []string{ "rtpmap:111 opus/48000/2", }, }, } // Create a media description md := &media.Media{ // This is a placeholder, actual media will be pushed Tracks: []*media.Track{ media.NewTrack(formats.Opus, 90000, "audio", "/dev/null"), }, } // Start the RTSP server err := server.ListenAndServe("0.0.0.0:8554", md) if err != nil { panic(err) } defer server.Close() // Ensure server is closed fmt.Println("RTSP server started on :8554") // Keep the server running select {} } ``` -------------------------------- ### RTSP Proxy and Server Examples (Go) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.1_tab=importedby Contains examples for setting up an RTSP proxy and a basic RTSP server in Go. The server example includes TLS support and functionality to save H264 streams to disk. ```Go package main import ( "fmt" "github.com/westpoint-robotics/gortsplib/v2/pkg/server" ) func main() { // Example for RTSP server fmt.Println("Starting RTSP server...") startRTSPServer() // Example for RTSP proxy fmt.Println("Starting RTSP proxy...") startRTSPProxy() // Example for RTSP server with TLS fmt.Println("Starting RTSP server with TLS...") startRTSPServerTLS() // Example for H264 save to disk fmt.Println("Starting H264 save to disk server...") startH264SaveToDiskServer() } func startRTSPServer() { // Placeholder for RTSP server logic } func startRTSPProxy() { // Placeholder for RTSP proxy logic } func startRTSPServerTLS() { // Placeholder for RTSP server with TLS logic } func startH264SaveToDiskServer() { // Placeholder for H264 save to disk server logic } ``` -------------------------------- ### RTSP Server Example with gortsplib (Go) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.8_tab=importedby This example provides a basic implementation of an RTSP server using the gortsplib library. It demonstrates how to set up a server that can accept client connections and serve media streams. This is a foundational example for building RTSP streaming services. Requires gortsplib. ```go package main import ( "fmt" "github.com/bluenviron/gortsplib/v3/examples/server" ) func main() { // Example usage of server // This would involve setting up an RTSP server. fmt.Println("Running basic RTSP server example...") // Placeholder for actual function call // server.Run() } ``` -------------------------------- ### RTSP Server Example (Go) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.7_tab=importedby An example demonstrating how to set up an RTSP server using the gortsplib library. This includes basic server functionality and an example for saving H.264 streams to disk. ```Go package main import ( "fmt" "github.com/moon-wind/gortsplib" ) func main() { // Example: Basic RTSP server server := gortsplib.NewServer(gortsplib.ServerOptions{}) defer server.Close() // Example: Server saving H.264 to disk // server.OnRequest(func(req *rtsp.Request) { // // Handle request // }) fmt.Println("RTSP Server Example") } ``` -------------------------------- ### RTSP Client Options Example (Go) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.1_tab=importedby This example explores the various options available when configuring an RTSP client using gortsplib. It helps in understanding how to customize client behavior. ```go package main import ( // ... other imports "github.com/bluenviron/gortsplib/v3/examples/client-publish-options" ) func main() { // Example usage would go here // client_publish_options.Run() } ``` -------------------------------- ### RTSP Client Recording Examples (Go) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.8_tab=importedby Provides examples for RTSP client recording functionalities using the gortsplib library. These examples demonstrate how to record streams in various formats (G.711, G.722, H.264, H.265, LPCM, MJPEG, MPEG4-Audio, Opus, VP8, VP9) from an RTSP server. Some examples also show saving the recorded data to disk. ```Go package main import ( "fmt" "os" "github.com/voicecom/gortsplib/v4" "github.com/voicecom/gortsplib/v4/pkg/format" "github.com/voicecom/gortsplib/v4/pkg/url" ) func main() { // Example: client-record-format-g711 // This example demonstrates recording an RTSP stream with G.711 audio format. // It connects to an RTSP server and captures the RTP packets. // Example: client-record-format-h264 // Shows how to record an RTSP stream encoded with H.264 video. // Example: client-record-format-h265-save-to-disk // This example records an H.265 stream from an RTSP server and saves the raw RTP data to a file. // Example: client-record-options // Demonstrates how to use the OPTIONS request to get server capabilities before recording. // Example: client-record-pause // Illustrates how to pause and resume recording of an RTSP stream. fmt.Println("RTSP Client Recording Examples") // Actual code for each example would go here. } ``` -------------------------------- ### RTSP Client Examples (Go) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.1_tab=importedby Demonstrates various client functionalities for the RTSP protocol using the gortsplib library. Includes examples for reading options, pausing streams, republishing, and proxying. ```Go package main import ( "fmt" "os" "github.com/ranulldd/gortsplib/v2" "github.com/ranulldd/gortsplib/v2/pkg/base" "github.com/ranulldd/gortsplib/v2/pkg/conn" "github.com/ranulldd/gortsplib/v2/pkg/headers" "github.com/ranulldd/gortsplib/v2/pkg/url" ) func main() { // Example: Client Read Options url, _ := url.Parse("rtsp://localhost:8554/test") options := &headers.Options res, err := client.Send(base.RequestOptions, url, options) if err != nil { fmt.Printf("Error: %v\n", err) os.Exit(1) } fmt.Printf("Options Response: %v\n", res.Header) // Example: Client Read Pause // ... (implementation for pause) // Example: Client Read Republish // ... (implementation for republish) // Example: Proxy // ... (implementation for proxy) } ``` -------------------------------- ### RTSP Client Examples (Go) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.1_tab=importedby This directory contains various examples demonstrating how to use the gortsplib library to build RTSP clients. Examples cover playing streams, handling backchannels, and specifying different media formats. ```Go package main import ( "fmt" "github.com/moon-wind/gortsplib" "github.com/moon-wind/gortsplib/pkg/url" ) func main() { client := gortsplib.NewClient("rtsp://localhost:8554/test") // Example: Play a stream err := client.Play() // Simplified example if err != nil { fmt.Println("Error playing stream:", err) return } fmt.Println("Stream playing...") // ... handle stream data ... client.Close() } ``` -------------------------------- ### WebRTC Application Examples in Go Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.1_tab=importedby Showcases various WebRTC application patterns using the pion/webrtc library. Includes examples for saving media to WebM files, streaming to Twitch, and converting RTMP to WebRTC. These examples demonstrate practical use cases for WebRTC. ```go package main import ( "fmt" "github.com/pion/example-webrtc-applications/save-to-webm" ) func main() { fmt.Println("Save to WebM Example") // save_to_webm.Run() } ``` ```go package main import ( "fmt" "github.com/pion/example-webrtc-applications/twitch" ) func main() { fmt.Println("Twitch Example") // twitch.Run() } ``` ```go package main import ( "fmt" "github.com/pion/example-webrtc-applications/v3/rtmp-to-webrtc" ) func main() { fmt.Println("RTMP to WebRTC Example") // rtmp_to_webrtc.Run() } ``` ```go package main import ( "fmt" "github.com/pion/example-webrtc-applications/v3/save-to-webm" ) func main() { fmt.Println("v3 Save to WebM Example") // save_to_webm.Run() } ``` ```go package main import ( "fmt" "github.com/pion/example-webrtc-applications/v3/snapshot" ) func main() { fmt.Println("Snapshot Example") // snapshot.Run() } ``` ```go package main import ( "fmt" "github.com/pion/example-webrtc-applications/v3/twitch" ) func main() { fmt.Println("v3 Twitch Example") // twitch.Run() } ``` -------------------------------- ### RTSP Server Example (Go) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.1_tab=importedby This example shows how to create a basic RTSP server using gortsplib. This server can be used to publish streams to clients. ```go package main import ( // ... other imports "github.com/bluenviron/gortsplib/v3/examples/server" ) func main() { // Example usage would go here // server.Run() } ``` -------------------------------- ### RTSP Client Play/Pause Example (Go) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.1_tab=importedby Illustrates how to control RTSP stream playback using the play and pause commands with the gortsplib library. This example shows the basic control flow for starting and stopping a stream remotely. ```Go package main import ( "fmt" "time" "github.com/voicecom/gortsplib/v4" "github.com/voicecom/gortsplib/v4/pkg/url" ) func main() { // Example: client-play-pause // This example demonstrates how to play and pause an RTSP stream. // Replace with your RTSP stream URL url, _ := url.Parse("rtsp://localhost:8554/live/stream") // Create a new RTSP client client := gortsplib.NewClient(url) // Connect to the server err := client.Start() if err != nil { panic(err) } defer client.Close() // Play the stream stream, err := client.Play(nil) if err != nil { panic(err) } fmt.Println("Stream started. Playing for 10 seconds...") time.Sleep(10 * time.Second) // Pause the stream err = client.Pause() if err != nil { panic(err) } fmt.Println("Stream paused.") time.Sleep(5 * time.Second) // Resume the stream (by calling Play again) stream, err = client.Play(nil) if err != nil { panic(err) } fmt.Println("Stream resumed. Playing for another 10 seconds...") time.Sleep(10 * time.Second) // Stop the stream (by closing the client) fmt.Println("Stopping stream.") } ``` -------------------------------- ### RTSP Proxy Example (Go) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.1_tab=importedby This example demonstrates how to set up a simple RTSP proxy server using gortsplib. A proxy can be used to forward RTSP streams or perform other network manipulations. ```go package main import ( // ... other imports "github.com/bluenviron/gortsplib/v3/examples/proxy" ) func main() { // Example usage would go here // proxy.Run() } ``` -------------------------------- ### RTSP Server Example (Go) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.2_tab=importedby Demonstrates how to set up an RTSP server using gortsplib. This example allows clients to connect and play a simulated media stream. ```Go package main import ( "fmt" "log" "os/signal" "syscall" "time" "github.com/loweyequeue/gortsplib/v4" "github.com/loweyequeue/gortsplib/v4/pkg/base" "github.com/loweyequeue/gortsplib/v4/pkg/confpalparse" "github.com/loweyequeue/gortsplib/v4/pkg/desc" "github.com/loweyequeue/gortsplib/v4/pkg/rtphandler" ) func main() { // Create a new RTSP server server := gortsplib.NewServer(gortsplib.ServerConf{}) // Create a new media description medias := []*desc.Media{ { Type: desc.MediaTypeVideo, Clock: 90000, Formats: []int{96}, // Example: dynamic payload type for H.264 Control: base.URLPath("stream"), Description: "\n\n a=rtpmap:96 H264/90000\n", }, } // Add a stream to the server streamPath := base.URLPath("/live/stream") stream := server.AddStream(streamPath, medias) // Handle incoming RTSP connections server.OnRequest(func(conn *gortsplib.Conn, req *base.Request) { log.Printf("<- %s %s %s", conn.RemoteAddr(), req.Method, req.URL.Path) // Handle requests stream.HandleRequest(conn, req) }) // Handle new clients server.OnDescribe(func(conn *gortsplib.Conn) (*base.Response, error) { return stream.Describe(), nil }) // Handle SETUP requests server.OnSetup(func(conn *gortsplib.Conn, ch *rtphandler.TransportHandler) (*base.Response, error) { return stream.Setup(ch) }) // Handle PLAY requests server.OnPlay(func(conn *gortsplib.Conn) (*base.Response, error) { return stream.Play()[:] }) // Handle TEARDOWN requests server.OnTeardown(func(conn *gortsplib.Conn) (*base.Response, error) { return stream.Teardown() }) // Start the server in a goroutine go func() { err := server.ListenAndServe("0.0.0.0:8554") if err != nil { log.Fatalf("Server error: %v", err) } }() log.Println("RTSP server started on :8554") // Simulate sending RTP packets (e.g., video frames) go func() { for { // In a real scenario, you would generate or receive media data // For simplicity, sending dummy RTP packets payload := []byte{0x01, 0x02, 0x03, 0x04} stream.WritePacket(&rtp.Packet{ Header: rtputils.RTPHeader{ Version: 2, PayloadType: 96, Timestamp: uint32(time.Now().UnixNano() / int64(time.Second/90000)), SSRC: stream.SSRC(), }, Payload: payload, }) time.Sleep(20 * time.Millisecond) // Simulate ~50fps } }() // Wait for termination signal quit := make(chan os.Signal, 1) ssignal.Notify(quit, syscall.SIGINT, syscall.SIGTERM) <-quit log.Println("Shutting down server...") server.Close() // Close the server <-server.WaitChannel() // Wait for all connections to close log.Println("Server stopped") } ``` -------------------------------- ### RTSP Server Example (Go) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.4_tab=importedby Provides an example of an RTSP server implementation using gortsplib. This server can handle DESCRIBE, SETUP, PLAY, and TEARDOWN requests. ```go package main import ( "fmt" "log" "os" "time" "github.com/loweyequeue/gortsplib/v4" "github.com/loweyequeue/gortsplib/v4/pkg/base" "github.com/loweyequeue/gortsplib/v4/pkg/confpalparse" "github.com/loweyequeue/gortsplib/v4/pkg/format" "github.com/loweyequeue/gortsplib/v4/pkg/media" "github.com/loweyequeue/gortsplib/v4/pkg/url" ) func main() { // Create a new RTSP server server := gortsplib.NewServer() // Define a media track (e.g., H.264 video) // Replace with your actual media source track := media.NewTrack(media.TransportUDP, format.FormatH264) // Add the track to the server's stream stream := server.NewStream("live") // Path for the stream stream.AddTrack(track) // Set up handlers for RTSP requests server.OnDescribe = func(client *gortsplib.Client, req *base.Request) (*base.Response, error) { fmt.Printf("Received DESCRIBE request from %s\n", client.RemoteAddr()) // Return the SDP description of the stream return client.RespondDescribe(stream.SPropParameterSets) } server.OnSetup = func(client *gortsplib.Client, req *base.Request) (*base.Response, error) { fmt.Printf("Received SETUP request from %s\n", client.RemoteAddr()) // Handle SETUP request, assign client ports, and return RTSP response return client.RespondSetup(nil) } server.OnPlay = func(client *gortsplib.Client, req *base.Request) (*base.Response, error) { fmt.Printf("Received PLAY request from %s\n", client.RemoteAddr()) // Start sending media data to the client go func() { for { // Simulate sending an RTP packet (replace with actual media data) // This is a placeholder and needs to be replaced with actual media encoding and RTP packetization. payload := []byte{0x00, 0x00, 0x01, 0x64, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00} // Dummy H.264 NAL unit packet := &rtp.Packet{ Header: rtp.Header{ Version: 2, PayloadType: 96, // Example payload type for H.264 SequenceNumber: 1, Timestamp: uint32(time.Now().UnixNano() / int64(time.Millisecond)), }, Payload: payload, } client.WritePacketRTP(track.ID, packet) time.Sleep(20 * time.Millisecond) // Simulate frame rate } }() return client.RespondPlay(nil) } server.OnTeardown = func(client *gortsplib.Client, req *base.Request) (*base.Response, error) { fmt.Printf("Received TEARDOWN request from %s\n", client.RemoteAddr()) // Stop sending media data and close the connection return client.RespondTeardown() // RespondTeardown() will close the connection } // Start the server addr := "0.0.0.0:8554" fmt.Printf("RTSP server listening on %s\n", addr) err := server.ListenAndServe(addr) if err != nil { log.Fatalf("Failed to start RTSP server: %v", err) } defer server.Close() } ``` -------------------------------- ### RTSP Client Publish Format MJPEG Example (Go) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.1_tab=importedby This example shows how to publish a Motion JPEG (MJPEG) stream to an RTSP server using gortsplib. This is a straightforward way to stream video, often used in simpler setups. ```go package main import ( // ... other imports "github.com/bluenviron/gortsplib/v3/examples/client-publish-format-mjpeg" ) func main() { // Example usage would go here // client_publish_format_mjpeg.Run() } ``` -------------------------------- ### RTSP Server Example in Go (gortsplib) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.8_tab=importedby Illustrates how to set up an RTSP server using the gortsplib library. This example covers basic server functionality, including handling client connections and serving media streams. ```Go package main import ( "fmt" "log" "github.com/loweyequeue/gortsplib/v4/examples/server" ) func main() { // Example usage of RTSP server // This would typically involve creating an RTSP server instance and listening for connections. fmt.Println("RTSP Server example started.") // Placeholder for actual server logic // server.Run(":8554") } ``` -------------------------------- ### RTSP Server Examples (Go) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.5_tab=importedby Provides examples for setting up and managing RTSP servers. Includes functionalities for basic server operations, authentication, playing back media (H264 from disk), recording media to disk, and secure server configurations. ```Go package main import ( "fmt" "github.com/ChinasMr/gortsplib/v5/examples/server" ) func main() { fmt.Println("Running basic RTSP server example...") // In a real scenario, you would call a function from the imported package // For demonstration, we'll just print a message. // server.Run() } ``` ```Go package main import ( "fmt" "github.com/ChinasMr/gortsplib/v5/examples/server-auth" ) func main() { fmt.Println("Running RTSP server with authentication example...") // In a real scenario, you would call a function from the imported package // For demonstration, we'll just print a message. // serverauth.Run() } ``` ```Go package main import ( "fmt" "github.com/ChinasMr/gortsplib/v5/examples/server-play-backchannel" ) func main() { fmt.Println("Running RTSP server with backchannel playback example...") // In a real scenario, you would call a function from the imported package // For demonstration, we'll just print a message. // serverplaybackchannel.Run() } ``` ```Go package main import ( "fmt" "github.com/ChinasMr/gortsplib/v5/examples/server-play-format-h264-from-disk" ) func main() { fmt.Println("Running RTSP server H264 playback from disk example...") // In a real scenario, you would call a function from the imported package // For demonstration, we'll just print a message. // serverplayformath264fromdisk.Run() } ``` ```Go package main import ( "fmt" "github.com/ChinasMr/gortsplib/v5/examples/server-record-format-h264-to-disk" ) func main() { fmt.Println("Running RTSP server H264 recording to disk example...") // In a real scenario, you would call a function from the imported package // For demonstration, we'll just print a message. // serverrecordformath264todisk.Run() } ``` ```Go package main import ( "fmt" "github.com/ChinasMr/gortsplib/v5/examples/server-secure" ) func main() { fmt.Println("Running secure RTSP server example...") // In a real scenario, you would call a function from the imported package // For demonstration, we'll just print a message. // serversecure.Run() } ``` -------------------------------- ### RTSP Client Play/Pause Example (Go) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.5_tab=importedby Illustrates controlling the playback of an RTSP stream using the PLAY and PAUSE commands. This example shows how to start playback, pause it, and then resume it. ```Go package main import ( "fmt" "time" "github.com/voicecom/gortsplib/v4" ) func main() { // Example: client-play-pause // This example demonstrates how to play, pause, and resume an RTSP stream. // It requires a RTSP URL as input. // Placeholder for actual RTSP URL rtspURL := "rtsp://example.com/stream" // Create a new RTSP client client := gortsplib.NewClient(rtspURL) // Connect to the RTSP server err := client.Start() // In a real scenario, handle errors if err != nil { fmt.Printf("Error connecting to RTSP server: %v\n", err) return } defer client.Close() // In a real scenario, handle errors // Start playing the stream stream, err := client.Play() // In a real scenario, handle errors if err != nil { fmt.Printf("Error playing stream: %v\n", err) return } fmt.Println("Stream started. Playing for 5 seconds...") time.Sleep(5 * time.Second) // Pause the stream err = client.Pause() // In a real scenario, handle errors if err != nil { fmt.Printf("Error pausing stream: %v\n", err) return } fmt.Println("Stream paused. Waiting for 5 seconds...") time.Sleep(5 * time.Second) // Resume the stream err = stream.Play() // In a real scenario, handle errors if err != nil { fmt.Printf("Error resuming stream: %v\n", err) return } fmt.Println("Stream resumed. Playing for another 5 seconds...") time.Sleep(5 * time.Second) fmt.Println("Finished playback control.") } ``` -------------------------------- ### RTSP Proxy and Server Examples (Go) Source: https://pkg.go.dev/github.com/pion/rtp/index_tab=importedby These examples demonstrate setting up an RTSP proxy and a basic RTSP server using gortsplib. The proxy forwards requests, while the server handles incoming connections and streams. ```Go package main import ( "github.com/aler9/gortsplib/v2/examples/proxy" ) func main() { proxy.main() } ``` ```Go package main import ( "github.com/aler9/gortsplib/v2/examples/server" ) func main() { server.main() } ``` -------------------------------- ### Run RTSP Server with H.264 Playback from Disk (Go) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.1_tab=importedby This example demonstrates how to set up an RTSP server that plays H.264 video streams directly from disk. It utilizes the gortsplib library to handle RTSP communication and H.264 format specifics. No external dependencies are required beyond the gortsplib library itself. ```go package main import ( "fmt" "os" "github.com/bluenviron/gortsplib/v4" "github.com/bluenviron/gortsplib/v4/pkg/format" "github.com/bluenviron/gortsplib/v4/pkg/format/rtph264" ) func main() { // parse H264 format var forma format.Format forma, err := format.Infer([]byte{0x01, 0x02, 0x03, 0x04}) if err != nil { panic(err) } if _, ok := forma.(*format.H264); ok { fmt.Println("H264 format detected") } // open file file, err := os.Open("video.h264") if err != nil { panic(err) } // create server server := &gortsplib.Server{ Handler: &serverPlayH264FromDisk{file: file, forma: forma}, } // run server fmt.Println("listening on :8554") err = server.ListenAndServe("0.0.0.0:8554") if err != nil { panic(err) } } type serverPlayH264FromDisk struct { file *os.File forma format.Format } func (s *serverPlayH264FromDisk) OnRequest(ctx *gortsplib.ServerOnRequestCtx) { // handle requests } func (s *serverPlayH264FromDisk) OnDescribe(ctx *gortsplib.ServerOnDescribeCtx) { // describe } func (s *serverPlayH264FromDisk) OnPlay(ctx *gortsplib.ServerOnPlayCtx) { // play } func (s *serverPlayH264FromDisk) OnRecord(ctx *gortsplib.ServerOnRecordCtx) { // record } func (s *serverPlayH264FromDisk) OnPause(ctx *gortsplib.ServerOnPauseCtx) { // pause } func (s *serverPlayH264FromDisk) OnClose(ctx *gortsplib.ServerOnCloseCtx) { // close } ``` -------------------------------- ### RTSP Client Play/Pause Control (Go) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.8_tab=importedby This example shows how an RTSP client can control the playback of a stream by sending PLAY and PAUSE commands. This allows for interactive control of the media stream, such as starting, stopping, or resuming playback. ```Go package main import ( "log" "os" "github.com/bluenviron/gortsplib/v5" "github.com/bluenviron/gortsplib/v5/pkg/media" ) func main() { // get URL from command line arguments url := "rtsp://localhost:8554/test" if len(os.Args) > 1 { url = os.Args[1] } // parse URL parsedURL, err := gortsplib.ParseURL(url) if err != nil { log.Fatalf("failed to parse URL: %v", err) } // create client client := &gortsplib.Client{} // connect to server err = client.Start(parsedURL.Host, parsedURL. ``` -------------------------------- ### RTSP Client Options Example (Go) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.1_tab=importedby Demonstrates how to retrieve and display RTSP session options using the gortsplib library. This example connects to an RTSP server and prints the supported options, which can be useful for understanding server capabilities. ```Go package main import ( "fmt" "github.com/voicecom/gortsplib/v4" "github.com/voicecom/gortsplib/v4/pkg/url" ) func main() { // Example: client-play-options // This example demonstrates how to retrieve RTSP session options. // Replace with your RTSP server URL url, _ := url.Parse("rtsp://localhost:8554/live/stream") // Create a new RTSP client client := gortsplib.NewClient(url) // Connect to the server and retrieve options err := client.Start() if err != nil { panic(err) } defer client.Close() // Print the supported options fmt.Printf("Supported RTSP options: %v\n", client.Options()) } ``` -------------------------------- ### SIP Client Call Out Example (Go) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.4_tab=importedby An example demonstrating how to make an outgoing call using the SIP protocol with a client. This package likely uses a SIP library to handle call setup and signaling. ```Go package call_out import ( "fmt" "github.com/go-av/gosip/examples/sip_client/call_out" ) func main() { fmt.Println("Starting SIP client call out example...") // The actual call out logic would be within the imported package // call_out.InitiateCall("sip:user@example.com") fmt.Println("SIP call out logic placeholder.") } ``` -------------------------------- ### RTSP Server and Proxy Examples (Go) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.6_tab=importedby Provides examples for setting up an RTSP server and a proxy using the gortsplib library. These demonstrate server-side capabilities and how to forward RTSP streams. ```Go package main import ( "fmt" "os" "github.com/galindocode/gortsplib/v4/pkg/server" ) func main() { fmt.Println("Starting RTSP server...") // Server setup and configuration would be here _ = server.Server{} // ... server logic ... os.Exit(0) } ``` ```Go package main import ( "fmt" "os" "github.com/galindocode/gortsplib/v4/pkg/client" ) func main() { fmt.Println("Starting RTSP proxy...") // Proxy setup and configuration would be here _ = client.Client{} // ... proxy logic ... os.Exit(0) } ``` -------------------------------- ### RTSP Client Read Example with gortsplib (Go) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.8_tab=importedby This example provides a basic demonstration of an RTSP client reading data using the gortsplib library. It covers the fundamental steps of connecting to an RTSP server and receiving media streams. This serves as a starting point for building more complex RTSP client applications. Requires gortsplib. ```go package main import ( "fmt" "github.com/bluenviron/gortsplib/v3/examples/client-read" ) func main() { // Example usage of client-read // This would involve setting up an RTSP client and receiving data. fmt.Println("Running basic RTSP client read example...") // Placeholder for actual function call // client_read.Run() } ``` -------------------------------- ### RTSP Server Examples (Go) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.6_tab=importedby Provides examples of setting up an RTSP server with various features. Includes handling authentication, serving H264 streams from disk, and supporting backchannel communication. ```Go package main import ( "fmt" "os" "github.com/ChinasMr/gortsplib/v5/pkg/auth" "github.com/ChinasMr/gortsplib/v5/pkg/server" ) func main() { // Example: Basic RTSP server setup // This is a simplified representation. fmt.Println("Setting up a basic RTSP server...") // Placeholder for server configuration conf := &server.ServerConf{ // Add server configuration options here } // Placeholder for authentication (optional) authenticator := auth.Authenticator{ // Basic authentication example // Add users and passwords here } // Create a new RTSP server instance ss := conf.NewServer("", "", "", nil) // In a real scenario, you would define routes, handle connections, and manage streams. _ = ss _ = authenticator fmt.Println("RTSP server setup complete.") } ``` -------------------------------- ### SIP Go Echo Example (Go) Source: https://pkg.go.dev/github.com/pion/rtp/%40v1.4_tab=importedby A simple echo example using the sipgox library for SIP (Session Initiation Protocol). This demonstrates basic SIP client functionality, including sending and receiving messages for call setup and control. ```Go package echouac import ( "fmt" "github.com/rawhiHannon/sipgox/pkg/client" "github.com/rawhiHannon/sipgox/pkg/message" "github.com/rawhiHannon/sipgox/pkg/transport" ) func main() { // Create a new SIP client cl, err := client.New("udp", "127.0.0.1:5060") if err != nil { panic(err) } // Set up a handler for incoming messages cl.OnRequest(func(req *message.Request) { fmt.Printf("Received Request: %s %s\n", req.Method, req.URL.String()) // Handle requests, e.g., respond to INVITE resp := message.NewResponse(200, "OK", req) cl.Respond(resp) }) cl.OnResponse(func(resp *message.Response) { fmt.Printf("Received Response: %d %s\n", resp.StatusCode, resp.ReasonPhrase) // Handle responses, e.g., ACK for INVITE }) // Create an INVITE request inviteReq, err := message.NewRequest("INVITE", "sip:user@example.com", "SIP/2.0") if err != nil { panic(err) } // Send the INVITE request err = cl.Send(inviteReq) if err != nil { panic(err) } fmt.Println("INVITE sent") // Keep the client running select {} } ```