2022-11-27 02:27:39 +03:00
|
|
|
/*
|
|
|
|
DESCRIPTION
|
|
|
|
utils.go houses generic vidforward utilities and helper functions.
|
|
|
|
|
|
|
|
AUTHORS
|
|
|
|
Saxon A. Nelson-Milton <saxon@ausocean.org>
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
2023-01-11 01:31:38 +03:00
|
|
|
"bitbucket.org/ausocean/av/codec/codecutil"
|
|
|
|
"bitbucket.org/ausocean/av/revid"
|
|
|
|
"bitbucket.org/ausocean/av/revid/config"
|
2022-11-27 02:27:39 +03:00
|
|
|
"bitbucket.org/ausocean/utils/logging"
|
|
|
|
)
|
|
|
|
|
2023-01-11 01:31:38 +03:00
|
|
|
var loggingLevel = logging.Info
|
|
|
|
|
2023-03-05 01:09:39 +03:00
|
|
|
func newRevid(log logging.Logger, urls []string) (*revid.Revid, error) {
|
2023-01-11 01:31:38 +03:00
|
|
|
return revid.New(
|
|
|
|
config.Config{
|
|
|
|
Logger: log,
|
|
|
|
Input: config.InputManual,
|
|
|
|
InputCodec: codecutil.H264_AU,
|
|
|
|
Outputs: []uint8{config.OutputRTMP},
|
2023-03-05 01:09:39 +03:00
|
|
|
RTMPURL: urls,
|
2023-01-11 01:31:38 +03:00
|
|
|
LogLevel: loggingLevel,
|
|
|
|
}, nil)
|
|
|
|
}
|
|
|
|
|
2022-11-27 02:27:39 +03:00
|
|
|
// 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
|
|
|
|
}
|