github.com/puellanivis/breton@v0.2.16/lib/net/dash/pickers.go (about)

     1  package dash
     2  
     3  import (
     4  	"github.com/puellanivis/breton/lib/net/dash/mpd"
     5  )
     6  
     7  // A Picker is a function that will take a series of DASH MPD Representations,
     8  // and returns either the given Representation, or an alternative,
     9  // if the given Representation is not appropriate by rules of the Picker.
    10  // After all Representations have been given to this function, the return value
    11  // will be the best-fitting Representation.
    12  type Picker func(cur *mpd.Representation) *mpd.Representation
    13  
    14  // PickFirst returns a Picker that will always return the first Representation passed into it.
    15  func PickFirst() Picker {
    16  	var best *mpd.Representation
    17  
    18  	return func(cur *mpd.Representation) *mpd.Representation {
    19  		if best == nil {
    20  			best = cur
    21  		}
    22  
    23  		return best
    24  	}
    25  }
    26  
    27  // PickHighestBandwidth returns a picker that selects the Representation with the highest Bandwidth.
    28  // Between two equal bandwidths, the first is picked.
    29  func PickHighestBandwidth() Picker {
    30  	var best *mpd.Representation
    31  
    32  	return func(cur *mpd.Representation) *mpd.Representation {
    33  		if best == nil || best.Bandwidth < cur.Bandwidth {
    34  			best = cur
    35  		}
    36  
    37  		return best
    38  	}
    39  }
    40  
    41  // PickLowestBandwidth returns a picker that selects the Representation with the lowest Bandwidth.
    42  // Between two equal bandwidths, the first is picked.
    43  func PickLowestBandwidth() Picker {
    44  	var best *mpd.Representation
    45  
    46  	return func(cur *mpd.Representation) *mpd.Representation {
    47  		if best == nil || best.Bandwidth > cur.Bandwidth {
    48  			best = cur
    49  		}
    50  
    51  		return best
    52  	}
    53  }