History

rtpenc: Change rtp_send_samples to handle sample sizes other than even bytes

Martin Storsjö committed 14 years ago

Commit 77e0c751 parent 2d31d891 file · +12 −9Browse files

Unified · Split

libavformat/rtpenc.c+12−9
@@ -248,14 +248,16 @@ void ff_rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m) · 247 unmodified lines
248248 /* send an integer number of samples and compute time stamp and fill
249249 the rtp send buffer before sending. */
250250 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)
252252 {
253253 RTPMuxContext *s = s1->priv_data;
254254 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);
255257
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)
259261 av_abort();
260262 n = 0;
261263 while (size > 0) {
@@ -267,7 +269,7 @@ static void rtp_send_samples(AVFormatContext *s1, · 5 unmodified lines
267269 s->buf_ptr += len;
268270 buf1 += len;
269271 size -= len;
270− s->timestamp = s->cur_timestamp + n / sample_size;
272+ s->timestamp = s->cur_timestamp + n * 8 / sample_size_bits;
271273 ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0);
272274 n += (s->buf_ptr - s->buf);
273275 }
@@ -394,19 +396,20 @@ static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt) · 120 unmodified lines
394396 case CODEC_ID_PCM_ALAW:
395397 case CODEC_ID_PCM_U8:
396398 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);
398400 break;
399401 case CODEC_ID_PCM_U16BE:
400402 case CODEC_ID_PCM_U16LE:
401403 case CODEC_ID_PCM_S16BE:
402404 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);
404406 break;
405407 case CODEC_ID_ADPCM_G722:
406408 /* The actual sample size is half a byte per sample, but since the
407409 * 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);
410413 break;
411414 case CODEC_ID_MP2:
412415 case CODEC_ID_MP3:

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t