revid: capitalize exported enums that are acronyms like Rtmp->RTMP, Mpegts->MPEGTS etc.

This commit is contained in:
Saxon 2019-05-13 16:18:41 +09:30
parent 001c8696aa
commit 51fcb18505
4 changed files with 27 additions and 38 deletions

View File

@ -107,7 +107,6 @@ func handleFlags() revid.Config {
inputPtr = flag.String("Input", "", "The input type: Raspivid, File, Webcam") inputPtr = flag.String("Input", "", "The input type: Raspivid, File, Webcam")
inputCodecPtr = flag.String("InputCodec", "", "The codec of the input: H264, Mjpeg") inputCodecPtr = flag.String("InputCodec", "", "The codec of the input: H264, Mjpeg")
rtmpMethodPtr = flag.String("RtmpMethod", "", "The method used to send over rtmp: Ffmpeg, Librtmp")
quantizePtr = flag.Bool("Quantize", false, "Quantize input (non-variable bitrate)") quantizePtr = flag.Bool("Quantize", false, "Quantize input (non-variable bitrate)")
verbosityPtr = flag.String("Verbosity", "Info", "Verbosity: Debug, Info, Warning, Error, Fatal") verbosityPtr = flag.String("Verbosity", "Info", "Verbosity: Debug, Info, Warning, Error, Fatal")
rtpAddrPtr = flag.String("RtpAddr", "", "Rtp destination address: <IP>:<port> (port is generally 6970-6999)") rtpAddrPtr = flag.String("RtpAddr", "", "Rtp destination address: <IP>:<port> (port is generally 6970-6999)")
@ -198,27 +197,17 @@ func handleFlags() revid.Config {
case "File": case "File":
cfg.Outputs = append(cfg.Outputs, revid.File) cfg.Outputs = append(cfg.Outputs, revid.File)
case "Http": case "Http":
cfg.Outputs = append(cfg.Outputs, revid.Http) cfg.Outputs = append(cfg.Outputs, revid.HTTP)
case "Rtmp": case "Rtmp":
cfg.Outputs = append(cfg.Outputs, revid.Rtmp) cfg.Outputs = append(cfg.Outputs, revid.RTMP)
case "Rtp": case "Rtp":
cfg.Outputs = append(cfg.Outputs, revid.Rtp) cfg.Outputs = append(cfg.Outputs, revid.RTP)
case "": case "":
default: default:
log.Log(logger.Error, pkg+"bad output argument", "arg", o) log.Log(logger.Error, pkg+"bad output argument", "arg", o)
} }
} }
switch *rtmpMethodPtr {
case "Ffmpeg":
cfg.RtmpMethod = revid.Ffmpeg
case "LibRtmp":
cfg.RtmpMethod = revid.LibRtmp
case "":
default:
log.Log(logger.Error, pkg+"bad rtmp method argument")
}
if *configFilePtr != "" { if *configFilePtr != "" {
netsender.ConfigFile = *configFilePtr netsender.ConfigFile = *configFilePtr
} }

View File

