From e114a234e0d7ba9c13a6d240bb622049d3eb0530 Mon Sep 17 00:00:00 2001 From: seanavery Date: Thu, 5 Sep 2024 14:04:46 -0400 Subject: [PATCH] Add codec enum handlers --- cam/cam.go | 6 +++--- cam/utils.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/cam/cam.go b/cam/cam.go index 53cb576..9973f3b 100644 --- a/cam/cam.go +++ b/cam/cam.go @@ -24,7 +24,7 @@ const ( // Default values for the video storage camera component. defaultSegmentSeconds = 30 // seconds defaultStorageSize = 10 // GB - defaultVideoCodec = "h264" + defaultVideoCodec = CodecH264 defaultVideoBitrate = 1000000 defaultVideoPreset = "medium" defaultVideoFormat = "mp4" @@ -129,8 +129,8 @@ func newvideostore( // Create encoder to handle encoding of frames. // TODO(seanp): Forcing h264 for now until h265 is supported. - if newConf.Video.Codec != "h264" { - newConf.Video.Codec = defaultVideoCodec + if ParseCodecType(newConf.Video.Codec) != CodecH264 { + newConf.Video.Codec = defaultVideoCodec.String() } if newConf.Video.Bitrate == 0 { newConf.Video.Bitrate = defaultVideoBitrate diff --git a/cam/utils.go b/cam/utils.go index 55e1d56..c80e927 100644 --- a/cam/utils.go +++ b/cam/utils.go @@ -19,6 +19,36 @@ import ( "time" ) +type CodecType int + +const ( + CodecUnknown CodecType = iota + CodecH264 + CodecH265 +) + +func (c CodecType) String() string { + switch c { + case CodecH264: + return "h264" + case CodecH265: + return "h265" + default: + return "unknown" + } +} + +func ParseCodecType(codec string) CodecType { + switch codec { + case "h264": + return CodecH264 + case "h265": + return CodecH265 + default: + return CodecUnknown + } +} + // ffmpegError returns a string representation of the ffmpeg error code. func ffmpegError(ret C.int) string { var errbuf [256]C.char