diff --git a/codec/codecutil/list.go b/codec/codecutil/list.go index 3024b5ab..e78824e3 100644 --- a/codec/codecutil/list.go +++ b/codec/codecutil/list.go @@ -24,51 +24,23 @@ LICENSE package codecutil -// Codec represents a media codec. -type Codec uint8 - -// A global list containing all available codecs for reference in any application. -// When adding or removing a codec from this list, the corresponding codec string const must be updated below. +// All available codecs for reference in any application. +// when adding or removing a codec from this list, IsValid below must be updated. const ( - Undef Codec = iota - PCM - ADPCM - H264 - H265 - MJPEG - JPEG - maxCodec + PCM = "pcm" + ADPCM = "adpcm" + H264 = "h264" + H265 = "h265" + MJPEG = "mjpeg" + JPEG = "jpeg" ) -const ( - pcmStr = "pcm" - adpcmStr = "adpcm" - h264Str = "h264" - h265Str = "h265" - mjpegStr = "mjpeg" - jpegStr = "jpeg" -) - -// IsValid checks if a codec is a known and valid codec. -func (c Codec) IsValid() bool { - return 0 < c && c < maxCodec -} - -func (c Codec) String() string { - switch c { - case PCM: - return pcmStr - case ADPCM: - return adpcmStr - case H264: - return h264Str - case H265: - return h265Str - case MJPEG: - return mjpegStr - case JPEG: - return jpegStr +// IsValid checks if a string is a known and valid codec in the right format. +func IsValid(s string) bool { + switch s { + case PCM, ADPCM, H264, H265, MJPEG, JPEG: + return true default: - return "" + return false } } diff --git a/device/alsa/alsa.go b/device/alsa/alsa.go index cd6f13b8..eb35d1b7 100644 --- a/device/alsa/alsa.go +++ b/device/alsa/alsa.go @@ -95,7 +95,7 @@ type Config struct { Channels uint BitDepth uint RecPeriod float64 - Codec uint8 + Codec string } // Logger enables any implementation of a logger to be used. diff --git a/device/geovision/geovision.go b/device/geovision/geovision.go index 9da7453c..d12ae8bc 100644 --- a/device/geovision/geovision.go +++ b/device/geovision/geovision.go @@ -173,7 +173,7 @@ func (g *GeoVision) Set(c avconfig.Config) error { g.cfg.CameraIP, gvconfig.Channel(g.cfg.CameraChan), gvconfig.CodecOut( - map[uint8]gvconfig.Codec{ + map[string]gvconfig.Codec{ codecutil.H264: gvconfig.CodecH264, codecutil.H265: gvconfig.CodecH265, codecutil.MJPEG: gvconfig.CodecMJPEG, diff --git a/revid/audio_linux.go b/revid/audio_linux.go index cac6a167..3511f367 100644 --- a/revid/audio_linux.go +++ b/revid/audio_linux.go @@ -72,7 +72,7 @@ func (r *Revid) setupAudio() error { mts.Meta.Add(ChannelsStr, strconv.Itoa(int(r.cfg.Channels))) mts.Meta.Add(PeriodStr, fmt.Sprintf("%.6f", r.cfg.RecPeriod)) mts.Meta.Add(BitDepthStr, strconv.Itoa(int(r.cfg.BitDepth))) - mts.Meta.Add(CodecStr, r.cfg.InputCodec.String()) + mts.Meta.Add(CodecStr, r.cfg.InputCodec) return nil } diff --git a/revid/config/config.go b/revid/config/config.go index b7c5d34d..1323c17e 100644 --- a/revid/config/config.go +++ b/revid/config/config.go @@ -29,7 +29,6 @@ package config import ( "time" - "bitbucket.org/ausocean/av/codec/codecutil" "bitbucket.org/ausocean/utils/logger" ) @@ -169,7 +168,7 @@ type Config struct { // InputCodec defines the input codec we wish to use, and therefore defines the // lexer for use in the pipeline. This defaults to H264, but H265 is also a // valid option if we expect this from the input. - InputCodec codecutil.Codec + InputCodec string // InputPath defines the input file location for File Input. This must be // defined if File input is to be used. diff --git a/revid/config/config_test.go b/revid/config/config_test.go index 43484226..4130f14b 100644 --- a/revid/config/config_test.go +++ b/revid/config/config_test.go @@ -95,7 +95,7 @@ func TestUpdate(t *testing.T) { "HorizontalFlip": "true", "HTTPAddress": "http://address", "Input": "rtsp", - "InputCodec": "MJPEG", + "InputCodec": "mjpeg", "InputPath": "/inputpath", "logging": "Error", "Loop": "true", diff --git a/revid/config/variables.go b/revid/config/variables.go index c5eb4b9b..726faf16 100644 --- a/revid/config/variables.go +++ b/revid/config/variables.go @@ -299,12 +299,10 @@ var Variables = []struct { Name: KeyInputCodec, Type_: "enum:H264,H265,MJPEG,JPEG,PCM,ADPCM", Update: func(c *Config, v string) { - c.InputCodec = codecutil.FromString(v) + c.InputCodec = v }, Validate: func(c *Config) { - switch c.InputCodec { - case codecutil.H264, codecutil.MJPEG, codecutil.JPEG, codecutil.PCM, codecutil.ADPCM: - default: + if !codecutil.IsValid(c.InputCodec) { c.LogInvalidField(KeyInputCodec, defaultInputCodec) c.InputCodec = defaultInputCodec } diff --git a/revid/pipeline.go b/revid/pipeline.go index 0c3302de..adace2f2 100644 --- a/revid/pipeline.go +++ b/revid/pipeline.go @@ -329,7 +329,7 @@ func (r *Revid) setupPipeline(mtsEnc func(dst io.WriteCloser, rate float64) (io. // setLexer sets the revid input lexer based on input codec and whether input // is RTSP or not, in which case an RTP/ extractor is used. -func (r *Revid) setLexer(c uint8, isRTSP bool) error { +func (r *Revid) setLexer(c string, isRTSP bool) error { switch c { case codecutil.H264: r.cfg.Logger.Log(logger.Debug, "using H.264 codec") diff --git a/revid/senders.go b/revid/senders.go index 9ada291e..a0172491 100644 --- a/revid/senders.go +++ b/revid/senders.go @@ -153,7 +153,7 @@ func extractMeta(r string, log func(lvl int8, msg string, args ...interface{})) log(logger.Debug, "No location in reply") } else { log(logger.Debug, fmt.Sprintf("got location: %v", g)) - mts.Meta.Add(LocStr, g) + mts.Meta.Add(mts.LocStr, g) } return nil