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 package codecutil
// Codec represents a media codec. // All available codecs for reference in any application.
type Codec uint8 // when adding or removing a codec from this list, IsValid below must be updated.
// 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.
const ( const (
Undef Codec = iota PCM = "pcm"
PCM ADPCM = "adpcm"
ADPCM H264 = "h264"
H264 H265 = "h265"
H265 MJPEG = "mjpeg"
MJPEG JPEG = "jpeg"
JPEG
maxCodec
) )
const ( // IsValid checks if a string is a known and valid codec in the right format.
pcmStr = "pcm" func IsValid(s string) bool {
adpcmStr = "adpcm" switch s {
h264Str = "h264" case PCM, ADPCM, H264, H265, MJPEG, JPEG:
h265Str = "h265" return true
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
default: default:
return "" return false
} }
} }

View File

@ -95,7 +95,7 @@ type Config struct {
Channels uint Channels uint
BitDepth uint BitDepth uint
RecPeriod float64 RecPeriod float64
Codec uint8 Codec string
} }
// Logger enables any implementation of a logger to be used. // 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, g.cfg.CameraIP,
gvconfig.Channel(g.cfg.CameraChan), gvconfig.Channel(g.cfg.CameraChan),
gvconfig.CodecOut( gvconfig.CodecOut(
map[uint8]gvconfig.Codec{ map[string]gvconfig.Codec{
codecutil.H264: gvconfig.CodecH264, codecutil.H264: gvconfig.CodecH264,
codecutil.H265: gvconfig.CodecH265, codecutil.H265: gvconfig.CodecH265,
codecutil.MJPEG: gvconfig.CodecMJPEG, 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(ChannelsStr, strconv.Itoa(int(r.cfg.Channels)))
mts.Meta.Add(PeriodStr, fmt.Sprintf("%.6f", r.cfg.RecPeriod)) mts.Meta.Add(PeriodStr, fmt.Sprintf("%.6f", r.cfg.RecPeriod))
mts.Meta.Add(BitDepthStr, strconv.Itoa(int(r.cfg.BitDepth))) 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 return nil
} }

View File

@ -29,7 +29,6 @@ package config
import ( import (
"time" "time"
"bitbucket.org/ausocean/av/codec/codecutil"
"bitbucket.org/ausocean/utils/logger" "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 // 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 // lexer for use in the pipeline. This defaults to H264, but H265 is also a
// valid option if we expect this from the input. // 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 // InputPath defines the input file location for File Input. This must be
// defined if File input is to be used. // defined if File input is to be used.

View File

@ -95,7 +95,7 @@ func TestUpdate(t *testing.T) {
"HorizontalFlip": "true", "HorizontalFlip": "true",
"HTTPAddress": "http://address", "HTTPAddress": "http://address",
"Input": "rtsp", "Input": "rtsp",
"InputCodec": "MJPEG", "InputCodec": "mjpeg",
"InputPath": "/inputpath", "InputPath": "/inputpath",
"logging": "Error", "logging": "Error",
"Loop": "true", "Loop": "true",

View File

@ -299,12 +299,10 @@ var Variables = []struct {
Name: KeyInputCodec, Name: KeyInputCodec,
Type_: "enum:H264,H265,MJPEG,JPEG,PCM,ADPCM", Type_: "enum:H264,H265,MJPEG,JPEG,PCM,ADPCM",
Update: func(c *Config, v string) { Update: func(c *Config, v string) {
c.InputCodec = codecutil.FromString(v) c.InputCodec = v
}, },
Validate: func(c *Config) { Validate: func(c *Config) {
switch c.InputCodec { if !codecutil.IsValid(c.InputCodec) {
case codecutil.H264, codecutil.MJPEG, codecutil.JPEG, codecutil.PCM, codecutil.ADPCM:
default:
c.LogInvalidField(KeyInputCodec, defaultInputCodec) c.LogInvalidField(KeyInputCodec, defaultInputCodec)
c.InputCodec = 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 // 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. // 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 { switch c {
case codecutil.H264: case codecutil.H264:
r.cfg.Logger.Log(logger.Debug, "using H.264 codec") 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") log(logger.Debug, "No location in reply")
} else { } else {
log(logger.Debug, fmt.Sprintf("got location: %v", g)) log(logger.Debug, fmt.Sprintf("got location: %v", g))
mts.Meta.Add(LocStr, g) mts.Meta.Add(mts.LocStr, g)
} }
return nil return nil