Skip to content

Commit 28317c5

Browse files
committed
export hls lib.
1 parent 37b4433 commit 28317c5

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@ import (
1111
"syscall"
1212
"time"
1313

14-
"github.com/m1k1o/go-transcode/internal/utils"
1514
"github.com/rs/zerolog"
1615
"github.com/rs/zerolog/log"
16+
17+
"github.com/m1k1o/go-transcode/internal/utils"
1718
)
1819

1920
const cleanupPeriod = 2 * time.Second
2021
const hlsMinimumSegments = 2
2122
const hlsSegmentDuration = 6
2223

23-
type HlsManagerCtx struct {
24+
type ManagerCtx struct {
2425
logger zerolog.Logger
2526
mu sync.Mutex
2627
cmdFactory func() *exec.Cmd
@@ -37,8 +38,8 @@ type HlsManagerCtx struct {
3738
shutdown chan interface{}
3839
}
3940

40-
func New(cmdFactory func() *exec.Cmd) *HlsManagerCtx {
41-
return &HlsManagerCtx{
41+
func New(cmdFactory func() *exec.Cmd) *ManagerCtx {
42+
return &ManagerCtx{
4243
logger: log.With().Str("module", "hls").Str("submodule", "manager").Logger(),
4344
cmdFactory: cmdFactory,
4445

@@ -47,7 +48,7 @@ func New(cmdFactory func() *exec.Cmd) *HlsManagerCtx {
4748
}
4849
}
4950

50-
func (m *HlsManagerCtx) Start() error {
51+
func (m *ManagerCtx) Start() error {
5152
m.mu.Lock()
5253
defer m.mu.Unlock()
5354

@@ -129,7 +130,7 @@ func (m *HlsManagerCtx) Start() error {
129130
return m.cmd.Start()
130131
}
131132

132-
func (m *HlsManagerCtx) Stop() {
133+
func (m *ManagerCtx) Stop() {
133134
m.mu.Lock()
134135
defer m.mu.Unlock()
135136

@@ -152,7 +153,7 @@ func (m *HlsManagerCtx) Stop() {
152153
})
153154
}
154155

155-
func (m *HlsManagerCtx) Cleanup() {
156+
func (m *ManagerCtx) Cleanup() {
156157
diff := time.Now().Unix() - m.lastRequest
157158
stop := m.active && diff > 2*hlsSegmentDuration || !m.active && diff > 4*hlsSegmentDuration
158159

@@ -168,7 +169,7 @@ func (m *HlsManagerCtx) Cleanup() {
168169
}
169170
}
170171

171-
func (m *HlsManagerCtx) ServePlaylist(w http.ResponseWriter, r *http.Request) {
172+
func (m *ManagerCtx) ServePlaylist(w http.ResponseWriter, r *http.Request) {
172173
m.lastRequest = time.Now().Unix()
173174
playlist := m.playlist
174175

@@ -198,7 +199,7 @@ func (m *HlsManagerCtx) ServePlaylist(w http.ResponseWriter, r *http.Request) {
198199
w.Write([]byte(playlist))
199200
}
200201

201-
func (m *HlsManagerCtx) ServeMedia(w http.ResponseWriter, r *http.Request) {
202+
func (m *ManagerCtx) ServeMedia(w http.ResponseWriter, r *http.Request) {
202203
fileName := path.Base(r.URL.RequestURI())
203204
path := path.Join(m.tempdir, fileName)
204205

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package types
1+
package hls
22

33
import "net/http"
44

5-
type HlsManager interface {
5+
type Manager interface {
66
Start() error
77
Stop()
88
Cleanup()

internal/api/hls.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ import (
99
"github.com/go-chi/chi"
1010
"github.com/rs/zerolog/log"
1111

12-
"github.com/m1k1o/go-transcode/internal/hls"
13-
"github.com/m1k1o/go-transcode/internal/types"
12+
"github.com/m1k1o/go-transcode/hls"
1413
)
1514

16-
var hlsManagers map[string]types.HlsManager = make(map[string]types.HlsManager)
15+
var hlsManagers map[string]hls.Manager = make(map[string]hls.Manager)
1716

1817
func (a *ApiManagerCtx) HLS(r chi.Router) {
1918
r.Get("/{profile}/{input}/index.m3u8", func(w http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)