A method for buffering packets of a media stream comprising: - forming media packets from at least one kind of media information in a stream generator; - forming forward error correction data on the basis of a first set of the media packets; - forming a second set of repair packets on the basis of the forward error correction data; - forming a forward error correction block from the first set of the media packets and the second set of repair packets; - generating a transmission schedule for packets to be transmitted, the packets to be transmitted comprising at least one of the second set of repair packets from the forward error correction block; and - performing hypothetical decoding according to the transmission schedule comprising: - buffering the packets to be transmitted according to the transmission schedule to a hypothetical decoding buffer; characterized in that the hypothetical decoding also comprises - controlling a buffer occupancy level of the hypothetical decoding buffer by ▪ affecting the transmission schedule of the packets to be transmitted, and ▪ removing all of the second set of repair packets to be transmitted from the hypothetical decoding buffer after the last of all packets to be scheduled of the forward error correction block is transmitted to ensure that the buffer occupancy level of the hypothetical decoding buffer does not exceed a required forward error correction decoding buffer size. - forming media packets from at least one kind of media information in a stream generator; - forming forward error correction data on the basis of a first set of the media packets; - forming a second set of repair packets on the basis of the forward error correction data; - forming a forward error correction block from the first set of the media packets and the second set of repair packets; - generating a transmission schedule for packets to be transmitted, the packets to be transmitted comprising at least one of the second set of repair packets from the forward error correction block; and - performing hypothetical decoding according to the transmission schedule comprising: - buffering the packets to be transmitted according to the transmission schedule to a hypothetical decoding buffer; characterized in that the hypothetical decoding also comprises - controlling a buffer occupancy level of the hypothetical decoding buffer by ▪ affecting the transmission schedule of the packets to be transmitted, and ▪ removing all of the second set of repair packets to be transmitted from the hypothetical decoding buffer after the last of all packets to be scheduled of the forward error correction block is transmitted - buffering the packets to be transmitted according to the transmission schedule to a hypothetical decoding buffer; - controlling a buffer occupancy level of the hypothetical decoding buffer by ▪ affecting the transmission schedule of the packets to be transmitted, and ▪ removing all of the second set of repair packets to be transmitted from the hypothetical decoding buffer after the last of all packets to be scheduled of the forward error correction block is transmitted ▪ affecting the transmission schedule of the packets to be transmitted, and ▪ removing all of the second set of repair packets to be transmitted from the hypothetical decoding buffer after the last of all packets to be scheduled of the forward error correction block is transmitted