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

Commit

Permalink
Merge pull request #28 from Roverr/fix/issues
Browse files Browse the repository at this point in the history
fix - Minor issues
  • Loading branch information
Roverr authored Nov 18, 2019
2 parents bda6df6 + 0d23f08 commit 376afe5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
10 changes: 5 additions & 5 deletions Gopkg.lock

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

27 changes: 8 additions & 19 deletions core/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func (c *Controller) StartStreamHandler(w http.ResponseWriter, r *http.Request,
c.SendError(w, err, http.StatusBadRequest)
return
}
// Process streams that are already known in the system
if index, ok := c.index[dto.URI]; ok {
stream, ok := c.streams[index]
if !ok {
Expand All @@ -135,7 +136,10 @@ func (c *Controller) StartStreamHandler(w http.ResponseWriter, r *http.Request,
c.handleAlreadyKnownStream(w, stream, c.spec, stream.StorePath)
return
}
streamResolved := c.startStream(dto.URI, c.spec)
// Process new streams
logrus.Infof("%s started processing", dto.URI)
stream, physicalPath, id := c.processor.NewStream(dto.URI)
streamResolved := c.manager.Start(stream.CMD, physicalPath)
select {
case <-time.After(c.timeout):
c.SendError(w, ErrTimeout, http.StatusRequestTimeout)
Expand All @@ -144,14 +148,9 @@ func (c *Controller) StartStreamHandler(w http.ResponseWriter, r *http.Request,
c.SendError(w, ErrUnexpected, http.StatusInternalServerError)
return
}
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})
c.streams[id] = stream
c.index[dto.URI] = id
b, _ := json.Marshal(StreamDto{URI: stream.Path})
w.Header().Add("Content-Type", "application/json")
w.Write(b)
}
Expand Down Expand Up @@ -256,16 +255,6 @@ func (c *Controller) FileHandler(w http.ResponseWriter, req *http.Request, ps ht
s.Streak.Activate().Hit()
}

// startStream creates a new stream then starts processing it with a manager
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
}

// marshalValidateURI is for validiting that the URI is in a valid format
// and marshaling it into the dto pointer
func (c *Controller) marshalValidatedURI(dto *StreamDto, body io.Reader) error {
Expand Down
1 change: 1 addition & 0 deletions core/streaming/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func (p Processor) getHLSFlags() string {

// NewProcess creates only the process for the stream
func (p Processor) NewProcess(path, URI string) *exec.Cmd {
os.MkdirAll(path, os.ModePerm)
cmd := exec.Command(
"ffmpeg",
"-y",
Expand Down

0 comments on commit 376afe5

Please sign in to comment.