mirror of https://bitbucket.org/ausocean/av.git
revid + mts +psi: wrote func to find pmt in byte slice, wrote func to get gps, changed the way in which psi are insterted, based no of mpgets packets to send on time, i.e. per second
This commit is contained in:
parent
7fa245bca3
commit
798add533b
|
@ -45,7 +45,7 @@ const (
|
||||||
progName = "revid-cli"
|
progName = "revid-cli"
|
||||||
|
|
||||||
// Logging is set to INFO level.
|
// Logging is set to INFO level.
|
||||||
defaultLogVerbosity = smartlogger.Info
|
defaultLogVerbosity = smartlogger.Debug
|
||||||
)
|
)
|
||||||
|
|
||||||
// Other misc consts
|
// Other misc consts
|
||||||
|
@ -231,8 +231,9 @@ func handleFlags() revid.Config {
|
||||||
switch *verbosityPtr {
|
switch *verbosityPtr {
|
||||||
case "No":
|
case "No":
|
||||||
cfg.LogLevel = smartlogger.Fatal
|
cfg.LogLevel = smartlogger.Fatal
|
||||||
case "Yes":
|
case "Debug":
|
||||||
cfg.LogLevel = smartlogger.Debug
|
cfg.LogLevel = smartlogger.Debug
|
||||||
|
//logger.SetLevel(smartlogger.Debug)
|
||||||
case "":
|
case "":
|
||||||
default:
|
default:
|
||||||
logger.Log(smartlogger.Error, pkg+"bad verbosity argument")
|
logger.Log(smartlogger.Error, pkg+"bad verbosity argument")
|
||||||
|
|
|
@ -125,6 +125,9 @@ type Revid struct {
|
||||||
isRunning bool
|
isRunning bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var now = time.Now()
|
||||||
|
var prevTime = now
|
||||||
|
|
||||||
// packer takes data segments and packs them into clips
|
// packer takes data segments and packs them into clips
|
||||||
// of the number frames specified in the owners config.
|
// of the number frames specified in the owners config.
|
||||||
type packer struct {
|
type packer struct {
|
||||||
|
@ -153,9 +156,11 @@ func (p *packer) Write(frame []byte) (int, error) {
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
p.packetCount++
|
p.packetCount++
|
||||||
if p.packetCount >= p.owner.config.FramesPerClip {
|
now = time.Now()
|
||||||
|
if now.Sub(prevTime) > clipDuration && p.packetCount%7 == 0 {
|
||||||
p.owner.buffer.Flush()
|
p.owner.buffer.Flush()
|
||||||
p.packetCount = 0
|
p.packetCount = 0
|
||||||
|
prevTime = now
|
||||||
}
|
}
|
||||||
return len(frame), nil
|
return len(frame), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ LICENSE
|
||||||
package revid
|
package revid
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
@ -160,13 +161,14 @@ func (s *httpSender) send() error {
|
||||||
func extractMeta(r string, s *httpSender) error {
|
func extractMeta(r string, s *httpSender) error {
|
||||||
dec, err := netsender.NewJsonDecoder(r)
|
dec, err := netsender.NewJsonDecoder(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.log(smartlogger.Warning, pkg+"Could not decode JSON to get metadata")
|
return nil
|
||||||
}
|
}
|
||||||
// Extract time from reply
|
// Extract time from reply
|
||||||
t, err := dec.Int("ts")
|
t, err := dec.Int("ts")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.log(smartlogger.Warning, pkg+"No timestamp in reply")
|
s.log(smartlogger.Warning, pkg+"No timestamp in reply")
|
||||||
} else {
|
} else {
|
||||||
|
s.log(smartlogger.Debug, fmt.Sprintf("%v got timestamp: %v", pkg, t))
|
||||||
mts.TimeMeta(uint64(t))
|
mts.TimeMeta(uint64(t))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,6 +177,7 @@ func extractMeta(r string, s *httpSender) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.log(smartlogger.Warning, pkg+"No gps in reply")
|
s.log(smartlogger.Warning, pkg+"No gps in reply")
|
||||||
} else {
|
} else {
|
||||||
|
s.log(smartlogger.Debug, fmt.Sprintf("%v got gps: %v", pkg, g))
|
||||||
mts.GpsMeta(g)
|
mts.GpsMeta(g)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ var (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
psiPacketSize = 184
|
psiPacketSize = 184
|
||||||
psiSendCount = 100
|
psiSendCount = 21
|
||||||
)
|
)
|
||||||
|
|
||||||
type MetaData struct {
|
type MetaData struct {
|
||||||
|
@ -92,7 +92,7 @@ type Encoder struct {
|
||||||
frameInterval time.Duration
|
frameInterval time.Duration
|
||||||
ptsOffset time.Duration
|
ptsOffset time.Duration
|
||||||
|
|
||||||
psiCount uint
|
psiCount int
|
||||||
|
|
||||||
continuity map[int]byte
|
continuity map[int]byte
|
||||||
}
|
}
|
||||||
|
@ -126,13 +126,7 @@ const (
|
||||||
// generate handles the incoming data and generates equivalent mpegts packets -
|
// generate handles the incoming data and generates equivalent mpegts packets -
|
||||||
// sending them to the output channel
|
// sending them to the output channel
|
||||||
func (e *Encoder) Encode(nalu []byte) error {
|
func (e *Encoder) Encode(nalu []byte) error {
|
||||||
if e.psiCount <= 0 {
|
|
||||||
err := e.writePSI()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
e.psiCount--
|
|
||||||
// Prepare PES data.
|
// Prepare PES data.
|
||||||
pesPkt := pes.Packet{
|
pesPkt := pes.Packet{
|
||||||
StreamID: streamID,
|
StreamID: streamID,
|
||||||
|
@ -162,6 +156,13 @@ func (e *Encoder) Encode(nalu []byte) error {
|
||||||
pkt.PCR = e.pcr()
|
pkt.PCR = e.pcr()
|
||||||
pusi = false
|
pusi = false
|
||||||
}
|
}
|
||||||
|
if e.psiCount <= 0 {
|
||||||
|
err := e.writePSI()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
e.psiCount--
|
||||||
_, err := e.dst.Write(pkt.Bytes())
|
_, err := e.dst.Write(pkt.Bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -28,6 +28,10 @@ LICENSE
|
||||||
|
|
||||||
package mts
|
package mts
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
mpegTsSize = 188
|
mpegTsSize = 188
|
||||||
mpegtsPayloadSize = 176
|
mpegtsPayloadSize = 176
|
||||||
|
@ -123,6 +127,19 @@ type Packet struct {
|
||||||
Payload []byte // Mpeg ts Payload
|
Payload []byte // Mpeg ts Payload
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindPMT will take a clip of mpegts and try to find a PMT table - if one
|
||||||
|
// is found, then it is returned, otherwise nil and an error is returned.
|
||||||
|
func FindPMT(d []byte) (p []byte, err error) {
|
||||||
|
for i := 0; i < len(d); i += mpegTsSize {
|
||||||
|
pid := (uint16(d[i+1]&0x1f) << 8) | uint16(d[i+2])
|
||||||
|
if pid == pmtPid {
|
||||||
|
p = d[i+4 : i+mpegTsSize]
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, errors.New("Could not find pmt table in mpegts data")
|
||||||
|
}
|
||||||
|
|
||||||
// FillPayload takes a channel and fills the packets Payload field until the
|
// FillPayload takes a channel and fills the packets Payload field until the
|
||||||
// channel is empty or we've the packet reaches capacity
|
// channel is empty or we've the packet reaches capacity
|
||||||
func (p *Packet) FillPayload(data []byte) int {
|
func (p *Packet) FillPayload(data []byte) int {
|
||||||
|
|
Loading…
Reference in New Issue