2018-02-10 16:25:55 +03:00
|
|
|
package generator
|
2018-02-10 09:59:56 +03:00
|
|
|
|
2018-02-10 16:25:55 +03:00
|
|
|
type flvGenerator struct {
|
|
|
|
fps uint
|
|
|
|
inputChan chan []byte
|
|
|
|
outputChan chan []byte
|
|
|
|
headerChan []
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *flvGenerator)GetInputChan() chan []byte {
|
|
|
|
return g.inputChan
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *flvGenerator)GetOutputChan() chan []byte {
|
|
|
|
return g.outputChan
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewFlvGenerator() (g *flvGenerator) {
|
|
|
|
g = new(flvGenerator)
|
|
|
|
g.timestamp = 0
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *flvGenerator) Start(){
|
|
|
|
g.GenHeader()
|
|
|
|
go g.generate()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *flvGenerator) GenHeader(){
|
|
|
|
header = flv.Header{
|
|
|
|
}
|
|
|
|
g.outputChan <- header
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *flvGenerator) GetNextTimestamp() (timestamp uint32){
|
|
|
|
timestamp = g.currentTimestamp
|
|
|
|
g.currentTimeStamp += 100*time.Millisecond() / g.fps
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *flvGenerator) ResetTimestamp() {
|
|
|
|
g.timestamp = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *tsGenerator) generate() {
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case videoFrame := <-g.inputChan
|
|
|
|
}
|
|
|
|
}
|
2018-02-10 09:59:56 +03:00
|
|
|
}
|