Unified · Split
| @@ -248,14 +248,16 @@ void ff_rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m) · 247 unmodified lines | ||
| 248 | 248 | /* send an integer number of samples and compute time stamp and fill |
| 249 | 249 | the rtp send buffer before sending. */ |
| 250 | 250 | static void rtp_send_samples(AVFormatContext *s1, |
| 251 | − const uint8_t *buf1, int size, int sample_size) | |
| 251 | + const uint8_t *buf1, int size, int sample_size_bits) | |
| 252 | 252 | { |
| 253 | 253 | RTPMuxContext *s = s1->priv_data; |
| 254 | 254 | int len, max_packet_size, n; |
| 255 | + /* Calculate the number of bytes to get samples aligned on a byte border */ | |
| 256 | + int aligned_samples_size = sample_size_bits/av_gcd(sample_size_bits, 8); | |
| 255 | 257 | |
| 256 | − max_packet_size = (s->max_payload_size / sample_size) * sample_size; | |
| 257 | − /* not needed, but who nows */ | |
| 258 | − if ((size % sample_size) != 0) | |
| 258 | + max_packet_size = (s->max_payload_size / aligned_samples_size) * aligned_samples_size; | |
| 259 | + /* Not needed, but who knows. Don't check if samples aren't an even number of bytes. */ | |
| 260 | + if ((sample_size_bits % 8) == 0 && ((8 * size) % sample_size_bits) != 0) | |
| 259 | 261 | av_abort(); |
| 260 | 262 | n = 0; |
| 261 | 263 | while (size > 0) { |
| @@ -267,7 +269,7 @@ static void rtp_send_samples(AVFormatContext *s1, · 5 unmodified lines | ||
| 267 | 269 | s->buf_ptr += len; |
| 268 | 270 | buf1 += len; |
| 269 | 271 | size -= len; |
| 270 | − s->timestamp = s->cur_timestamp + n / sample_size; | |
| 272 | + s->timestamp = s->cur_timestamp + n * 8 / sample_size_bits; | |
| 271 | 273 | ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0); |
| 272 | 274 | n += (s->buf_ptr - s->buf); |
| 273 | 275 | } |
| @@ -394,19 +396,20 @@ static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt) · 120 unmodified lines | ||
| 394 | 396 | case CODEC_ID_PCM_ALAW: |
| 395 | 397 | case CODEC_ID_PCM_U8: |
| 396 | 398 | case CODEC_ID_PCM_S8: |
| 397 | − rtp_send_samples(s1, pkt->data, size, 1 * st->codec->channels); | |
| 399 | + rtp_send_samples(s1, pkt->data, size, 8 * st->codec->channels); | |
| 398 | 400 | break; |
| 399 | 401 | case CODEC_ID_PCM_U16BE: |
| 400 | 402 | case CODEC_ID_PCM_U16LE: |
| 401 | 403 | case CODEC_ID_PCM_S16BE: |
| 402 | 404 | case CODEC_ID_PCM_S16LE: |
| 403 | − rtp_send_samples(s1, pkt->data, size, 2 * st->codec->channels); | |
| 405 | + rtp_send_samples(s1, pkt->data, size, 16 * st->codec->channels); | |
| 404 | 406 | break; |
| 405 | 407 | case CODEC_ID_ADPCM_G722: |
| 406 | 408 | /* The actual sample size is half a byte per sample, but since the |
| 407 | 409 | * stream clock rate is 8000 Hz while the sample rate is 16000 Hz, |
| 408 | − * the correct parameter for send_samples is 1 byte per stream clock. */ | |
| 409 | − rtp_send_samples(s1, pkt->data, size, 1 * st->codec->channels); | |
| 410 | + * the correct parameter for send_samples_bits is 8 bits per stream | |
| 411 | + * clock. */ | |
| 412 | + rtp_send_samples(s1, pkt->data, size, 8 * st->codec->channels); | |
| 410 | 413 | break; |
| 411 | 414 | case CODEC_ID_MP2: |
| 412 | 415 | case CODEC_ID_MP3: |