Removed continuity check and also checked read error rather than whether or not clip is nil.

This commit is contained in:
Saxon1 2017-12-03 02:34:14 +10:30
parent 0f028b799c
commit d63b5f6751
1 changed files with 2 additions and 7 deletions

View File

@ -303,7 +303,7 @@ func output(output string) {
now := time.Now() now := time.Now()
prevTime := now prevTime := now
for { for {
if clip, clipSize, _ := ringBuffer.Read(); clip != nil { if clip, clipSize, err := ringBuffer.Read(); err == nil {
now := time.Now() now := time.Now()
err := sendClip(clip[:clipSize], output, conn) err := sendClip(clip[:clipSize], output, conn)
for err != nil { for err != nil {
@ -338,10 +338,6 @@ func sendClipToFile(clip []byte, _ string, _ net.Conn) error {
// sendClipToHTPP posts a video clip via HTTP, using a new TCP connection each time. // sendClipToHTPP posts a video clip via HTTP, using a new TCP connection each time.
func sendClipToHTTP(clip []byte, output string, _ net.Conn) error { func sendClipToHTTP(clip []byte, output string, _ net.Conn) error {
if err := checkContinuityCounts(clip); err != nil {
return err
}
timeout := time.Duration(httpTimeOut * time.Second) timeout := time.Duration(httpTimeOut * time.Second)
client := http.Client{ client := http.Client{
Timeout: timeout, Timeout: timeout,
@ -397,13 +393,12 @@ func sendClipToRTP(clip []byte, _ string, conn net.Conn) error {
return nil return nil
} }
// checkContinuityCounts checks that the continuity of the clip is correct
func checkContinuityCounts(clip []byte) error { func checkContinuityCounts(clip []byte) error {
for offset := 0; offset < len(clip); offset += mp2tPacketSize { for offset := 0; offset < len(clip); offset += mp2tPacketSize {
dumpCC = -1 dumpCC = -1
pkt := clip[offset : offset+mp2tPacketSize] pkt := clip[offset : offset+mp2tPacketSize]
cc := int(pkt[3] & 0xf) cc := int(pkt[3] & 0xf)
if dumpCC != -1 && cc != dumpCC { if dumpCC != -1 && cc != dumpCC {
return fmt.Errorf("Continuity count out of order. Expected %v, Got: %v.", dumpCC, cc) return fmt.Errorf("Continuity count out of order. Expected %v, Got: %v.", dumpCC, cc)
} }