Skip to content

Commit

Permalink
fix: publisher close course hls server panic
Browse files Browse the repository at this point in the history
  • Loading branch information
halwu(吴浩麟) committed May 30, 2017
1 parent da522e2 commit 09976a1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 42 deletions.
42 changes: 0 additions & 42 deletions protocol/hls/ts_cache.go → protocol/hls/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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 changes: 4 additions & 0 deletions protocol/hls/hls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions protocol/hls/item.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 09976a1

Please sign in to comment.