@ -76,20 +76,20 @@ const (
V4L V4L
// Outputs. // Outputs.
Rtmp RTMP
Rtp RTP
Http HTTP
Mpegts MPEGTS
// Codecs. // Codecs.
H264 H264
Mjpeg MJPEG
) )
// Default config settings // Default config settings
const ( const (
defaultInput = Raspivid defaultInput = Raspivid
defaultOutput = Http defaultOutput = HTTP
defaultFrameRate = 25 defaultFrameRate = 25
defaultWidth = 1280 defaultWidth = 1280
defaultHeight = 720 defaultHeight = 720
@ -220,7 +220,7 @@ func (c *Config) Validate(r *Revid) error {
return errors.New("bad bitrate and quantization combination for H264 input") return errors.New("bad bitrate and quantization combination for H264 input")
} }
case Mjpeg: case MJPEG:
if c.Quantization > 0 || c.Bitrate == 0 { if c.Quantization > 0 || c.Bitrate == 0 {
return errors.New("bad bitrate or quantization for mjpeg input") return errors.New("bad bitrate or quantization for mjpeg input")
} }
@ -241,10 +241,10 @@ func (c *Config) Validate(r *Revid) error {
for i, o := range c.Outputs { for i, o := range c.Outputs {
switch o { switch o {
case File: case File:
case Rtmp: case RTMP:
if c.RtmpUrl == "" { if c.RtmpUrl == "" {
c.Logger.Log(logger.Info, pkg+"no RTMP URL: falling back to HTTP") c.Logger.Log(logger.Info, pkg+"no RTMP URL: falling back to HTTP")
c.Outputs[i] = Http c.Outputs[i] = HTTP
// FIXME(kortschak): Does this want the same line as below? // FIXME(kortschak): Does this want the same line as below?
// c.FramesPerClip = httpFramesPerClip // c.FramesPerClip = httpFramesPerClip
break break
@ -252,7 +252,7 @@ func (c *Config) Validate(r *Revid) error {
c.Logger.Log(logger.Info, pkg+"defaulting frames per clip for rtmp out", "framesPerClip", defaultFramesPerClip) c.Logger.Log(logger.Info, pkg+"defaulting frames per clip for rtmp out", "framesPerClip", defaultFramesPerClip)
c.FramesPerClip = defaultFramesPerClip c.FramesPerClip = defaultFramesPerClip
c.SendRetry = true c.SendRetry = true
case Http, Rtp: case HTTP, RTP:
c.Logger.Log(logger.Info, pkg+"defaulting frames per clip for http out", "framesPerClip", httpFramesPerClip) c.Logger.Log(logger.Info, pkg+"defaulting frames per clip for http out", "framesPerClip", httpFramesPerClip)
c.FramesPerClip = httpFramesPerClip c.FramesPerClip = httpFramesPerClip
default: default:

View File

@ -212,10 +212,10 @@ func (r *Revid) setupPipeline(mtsEnc, flvEnc func(dst io.WriteCloser, rate int)
var w io.WriteCloser var w io.WriteCloser
for _, out := range r.config.Outputs { for _, out := range r.config.Outputs {
switch out { switch out {
case Http: case HTTP:
w = newMtsSender(newHttpSender(r.ns, r.config.Logger.Log), r.config.Logger.Log, rbSize, rbElementSize, 0) w = newMtsSender(newHttpSender(r.ns, r.config.Logger.Log), r.config.Logger.Log, rbSize, rbElementSize, 0)
mtsSenders = append(mtsSenders, w) mtsSenders = append(mtsSenders, w)
case Rtp: case RTP:
w, err := newRtpSender(r.config.RtpAddress, r.config.Logger.Log, r.config.FrameRate) w, err := newRtpSender(r.config.RtpAddress, r.config.Logger.Log, r.config.FrameRate)
if err != nil { if err != nil {
r.config.Logger.Log(logger.Warning, pkg+"rtp connect error", "error", err.Error()) r.config.Logger.Log(logger.Warning, pkg+"rtp connect error", "error", err.Error())
@ -227,7 +227,7 @@ func (r *Revid) setupPipeline(mtsEnc, flvEnc func(dst io.WriteCloser, rate int)
return err return err
} }
mtsSenders = append(mtsSenders, w) mtsSenders = append(mtsSenders, w)
case Rtmp: case RTMP:
w, err := newRtmpSender(r.config.RtmpUrl, rtmpConnectionTimeout, rtmpConnectionMaxTries, r.config.Logger.Log) w, err := newRtmpSender(r.config.RtmpUrl, rtmpConnectionTimeout, rtmpConnectionMaxTries, r.config.Logger.Log)
if err != nil { if err != nil {
r.config.Logger.Log(logger.Warning, pkg+"rtmp connect error", "error", err.Error()) r.config.Logger.Log(logger.Warning, pkg+"rtmp connect error", "error", err.Error())
@ -272,7 +272,7 @@ func (r *Revid) setupPipeline(mtsEnc, flvEnc func(dst io.WriteCloser, rate int)
case H264: case H264:
r.config.Logger.Log(logger.Info, pkg+"using H264 lexer") r.config.Logger.Log(logger.Info, pkg+"using H264 lexer")
r.lexTo = lex.H264 r.lexTo = lex.H264
case Mjpeg: case MJPEG:
r.config.Logger.Log(logger.Info, pkg+"using MJPEG lexer") r.config.Logger.Log(logger.Info, pkg+"using MJPEG lexer")
r.lexTo = lex.MJPEG r.lexTo = lex.MJPEG
} }
@ -366,11 +366,11 @@ func (r *Revid) Update(vars map[string]string) error {
case "File": case "File":
r.config.Outputs[i] = File r.config.Outputs[i] = File
case "Http": case "Http":
r.config.Outputs[i] = Http r.config.Outputs[i] = HTTP
case "Rtmp": case "Rtmp":
r.config.Outputs[i] = Rtmp r.config.Outputs[i] = RTMP
case "Rtp": case "Rtp":
r.config.Outputs[i] = Rtp r.config.Outputs[i] = RTP
default: default:
r.config.Logger.Log(logger.Warning, pkg+"invalid output param", "value", value) r.config.Logger.Log(logger.Warning, pkg+"invalid output param", "value", value)
continue continue
@ -527,7 +527,7 @@ func (r *Revid) startRaspivid() (func() error, error) {
if r.config.Quantize { if r.config.Quantize {
args = append(args, "-qp", fmt.Sprint(r.config.Quantization)) args = append(args, "-qp", fmt.Sprint(r.config.Quantization))
} }
case Mjpeg: case MJPEG:
args = append(args, "--codec", "MJPEG") args = append(args, "--codec", "MJPEG")
} }
r.config.Logger.Log(logger.Info, pkg+"raspivid args", "raspividArgs", strings.Join(args, " ")) r.config.Logger.Log(logger.Info, pkg+"raspivid args", "raspividArgs", strings.Join(args, " "))

View File

@ -148,7 +148,7 @@ func TestResetEncoderSenderSetup(t *testing.T) {
encoders []encoder encoders []encoder
}{ }{
{ {
outputs: []uint8{Http}, outputs: []uint8{HTTP},
encoders: []encoder{ encoders: []encoder{
{ {
encoderType: mtsEncoderStr, encoderType: mtsEncoderStr,
@ -157,7 +157,7 @@ func TestResetEncoderSenderSetup(t *testing.T) {
}, },
}, },
{ {
outputs: []uint8{Rtmp}, outputs: []uint8{RTMP},
encoders: []encoder{ encoders: []encoder{
{ {
encoderType: flvEncoderStr, encoderType: flvEncoderStr,
@ -166,7 +166,7 @@ func TestResetEncoderSenderSetup(t *testing.T) {
}, },
}, },
{ {
outputs: []uint8{Rtp}, outputs: []uint8{RTP},
encoders: []encoder{ encoders: []encoder{
{ {
encoderType: mtsEncoderStr, encoderType: mtsEncoderStr,
@ -175,7 +175,7 @@ func TestResetEncoderSenderSetup(t *testing.T) {
}, },
}, },
{ {
outputs: []uint8{Http, Rtmp}, outputs: []uint8{HTTP, RTMP},
encoders: []encoder{ encoders: []encoder{
{ {
encoderType: mtsEncoderStr, encoderType: mtsEncoderStr,
@ -188,7 +188,7 @@ func TestResetEncoderSenderSetup(t *testing.T) {
}, },
}, },
{ {
outputs: []uint8{Http, Rtp, Rtmp}, outputs: []uint8{HTTP, RTP, RTMP},
encoders: []encoder{ encoders: []encoder{
{ {
encoderType: mtsEncoderStr, encoderType: mtsEncoderStr,
@ -201,7 +201,7 @@ func TestResetEncoderSenderSetup(t *testing.T) {
}, },
}, },
{ {
outputs: []uint8{Rtp, Rtmp}, outputs: []uint8{RTP, RTMP},
encoders: []encoder{ encoders: []encoder{
{ {
encoderType: mtsEncoderStr, encoderType: mtsEncoderStr,