codecutil, revid: made codecs represented as strings, updated where used

This commit is contained in:
Trek H 2021-02-22 15:15:30 +10:30
parent 9211ae4338
commit 778a19f939
9 changed files with 23 additions and 54 deletions

View File

@ -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
}
}

View File

@ -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.

View File

@ -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,

View File

@ -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
}

View File

@ -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.

View File

@ -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",

View File

@ -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
}

View File

@ -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/<codec> 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")

View File

@ -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