mirror of https://bitbucket.org/ausocean/av.git
Increased debugging messages and also potentially fixed blocking issue
This commit is contained in:
parent
3ce4fae82b
commit
8179b371e6
|
@ -346,31 +346,38 @@ func (r *revid) packClips() {
|
|||
}
|
||||
r.Log(Debug, "Finally got mem from ringbuffer!")
|
||||
}
|
||||
|
||||
for r.isRunning {
|
||||
frame := r.getFrame()
|
||||
lenOfFrame := len(frame)
|
||||
if lenOfFrame > ringBufferElementSize {
|
||||
r.Log(Warning, fmt.Sprintf("Frame was too big: %v bytes, getting another one!", lenOfFrame))
|
||||
frame = r.getFrame()
|
||||
lenOfFrame = len(frame)
|
||||
}
|
||||
upperBound := clipSize + lenOfFrame
|
||||
copy(clip[clipSize:upperBound], frame)
|
||||
packetCount++
|
||||
clipSize += lenOfFrame
|
||||
fpcAsInt, err := strconv.Atoi(r.config.FramesPerClip)
|
||||
if err != nil {
|
||||
r.Log(Error, "Frames per clip not quite right! Defaulting to 1!")
|
||||
r.config.FramesPerClip = "1"
|
||||
}
|
||||
if packetCount >= fpcAsInt {
|
||||
if err := r.ringBuffer.DoneWriting(clipSize); err != nil {
|
||||
r.Log(Error, err.Error())
|
||||
r.Log(Warning, "Dropping clip!")
|
||||
select {
|
||||
// TODO: This is temporary, need to work out how to make this work
|
||||
// for cases when there is not packetisation.
|
||||
case frame := <-(r.generator.GetOutputChan()):
|
||||
lenOfFrame := len(frame)
|
||||
if lenOfFrame > ringBufferElementSize {
|
||||
r.Log(Warning, fmt.Sprintf("Frame was too big: %v bytes, getting another one!", lenOfFrame))
|
||||
frame = r.getFrame()
|
||||
lenOfFrame = len(frame)
|
||||
}
|
||||
clipSize = 0
|
||||
packetCount = 0
|
||||
break
|
||||
upperBound := clipSize + lenOfFrame
|
||||
copy(clip[clipSize:upperBound], frame)
|
||||
packetCount++
|
||||
clipSize += lenOfFrame
|
||||
fpcAsInt, err := strconv.Atoi(r.config.FramesPerClip)
|
||||
if err != nil {
|
||||
r.Log(Error, "Frames per clip not quite right! Defaulting to 1!")
|
||||
r.config.FramesPerClip = "1"
|
||||
}
|
||||
if packetCount >= fpcAsInt {
|
||||
if err := r.ringBuffer.DoneWriting(clipSize); err != nil {
|
||||
r.Log(Error, err.Error())
|
||||
r.Log(Warning, "Dropping clip!")
|
||||
}
|
||||
clipSize = 0
|
||||
packetCount = 0
|
||||
break
|
||||
}
|
||||
default:
|
||||
time.Sleep(time.Duration(5)*time.Millisecond)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -396,31 +403,42 @@ func (r *revid) outputClips() {
|
|||
// If the ringbuffer has something we can read and send off
|
||||
if clip, err := r.ringBuffer.Read(); err == nil && r.isRunning {
|
||||
bytes += len(clip)
|
||||
r.Log(Debug, "About to send!")
|
||||
r.Log(Debug, "About to send")
|
||||
err2 := r.sendClip(clip)
|
||||
r.Log(Debug, "Finished send!")
|
||||
r.Log(Debug, "Finished send")
|
||||
|
||||
if err2 != nil && len(clip) > 11 {
|
||||
r.Log(Debug, "Send failed! Trying again")
|
||||
// Try and send again
|
||||
err2 = r.sendClip(clip)
|
||||
|
||||
// if there's still an error we try and reconnect
|
||||
for err2 != nil {
|
||||
r.Log(Debug, "Send failed a again! Trying to reconnect...")
|
||||
time.Sleep(time.Duration(5)*time.Millisecond)
|
||||
r.Log(Error, err2.Error())
|
||||
|
||||
if r.config.Output == NativeRtmp {
|
||||
r.Log(Debug, "Ending current rtmp session...")
|
||||
r.rtmpInst.EndSession()
|
||||
}
|
||||
if r.ringBuffer.Full() {
|
||||
r.Log(Debug, "Flushing incoming data...")
|
||||
r.flushData()
|
||||
}
|
||||
|
||||
if r.config.Output == NativeRtmp {
|
||||
r.Log(Debug, "Restarting rtmp session...")
|
||||
r.rtmpInst.StartSession()
|
||||
}
|
||||
|
||||
r.Log(Debug, "Trying to send again with new connection...")
|
||||
// and if the ring buffer is full then we flush the incoming data
|
||||
err2 = r.sendClip(clip)
|
||||
}
|
||||
}
|
||||
|
||||
r.Log(Debug, "Done reading that clip from ringbuffer...")
|
||||
// let the ringbuffer know that we're done with the memory we grabbed when
|
||||
// we call ringBuffer.Get()
|
||||
if err := r.ringBuffer.DoneReading(); err != nil {
|
||||
|
|
Loading…
Reference in New Issue