Skip to content

Commit

Permalink
Small refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
deluan committed Jul 21, 2021
1 parent 1cef44a commit 86c0b42
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
12 changes: 6 additions & 6 deletions core/media_streamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ type MediaStreamer interface {

type TranscodingCache cache.FileCache

func NewMediaStreamer(ds model.DataStore, ffm transcoder.Transcoder, cache TranscodingCache) MediaStreamer {
return &mediaStreamer{ds: ds, ffm: ffm, cache: cache}
func NewMediaStreamer(ds model.DataStore, t transcoder.Transcoder, cache TranscodingCache) MediaStreamer {
return &mediaStreamer{ds: ds, transcoder: t, cache: cache}
}

type mediaStreamer struct {
ds model.DataStore
ffm transcoder.Transcoder
cache cache.FileCache
ds model.DataStore
transcoder transcoder.Transcoder
cache cache.FileCache
}

type streamJob struct {
Expand Down Expand Up @@ -182,7 +182,7 @@ func GetTranscodingCache() TranscodingCache {
log.Error(ctx, "Error loading transcoding command", "format", job.format, err)
return nil, os.ErrInvalid
}
out, err := job.ms.ffm.Start(ctx, t.Command, job.mf.Path, job.bitRate)
out, err := job.ms.transcoder.Start(ctx, t.Command, job.mf.Path, job.bitRate)
if err != nil {
log.Error(ctx, "Error starting transcoder", "id", job.mf.ID, err)
return nil, os.ErrInvalid
Expand Down
12 changes: 4 additions & 8 deletions core/transcoder/ffmpeg.go → core/transcoder/transcoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,15 @@ type Transcoder interface {
}

func New() Transcoder {
_, err := exec.LookPath("ffmpeg")
if err != nil {
log.Error("Unable to find ffmpeg", err)
}
return &ffmpeg{}
return &externalTranscoder{}
}

type ffmpeg struct{}
type externalTranscoder struct{}

func (ff *ffmpeg) Start(ctx context.Context, command, path string, maxBitRate int) (f io.ReadCloser, err error) {
func (e *externalTranscoder) Start(ctx context.Context, command, path string, maxBitRate int) (f io.ReadCloser, err error) {
args := createTranscodeCommand(command, path, maxBitRate)

log.Trace(ctx, "Executing ffmpeg command", "cmd", args)
log.Trace(ctx, "Executing transcoding command", "cmd", args)
cmd := exec.Command(args[0], args[1:]...) // #nosec
cmd.Stderr = os.Stderr
if f, err = cmd.StdoutPipe(); err != nil {
Expand Down
File renamed without changes.

0 comments on commit 86c0b42

Please sign in to comment.