Browse Source

fix: publisher close course hls server panic

pull/6/head
halwu(吴浩麟) 8 years ago
parent
commit
09976a14a4
  1. 42
      protocol/hls/cache.go
  2. 4
      protocol/hls/hls.go
  3. 18
      protocol/hls/item.go

42
protocol/hls/ts_cache.go → protocol/hls/cache.go

@ -8,31 +8,6 @@ import ( @@ -8,31 +8,6 @@ import (
"sync"
)
type TSCache struct {
entrys map[string]*TSCacheItem
}
func NewTSCache() *TSCache {
return &TSCache{
entrys: make(map[string]*TSCacheItem),
}
}
func (cache *TSCache) Set(key string, e *TSCacheItem) {
v, ok := cache.entrys[key]
if !ok {
cache.entrys[key] = e
}
if v.ID() != e.ID() {
cache.entrys[key] = e
}
}
func (cache *TSCache) Get(key string) *TSCacheItem {
v := cache.entrys[key]
return v
}
const (
maxTSCacheNum = 3
)
@ -108,20 +83,3 @@ func (tcCacheItem *TSCacheItem) GetItem(key string) (TSItem, error) { @@ -108,20 +83,3 @@ func (tcCacheItem *TSCacheItem) GetItem(key string) (TSItem, error) {
}
return item, nil
}
type TSItem struct {
Name string
SeqNum int
Duration int
Data []byte
}
func NewTSItem(name string, duration, seqNum int, b []byte) TSItem {
var item TSItem
item.Name = name
item.SeqNum = seqNum
item.Duration = duration
item.Data = make([]byte, len(b))
copy(item.Data, b)
return item
}

4
protocol/hls/hls.go

@ -104,6 +104,10 @@ func (server *Server) handle(w http.ResponseWriter, r *http.Request) { @@ -104,6 +104,10 @@ func (server *Server) handle(w http.ResponseWriter, r *http.Request) {
return
}
tsCache := conn.GetCacheInc()
if tsCache == nil {
http.Error(w, ErrNoPublisher.Error(), http.StatusForbidden)
return
}
body, err := tsCache.GenM3U8PlayList()
if err != nil {
log.Println("GenM3U8PlayList error: ", err)

18
protocol/hls/item.go

@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
package hls
type TSItem struct {
Name string
SeqNum int
Duration int
Data []byte
}
func NewTSItem(name string, duration, seqNum int, b []byte) TSItem {
var item TSItem
item.Name = name
item.SeqNum = seqNum
item.Duration = duration
item.Data = make([]byte, len(b))
copy(item.Data, b)
return item
}
Loading…
Cancel
Save