mirror of https://bitbucket.org/ausocean/av.git
comments and some other small changes made to revid.go encoder.go and config.go
This commit is contained in:
parent
222864108f
commit
0ec0a08e0e
|
@ -159,7 +159,7 @@ type Encoder struct {
|
|||
pktCount int
|
||||
psiSendCount int
|
||||
psiTime time.Duration
|
||||
temp time.Duration
|
||||
psiSetTime time.Duration
|
||||
startTime time.Time
|
||||
mediaPid uint16
|
||||
streamID byte
|
||||
|
@ -170,24 +170,24 @@ type Encoder struct {
|
|||
func NewEncoder(dst io.WriteCloser, rate float64, mediaType int, options ...func(*Encoder) error) (*Encoder, error) {
|
||||
var mPID uint16
|
||||
var sID byte
|
||||
psim := timeBased
|
||||
psiM := timeBased
|
||||
switch mediaType {
|
||||
case EncodeAudio:
|
||||
mPID = AudioPid
|
||||
sID = audioStreamID
|
||||
psim = pktBased
|
||||
psiM = pktBased
|
||||
case EncodeH265:
|
||||
mPID = VideoPid
|
||||
sID = H265ID
|
||||
psim = nalBased
|
||||
psiM = nalBased
|
||||
case EncodeH264:
|
||||
mPID = VideoPid
|
||||
sID = H264ID
|
||||
psim = nalBased
|
||||
psiM = nalBased
|
||||
case EncodeMJPEG:
|
||||
mPID = VideoPid
|
||||
sID = MJPEGID
|
||||
psim = timeBased
|
||||
psiM = timeBased
|
||||
}
|
||||
|
||||
pmt := BasePMT
|
||||
|
@ -208,7 +208,7 @@ func NewEncoder(dst io.WriteCloser, rate float64, mediaType int, options ...func
|
|||
writePeriod: time.Duration(float64(time.Second) / rate),
|
||||
ptsOffset: ptsOffset,
|
||||
|
||||
psiMethod: psim,
|
||||
psiMethod: psiM,
|
||||
|
||||
pktCount: 8,
|
||||
|
||||
|
@ -231,6 +231,8 @@ func NewEncoder(dst io.WriteCloser, rate float64, mediaType int, options ...func
|
|||
return e, nil
|
||||
}
|
||||
|
||||
// These three constants are used to select between the three different
|
||||
// methods of when the PSI is sent.
|
||||
const (
|
||||
pktBased = iota
|
||||
timeBased
|
||||
|
@ -249,11 +251,14 @@ func PacketBasedPSI(sendCount int) func(*Encoder) error {
|
|||
}
|
||||
}
|
||||
|
||||
func TimeBasedPSI(timeBetweenPSI time.Duration) func(*Encoder) error {
|
||||
// TimeBasedPSI is another option that can be passed to NewEncoder to select
|
||||
// time based PSI writing, i.e. PSI are written to the destination every dur (duration)
|
||||
// (defualt is 2 seconds).
|
||||
func TimeBasedPSI(dur time.Duration) func(*Encoder) error {
|
||||
return func(e *Encoder) error {
|
||||
e.psiMethod = timeBased
|
||||
e.psiTime = 0
|
||||
e.temp = timeBetweenPSI
|
||||
e.psiSetTime = dur
|
||||
e.startTime = time.Now()
|
||||
return nil
|
||||
}
|
||||
|
@ -285,7 +290,7 @@ func (e *Encoder) Write(data []byte) (int, error) {
|
|||
}
|
||||
case timeBased:
|
||||
if time.Now().Sub(e.startTime) >= e.psiTime {
|
||||
e.psiTime = e.temp
|
||||
e.psiTime = e.psiSetTime
|
||||
e.startTime = time.Now()
|
||||
err := e.writePSI()
|
||||
if err != nil {
|
||||
|
@ -294,6 +299,7 @@ func (e *Encoder) Write(data []byte) (int, error) {
|
|||
|
||||
}
|
||||
default:
|
||||
panic("No PSI method found")
|
||||
}
|
||||
|
||||
// Prepare PES data.
|
||||
|
|
|
@ -82,7 +82,7 @@ const (
|
|||
defaultWriteRate = 25
|
||||
defaultClipDuration = 0
|
||||
defaultAudioInputCodec = codecutil.ADPCM
|
||||
defaultPsiTime = 2
|
||||
defaultPSITime = 2
|
||||
|
||||
// MTS ring buffer defaults.
|
||||
defaultMTSRBSize = 100
|
||||
|
@ -248,7 +248,7 @@ type Config struct {
|
|||
|
||||
HorizontalFlip bool // HorizontalFlip flips video horizontally for Raspivid input.
|
||||
VerticalFlip bool // VerticalFlip flips video vertically for Raspivid input.
|
||||
PsiTime int // Sets the time between a packet being sent
|
||||
PSITime int // Sets the time between a packet being sent
|
||||
|
||||
// RTMP ring buffer parameters.
|
||||
RTMPRBSize int // The number of elements in the RTMP sender ringbuffer.
|
||||
|
@ -388,9 +388,9 @@ func (c *Config) Validate() error {
|
|||
c.MTSRBWriteTimeout = defaultMTSRBWriteTimeout
|
||||
}
|
||||
|
||||
if c.PsiTime <= 0 {
|
||||
c.Logger.Log(logger.Info, pkg+"PsiTime bad or unset, defaulting", "PsiTime", defaultPsiTime)
|
||||
c.PsiTime = defaultPsiTime
|
||||
if c.PSITime <= 0 {
|
||||
c.Logger.Log(logger.Info, pkg+"PSITime bad or unset, defaulting", "PSITime", defaultPSITime)
|
||||
c.PSITime = defaultPSITime
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -76,7 +76,7 @@ const (
|
|||
)
|
||||
|
||||
const (
|
||||
defualtPsiTime = 4
|
||||
defualtPSITime = 2
|
||||
)
|
||||
|
||||
const pkg = "revid: "
|
||||
|
@ -190,7 +190,7 @@ func (r *Revid) reset(c config.Config) error {
|
|||
st = mts.EncodeH264
|
||||
case codecutil.MJPEG:
|
||||
st = mts.EncodeMJPEG
|
||||
encOptions = append(encOptions, mts.TimeBasedPSI(time.Duration(r.cfg.PsiTime)*time.Second))
|
||||
encOptions = append(encOptions, mts.TimeBasedPSI(time.Duration(r.cfg.PSITime)*time.Second))
|
||||
default:
|
||||
panic("unknown input codec for raspivid input")
|
||||
}
|
||||
|
@ -200,7 +200,7 @@ func (r *Revid) reset(c config.Config) error {
|
|||
st = mts.EncodeH264
|
||||
case codecutil.MJPEG:
|
||||
st = mts.EncodeMJPEG
|
||||
encOptions = append(encOptions, mts.TimeBasedPSI(time.Duration(r.cfg.PsiTime)*time.Second))
|
||||
encOptions = append(encOptions, mts.TimeBasedPSI(time.Duration(r.cfg.PSITime)*time.Second))
|
||||
default:
|
||||
panic("unknown input codec for v4l or input file input")
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ func (r *Revid) reset(c config.Config) error {
|
|||
st = mts.EncodeH264
|
||||
case codecutil.MJPEG:
|
||||
st = mts.EncodeMJPEG
|
||||
encOptions = append(encOptions, mts.TimeBasedPSI(time.Duration(r.cfg.PsiTime)*time.Second))
|
||||
encOptions = append(encOptions, mts.TimeBasedPSI(time.Duration(r.cfg.PSITime)*time.Second))
|
||||
default:
|
||||
panic("unknown input codec for RTSP input")
|
||||
}
|
||||
|
@ -615,13 +615,13 @@ func (r *Revid) Update(vars map[string]string) error {
|
|||
default:
|
||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid VerticalFlip param", "value", value)
|
||||
}
|
||||
case "PsiTime":
|
||||
case "PSITime":
|
||||
v, err := strconv.Atoi(value)
|
||||
if err != nil || v < 0 {
|
||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid PsiTime var", "value", value)
|
||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid PSITime var", "value", value)
|
||||
break
|
||||
}
|
||||
r.cfg.PsiTime = v
|
||||
r.cfg.PSITime = v
|
||||
case "BurstPeriod":
|
||||
v, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue