github.com/randomizedcoder/goTrackRTP@v0.0.2/TrackRTP_validate.go (about)

     1  package goTrackRTP
     2  
     3  // Input validation
     4  
     5  import (
     6  	"errors"
     7  	"log"
     8  )
     9  
    10  const (
    11  	MinWindowCst = 3
    12  	MaxWindowCst = 1500
    13  	MinDegree    = 2
    14  	MaxDegree    = 10
    15  )
    16  
    17  var (
    18  	ErrWindowAWMin     = errors.New("ErrWindow window ahead min")
    19  	ErrWindowAWMax     = errors.New("ErrWindow window ahead max")
    20  	ErrWindowBWMin     = errors.New("ErrWindow window behind min")
    21  	ErrWindowBWMax     = errors.New("ErrWindow window behind max")
    22  	ErrWindowABMin     = errors.New("ErrWindow buffer ahead min")
    23  	ErrWindowABMax     = errors.New("ErrWindow buffer ahead max")
    24  	ErrWindowBBMin     = errors.New("ErrWindow buffer behind min")
    25  	ErrWindowBBMax     = errors.New("ErrWindow buffer behind max")
    26  	ErrWindowDegreeMin = errors.New("ErrWindow degree min")
    27  	ErrWindowDegreeMax = errors.New("ErrWindow degree max")
    28  )
    29  
    30  // validateNew performs simple min/max checks of the Tracker creation variables
    31  func validateNew(aw uint16, bw uint16, ab uint16, bb uint16, degree int) error {
    32  
    33  	if aw <= MinWindowCst {
    34  		log.Printf("aw:%v, aw < MinWindowCst:%v", aw, MinWindowCst)
    35  		return ErrWindowAWMin
    36  	}
    37  	if aw > MaxWindowCst {
    38  		log.Printf("aw:%v, aw > MaxWindowCst:%v", aw, MaxWindowCst)
    39  		return ErrWindowAWMax
    40  	}
    41  	if bw <= MinWindowCst {
    42  		log.Printf("bw:%v, bw < MinWindowCst:%v", bw, MinWindowCst)
    43  		return ErrWindowBWMin
    44  	}
    45  	if bw > MaxWindowCst {
    46  		log.Printf("bw:%v, bw > MaxWindowCst:%v", bw, MaxWindowCst)
    47  		return ErrWindowBWMax
    48  	}
    49  
    50  	if ab <= MinWindowCst {
    51  		log.Printf("ab:%v, ab < MinWindowCst:%v", ab, MinWindowCst)
    52  		return ErrWindowABMin
    53  	}
    54  	if ab > MaxWindowCst {
    55  		log.Printf("ab:%v, ab > MaxWindowCst:%v", ab, MaxWindowCst)
    56  		return ErrWindowABMax
    57  	}
    58  	if bb <= MinWindowCst {
    59  		log.Printf("bb:%v, bb < MinWindowCst:%v", bb, MinWindowCst)
    60  		return ErrWindowBBMin
    61  	}
    62  	if bb > MaxWindowCst {
    63  		log.Printf("bb:%v, bb > MaxWindowCst:%v", bb, MaxWindowCst)
    64  		return ErrWindowBBMax
    65  	}
    66  
    67  	if degree < MinDegree {
    68  		log.Printf("degree:%v, degree < MinDegree:%v", degree, MinDegree)
    69  		return ErrWindowDegreeMin
    70  	}
    71  	if degree > MaxDegree {
    72  		log.Printf("degree:%v, degree > MaxDegree:%v", degree, MaxDegree)
    73  		return ErrWindowDegreeMax
    74  	}
    75  
    76  	return nil
    77  }