mirror of https://bitbucket.org/ausocean/av.git
Merged and ready to start getting things ready
This commit is contained in:
parent
c888448d8e
commit
f50e1085b2
|
@ -45,7 +45,7 @@ type Config struct {
|
|||
Packetization uint8
|
||||
QuantizationMode uint8
|
||||
Verbosity uint8
|
||||
FramesPerClip int
|
||||
FramesPerClip string
|
||||
RtmpUrl string
|
||||
Bitrate string
|
||||
OutputFileName string
|
||||
|
@ -94,7 +94,7 @@ const (
|
|||
defaultQuantization = "40"
|
||||
defaultBitrate = "0"
|
||||
defaultQuantizationMode = QuantizationOff
|
||||
defaultFramesPerClip = 1
|
||||
defaultFramesPerClip = "1"
|
||||
)
|
||||
|
||||
// Validate checks for any errors in the config fields and defaults settings
|
||||
|
@ -174,13 +174,13 @@ func (config *Config) Validate(r *revid) error {
|
|||
return errors.New("Bad RTMP URL")
|
||||
}
|
||||
r.Log(Info, "Defaulting frames per clip to 1 for rtmp output!")
|
||||
config.FramesPerClip = 1
|
||||
config.FramesPerClip = "1"
|
||||
case FfmpegRtmp:
|
||||
if config.RtmpUrl == "" {
|
||||
return errors.New("Bad RTMP URL")
|
||||
}
|
||||
r.Log(Info, "Defaulting frames per clip to 1 for rtmp output!")
|
||||
config.FramesPerClip = 1
|
||||
config.FramesPerClip = "1"
|
||||
case NothingDefined:
|
||||
r.Log(Warning, "No output defined, defaulting to httpOut!")
|
||||
config.Output = Http
|
||||
|
@ -199,13 +199,13 @@ func (config *Config) Validate(r *revid) error {
|
|||
return errors.New("Bad packetization option defined in config!")
|
||||
}
|
||||
|
||||
switch {
|
||||
case config.FramesPerClip > 0:
|
||||
case config.FramesPerClip == 0:
|
||||
r.Log(Warning, "No frames per clip defined, defaulting to 1!")
|
||||
config.FramesPerClip = defaultFramesPerClip
|
||||
case config.FramesPerClip < 0:
|
||||
return errors.New("Bad frames per clip given!")
|
||||
if fpcAsInt, err := strconv.Aoit(config.FramesPerClip); fpc > 0 || err != nil {
|
||||
return errors.New("Bad frames per clip in config!")
|
||||
} else {
|
||||
if fpcAsInt == 0 {
|
||||
r.Log(Warning, "No frames per clip defined, defaulting to 1!")
|
||||
config.FramesPerClip = defaultFramesPerClip
|
||||
}
|
||||
}
|
||||
|
||||
if config.Width == "" {
|
||||
|
|
|
@ -314,7 +314,8 @@ func (r *revid) packClips() {
|
|||
copy(clip[clipSize:upperBound], frame)
|
||||
packetCount++
|
||||
clipSize += lenOfFrame
|
||||
if packetCount >= r.config.FramesPerClip {
|
||||
fpcAsInt,_ := strconv.Atoi(r.config.FramesPerClip)
|
||||
if packetCount >= fpcAsInt {
|
||||
if err := r.ringBuffer.DoneWriting(clipSize); err != nil {
|
||||
r.Log(Error, err.Error())
|
||||
r.Log(Warning, "Dropping clip!")
|
||||
|
|
|
@ -2,10 +2,12 @@ package main
|
|||
|
||||
import (
|
||||
"flag"
|
||||
"strconv"
|
||||
|
||||
"bitbucket.org/ausocean/IoT/pi/netsender"
|
||||
)
|
||||
|
||||
// Indexes for flags
|
||||
const (
|
||||
inputPtr = 0
|
||||
inputCodecPtr = 1
|
||||
|
@ -26,45 +28,57 @@ const (
|
|||
quantizationPtr = 18
|
||||
timeoutPtr = 19
|
||||
intraRefreshPeriodPtr = 20
|
||||
sleepTime = 2 * 43200
|
||||
)
|
||||
|
||||
var(
|
||||
// Other misc consts
|
||||
const (
|
||||
sleepTime = 2 * 43200
|
||||
defaultRunDuration = 2 * 43200
|
||||
noOfConfigFlags = 20
|
||||
revidStopTime = 5
|
||||
)
|
||||
|
||||
// Globals
|
||||
var (
|
||||
configReceived bool = true
|
||||
varSum int = 0
|
||||
vars = make(map[string]string)
|
||||
revidInst *revidInst
|
||||
config = Config{}
|
||||
varSum int = 0
|
||||
vars = make(map[string]string)
|
||||
revid Revid
|
||||
config = Config{}
|
||||
)
|
||||
|
||||
func main() {
|
||||
flagNames := [19][2]string{
|
||||
{"Input", "The input type"},
|
||||
{"InputCodec", "The codec of the input"},
|
||||
{"Output", "The output type"},
|
||||
{"RtmpMethod", "The method used to send over rtmp (ffmpeg or librtmp)"},
|
||||
{"Packetization", "The method of data packetisation"},
|
||||
{"QuantizationMode", "The level of quantization"},
|
||||
{"Verbosity", "Verbosity on or off"},
|
||||
{"FramesPerClip", "Number of frames per clip sent"},
|
||||
{"RtmpUrl", "Url of rtmp endpoint"},
|
||||
{"Bitrate", "Bitrate of recorded video"},
|
||||
{"OutputFileName", "The directory of the output file"},
|
||||
{"InputFileName", "The directory of the input file"},
|
||||
{"Height", "Height in pixels"},
|
||||
{"Width", "Width in pixels"},
|
||||
{"FrameRate", "Frame rate of captured video"},
|
||||
{"HttpAddress", "Destination address of http posts"},
|
||||
{"Quantization", "Desired quantization value"},
|
||||
{"Timeout", "Http timeout in seconds"},
|
||||
{"IntraRefreshPeriod", "The IntraRefreshPeriod i.e. how many keyframes we send"},
|
||||
{"Input", "The input type"},
|
||||
{"InputCodec", "The codec of the input"},
|
||||
{"Output", "The output type"},
|
||||
{"RtmpMethod", "The method used to send over rtmp (ffmpeg or librtmp)"},
|
||||
{"Packetization", "The method of data packetisation"},
|
||||
{"QuantizationMode", "The level of quantization"},
|
||||
{"Verbosity", "Verbosity on or off"},
|
||||
{"FramesPerClip", "Number of frames per clip sent"},
|
||||
{"RtmpUrl", "Url of rtmp endpoint"},
|
||||
{"Bitrate", "Bitrate of recorded video"},
|
||||
{"OutputFileName", "The directory of the output file"},
|
||||
{"InputFileName", "The directory of the input file"},
|
||||
{"Height", "Height in pixels"},
|
||||
{"Width", "Width in pixels"},
|
||||
{"FrameRate", "Frame rate of captured video"},
|
||||
{"HttpAddress", "Destination address of http posts"},
|
||||
{"Quantization", "Desired quantization value"},
|
||||
{"Timeout", "Http timeout in seconds"},
|
||||
{"IntraRefreshPeriod", "The IntraRefreshPeriod i.e. how many keyframes we send"},
|
||||
}
|
||||
|
||||
var flags [20](*string)
|
||||
// Create the flags based on the flagNames array
|
||||
var configFlags [noOfConfigFlags](*string)
|
||||
for i := 0; i < 20; i++ {
|
||||
flags[i] = flag.String(flagNames[i][0], "", flagNames[i][1])
|
||||
}
|
||||
|
||||
netSenderFlagPtr := flag.Bool("netSender", false, "Are we checking vars through netsender?")
|
||||
runDurationPtr := flag.Int("runDuration",defaultRunDuration,"how long do you want revid to run for?")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
switch flags[inputPtr] {
|
||||
|
@ -120,31 +134,40 @@ func main() {
|
|||
config.Verbosity = Yes
|
||||
}
|
||||
|
||||
config.FramesPerClip = flags[framesPerClipPtr]
|
||||
config.RtmpUrl = flags[rtmpUrlPtr]
|
||||
config.Bitrate = flags[bitratePtr]
|
||||
config.OutputFileName = flags[outputFileNamePtr]
|
||||
config.InputFileName = flags[inputFileNamePtr]
|
||||
config.Height = flags[heightPtr]
|
||||
config.Width = flags[widthPtr]
|
||||
config.FrameRate = flags[frameRatePtr]
|
||||
config.HttpAddress = flags[httpAddressPtr]
|
||||
config.Quantization = flags[quantisationPtr]
|
||||
config.Timeout = flags[timeoutPtr]
|
||||
config.IntraRefreshPeriod = flags[intraRefreshPeriodPtr]
|
||||
config.FramesPerClip = flags[framesPerClipPtr]
|
||||
config.RtmpUrl = flags[rtmpUrlPtr]
|
||||
config.Bitrate = flags[bitratePtr]
|
||||
config.OutputFileName = flags[outputFileNamePtr]
|
||||
config.InputFileName = flags[inputFileNamePtr]
|
||||
config.Height = flags[heightPtr]
|
||||
config.Width = flags[widthPtr]
|
||||
config.FrameRate = flags[frameRatePtr]
|
||||
config.HttpAddress = flags[httpAddressPtr]
|
||||
config.Quantization = flags[quantisationPtr]
|
||||
config.Timeout = flags[timeoutPtr]
|
||||
config.IntraRefreshPeriod = flags[intraRefreshPeriodPtr]
|
||||
|
||||
revidInst, err := NewRevidInstance(config)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
// Try to create the revid instance with the given config
|
||||
for revid, err := NewRevid(config); err != nil; {
|
||||
// If the config does have a logger, use it to output error, otherwise
|
||||
// just output to std output
|
||||
if config.Logger != nil {
|
||||
config.Logger.Log("FATAL ERROR", err)
|
||||
} else {
|
||||
fmt.Printf("FATAL ERROR: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
revidInst.Start()
|
||||
revid.Start()
|
||||
|
||||
for {
|
||||
for *netSenderFlagPtr {
|
||||
periodicNetsenderReport()
|
||||
sleepTime, err := strconv.Atoi(netsender.GetConfigParam("monPeriod"))
|
||||
time.Sleep(time.Duration(sleepTime) * time.Second)
|
||||
}
|
||||
|
||||
time.Sleep( time.Duration(*runDurationPtr) * time.Second )
|
||||
revid.Stop()
|
||||
}
|
||||
|
||||
func netsenderInit() {
|
||||
|
@ -185,13 +208,13 @@ func periodicNetsenderReport(){
|
|||
}
|
||||
}
|
||||
updateRevid()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func updateRevid() {
|
||||
|
||||
revidInst.Stop()
|
||||
|
||||
revid.Stop()
|
||||
time.Sleep( time.Duration(revidStopTime) * time.Second )
|
||||
for key, value := range vars {
|
||||
switch key {
|
||||
case "FramesPerClip":
|
||||
|
@ -221,12 +244,12 @@ func updateRevid() {
|
|||
}
|
||||
}
|
||||
|
||||
revidInst, err := NewRevidInstance(config)
|
||||
revid, err := Newrevidance(config)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
revidInst.Start()
|
||||
revid.Start()
|
||||
}
|
||||
|
||||
func revidReportActions(pin int) (int, error) {
|
||||
|
@ -290,7 +313,10 @@ func revidReportActions(pin int) (int, error) {
|
|||
if err != nil {
|
||||
return -1, errors.New("CPU Uage Read Err: " + err.Error())
|
||||
}
|
||||
total1 := stat.CPUStatAll.User + stat.CPUStatAll.Nice + stat.CPUStatAll.System + stat.CPUStatAll.Idle + stat.CPUStatAll.IOWait + stat.CPUStatAll.IRQ + stat.CPUStatAll.SoftIRQ + stat.CPUStatAll.Steal + stat.CPUStatAll.Guest + stat.CPUStatAll.GuestNice
|
||||
total1 := stat.CPUStatAll.User + stat.CPUStatAll.Nice + stat.CPUStatAll.System +
|
||||
stat.CPUStatAll.Idle + stat.CPUStatAll.IOWait + stat.CPUStatAll.IRQ +
|
||||
stat.CPUStatAll.SoftIRQ + stat.CPUStatAll.Steal + stat.CPUStatAll.Guest +
|
||||
stat.CPUStatAll.GuestNice
|
||||
idle1 := stat.CPUStatAll.Idle
|
||||
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
|
@ -299,7 +325,10 @@ func revidReportActions(pin int) (int, error) {
|
|||
if err != nil {
|
||||
return -1, errors.New("CPU Uage Read Err: " + err.Error())
|
||||
}
|
||||
total2 := stat.CPUStatAll.User + stat.CPUStatAll.Nice + stat.CPUStatAll.System + stat.CPUStatAll.Idle + stat.CPUStatAll.IOWait + stat.CPUStatAll.IRQ + stat.CPUStatAll.SoftIRQ + stat.CPUStatAll.Steal + stat.CPUStatAll.Guest + stat.CPUStatAll.GuestNice
|
||||
total2 := stat.CPUStatAll.User + stat.CPUStatAll.Nice + stat.CPUStatAll.System +
|
||||
stat.CPUStatAll.Idle + stat.CPUStatAll.IOWait + stat.CPUStatAll.IRQ +
|
||||
stat.CPUStatAll.SoftIRQ + stat.CPUStatAll.Steal + stat.CPUStatAll.Guest +
|
||||
stat.CPUStatAll.GuestNice
|
||||
idle2 := stat.CPUStatAll.Idle
|
||||
|
||||
return int((1.0 - (float64(idle2-idle1) / float64(total2-total1))) * 100), nil
|
||||
|
@ -311,4 +340,3 @@ func revidReportActions(pin int) (int, error) {
|
|||
return -1, errors.New("External pin not defined")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue