Ejemplo n.º 1
0
// update the absolute positional information (distance from the BOF or EOF)
// for keyFrames based on the other keyFrames in the signature
func updatePositions(ks []keyFrame) {
	var min, max int64
	// first forwards, for BOF and PREV
	for i := range ks {
		if ks[i].typ == frames.BOF {
			min, max = calcMinMax(0, 0, ks[i].seg)
			// Apply max bof
			if config.MaxBOF() > 0 {
				if ks[i].key.pMax < 0 || ks[i].key.pMax > int64(config.MaxBOF()) {
					ks[i].key.pMax = int64(config.MaxBOF())
				}
			}
		}
		if ks[i].typ == frames.PREV {
			ks[i].key.pMin = min + ks[i].key.pMin
			if max > -1 && ks[i].key.pMax > -1 {
				ks[i].key.pMax = max + ks[i].key.pMax
			} else {
				ks[i].key.pMax = -1
			}
			min, max = calcMinMax(min, max, ks[i].seg)
			// Apply max bof
			if config.MaxBOF() > 0 {
				if ks[i].key.pMax < 0 || ks[i].key.pMax > int64(config.MaxBOF()) {
					ks[i].key.pMax = int64(config.MaxBOF())
				}
			}
		}
	}
	// now backwards for EOF and SUCC
	min, max = 0, 0
	for i := len(ks) - 1; i >= 0; i-- {
		if ks[i].typ == frames.EOF {
			min, max = calcMinMax(0, 0, ks[i].seg)
			// apply max eof
			if config.MaxEOF() > 0 {
				if ks[i].key.pMax < 0 || ks[i].key.pMax > int64(config.MaxEOF()) {
					ks[i].key.pMax = int64(config.MaxEOF())
				}
			}
		}
		if ks[i].typ == frames.SUCC {
			ks[i].key.pMin = min + ks[i].key.pMin
			if max > -1 && ks[i].key.pMax > -1 {
				ks[i].key.pMax = max + ks[i].key.pMax
			} else {
				ks[i].key.pMax = -1
			}
			min, max = calcMinMax(min, max, ks[i].seg)
			// apply max eof
			if config.MaxEOF() > 0 {
				if ks[i].key.pMax < 0 || ks[i].key.pMax > int64(config.MaxEOF()) {
					ks[i].key.pMax = int64(config.MaxEOF())
				}
			}
		}
	}
}
Ejemplo n.º 2
0
func ApplyConfig(p Parseable) Parseable {
	if config.NoName() {
		p = noName{p}
	}
	if config.NoMIME() {
		p = noMIME{p}
	}
	if config.NoXML() {
		p = noXML{p}
	}
	if config.NoContainer() {
		p = noContainers{p}
	}
	if config.NoRIFF() {
		p = noRIFF{p}
	}
	if config.NoText() {
		p = noText{p}
	}
	if config.NoPriority() {
		p = noPriority{p}
	}
	// mirror PREV wild segments into EOF if maxBof and maxEOF set
	if config.MaxBOF() > 0 && config.MaxEOF() > 0 {
		p = Mirror{p}
	}
	if config.HasLimit() || config.HasExclude() {
		ids := p.IDs()
		if config.HasLimit() {
			ids = config.Limit(ids)
		} else {
			ids = config.Exclude(ids)
		}
		p = Filter(ids, p)
	}
	return p
}