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
248/* send an integer number of samples and compute time stamp and fill248/* send an integer number of samples and compute time stamp and fill
249 the rtp send buffer before sending. */249 the rtp send buffer before sending. */
250static void rtp_send_samples(AVFormatContext *s1,250static 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 RTPMuxContext *s = s1->priv_data;253 RTPMuxContext *s = s1->priv_data;
254 int len, max_packet_size, n;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;258 max_packet_size = (s->max_payload_size / aligned_samples_size) * aligned_samples_size;
257 /* not needed, but who nows */259 /* Not needed, but who knows. Don't check if samples aren't an even number of bytes. */
258 if ((size % sample_size) != 0)260 if ((sample_size_bits % 8) == 0 && ((8 * size) % sample_size_bits) != 0)
259 av_abort();261 av_abort();
260 n = 0;262 n = 0;
261 while (size > 0) {263 while (size > 0) {
@@ -267,7 +269,7 @@ static void rtp_send_samples(AVFormatContext *s1, · 5 unmodified lines
267 s->buf_ptr += len;269 s->buf_ptr += len;
268 buf1 += len;270 buf1 += len;
269 size -= len;271 size -= len;
270 s->timestamp = s->cur_timestamp + n / sample_size;272 s->timestamp = s->cur_timestamp + n * 8 / sample_size_bits;
271 ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0);273 ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0);
272 n += (s->buf_ptr - s->buf);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 case CODEC_ID_PCM_ALAW:396 case CODEC_ID_PCM_ALAW:
395 case CODEC_ID_PCM_U8:397 case CODEC_ID_PCM_U8:
396 case CODEC_ID_PCM_S8: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 break;400 break;
399 case CODEC_ID_PCM_U16BE:401 case CODEC_ID_PCM_U16BE:
400 case CODEC_ID_PCM_U16LE:402 case CODEC_ID_PCM_U16LE:
401 case CODEC_ID_PCM_S16BE:403 case CODEC_ID_PCM_S16BE:
402 case CODEC_ID_PCM_S16LE: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 break;406 break;
405 case CODEC_ID_ADPCM_G722:407 case CODEC_ID_ADPCM_G722:
406 /* The actual sample size is half a byte per sample, but since the408 /* The actual sample size is half a byte per sample, but since the
407 * stream clock rate is 8000 Hz while the sample rate is 16000 Hz,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. */410 * the correct parameter for send_samples_bits is 8 bits per stream
409 rtp_send_samples(s1, pkt->data, size, 1 * st->codec->channels);411 * clock. */
412 rtp_send_samples(s1, pkt->data, size, 8 * st->codec->channels);
410 break;413 break;
411 case CODEC_ID_MP2:414 case CODEC_ID_MP2:
412 case CODEC_ID_MP3:415 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