github.com/cnotch/ipchub@v1.1.0/media/options.go (about) 1 // Copyright (c) 2019,CAOHONGJU All rights reserved. 2 // Use of this source code is governed by a MIT-style 3 // license that can be found in the LICENSE file. 4 5 package media 6 7 import ( 8 "io" 9 "strings" 10 "time" 11 ) 12 13 // Multicastable 支持组播模式的源 14 type Multicastable interface { 15 AddMember(io.Closer) 16 ReleaseMember(io.Closer) 17 MulticastIP() string 18 Port(index int) int 19 TTL() int 20 SourceIP() string 21 } 22 23 // Hlsable 支持Hls访问 24 type Hlsable interface { 25 M3u8(token string) ([]byte, error) 26 Segment(seq int) (io.Reader, int, error) 27 LastAccessTime() time.Time 28 } 29 30 // Option 配置 Stream 的选项接口 31 type Option interface { 32 apply(*Stream) 33 } 34 35 // optionFunc 包装函数以便它满足 Option 接口 36 type optionFunc func(*Stream) 37 38 func (f optionFunc) apply(s *Stream) { 39 f(s) 40 } 41 42 // Attr 流属性选项 43 func Attr(k, v string) Option { 44 return optionFunc(func(s *Stream) { 45 k := strings.ToLower(strings.TrimSpace(k)) 46 s.attrs[k] = v 47 }) 48 } 49 50 // Multicast 流组播选项 51 func Multicast(multicast Multicastable) Option { 52 return optionFunc(func(s *Stream) { 53 s.multicast = multicast 54 }) 55 } 56 57 // Hls Hls选项 58 func Hls(hls Hlsable) Option { 59 return optionFunc(func(s *Stream) { 60 s.hls = hls 61 }) 62 }