Skip to content

Commit

Permalink
Add codec enum handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
seanavery committed Sep 5, 2024
1 parent a8fc69a commit e114a23
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cam/cam.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions cam/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,36 @@ import (
"time"
)

type CodecType int

Check failure on line 22 in cam/utils.go

View workflow job for this annotation

GitHub Actions / quality-checks

exported: exported type CodecType should have comment or be unexported (revive)

const (
CodecUnknown CodecType = iota

Check failure on line 25 in cam/utils.go

View workflow job for this annotation

GitHub Actions / quality-checks

exported: exported const CodecUnknown should have comment (or a comment on this block) or be unexported (revive)
CodecH264
CodecH265
)

func (c CodecType) String() string {
switch c {
case CodecH264:
return "h264"

Check failure on line 33 in cam/utils.go

View workflow job for this annotation

GitHub Actions / quality-checks

string `h264` has 3 occurrences, make it a constant (goconst)
case CodecH265:
return "h265"
default:
return "unknown"
}
}

func ParseCodecType(codec string) CodecType {

Check failure on line 41 in cam/utils.go

View workflow job for this annotation

GitHub Actions / quality-checks

exported: exported function ParseCodecType should have comment or be unexported (revive)
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
Expand Down

0 comments on commit e114a23

Please sign in to comment.