Boxer Anthony Joshua endured a frustrating night before eventually stopping Carlos Takam and defending his IBF and WBA heavyweight titles in 10 rounds in Cardiff.