Takes into account maximum number of samples to be processed or maximum duration, whichever comes first.