The word “stop” as a starter, said firmly with eye contact to avoid ambiguity. Make it immediately clear that you’re shifting the mood and mean to.
But then it’s circumstantial. Not conditional; there’s no right approach that includes not challenging the behavior because [excuse]. But if, e.g., the person’s a long-time friend, you have an opportunity to draw from that familiarity in a way you can’t with a stranger.
Those circumstances are a wide space to navigate, so I’m not sure there’s a guiding rule other than to communicate with conviction. But the close should always be consistent: Provide consequences. Avoid the *two guys share a serious moment, look down quietly, but then back up at the TV like nothing just happened* scenario that costs neither of you anything. Make it clear that if the behavior happens again, you will do X or won’t do Y. Punctuate.