Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
Adding a new stream now should be unique for each URI (#25)
Browse files Browse the repository at this point in the history
Adding a new stream now should be unique for each URI
  • Loading branch information
Roverr authored Oct 28, 2019
2 parents ce35f6f + 846c206 commit 2a710e5
Show file tree
Hide file tree
Showing 14 changed files with 916 additions and 1,180 deletions.
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
## Build stage
FROM golang:1.11-alpine AS build-env
FROM golang:1.13-alpine AS build-env
ADD ./main.go /go/src/github.com/Roverr/rtsp-stream/main.go
ADD ./core /go/src/github.com/Roverr/rtsp-stream/core
ADD ./Gopkg.lock /go/src/github.com/Roverr/rtsp-stream/Gopkg.lock
ADD ./Gopkg.toml /go/src/github.com/Roverr/rtsp-stream/Gopkg.toml
WORKDIR /go/src/github.com/Roverr/rtsp-stream
RUN apk add --update --no-cache git
RUN go get -u github.com/golang/dep/cmd/dep
RUN dep ensure
RUN dep ensure -v
RUN go build -o server

## Creating potential production image
Expand Down
5 changes: 2 additions & 3 deletions Dockerfile.management
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
## Build server
FROM golang:1.11-alpine AS build-backend
FROM golang:1.13-alpine AS build-backend
ADD ./main.go /go/src/github.com/Roverr/rtsp-stream/main.go
ADD ./core /go/src/github.com/Roverr/rtsp-stream/core
ADD ./Gopkg.lock /go/src/github.com/Roverr/rtsp-stream/Gopkg.lock
ADD ./Gopkg.toml /go/src/github.com/Roverr/rtsp-stream/Gopkg.toml
WORKDIR /go/src/github.com/Roverr/rtsp-stream
RUN apk add --update --no-cache git
RUN go get -u github.com/golang/dep/cmd/dep
RUN dep ensure
RUN dep ensure -v
RUN go build -o server

## Build UI
Expand Down
90 changes: 38 additions & 52 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@
name = "github.com/rs/cors"
version = "1.6.0"

[[constraint]]
name = "github.com/kennygrant/sanitize"
version = "1.2.4"

[[constraint]]
name = "github.com/brianvoe/gofakeit"
version = "3.15.0"
Expand All @@ -68,3 +64,7 @@
[[constraint]]
name = "github.com/natefinch/lumberjack"
version = "2.1.0"

[[constraint]]
name = "github.com/google/uuid"
version = "1.1.1"
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,16 @@ The following list of players has been already tried out in production environme
* Angular - [videogular](http://www.videogular.com/)
* React - [ReactHLS](https://github.com/foxford/react-hls)

## Coming soon features

✅ - Done

🤷‍♂️ - Needs more labour

* ✅ Proper logging - File logging for the output of ffmpeg with the option of rotating file log
* ✅ Improved cleanup - Unused streams should be removed from the system after a while
* 🤷‍♂️ API improvements - Delete endpoint for streams so clients can remove streams whenever they would like to
* ✅ Authentication layer - More options for creating authentication within the service
## Coming soon
Codebase will be refactored as soon as I'll find some time to do it. 🙏
That will mean a major version bump. The goal is still the same. Keep it relatively simple and easy to integrate.
Solve the issue of not being able to play RTSP natively in browsers.

Plans for the future:
- Throw out URI based directory creation completely
- Add better logging and debug options
- Separate HTTP from Stream processing completely
- Add option to remove streams from the client (Could be tricky, gotta figure out if this should be an option even if non-authenticated mode is used)
- Add better documentation about how to debug streams
- Add documentation about how to create issues
- Add guide for PRs
39 changes: 23 additions & 16 deletions core/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type SummariseDto struct {
type Controller struct {
spec *config.Specification
streams map[string]*streaming.Stream
index map[string]string
fileServer http.Handler
manager IManager
processor streaming.IProcessor
Expand All @@ -67,6 +68,7 @@ func NewController(spec *config.Specification, fileServer http.Handler) *Control
return &Controller{
spec,
map[string]*streaming.Stream{},
map[string]string{},
fileServer,
*manager,
streaming.NewProcessor(spec.Process.StoreDir, spec.Process.KeepFiles, spec.ProcessLogging),
Expand Down Expand Up @@ -123,19 +125,17 @@ func (c *Controller) StartStreamHandler(w http.ResponseWriter, r *http.Request,
c.SendError(w, err, http.StatusBadRequest)
return
}
// Calculate directory from URI
dir, err := streaming.GetURIDirectory(dto.URI)
if err != nil {
logrus.Error(err)
c.SendError(w, ErrUnexpected, http.StatusInternalServerError)
return
}
if stream, ok := c.streams[dir]; ok {
c.handleAlreadyKnownStream(w, stream, c.spec, dir)
if index, ok := c.index[dto.URI]; ok {
stream, ok := c.streams[index]
if !ok {
logrus.Error("Missing index for URI: ", dto.URI)
c.SendError(w, ErrUnexpected, http.StatusInternalServerError)
return
}
c.handleAlreadyKnownStream(w, stream, c.spec, stream.StorePath)
return
}
streamResolved := c.startStream(dto.URI, dir, c.spec)
defer close(streamResolved)
streamResolved := c.startStream(dto.URI, c.spec)
select {
case <-time.After(c.timeout):
c.SendError(w, ErrTimeout, http.StatusRequestTimeout)
Expand All @@ -144,7 +144,13 @@ func (c *Controller) StartStreamHandler(w http.ResponseWriter, r *http.Request,
c.SendError(w, ErrUnexpected, http.StatusInternalServerError)
return
}
s := c.streams[dir]
index, ok := c.index[dto.URI]
if !ok {
logrus.Error("Did not find any index for ", dto.URI)
c.SendError(w, ErrUnexpected, http.StatusInternalServerError)
return
}
s := c.streams[index]
b, _ := json.Marshal(StreamDto{URI: s.Path})
w.Header().Add("Content-Type", "application/json")
w.Write(b)
Expand Down Expand Up @@ -251,10 +257,11 @@ func (c *Controller) FileHandler(w http.ResponseWriter, req *http.Request, ps ht
}

// startStream creates a new stream then starts processing it with a manager
func (c *Controller) startStream(uri, dir string, spec *config.Specification) chan bool {
logrus.Infof("%s started processing", dir)
stream, physicalPath := c.processor.NewStream(uri)
c.streams[dir] = stream
func (c *Controller) startStream(uri string, spec *config.Specification) chan bool {
logrus.Infof("%s started processing", uri)
stream, physicalPath, id := c.processor.NewStream(uri)
c.streams[id] = stream
c.index[uri] = id
ch := c.manager.Start(stream.CMD, physicalPath)
return ch
}
Expand Down
Loading

0 comments on commit 2a710e5

Please sign in to comment.