Medium effects on pion production in heavy ion collisions