Skip to content

Commit

Permalink
feat: optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
Danile71 committed Jan 26, 2024
1 parent 862c146 commit 0c1ab0d
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 21 deletions.
8 changes: 1 addition & 7 deletions example/file/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"

"github.com/Danile71/go-rtsp"
"github.com/gorilla/mux"
"github.com/mattn/go-mjpeg"
)

Expand Down Expand Up @@ -54,13 +53,8 @@ func main() {
}
}()

streamHandler := func(w http.ResponseWriter, r *http.Request) {
s.ServeHTTP(w, r)
}
http.Handle("/stream", s)

router := mux.NewRouter()
router.HandleFunc("/stream", streamHandler)
http.Handle("/", router)
if err := http.ListenAndServe(":8181", nil); err != nil {
slog.Error(
"listen",
Expand Down
10 changes: 2 additions & 8 deletions example/url/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import (
"os"

"github.com/Danile71/go-rtsp"
"github.com/gorilla/mux"
"github.com/mattn/go-mjpeg"
)

const uri = "rtsp://192.168.139.24:8554/mystream"

func main() {
// Set ffmpeg log level
rtsp.SetLogLevel(rtsp.AV_LOG_QUIET)
rtsp.SetLogLevel(rtsp.AV_LOG_TRACE)

// Create mjpeg instance
s := mjpeg.NewStream()
Expand Down Expand Up @@ -67,13 +66,8 @@ func main() {
}
}()

streamHandler := func(w http.ResponseWriter, r *http.Request) {
s.ServeHTTP(w, r)
}
http.Handle("/stream", s)

router := mux.NewRouter()
router.HandleFunc("/stream", streamHandler)
http.Handle("/", router)
if err := http.ListenAndServe(":8181", nil); err != nil {
slog.Error(
"listen",
Expand Down
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@ module github.com/Danile71/go-rtsp

go 1.21

require (
github.com/gorilla/mux v1.8.1
github.com/mattn/go-mjpeg v0.0.3
)
require github.com/mattn/go-mjpeg v0.0.3
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/mattn/go-mjpeg v0.0.3 h1:0G/+KddrbI5Hnq83B11O1O4vP7Q6L9MsBu6aW71jhUM=
github.com/mattn/go-mjpeg v0.0.3/go.mod h1:65z7Cj+u5y5K3B8Sy5NtrJFTWAhguGHs9FEkADdx6kE=

0 comments on commit 0c1ab0d

Please sign in to comment.