From 2bb1d4cfe020347d60c6af1f66e76a9bef9dab76 Mon Sep 17 00:00:00 2001 From: Saxon Milton Date: Sat, 10 Feb 2018 23:55:55 +1030 Subject: [PATCH] working on flv --- flv/FLV.go | 46 +++++++++++++++++++++++++++++++++++ generator/FLVGenerator.go | 50 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 flv/FLV.go diff --git a/flv/FLV.go b/flv/FLV.go new file mode 100644 index 00000000..8d00571d --- /dev/null +++ b/flv/FLV.go @@ -0,0 +1,46 @@ +package flv + +import ( + "../tools" +) + +const ( + headerLength = 72 + version = 0x01 +) + +type Header struct { + audioFlag bool + videoFlag bool +} + +func (h *Header) toByteSlice() []byte { + output = make([]byte, 0, headerLength) + output = append(output, []byte{ 0x46, 0x4C, 0x56, + version, + 0x00 | tools.boolToByte(h.audioFlag) << 3 | tools.boolToByte(h.videoFlag), + 0x00, 0x00, 0x00, byte(72), + }...) + return +} + +type VideoTag struct { + prevTagSize uint32 + tagType uint + dataSize uint32 + timeStamp uint32 + timestampExtended uint32 + data []byte +} + +func (t *VideoTag) toByteSlice() (output []byte) { + +} + +type AudioTag struct { + +} + +func (t *AudioTage) toByteSlice() (output []byte) { + +} diff --git a/generator/FLVGenerator.go b/generator/FLVGenerator.go index 8ef79225..b3187aa6 100644 --- a/generator/FLVGenerator.go +++ b/generator/FLVGenerator.go @@ -1,3 +1,51 @@ -type FLVGenerator struct { +package generator +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 + } + } }