Increased debugging messages and also potentially fixed blocking issue

This commit is contained in:
Saxon Milton 2018-05-06 23:03:44 +09:30
parent 3ce4fae82b
commit 8179b371e6
1 changed files with 43 additions and 25 deletions

View File

@ -346,31 +346,38 @@ func (r *revid) packClips() {
} }
r.Log(Debug, "Finally got mem from ringbuffer!") r.Log(Debug, "Finally got mem from ringbuffer!")
} }
for r.isRunning { for r.isRunning {
frame := r.getFrame() select {
lenOfFrame := len(frame) // TODO: This is temporary, need to work out how to make this work
if lenOfFrame > ringBufferElementSize { // for cases when there is not packetisation.
r.Log(Warning, fmt.Sprintf("Frame was too big: %v bytes, getting another one!", lenOfFrame)) case frame := <-(r.generator.GetOutputChan()):
frame = r.getFrame() lenOfFrame := len(frame)
lenOfFrame = len(frame) if lenOfFrame > ringBufferElementSize {
} r.Log(Warning, fmt.Sprintf("Frame was too big: %v bytes, getting another one!", lenOfFrame))
upperBound := clipSize + lenOfFrame frame = r.getFrame()
copy(clip[clipSize:upperBound], frame) lenOfFrame = len(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 upperBound := clipSize + lenOfFrame
packetCount = 0 copy(clip[clipSize:upperBound], frame)
break 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 the ringbuffer has something we can read and send off
if clip, err := r.ringBuffer.Read(); err == nil && r.isRunning { if clip, err := r.ringBuffer.Read(); err == nil && r.isRunning {
bytes += len(clip) bytes += len(clip)
r.Log(Debug, "About to send!") r.Log(Debug, "About to send")
err2 := r.sendClip(clip) err2 := r.sendClip(clip)
r.Log(Debug, "Finished send!") r.Log(Debug, "Finished send")
if err2 != nil && len(clip) > 11 { if err2 != nil && len(clip) > 11 {
r.Log(Debug, "Send failed! Trying again")
// Try and send again // Try and send again
err2 = r.sendClip(clip) err2 = r.sendClip(clip)
// if there's still an error we try and reconnect // if there's still an error we try and reconnect
for err2 != nil { for err2 != nil {
r.Log(Debug, "Send failed a again! Trying to reconnect...")
time.Sleep(time.Duration(5)*time.Millisecond) time.Sleep(time.Duration(5)*time.Millisecond)
r.Log(Error, err2.Error()) r.Log(Error, err2.Error())
if r.config.Output == NativeRtmp { if r.config.Output == NativeRtmp {
r.Log(Debug, "Ending current rtmp session...")
r.rtmpInst.EndSession() r.rtmpInst.EndSession()
} }
if r.ringBuffer.Full() { if r.ringBuffer.Full() {
r.Log(Debug, "Flushing incoming data...")
r.flushData() r.flushData()
} }
if r.config.Output == NativeRtmp { if r.config.Output == NativeRtmp {
r.Log(Debug, "Restarting rtmp session...")
r.rtmpInst.StartSession() 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 // and if the ring buffer is full then we flush the incoming data
err2 = r.sendClip(clip) 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 // let the ringbuffer know that we're done with the memory we grabbed when
// we call ringBuffer.Get() // we call ringBuffer.Get()
if err := r.ringBuffer.DoneReading(); err != nil { if err := r.ringBuffer.DoneReading(); err != nil {