/* DESCRIPTION utils.go houses generic vidforward utilities and helper functions. AUTHORS Saxon A. Nelson-Milton LICENSE Copyright (C) 2022 the Australian Ocean Lab (AusOcean) It is free software: you can redistribute it and/or modify them under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. It is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with revid in gpl.txt. If not, see http://www.gnu.org/licenses. */ package main import ( "fmt" "net/http" "strconv" "bitbucket.org/ausocean/av/codec/codecutil" "bitbucket.org/ausocean/av/revid" "bitbucket.org/ausocean/av/revid/config" "bitbucket.org/ausocean/utils/logging" ) var loggingLevel = logging.Info func newRevid(log logging.Logger, urls []string) (*revid.Revid, error) { if len(urls) <= 0 { return nil, fmt.Errorf("cannot have %d URLs", len(urls)) } var outputs []uint8 for _ = range urls { outputs = append(outputs, config.OutputRTMP) } cfg := config.Config{ Logger: log, Input: config.InputManual, InputCodec: codecutil.H264_AU, Outputs: outputs, RTMPURL: urls, LogLevel: logging.Debug, } return revid.New( cfg, nil) } // writeError logs an error and writes to w in JSON format. func (m *broadcastManager) errorLogWrite(log logging.Logger, w http.ResponseWriter, msg string, args ...interface{}) { log.Error(msg, args...) w.Header().Add("Content-Type", "application/json") fmt.Fprint(w, `{"er":"`+msg+`"}`) } // isMac returns true if the provided string is a valid mac address. func isMac(m string) bool { if len(m) != 17 || m == "00:00:00:00:00:00" { return false } for i := 0; i <= 15; i++ { if (i+1)%3 == 0 && m[i] != ':' { return false } if (3-i)%3 != 0 { continue } _, err := strconv.ParseUint(m[i:i+2], 16, 64) if err != nil { return false } } return true }